Commit 4d15bc6e authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: improve file reader support for runTimePostProcessing (#1091)

- support .vtp format for geometry, surface, line, cloud.

- use native reader for handling vtk, vtp, obj, stl surface files.
  For other formats, use the MeshedSurface (the surfMesh lib) to
  handle reading and Foam::vtk::Tools::Patch to handle the
  conversion to vtkPolyData. This combination is more memory efficient.

- update tutorial case to include vtp surface geometry
parent d18bdd8b
...@@ -22,14 +22,14 @@ License ...@@ -22,14 +22,14 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::functionObjects::runTimePostPro::runTimePostProcessingDummy Foam::functionObjects::runTimePostProcessingDummy
Group Group
grpGraphicsFunctionObjects grpGraphicsFunctionObjects
Description Description
Dummy implementation of runTimePostProcessing to report when Dummy implementation of Foam::functionObjects::runTimePostProcessing
the real version is unavailable. to report when the real version is unavailable.
SourceFiles SourceFiles
runTimePostProcessingDummy.C runTimePostProcessingDummy.C
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -49,9 +49,11 @@ License ...@@ -49,9 +49,11 @@ License
const Foam::Enum const Foam::Enum
< <
Foam::functionObjects::fieldVisualisationBase::colourByType Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
colourByType
> >
Foam::functionObjects::fieldVisualisationBase::colourByTypeNames Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
colourByTypeNames
({ ({
{ colourByType::cbColour, "colour" }, { colourByType::cbColour, "colour" },
{ colourByType::cbField, "field" }, { colourByType::cbField, "field" },
...@@ -59,9 +61,11 @@ Foam::functionObjects::fieldVisualisationBase::colourByTypeNames ...@@ -59,9 +61,11 @@ Foam::functionObjects::fieldVisualisationBase::colourByTypeNames
const Foam::Enum const Foam::Enum
< <
Foam::functionObjects::fieldVisualisationBase::colourMapType Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
colourMapType
> >
Foam::functionObjects::fieldVisualisationBase::colourMapTypeNames Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
colourMapTypeNames
({ ({
{ colourMapType::cmRainbow, "rainbow" }, { colourMapType::cmRainbow, "rainbow" },
{ colourMapType::cmBlueWhiteRed, "blueWhiteRed" }, { colourMapType::cmBlueWhiteRed, "blueWhiteRed" },
...@@ -72,7 +76,8 @@ Foam::functionObjects::fieldVisualisationBase::colourMapTypeNames ...@@ -72,7 +76,8 @@ Foam::functionObjects::fieldVisualisationBase::colourMapTypeNames
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldVisualisationBase::setColourMap void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
setColourMap
( (
vtkLookupTable* lut vtkLookupTable* lut
) const ) const
...@@ -130,7 +135,8 @@ void Foam::functionObjects::fieldVisualisationBase::setColourMap ...@@ -130,7 +135,8 @@ void Foam::functionObjects::fieldVisualisationBase::setColourMap
} }
void Foam::functionObjects::fieldVisualisationBase::addScalarBar void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
addScalarBar
( (
const scalar position, const scalar position,
vtkRenderer* renderer, vtkRenderer* renderer,
...@@ -239,7 +245,8 @@ void Foam::functionObjects::fieldVisualisationBase::addScalarBar ...@@ -239,7 +245,8 @@ void Foam::functionObjects::fieldVisualisationBase::addScalarBar
} }
void Foam::functionObjects::fieldVisualisationBase::setField void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
setField
( (
const scalar position, const scalar position,
const word& colourFieldName, const word& colourFieldName,
...@@ -272,11 +279,11 @@ void Foam::functionObjects::fieldVisualisationBase::setField ...@@ -272,11 +279,11 @@ void Foam::functionObjects::fieldVisualisationBase::setField
// Note: if both point and cell data exists, preferentially // Note: if both point and cell data exists, preferentially
// choosing point data. This is often the case when using // choosing point data. This is often the case when using
// glyphs // glyphs
if (pData->GetPointData()->HasArray(fieldName) == 1) if (pData->GetPointData()->HasArray(fieldName))
{ {
mapper->SetScalarModeToUsePointFieldData(); mapper->SetScalarModeToUsePointFieldData();
} }
else if (pData->GetCellData()->HasArray(fieldName) == 1) else if (pData->GetCellData()->HasArray(fieldName))
{ {
mapper->SetScalarModeToUseCellFieldData(); mapper->SetScalarModeToUseCellFieldData();
} }
...@@ -302,8 +309,8 @@ void Foam::functionObjects::fieldVisualisationBase::setField ...@@ -302,8 +309,8 @@ void Foam::functionObjects::fieldVisualisationBase::setField
} }
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
void Foam::functionObjects::fieldVisualisationBase::addGlyphs addGlyphs
( (
const scalar position, const scalar position,
const word& scaleFieldName, const word& scaleFieldName,
...@@ -320,38 +327,59 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs ...@@ -320,38 +327,59 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs
glyph->SetInputData(data); glyph->SetInputData(data);
glyph->ScalingOn(); glyph->ScalingOn();
bool ok = true;
bool needPointData = false;
// Determine whether we have scalar or vector data // Determine whether we have scalar or vector data
// and if we need to convert CellData -> PointData
label nComponents = -1; label nComponents = -1;
const char* scaleFieldNameChar = scaleFieldName.c_str(); const char* scaleFieldNameChar = scaleFieldName.c_str();
if (data->GetPointData()->HasArray(scaleFieldNameChar) == 1) if (data->GetPointData()->HasArray(scaleFieldNameChar))
{ {
nComponents = nComponents =
data->GetPointData()->GetArray(scaleFieldNameChar) data->GetPointData()->GetArray(scaleFieldNameChar)
->GetNumberOfComponents(); ->GetNumberOfComponents();
} }
else if (data->GetCellData()->HasArray(scaleFieldNameChar) == 1) else if (data->GetCellData()->HasArray(scaleFieldNameChar))
{ {
// Need to convert cell data to point data // Need to convert CellData to PointData
auto cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New(); needPointData = true;
cellToPoint->SetInputData(data);
cellToPoint->Update();
vtkDataSet* pds = cellToPoint->GetOutput();
vtkDataArray* pData = pds->GetPointData()->GetArray(scaleFieldNameChar);
// Store in main vtkPolyData nComponents =
data->GetPointData()->AddArray(pData); data->GetCellData()->GetArray(scaleFieldNameChar)
->GetNumberOfComponents();
nComponents = pData->GetNumberOfComponents();
} }
else else
{
WarningInFunction
<< "Cannot add glyphs. No such cell or point field: "
<< scaleFieldName << endl;
return;
}
const bool ok = (nComponents == 1 || nComponents == 3);
if (!ok)
{ {
WarningInFunction WarningInFunction
<< "Glyphs can only be added to scalar or vector data. " << "Glyphs can only be added to scalar or vector data. "
<< "Unable to process field " << scaleFieldName << endl; << "Unable to process field " << scaleFieldName << endl;
return; return;
} }
else if (needPointData)
{
auto cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
cellToPoint->SetInputData(data);
cellToPoint->Update();
vtkDataSet* pds = cellToPoint->GetOutput();
vtkDataArray* pData = pds->GetPointData()->GetArray(scaleFieldNameChar);
// Store in main vtkPolyData
data->GetPointData()->AddArray(pData);
}
if (nComponents == 1) if (nComponents == 1)
{ {
...@@ -367,18 +395,16 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs ...@@ -367,18 +395,16 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs
if (maxGlyphLength > 0) if (maxGlyphLength > 0)
{ {
double range[2]; // Can get range from point data:
// Can use values to find range // double range[2];
// vtkDataArray* values = // vtkDataArray* values =
// data->GetPointData()->GetScalars(scaleFieldNameChar); // data->GetPointData()->GetScalars(scaleFieldNameChar);
// values->GetRange(range); // values->GetRange(range);
// Set range according to user-supplied limits // Set range according to user-supplied limits
range[0] = range_.first();
range[1] = range_.second();
glyph->ClampingOn(); glyph->ClampingOn();
glyph->SetRange(range); glyph->SetRange(range_.first(), range_.second());
// If range[0] != min(value), maxGlyphLength behaviour will not // If range[0] != min(value), maxGlyphLength behaviour will not
// be correct... // be correct...
...@@ -450,15 +476,7 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs ...@@ -450,15 +476,7 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs
scaleFieldNameChar scaleFieldNameChar
); );
} }
else
{
WarningInFunction
<< "Glyphs can only be added to scalar and vector fields."
<< " Field " << scaleFieldName << " has " << nComponents
<< " components" << endl;
ok = false;
}
if (ok) if (ok)
{ {
...@@ -477,10 +495,11 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs ...@@ -477,10 +495,11 @@ void Foam::functionObjects::fieldVisualisationBase::addGlyphs
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
fieldVisualisationBase
( (
const dictionary& dict, const dictionary& dict,
const HashPtrTable<Function1<vector>, word>& colours const HashPtrTable<Function1<vector>>& colours
) )
: :
colours_(colours), colours_(colours),
...@@ -504,16 +523,17 @@ Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase ...@@ -504,16 +523,17 @@ Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase
colourMapTypeNames.readIfPresent("colourMap", dict, colourMap_); colourMapTypeNames.readIfPresent("colourMap", dict, colourMap_);
const dictionary& sbarDict = dict.subDict("scalarBar"); const dictionary& sbDict = dict.subDict("scalarBar");
sbarDict.readEntry("visible", scalarBar_.visible_); sbDict.readEntry("visible", scalarBar_.visible_);
if (scalarBar_.visible_) if (scalarBar_.visible_)
{ {
sbarDict.readEntry("vertical", scalarBar_.vertical_); sbDict.readEntry("vertical", scalarBar_.vertical_);
sbarDict.readEntry("position", scalarBar_.position_); sbDict.readEntry("position", scalarBar_.position_);
sbarDict.readEntry("title", scalarBar_.title_); sbDict.readEntry("title", scalarBar_.title_);
sbarDict.readEntry("fontSize", scalarBar_.fontSize_); sbDict.readEntry("fontSize", scalarBar_.fontSize_);
sbarDict.readEntry("labelFormat", scalarBar_.labelFormat_); sbDict.readEntry("labelFormat", scalarBar_.labelFormat_);
sbarDict.readEntry("numberOfLabels", scalarBar_.numberOfLabels_); sbDict.readEntry("numberOfLabels", scalarBar_.numberOfLabels_);
} }
break; break;
} }
...@@ -523,21 +543,23 @@ Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase ...@@ -523,21 +543,23 @@ Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldVisualisationBase::~fieldVisualisationBase() Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
~fieldVisualisationBase()
{} {}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::HashPtrTable<Foam::Function1<Foam::vector>, Foam::word>& const Foam::HashPtrTable<Foam::Function1<Foam::vector>, Foam::word>&
Foam::functionObjects::fieldVisualisationBase::colours() const Foam::functionObjects::runTimePostPro::fieldVisualisationBase::colours() const
{ {
return colours_; return colours_;
} }
const Foam::word& const Foam::word&
Foam::functionObjects::fieldVisualisationBase::fieldName() const Foam::functionObjects::runTimePostPro::fieldVisualisationBase::fieldName()
const
{ {
return fieldName_; return fieldName_;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -22,7 +22,7 @@ License ...@@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::functionObjects::fieldVisualisationBase Foam::functionObjects::runTimePostPro::fieldVisualisationBase
Description Description
Base class for scene objects Base class for scene objects
...@@ -42,26 +42,29 @@ SourceFiles ...@@ -42,26 +42,29 @@ SourceFiles
#include "HashPtrTable.H" #include "HashPtrTable.H"
#include "Function1.H" #include "Function1.H"
// VTK includes
#include "vtkSmartPointer.h" #include "vtkSmartPointer.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward declarations
class vtkActor; class vtkActor;
class vtkLookupTable; class vtkLookupTable;
class vtkMapper;
class vtkPolyData; class vtkPolyData;
class vtkPolyDataMapper; class vtkPolyDataMapper;
class vtkRenderer; class vtkRenderer;
class vtkMapper;
namespace Foam namespace Foam
{ {
namespace functionObjects namespace functionObjects
{ {
// Forward declarations
class runTimePostProcessing; class runTimePostProcessing;
namespace runTimePostPro
{
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class fieldVisualisationBase Declaration Class fieldVisualisationBase Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
...@@ -91,20 +94,9 @@ public: ...@@ -91,20 +94,9 @@ public:
static const Enum<colourMapType> colourMapTypeNames; static const Enum<colourMapType> colourMapTypeNames;
private:
// Private Member Functions
//- No copy construct
fieldVisualisationBase(const fieldVisualisationBase&) = delete;
//- No copy assignment
void operator=(const fieldVisualisationBase&) = delete;
protected: protected:
// Protected data // Protected Data
struct scalarBar struct scalarBar
{ {
...@@ -118,7 +110,7 @@ protected: ...@@ -118,7 +110,7 @@ protected:
}; };
//- Colours //- Colours
const HashPtrTable<Function1<vector>, word>& colours_; const HashPtrTable<Function1<vector>>& colours_;
//- Field name //- Field name
word fieldName_; word fieldName_;
...@@ -171,6 +163,12 @@ protected: ...@@ -171,6 +163,12 @@ protected:
vtkRenderer* renderer vtkRenderer* renderer
) const; ) const;
//- No copy construct
fieldVisualisationBase(const fieldVisualisationBase&) = delete;
//- No copy assignment
void operator=(const fieldVisualisationBase&) = delete;
public: public:
...@@ -180,7 +178,7 @@ public: ...@@ -180,7 +178,7 @@ public:
fieldVisualisationBase fieldVisualisationBase
( (
const dictionary& dict, const dictionary& dict,
const HashPtrTable<Function1<vector>, word>& colours const HashPtrTable<Function1<vector>>& colours
); );
...@@ -190,18 +188,19 @@ public: ...@@ -190,18 +188,19 @@ public:
// Member Functions // Member Functions
// Access // Access
//- Return the colours //- Return the colours
const HashPtrTable<Function1<vector>, word>& colours() const; const HashPtrTable<Function1<vector>>& colours() const;
//- Return the field name //- Return the field name
const word& fieldName() const; const word& fieldName() const;
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace runTimePostPro
} // End namespace functionObjects } // End namespace functionObjects
} // End namespace Foam } // End namespace Foam
......
...@@ -79,7 +79,7 @@ Foam::functionObjects::runTimePostPro::functionObjectBase::functionObjectBase ...@@ -79,7 +79,7 @@ Foam::functionObjects::runTimePostPro::functionObjectBase::functionObjectBase
( (
const stateFunctionObject& state, const stateFunctionObject& state,
const dictionary& dict, const dictionary& dict,
const HashPtrTable<Function1<vector>, word>& colours const HashPtrTable<Function1<vector>>& colours
) )
: :
fieldVisualisationBase(dict, colours), fieldVisualisationBase(dict, colours),
......
...@@ -109,13 +109,13 @@ protected: ...@@ -109,13 +109,13 @@ protected:
// \note does not change the stateFunctionObject // \note does not change the stateFunctionObject
bool removeFile(const word& keyword, const word& subDictName); bool removeFile(const word& keyword, const word& subDictName);
//- No copy construct //- No copy construct
functionObjectBase(const functionObjectBase&) = delete; functionObjectBase(const functionObjectBase&) = delete;
//- No copy assignment //- No copy assignment