mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -30,12 +30,16 @@ License
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// VTK Readers
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkXMLPolyDataReader.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -51,6 +55,44 @@ namespace runTimePostPro
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static vtkSmartPointer<vtkPolyData> getPolyDataFile(const Foam::fileName& fName)
|
||||
{
|
||||
// Not extremely elegant...
|
||||
vtkSmartPointer<vtkPolyData> dataset;
|
||||
|
||||
if (fName.ext() == "vtk")
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if (fName.ext() == "vtp")
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
} // End anonymous namespace
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::functionObjectSurface::
|
||||
@ -58,7 +100,7 @@ functionObjectSurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>, word>& colours
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometrySurface(parent, dict, colours, List<fileName>()),
|
||||
@ -99,37 +141,38 @@ addGeometryToScene
|
||||
}
|
||||
|
||||
|
||||
auto polyData = getPolyDataFile(fName);
|
||||
|
||||
if (!polyData || polyData->GetNumberOfPoints() == 0)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Could not read "<< fName << nl
|
||||
<< "Only VTK (.vtp, .vtk) files are supported"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
auto surf = vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
surf->SetFileName(fName.c_str());
|
||||
surf->Update();
|
||||
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
fieldName_,
|
||||
maxGlyphLength_,
|
||||
surf->GetOutput(),
|
||||
polyData,
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fName.hasExt("vtk"))
|
||||
else
|
||||
{
|
||||
auto surf = vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
surf->SetFileName(fName.c_str());
|
||||
surf->Update();
|
||||
|
||||
addFeatureEdges(renderer, surf->GetOutput());
|
||||
addFeatureEdges(renderer, polyData);
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(surf->GetOutputPort());
|
||||
mapper->SetInputData(polyData);
|
||||
|
||||
setField(position, fieldName_, mapper, renderer, surf->GetOutput());
|
||||
setField(position, fieldName_, mapper, renderer, polyData);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
@ -137,12 +180,6 @@ addGeometryToScene
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Only VTK file types are supported"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user