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
This commit is contained in:
Mark Olesen
2018-12-16 19:14:22 +01:00
parent b6983e6af5
commit c3507f74f2
33 changed files with 681 additions and 441 deletions

View File

@ -39,7 +39,6 @@ License
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
#include "vtkLight.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -60,6 +59,48 @@ namespace functionObjects
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
static void addGeometryToScene
(
PtrList<Type>& objects,
const scalar position,
vtkRenderer* renderer
)
{
for (Type& obj : objects)
{
obj.addGeometryToScene(position, renderer);
}
}
template<class Type>
static void updateActors(PtrList<Type>& objects, const scalar position)
{
for (Type& obj : objects)
{
obj.updateActors(position);
}
}
template<class Type>
static void cleanup(PtrList<Type>& objects)
{
for (Type& obj : objects)
{
obj.clear();
}
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimePostProcessing::runTimePostProcessing
@ -95,7 +136,6 @@ bool Foam::functionObjects::runTimePostProcessing::read(const dictionary& dict)
outputDict.readEntry("width", output_.width_);
outputDict.readEntry("height", output_.height_);
readObjects(dict.subOrEmptyDict("points"), points_);
readObjects(dict.subOrEmptyDict("lines"), lines_);
readObjects(dict.subOrEmptyDict("surfaces"), surfaces_);
@ -107,16 +147,19 @@ bool Foam::functionObjects::runTimePostProcessing::read(const dictionary& dict)
if (!dEntry.isDict())
{
FatalIOErrorInFunction(textDict)
<< textDict.dictName()
<< "text must be specified in dictionary format"
<< exit(FatalIOError);
}
const dictionary& objectDict = dEntry.dict();
text_.append
(
new runTimePostPro::text
(
*this,
dEntry.dict(),
objectDict,
scene_.colours()
)
);
@ -167,76 +210,27 @@ bool Foam::functionObjects::runTimePostProcessing::write()
renderWindow->AddRenderer(renderer);
// Add the points
forAll(points_, i)
{
points_[i].addGeometryToScene(0, renderer);
}
// Add the lines
forAll(lines_, i)
{
lines_[i].addGeometryToScene(0, renderer);
}
// Add the surfaces
forAll(surfaces_, i)
{
surfaces_[i].addGeometryToScene(0, renderer);
}
// Add the text
forAll(text_, i)
{
text_[i].addGeometryToScene(0, renderer);
}
addGeometryToScene(points_, 0, renderer);
addGeometryToScene(lines_, 0, renderer);
addGeometryToScene(surfaces_, 0, renderer);
addGeometryToScene(text_, 0, renderer);
while (scene_.loop(renderer))
{
scalar position = scene_.position();
const scalar position = scene_.position();
// Update the text
forAll(text_, i)
{
text_[i].updateActors(position);
}
// Update the points
forAll(points_, i)
{
points_[i].updateActors(position);
}
// Update the lines
forAll(lines_, i)
{
lines_[i].updateActors(position);
}
// Update the surfaces
forAll(surfaces_, i)
{
surfaces_[i].updateActors(position);
}
updateActors(text_, position);
updateActors(points_, position);
updateActors(lines_, position);
updateActors(surfaces_, position);
}
// Clean up
forAll(text_, i)
{
text_[i].clear();
}
forAll(points_, i)
{
points_[i].clear();
}
forAll(lines_, i)
{
lines_[i].clear();
}
forAll(surfaces_, i)
{
surfaces_[i].clear();
}
// Cleanup
cleanup(text_);
cleanup(points_);
cleanup(lines_);
cleanup(surfaces_);
// Instead of relying on the destructor, manually restore the previous