mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use smart pointers for paraview readers
- adds flexiblity and reduces risk of memory leaks as we add/change features STYLE: adjust naming for paraview internal polyDecomp
This commit is contained in:
@ -39,6 +39,7 @@ License
|
||||
#include "vtkSMRenderViewProxy.h"
|
||||
#include "vtkStreamingDemandDrivenPipeline.h"
|
||||
#include "vtkStringArray.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "vtkPVFoam.H"
|
||||
@ -69,11 +70,13 @@ vtkPVFoamReader::vtkPVFoamReader()
|
||||
#ifdef VTKPVFOAM_DUALPORT
|
||||
// Add second output for the Lagrangian
|
||||
this->SetNumberOfOutputPorts(2);
|
||||
vtkMultiBlockDataSet *lagrangian = vtkMultiBlockDataSet::New();
|
||||
|
||||
vtkSmartPointer<vtkMultiBlockDataSet> lagrangian =
|
||||
vtkSmartPointer<vtkMultiBlockDataSet>::New();
|
||||
|
||||
lagrangian->ReleaseData();
|
||||
|
||||
this->GetExecutive()->SetOutputData(1, lagrangian);
|
||||
lagrangian->Delete();
|
||||
#endif
|
||||
|
||||
TimeStepRange[0] = 0;
|
||||
@ -218,7 +221,7 @@ int vtkPVFoamReader::RequestInformation
|
||||
{
|
||||
vtkErrorMacro("could not find valid OpenFOAM mesh");
|
||||
|
||||
// delete foamData and flag it as fatal error
|
||||
// delete backend handler and flag it as fatal error
|
||||
delete backend_;
|
||||
backend_ = nullptr;
|
||||
return 0;
|
||||
@ -326,7 +329,8 @@ int vtkPVFoamReader::RequestData
|
||||
{
|
||||
vtkInformation *outInfo = outputVector->GetInformationObject(infoI);
|
||||
|
||||
int nsteps = outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
|
||||
const int nsteps =
|
||||
outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
|
||||
|
||||
if
|
||||
(
|
||||
@ -419,7 +423,7 @@ int vtkPVFoamReader::RequestData
|
||||
(
|
||||
vtkMultiBlockDataSet::DATA_OBJECT()
|
||||
)
|
||||
);
|
||||
)
|
||||
);
|
||||
#else
|
||||
backend_->Update(output, output);
|
||||
|
||||
@ -46,6 +46,7 @@ SourceFiles
|
||||
// VTK forward declarations
|
||||
class vtkDataArraySelection;
|
||||
class vtkCallbackCommand;
|
||||
template<class T> class vtkSmartPointer;
|
||||
|
||||
// OpenFOAM forward declarations
|
||||
namespace Foam
|
||||
|
||||
@ -37,6 +37,7 @@ License
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkTextActor.h"
|
||||
#include "vtkTextProperty.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -48,29 +49,37 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
vtkTextActor* Foam::vtkPVFoam::createTextActor
|
||||
(
|
||||
const std::string& s,
|
||||
const point& pt
|
||||
)
|
||||
namespace Foam
|
||||
{
|
||||
vtkTextActor* txt = vtkTextActor::New();
|
||||
txt->SetInput(s.c_str());
|
||||
// file-scope
|
||||
|
||||
// Set text properties
|
||||
vtkTextProperty* tprop = txt->GetTextProperty();
|
||||
tprop->SetFontFamilyToArial();
|
||||
tprop->BoldOn();
|
||||
tprop->ShadowOff();
|
||||
tprop->SetLineSpacing(1.0);
|
||||
tprop->SetFontSize(14);
|
||||
tprop->SetColor(1.0, 0.0, 1.0);
|
||||
tprop->SetJustificationToCentered();
|
||||
//- Create a text actor
|
||||
vtkSmartPointer<vtkTextActor> createTextActor
|
||||
(
|
||||
const std::string& s,
|
||||
const Foam::point& pt
|
||||
)
|
||||
{
|
||||
vtkSmartPointer<vtkTextActor> txt =
|
||||
vtkSmartPointer<vtkTextActor>::New();
|
||||
|
||||
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
|
||||
txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z());
|
||||
txt->SetInput(s.c_str());
|
||||
|
||||
return txt;
|
||||
// Set text properties
|
||||
vtkTextProperty* tprop = txt->GetTextProperty();
|
||||
tprop->SetFontFamilyToArial();
|
||||
tprop->BoldOn();
|
||||
tprop->ShadowOff();
|
||||
tprop->SetLineSpacing(1.0);
|
||||
tprop->SetFontSize(14);
|
||||
tprop->SetColor(1.0, 0.0, 1.0);
|
||||
tprop->SetJustificationToCentered();
|
||||
|
||||
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
|
||||
txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z());
|
||||
|
||||
return txt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -93,19 +102,19 @@ void Foam::vtkPVFoam::resetCounters()
|
||||
|
||||
void Foam::vtkPVFoam::reduceMemory()
|
||||
{
|
||||
forAll(regionPolyDecomp_, i)
|
||||
forAll(regionVtus_, i)
|
||||
{
|
||||
regionPolyDecomp_[i].clear();
|
||||
regionVtus_[i].clear();
|
||||
}
|
||||
|
||||
forAll(zonePolyDecomp_, i)
|
||||
forAll(zoneVtus_, i)
|
||||
{
|
||||
zonePolyDecomp_[i].clear();
|
||||
zoneVtus_[i].clear();
|
||||
}
|
||||
|
||||
forAll(csetPolyDecomp_, i)
|
||||
forAll(csetVtus_, i)
|
||||
{
|
||||
csetPolyDecomp_[i].clear();
|
||||
csetVtus_[i].clear();
|
||||
}
|
||||
|
||||
if (!reader_->GetCacheMesh())
|
||||
@ -640,12 +649,11 @@ void Foam::vtkPVFoam::renderPatchNames
|
||||
{
|
||||
// always remove old actors first
|
||||
|
||||
forAll(patchTextActorsPtrs_, patchi)
|
||||
forAll(patchTextActors_, patchi)
|
||||
{
|
||||
renderer->RemoveViewProp(patchTextActorsPtrs_[patchi]);
|
||||
patchTextActorsPtrs_[patchi]->Delete();
|
||||
renderer->RemoveViewProp(patchTextActors_[patchi]);
|
||||
}
|
||||
patchTextActorsPtrs_.clear();
|
||||
patchTextActors_.clear();
|
||||
|
||||
if (show && meshPtr_)
|
||||
{
|
||||
@ -750,7 +758,7 @@ void Foam::vtkPVFoam::renderPatchNames
|
||||
}
|
||||
|
||||
// Set the size of the patch labels to max number of zones
|
||||
patchTextActorsPtrs_.setSize(displayZoneI);
|
||||
patchTextActors_.setSize(displayZoneI);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -783,7 +791,7 @@ void Foam::vtkPVFoam::renderPatchNames
|
||||
}
|
||||
|
||||
// Into a list for later removal
|
||||
patchTextActorsPtrs_[displayZoneI++] = createTextActor
|
||||
patchTextActors_[displayZoneI++] = createTextActor
|
||||
(
|
||||
pp.name(),
|
||||
zoneCentre[patchi][globalZoneI]
|
||||
@ -792,13 +800,13 @@ void Foam::vtkPVFoam::renderPatchNames
|
||||
}
|
||||
|
||||
// Resize the patch names list to the actual number of patch names added
|
||||
patchTextActorsPtrs_.setSize(displayZoneI);
|
||||
patchTextActors_.setSize(displayZoneI);
|
||||
}
|
||||
|
||||
// Add text to each renderer
|
||||
forAll(patchTextActorsPtrs_, actori)
|
||||
forAll(patchTextActors_, actori)
|
||||
{
|
||||
renderer->AddViewProp(patchTextActorsPtrs_[actori]);
|
||||
renderer->AddViewProp(patchTextActors_[actori]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -71,6 +71,8 @@ class vtkPolyData;
|
||||
class vtkUnstructuredGrid;
|
||||
class vtkIndent;
|
||||
|
||||
template<class T> class vtkSmartPointer;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -105,9 +107,9 @@ class vtkPVFoam
|
||||
// hide in extra pointMap (cellSet/cellZone) for now
|
||||
class polyDecomp
|
||||
{
|
||||
labelList superCells_;
|
||||
labelList addPointCellLabels_;
|
||||
labelList cellMap_;
|
||||
labelList pointMap_;
|
||||
labelList additionalIds_;
|
||||
|
||||
public:
|
||||
|
||||
@ -115,27 +117,15 @@ class vtkPVFoam
|
||||
{}
|
||||
|
||||
//- Label of original cell for decomposed cells
|
||||
labelList& superCells()
|
||||
labelList& cellMap()
|
||||
{
|
||||
return superCells_;
|
||||
return cellMap_;
|
||||
}
|
||||
|
||||
//- Label of original cell for decomposed cells
|
||||
const labelList& superCells() const
|
||||
const labelList& cellMap() const
|
||||
{
|
||||
return superCells_;
|
||||
}
|
||||
|
||||
//- Cell-centre labels for additional points of decomposed cells
|
||||
labelList& addPointCellLabels()
|
||||
{
|
||||
return addPointCellLabels_;
|
||||
}
|
||||
|
||||
//- Cell-centre labels for additional points of decomposed cells
|
||||
const labelList& addPointCellLabels() const
|
||||
{
|
||||
return addPointCellLabels_;
|
||||
return cellMap_;
|
||||
}
|
||||
|
||||
//- Point labels for subsetted meshes
|
||||
@ -151,15 +141,29 @@ class vtkPVFoam
|
||||
}
|
||||
|
||||
|
||||
//- Cell-centre labels for additional points of decomposed cells
|
||||
labelList& additionalIds()
|
||||
{
|
||||
return additionalIds_;
|
||||
}
|
||||
|
||||
//- Cell-centre labels for additional points of decomposed cells
|
||||
const labelList& additionalIds() const
|
||||
{
|
||||
return additionalIds_;
|
||||
}
|
||||
|
||||
//- Clear
|
||||
void clear()
|
||||
{
|
||||
superCells_.clear();
|
||||
addPointCellLabels_.clear();
|
||||
cellMap_.clear();
|
||||
pointMap_.clear();
|
||||
additionalIds_.clear();
|
||||
}
|
||||
};
|
||||
|
||||
typedef polyDecomp foamVtuData;
|
||||
|
||||
|
||||
// Private Data
|
||||
|
||||
@ -208,27 +212,20 @@ class vtkPVFoam
|
||||
|
||||
//- Decomposed cells information (mesh regions)
|
||||
// TODO: regions
|
||||
List<polyDecomp> regionPolyDecomp_;
|
||||
List<foamVtuData> regionVtus_;
|
||||
|
||||
//- Decomposed cells information (cellZone meshes)
|
||||
List<polyDecomp> zonePolyDecomp_;
|
||||
List<foamVtuData> zoneVtus_;
|
||||
|
||||
//- Decomposed cells information (cellSet meshes)
|
||||
List<polyDecomp> csetPolyDecomp_;
|
||||
List<foamVtuData> csetVtus_;
|
||||
|
||||
//- List of patch names for rendering to window
|
||||
List<vtkTextActor*> patchTextActorsPtrs_;
|
||||
List<vtkSmartPointer<vtkTextActor>> patchTextActors_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Create a text actor
|
||||
static vtkTextActor* createTextActor
|
||||
(
|
||||
const std::string& s,
|
||||
const point& pt
|
||||
);
|
||||
|
||||
//- Reset data counters
|
||||
void resetCounters();
|
||||
|
||||
@ -318,14 +315,14 @@ class vtkPVFoam
|
||||
// Add mesh functions
|
||||
|
||||
//- Volume meshes as vtkUnstructuredGrid
|
||||
vtkUnstructuredGrid* volumeVTKMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> volumeVTKMesh
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
polyDecomp& decompInfo
|
||||
foamVtuData& vtuData
|
||||
);
|
||||
|
||||
//- Lagrangian positions as vtkPolyData
|
||||
vtkPolyData* lagrangianVTKMesh
|
||||
vtkSmartPointer<vtkPolyData> lagrangianVTKMesh
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const word& cloudName
|
||||
@ -333,7 +330,7 @@ class vtkPVFoam
|
||||
|
||||
//- Patches (mesh or primitive) as vtkPolyData
|
||||
template<class PatchType>
|
||||
vtkPolyData* patchVTKMesh
|
||||
vtkSmartPointer<vtkPolyData> patchVTKMesh
|
||||
(
|
||||
const word& name,
|
||||
const PatchType& p
|
||||
@ -344,7 +341,7 @@ class vtkPVFoam
|
||||
|
||||
//- Convert Field to VTK field
|
||||
template<class Type>
|
||||
vtkFloatArray* convertFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> convertFieldToVTK
|
||||
(
|
||||
const word& name,
|
||||
const Field<Type>& fld
|
||||
@ -352,7 +349,7 @@ class vtkPVFoam
|
||||
|
||||
//- Face set/zone field
|
||||
template<class Type>
|
||||
vtkFloatArray* convertFaceFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> convertFaceFieldToVTK
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& fld,
|
||||
const labelUList& faceLabels
|
||||
@ -360,10 +357,10 @@ class vtkPVFoam
|
||||
|
||||
//- Volume field
|
||||
template<class Type>
|
||||
vtkFloatArray* convertVolFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> convertVolFieldToVTK
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& fld,
|
||||
const polyDecomp& decompInfo
|
||||
const foamVtuData& vtuData
|
||||
);
|
||||
|
||||
|
||||
@ -416,7 +413,7 @@ class vtkPVFoam
|
||||
autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr,
|
||||
vtkMultiBlockDataSet* output,
|
||||
const arrayRange& range,
|
||||
const List<polyDecomp>& decompLst
|
||||
const List<foamVtuData>& vtuDataList
|
||||
);
|
||||
|
||||
//- Lagrangian fields - all types
|
||||
@ -444,7 +441,7 @@ class vtkPVFoam
|
||||
const GeometricField<Type, pointPatchField, pointMesh>& pfld,
|
||||
vtkMultiBlockDataSet* output,
|
||||
const arrayRange& range,
|
||||
const List<polyDecomp>& decompLst
|
||||
const List<foamVtuData>& vtuDataList
|
||||
);
|
||||
|
||||
//- Point field
|
||||
@ -454,7 +451,7 @@ class vtkPVFoam
|
||||
vtkUnstructuredGrid* vtkmesh,
|
||||
const GeometricField<Type, pointPatchField, pointMesh>& pfld,
|
||||
const GeometricField<Type, fvPatchField, volMesh>& vfld,
|
||||
const polyDecomp& decomp
|
||||
const foamVtuData& vtuData
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ InClass
|
||||
#include "vtkFloatArray.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
//
|
||||
@ -84,7 +85,7 @@ void Foam::vtkPVFoam::convertVolField
|
||||
ptfPtr,
|
||||
output,
|
||||
rangeVolume_,
|
||||
regionPolyDecomp_
|
||||
regionVtus_
|
||||
);
|
||||
|
||||
// Convert activated cellZones
|
||||
@ -94,7 +95,7 @@ void Foam::vtkPVFoam::convertVolField
|
||||
ptfPtr,
|
||||
output,
|
||||
rangeCellZones_,
|
||||
zonePolyDecomp_
|
||||
zoneVtus_
|
||||
);
|
||||
|
||||
// Convert activated cellSets
|
||||
@ -104,7 +105,7 @@ void Foam::vtkPVFoam::convertVolField
|
||||
ptfPtr,
|
||||
output,
|
||||
rangeCellSets_,
|
||||
csetPolyDecomp_
|
||||
csetVtus_
|
||||
);
|
||||
|
||||
|
||||
@ -151,38 +152,44 @@ void Foam::vtkPVFoam::convertVolField
|
||||
fvPatchField<Type>(p, fld).patchInternalField()
|
||||
);
|
||||
|
||||
vtkFloatArray* cdata = convertFieldToVTK(fld.name(), tpptf());
|
||||
vtkSmartPointer<vtkFloatArray> cdata =
|
||||
convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
tpptf()
|
||||
);
|
||||
vtkmesh->GetCellData()->AddArray(cdata);
|
||||
cdata->Delete();
|
||||
|
||||
if (patchId < patchInterpList.size())
|
||||
{
|
||||
vtkFloatArray* pdata = convertFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> pdata = convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
patchInterpList[patchId].faceToPointInterpolate(tpptf)()
|
||||
);
|
||||
|
||||
vtkmesh->GetPointData()->AddArray(pdata);
|
||||
pdata->Delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkFloatArray* cdata = convertFieldToVTK(fld.name(), ptf);
|
||||
vtkSmartPointer<vtkFloatArray> cdata =
|
||||
convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
ptf
|
||||
);
|
||||
vtkmesh->GetCellData()->AddArray(cdata);
|
||||
cdata->Delete();
|
||||
|
||||
if (patchId < patchInterpList.size())
|
||||
{
|
||||
vtkFloatArray* pdata = convertFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> pdata = convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
patchInterpList[patchId].faceToPointInterpolate(ptf)()
|
||||
);
|
||||
|
||||
vtkmesh->GetPointData()->AddArray(pdata);
|
||||
pdata->Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,14 +222,13 @@ void Foam::vtkPVFoam::convertVolField
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
vtkFloatArray* cdata = convertFaceFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertFaceFieldToVTK
|
||||
(
|
||||
fld,
|
||||
zMesh[zoneId]
|
||||
);
|
||||
|
||||
vtkmesh->GetCellData()->AddArray(cdata);
|
||||
cdata->Delete();
|
||||
}
|
||||
|
||||
// TODO: points
|
||||
@ -253,14 +259,13 @@ void Foam::vtkPVFoam::convertVolField
|
||||
|
||||
const faceSet fSet(mesh, selectName);
|
||||
|
||||
vtkFloatArray* cdata = convertFaceFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertFaceFieldToVTK
|
||||
(
|
||||
fld,
|
||||
fSet.sortedToc()
|
||||
);
|
||||
|
||||
vtkmesh->GetCellData()->AddArray(cdata);
|
||||
cdata->Delete();
|
||||
|
||||
// TODO: points
|
||||
}
|
||||
@ -369,7 +374,7 @@ void Foam::vtkPVFoam::convertVolFieldBlock
|
||||
autoPtr<GeometricField<Type, pointPatchField, pointMesh>>& ptfPtr,
|
||||
vtkMultiBlockDataSet* output,
|
||||
const arrayRange& range,
|
||||
const List<polyDecomp>& decompLst
|
||||
const List<foamVtuData>& vtuDataList
|
||||
)
|
||||
{
|
||||
for (auto partId : range)
|
||||
@ -389,18 +394,16 @@ void Foam::vtkPVFoam::convertVolFieldBlock
|
||||
continue;
|
||||
}
|
||||
|
||||
vtkFloatArray* cdata = convertVolFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertVolFieldToVTK
|
||||
(
|
||||
fld,
|
||||
decompLst[datasetNo]
|
||||
vtuDataList[datasetNo]
|
||||
);
|
||||
|
||||
vtkmesh->GetCellData()->AddArray(cdata);
|
||||
cdata->Delete();
|
||||
|
||||
if (ptfPtr.valid())
|
||||
{
|
||||
convertPointField(vtkmesh, ptfPtr(), fld, decompLst[datasetNo]);
|
||||
convertPointField(vtkmesh, ptfPtr(), fld, vtuDataList[datasetNo]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -449,7 +452,7 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
pfld,
|
||||
output,
|
||||
rangeVolume_,
|
||||
regionPolyDecomp_
|
||||
regionVtus_
|
||||
);
|
||||
|
||||
// Convert activated cellZones
|
||||
@ -458,7 +461,7 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
pfld,
|
||||
output,
|
||||
rangeCellZones_,
|
||||
zonePolyDecomp_
|
||||
zoneVtus_
|
||||
);
|
||||
|
||||
// Convert activated cellSets
|
||||
@ -467,7 +470,7 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
pfld,
|
||||
output,
|
||||
rangeCellSets_,
|
||||
csetPolyDecomp_
|
||||
csetVtus_
|
||||
);
|
||||
|
||||
|
||||
@ -492,14 +495,13 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
vtkFloatArray* pdata = convertFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray> pdata = convertFieldToVTK
|
||||
(
|
||||
fieldName,
|
||||
pfld.boundaryField()[patchId].patchInternalField()()
|
||||
);
|
||||
|
||||
vtkmesh->GetPointData()->AddArray(pdata);
|
||||
pdata->Delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,10 +533,14 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
mesh.faceZones()[zoneId]().meshPoints()
|
||||
);
|
||||
|
||||
vtkFloatArray* pdata = convertFieldToVTK(fieldName, znfld);
|
||||
vtkSmartPointer<vtkFloatArray> pdata =
|
||||
convertFieldToVTK
|
||||
(
|
||||
fieldName,
|
||||
znfld
|
||||
);
|
||||
|
||||
vtkmesh->GetPointData()->AddArray(pdata);
|
||||
pdata->Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -547,7 +553,7 @@ void Foam::vtkPVFoam::convertPointFieldBlock
|
||||
const GeometricField<Type, pointPatchField, pointMesh>& pfld,
|
||||
vtkMultiBlockDataSet* output,
|
||||
const arrayRange& range,
|
||||
const List<polyDecomp>& decompLst
|
||||
const List<foamVtuData>& vtuDataList
|
||||
)
|
||||
{
|
||||
for (auto partId : range)
|
||||
@ -571,7 +577,7 @@ void Foam::vtkPVFoam::convertPointFieldBlock
|
||||
vtkmesh,
|
||||
pfld,
|
||||
GeometricField<Type, fvPatchField, volMesh>::null(),
|
||||
decompLst[datasetNo]
|
||||
vtuDataList[datasetNo]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -584,7 +590,7 @@ void Foam::vtkPVFoam::convertPointField
|
||||
vtkUnstructuredGrid* vtkmesh,
|
||||
const GeometricField<Type, pointPatchField, pointMesh>& pfld,
|
||||
const GeometricField<Type, fvPatchField, volMesh>& vfld,
|
||||
const polyDecomp& decomp
|
||||
const foamVtuData& vtuData
|
||||
)
|
||||
{
|
||||
if (!vtkmesh)
|
||||
@ -593,13 +599,15 @@ void Foam::vtkPVFoam::convertPointField
|
||||
}
|
||||
|
||||
const label nComp = pTraits<Type>::nComponents;
|
||||
const labelUList& addPointCellLabels = decomp.addPointCellLabels();
|
||||
const labelUList& pointMap = decomp.pointMap();
|
||||
const labelUList& addPointCellLabels = vtuData.additionalIds();
|
||||
const labelUList& pointMap = vtuData.pointMap();
|
||||
|
||||
// use a pointMap or address directly into mesh
|
||||
const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size());
|
||||
|
||||
vtkFloatArray* fldData = vtkFloatArray::New();
|
||||
vtkSmartPointer<vtkFloatArray> fldData =
|
||||
vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
fldData->SetNumberOfTuples(nPoints + addPointCellLabels.size());
|
||||
fldData->SetNumberOfComponents(nComp);
|
||||
fldData->Allocate(nComp*(nPoints + addPointCellLabels.size()));
|
||||
@ -689,7 +697,6 @@ void Foam::vtkPVFoam::convertPointField
|
||||
}
|
||||
|
||||
vtkmesh->GetPointData()->AddArray(fldData);
|
||||
fldData->Delete();
|
||||
}
|
||||
|
||||
|
||||
@ -720,9 +727,13 @@ void Foam::vtkPVFoam::convertLagrangianFields
|
||||
{
|
||||
IOField<Type> fld(*iter());
|
||||
|
||||
vtkFloatArray* fldData = convertFieldToVTK(fld.name(), fld);
|
||||
vtkSmartPointer<vtkFloatArray> fldData =
|
||||
convertFieldToVTK
|
||||
(
|
||||
fld.name(),
|
||||
fld
|
||||
);
|
||||
vtkmesh->GetPointData()->AddArray(fldData);
|
||||
fldData->Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -735,7 +746,8 @@ void Foam::vtkPVFoam::convertLagrangianFields
|
||||
//
|
||||
|
||||
template<class Type>
|
||||
vtkFloatArray* Foam::vtkPVFoam::convertFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtkPVFoam::convertFieldToVTK
|
||||
(
|
||||
const word& name,
|
||||
const Field<Type>& fld
|
||||
@ -751,7 +763,9 @@ vtkFloatArray* Foam::vtkPVFoam::convertFieldToVTK
|
||||
|
||||
const label nComp = pTraits<Type>::nComponents;
|
||||
|
||||
vtkFloatArray* fldData = vtkFloatArray::New();
|
||||
vtkSmartPointer<vtkFloatArray> fldData =
|
||||
vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
fldData->SetNumberOfTuples(fld.size());
|
||||
fldData->SetNumberOfComponents(nComp);
|
||||
fldData->Allocate(nComp*fld.size());
|
||||
@ -775,7 +789,8 @@ vtkFloatArray* Foam::vtkPVFoam::convertFieldToVTK
|
||||
|
||||
|
||||
template<class Type>
|
||||
vtkFloatArray* Foam::vtkPVFoam::convertFaceFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtkPVFoam::convertFaceFieldToVTK
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& fld,
|
||||
const labelUList& faceLabels
|
||||
@ -796,7 +811,9 @@ vtkFloatArray* Foam::vtkPVFoam::convertFaceFieldToVTK
|
||||
const labelList& faceOwner = mesh.faceOwner();
|
||||
const labelList& faceNeigh = mesh.faceNeighbour();
|
||||
|
||||
vtkFloatArray* fldData = vtkFloatArray::New();
|
||||
vtkSmartPointer<vtkFloatArray> fldData =
|
||||
vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
fldData->SetNumberOfTuples(faceLabels.size());
|
||||
fldData->SetNumberOfComponents(nComp);
|
||||
fldData->Allocate(nComp*faceLabels.size());
|
||||
@ -836,35 +853,38 @@ vtkFloatArray* Foam::vtkPVFoam::convertFaceFieldToVTK
|
||||
|
||||
|
||||
template<class Type>
|
||||
vtkFloatArray* Foam::vtkPVFoam::convertVolFieldToVTK
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtkPVFoam::convertVolFieldToVTK
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& fld,
|
||||
const polyDecomp& decompInfo
|
||||
const foamVtuData& vtuData
|
||||
)
|
||||
{
|
||||
const label nComp = pTraits<Type>::nComponents;
|
||||
const labelList& superCells = decompInfo.superCells();
|
||||
const labelList& cellMap = vtuData.cellMap();
|
||||
|
||||
vtkFloatArray* fldData = vtkFloatArray::New();
|
||||
fldData->SetNumberOfTuples(superCells.size());
|
||||
vtkSmartPointer<vtkFloatArray> fldData =
|
||||
vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
fldData->SetNumberOfTuples(cellMap.size());
|
||||
fldData->SetNumberOfComponents(nComp);
|
||||
fldData->Allocate(nComp*superCells.size());
|
||||
fldData->Allocate(nComp*cellMap.size());
|
||||
fldData->SetName(fld.name().c_str());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "convert volField: "
|
||||
<< fld.name()
|
||||
<< " size=" << superCells.size()
|
||||
<< " size=" << cellMap.size()
|
||||
<< " (" << fld.size() << " + "
|
||||
<< (superCells.size() - fld.size())
|
||||
<< (cellMap.size() - fld.size())
|
||||
<< ") nComp=" << nComp << endl;
|
||||
}
|
||||
|
||||
float vec[nComp];
|
||||
forAll(superCells, i)
|
||||
forAll(cellMap, i)
|
||||
{
|
||||
const Type& t = fld[superCells[i]];
|
||||
const Type& t = fld[cellMap[i]];
|
||||
for (direction d=0; d<nComp; ++d)
|
||||
{
|
||||
vec[d] = component(t, d);
|
||||
|
||||
@ -38,6 +38,7 @@ License
|
||||
#include "vtkMultiBlockDataSet.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkUnstructuredGrid.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -53,7 +54,7 @@ void Foam::vtkPVFoam::convertMeshVolume
|
||||
const fvMesh& mesh = *meshPtr_;
|
||||
|
||||
// resize for decomposed polyhedra
|
||||
regionPolyDecomp_.setSize(range.size());
|
||||
regionVtus_.setSize(range.size());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -72,17 +73,15 @@ void Foam::vtkPVFoam::convertMeshVolume
|
||||
continue;
|
||||
}
|
||||
|
||||
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh = volumeVTKMesh
|
||||
(
|
||||
mesh,
|
||||
regionPolyDecomp_[datasetNo]
|
||||
regionVtus_[datasetNo]
|
||||
);
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, partName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -127,13 +126,12 @@ void Foam::vtkPVFoam::convertMeshLagrangian
|
||||
continue;
|
||||
}
|
||||
|
||||
vtkPolyData* vtkmesh = lagrangianVTKMesh(mesh, cloudName);
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
lagrangianVTKMesh(mesh, cloudName);
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, cloudName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -188,7 +186,7 @@ void Foam::vtkPVFoam::convertMeshPatches
|
||||
<< patchName << endl;
|
||||
}
|
||||
|
||||
vtkPolyData* vtkmesh = nullptr;
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh;
|
||||
if (patchIds.size() == 1)
|
||||
{
|
||||
vtkmesh = patchVTKMesh(patchName, patches[patchIds.begin().key()]);
|
||||
@ -228,8 +226,6 @@ void Foam::vtkPVFoam::convertMeshPatches
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, patchName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -260,7 +256,7 @@ void Foam::vtkPVFoam::convertMeshCellZones
|
||||
const fvMesh& mesh = *meshPtr_;
|
||||
|
||||
// resize for decomposed polyhedra
|
||||
zonePolyDecomp_.setSize(range.size());
|
||||
zoneVtus_.setSize(range.size());
|
||||
|
||||
if (range.empty())
|
||||
{
|
||||
@ -293,32 +289,30 @@ void Foam::vtkPVFoam::convertMeshCellZones
|
||||
fvMeshSubset subsetter(mesh);
|
||||
subsetter.setLargeCellSubset(zMesh[zoneId]);
|
||||
|
||||
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh = volumeVTKMesh
|
||||
(
|
||||
subsetter.subMesh(),
|
||||
zonePolyDecomp_[datasetNo]
|
||||
zoneVtus_[datasetNo]
|
||||
);
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
// superCells + addPointCellLabels must contain global cell ids
|
||||
// cellMap + addPointCellLabels must contain global cell ids
|
||||
inplaceRenumber
|
||||
(
|
||||
subsetter.cellMap(),
|
||||
zonePolyDecomp_[datasetNo].superCells()
|
||||
zoneVtus_[datasetNo].cellMap()
|
||||
);
|
||||
inplaceRenumber
|
||||
(
|
||||
subsetter.cellMap(),
|
||||
zonePolyDecomp_[datasetNo].addPointCellLabels()
|
||||
zoneVtus_[datasetNo].additionalIds()
|
||||
);
|
||||
|
||||
// copy pointMap as well, otherwise pointFields fail
|
||||
zonePolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();
|
||||
zoneVtus_[datasetNo].pointMap() = subsetter.pointMap();
|
||||
|
||||
addToBlock(output, vtkmesh, range, datasetNo, zoneName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -349,7 +343,7 @@ void Foam::vtkPVFoam::convertMeshCellSets
|
||||
const fvMesh& mesh = *meshPtr_;
|
||||
|
||||
// resize for decomposed polyhedra
|
||||
csetPolyDecomp_.setSize(range.size());
|
||||
csetVtus_.setSize(range.size());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -375,32 +369,30 @@ void Foam::vtkPVFoam::convertMeshCellSets
|
||||
fvMeshSubset subsetter(mesh);
|
||||
subsetter.setLargeCellSubset(cSet);
|
||||
|
||||
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh = volumeVTKMesh
|
||||
(
|
||||
subsetter.subMesh(),
|
||||
csetPolyDecomp_[datasetNo]
|
||||
csetVtus_[datasetNo]
|
||||
);
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
// superCells + addPointCellLabels must contain global cell ids
|
||||
// cellMap + addPointCellLabels must contain global cell ids
|
||||
inplaceRenumber
|
||||
(
|
||||
subsetter.cellMap(),
|
||||
csetPolyDecomp_[datasetNo].superCells()
|
||||
csetVtus_[datasetNo].cellMap()
|
||||
);
|
||||
inplaceRenumber
|
||||
(
|
||||
subsetter.cellMap(),
|
||||
csetPolyDecomp_[datasetNo].addPointCellLabels()
|
||||
csetVtus_[datasetNo].additionalIds()
|
||||
);
|
||||
|
||||
// copy pointMap as well, otherwise pointFields fail
|
||||
csetPolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();
|
||||
csetVtus_[datasetNo].pointMap() = subsetter.pointMap();
|
||||
|
||||
addToBlock(output, vtkmesh, range, datasetNo, partName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -458,13 +450,12 @@ void Foam::vtkPVFoam::convertMeshFaceZones
|
||||
<< zoneName << endl;
|
||||
}
|
||||
|
||||
vtkPolyData* vtkmesh = patchVTKMesh(zoneName, zMesh[zoneId]());
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
patchVTKMesh(zoneName, zMesh[zoneId]());
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, zoneName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -530,12 +521,12 @@ void Foam::vtkPVFoam::convertMeshFaceSets
|
||||
continue;
|
||||
}
|
||||
|
||||
vtkPolyData* vtkmesh = patchVTKMesh("faceSet:" + partName, p);
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
patchVTKMesh("faceSet:" + partName, p);
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, partName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -586,7 +577,9 @@ void Foam::vtkPVFoam::convertMeshPointZones
|
||||
|
||||
const labelUList& pointLabels = zMesh[zoneId];
|
||||
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->Allocate(pointLabels.size());
|
||||
|
||||
const pointField& meshPoints = mesh.points();
|
||||
@ -595,15 +588,14 @@ void Foam::vtkPVFoam::convertMeshPointZones
|
||||
vtkpoints->InsertNextPoint(meshPoints[pointLabels[pointi]].v_);
|
||||
}
|
||||
|
||||
vtkPolyData* vtkmesh = vtkPolyData::New();
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, zoneName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
@ -657,7 +649,9 @@ void Foam::vtkPVFoam::convertMeshPointSets
|
||||
|
||||
const pointSet pSet(mesh, partName);
|
||||
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->Allocate(pSet.size());
|
||||
|
||||
const pointField& meshPoints = mesh.points();
|
||||
@ -666,15 +660,14 @@ void Foam::vtkPVFoam::convertMeshPointSets
|
||||
vtkpoints->InsertNextPoint(meshPoints[iter.key()].v_);
|
||||
}
|
||||
|
||||
vtkPolyData* vtkmesh = vtkPolyData::New();
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
if (vtkmesh)
|
||||
{
|
||||
addToBlock(output, vtkmesh, range, datasetNo, partName);
|
||||
vtkmesh->Delete();
|
||||
|
||||
partDataset_[partId] = datasetNo++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,16 +35,17 @@ License
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkPoints.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh
|
||||
vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::lagrangianVTKMesh
|
||||
(
|
||||
const polyMesh& mesh,
|
||||
const word& cloudName
|
||||
)
|
||||
{
|
||||
vtkPolyData* vtkmesh = nullptr;
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -72,9 +73,13 @@ vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh
|
||||
Info<< "cloud with " << parcels.size() << " parcels" << endl;
|
||||
}
|
||||
|
||||
vtkmesh = vtkPolyData::New();
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkCellArray* vtkcells = vtkCellArray::New();
|
||||
vtkmesh = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkSmartPointer<vtkCellArray> vtkcells =
|
||||
vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
vtkpoints->Allocate(parcels.size());
|
||||
vtkcells->Allocate(parcels.size());
|
||||
@ -89,10 +94,7 @@ vtkPolyData* Foam::vtkPVFoam::lagrangianVTKMesh
|
||||
}
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
vtkmesh->SetVerts(vtkcells);
|
||||
vtkcells->Delete();
|
||||
}
|
||||
|
||||
if (debug)
|
||||
|
||||
@ -34,13 +34,14 @@ License
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkIdTypeArray.h"
|
||||
#include "vtkUnstructuredGrid.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
polyDecomp& decompInfo
|
||||
foamVtuData& vtuData
|
||||
)
|
||||
{
|
||||
const cellModel& tet = *(cellModeller::lookup("tet"));
|
||||
@ -50,7 +51,8 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
|
||||
const cellModel& hex = *(cellModeller::lookup("hex"));
|
||||
|
||||
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh =
|
||||
vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -69,8 +71,8 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
// face owner is needed to determine the face orientation
|
||||
const labelList& owner = mesh.faceOwner();
|
||||
|
||||
labelList& superCells = decompInfo.superCells();
|
||||
labelList& addPointCellLabels = decompInfo.addPointCellLabels();
|
||||
labelList& cellMap = vtuData.cellMap();
|
||||
labelList& addPointCellLabels = vtuData.additionalIds();
|
||||
|
||||
// Scan for cells which need to be decomposed and count additional points
|
||||
// and cells
|
||||
@ -116,10 +118,11 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
// Set size of additional cells mapping array
|
||||
// (from added cell to original cell)
|
||||
|
||||
superCells.setSize(mesh.nCells() + nAddCells);
|
||||
cellMap.setSize(mesh.nCells() + nAddCells);
|
||||
|
||||
// Convert OpenFOAM mesh vertices to VTK
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkSmartPointer<vtkPoints> vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->Allocate(mesh.nPoints() + nAddPoints);
|
||||
|
||||
const Foam::pointField& points = mesh.points();
|
||||
@ -147,7 +150,7 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
const cellShape& cellShape = cellShapes[celli];
|
||||
const cellModel& cellModel = cellShape.model();
|
||||
|
||||
superCells[addCelli++] = celli;
|
||||
cellMap[addCelli++] = celli;
|
||||
|
||||
if (cellModel == tet)
|
||||
{
|
||||
@ -334,7 +337,7 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
}
|
||||
else
|
||||
{
|
||||
superCells[addCelli++] = celli;
|
||||
cellMap[addCelli++] = celli;
|
||||
}
|
||||
|
||||
const face& quad = quadFcs[quadI];
|
||||
@ -377,7 +380,7 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
}
|
||||
else
|
||||
{
|
||||
superCells[addCelli++] = celli;
|
||||
cellMap[addCelli++] = celli;
|
||||
}
|
||||
|
||||
const face& tri = triFcs[triI];
|
||||
@ -411,7 +414,6 @@ vtkUnstructuredGrid* Foam::vtkPVFoam::volumeVTKMesh
|
||||
}
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
|
||||
@ -33,17 +33,19 @@ License
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkPoints.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class PatchType>
|
||||
vtkPolyData* Foam::vtkPVFoam::patchVTKMesh
|
||||
vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::patchVTKMesh
|
||||
(
|
||||
const word& name,
|
||||
const PatchType& p
|
||||
)
|
||||
{
|
||||
vtkPolyData* vtkmesh = vtkPolyData::New();
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -54,20 +56,22 @@ vtkPolyData* Foam::vtkPVFoam::patchVTKMesh
|
||||
// Convert OpenFOAM mesh vertices to VTK
|
||||
const Foam::pointField& points = p.localPoints();
|
||||
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->Allocate(points.size());
|
||||
forAll(points, i)
|
||||
{
|
||||
vtkpoints->InsertNextPoint(points[i].v_);
|
||||
}
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
// Add faces as polygons
|
||||
const faceList& faces = p.localFaces();
|
||||
|
||||
vtkCellArray* vtkcells = vtkCellArray::New();
|
||||
vtkSmartPointer<vtkCellArray> vtkcells =
|
||||
vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
vtkcells->Allocate(faces.size());
|
||||
forAll(faces, facei)
|
||||
{
|
||||
@ -82,7 +86,6 @@ vtkPolyData* Foam::vtkPVFoam::patchVTKMesh
|
||||
}
|
||||
|
||||
vtkmesh->SetPolys(vtkcells);
|
||||
vtkcells->Delete();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
|
||||
@ -39,6 +39,7 @@ License
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkTextActor.h"
|
||||
#include "vtkTextProperty.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -47,32 +48,38 @@ namespace Foam
|
||||
defineTypeNameAndDebug(vtkPVblockMesh, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
vtkTextActor* Foam::vtkPVblockMesh::createTextActor
|
||||
(
|
||||
const std::string& s,
|
||||
const point& pt
|
||||
)
|
||||
namespace Foam
|
||||
{
|
||||
vtkTextActor* txt = vtkTextActor::New();
|
||||
txt->SetInput(s.c_str());
|
||||
// file-scope
|
||||
//- Create a text actor
|
||||
static vtkSmartPointer<vtkTextActor> createTextActor
|
||||
(
|
||||
const std::string& s,
|
||||
const Foam::point& pt
|
||||
)
|
||||
{
|
||||
vtkSmartPointer<vtkTextActor> txt =
|
||||
vtkSmartPointer<vtkTextActor>::New();
|
||||
|
||||
// Set text properties
|
||||
vtkTextProperty* tprop = txt->GetTextProperty();
|
||||
tprop->SetFontFamilyToArial();
|
||||
tprop->BoldOn();
|
||||
tprop->ShadowOff();
|
||||
tprop->SetLineSpacing(1.0);
|
||||
tprop->SetFontSize(14);
|
||||
tprop->SetColor(1.0, 0.0, 1.0);
|
||||
tprop->SetJustificationToCentered();
|
||||
txt->SetInput(s.c_str());
|
||||
|
||||
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
|
||||
txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z());
|
||||
// Set text properties
|
||||
vtkTextProperty* tprop = txt->GetTextProperty();
|
||||
tprop->SetFontFamilyToArial();
|
||||
tprop->BoldOn();
|
||||
tprop->ShadowOff();
|
||||
tprop->SetLineSpacing(1.0);
|
||||
tprop->SetFontSize(14);
|
||||
tprop->SetColor(1.0, 0.0, 1.0);
|
||||
tprop->SetJustificationToCentered();
|
||||
|
||||
return txt;
|
||||
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
|
||||
txt->GetPositionCoordinate()->SetValue(pt.x(), pt.y(), pt.z());
|
||||
|
||||
return txt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -436,12 +443,11 @@ void Foam::vtkPVblockMesh::renderPatchNames
|
||||
)
|
||||
{
|
||||
// always remove old actors first
|
||||
forAll(patchTextActorsPtrs_, actori)
|
||||
forAll(patchTextActors_, actori)
|
||||
{
|
||||
renderer->RemoveViewProp(patchTextActorsPtrs_[actori]);
|
||||
patchTextActorsPtrs_[actori]->Delete();
|
||||
renderer->RemoveViewProp(patchTextActors_[actori]);
|
||||
}
|
||||
patchTextActorsPtrs_.clear();
|
||||
patchTextActors_.clear();
|
||||
|
||||
// the number of text actors
|
||||
label nActors = 0;
|
||||
@ -459,7 +465,7 @@ void Foam::vtkPVblockMesh::renderPatchNames
|
||||
}
|
||||
|
||||
// 8 sides per block is plenty
|
||||
patchTextActorsPtrs_.setSize(8*blkMesh.size());
|
||||
patchTextActors_.setSize(8*blkMesh.size());
|
||||
|
||||
// Collect all variables
|
||||
dictionary varDict(meshDescription.subOrEmptyDict("namedVertices"));
|
||||
@ -495,33 +501,33 @@ void Foam::vtkPVblockMesh::renderPatchNames
|
||||
const face& f = patchFaces[facei];
|
||||
|
||||
// Into a list for later removal
|
||||
patchTextActorsPtrs_[nActors++] = createTextActor
|
||||
patchTextActors_[nActors++] = createTextActor
|
||||
(
|
||||
patchName,
|
||||
f.centre(cornerPts) * scaleFactor
|
||||
);
|
||||
|
||||
if (nActors == patchTextActorsPtrs_.size())
|
||||
if (nActors == patchTextActors_.size())
|
||||
{
|
||||
// hit max allocated space - bail out
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nActors == patchTextActorsPtrs_.size())
|
||||
if (nActors == patchTextActors_.size())
|
||||
{
|
||||
// hit max allocated space - bail out
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
patchTextActorsPtrs_.setSize(nActors);
|
||||
patchTextActors_.setSize(nActors);
|
||||
}
|
||||
|
||||
// Add text to each renderer
|
||||
forAll(patchTextActorsPtrs_, actori)
|
||||
forAll(patchTextActors_, actori)
|
||||
{
|
||||
renderer->AddViewProp(patchTextActorsPtrs_[actori]);
|
||||
renderer->AddViewProp(patchTextActors_[actori]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -534,12 +540,11 @@ void Foam::vtkPVblockMesh::renderPointNumbers
|
||||
{
|
||||
// always remove old actors first
|
||||
|
||||
forAll(pointTextActorsPtrs_, actori)
|
||||
forAll(pointTextActors_, actori)
|
||||
{
|
||||
renderer->RemoveViewProp(pointTextActorsPtrs_[actori]);
|
||||
pointTextActorsPtrs_[actori]->Delete();
|
||||
renderer->RemoveViewProp(pointTextActors_[actori]);
|
||||
}
|
||||
pointTextActorsPtrs_.clear();
|
||||
pointTextActors_.clear();
|
||||
|
||||
if (show && meshPtr_)
|
||||
{
|
||||
@ -547,7 +552,7 @@ void Foam::vtkPVblockMesh::renderPointNumbers
|
||||
const pointField& cornerPts = blkMesh.vertices();
|
||||
const scalar scaleFactor = blkMesh.scaleFactor();
|
||||
|
||||
pointTextActorsPtrs_.setSize(cornerPts.size());
|
||||
pointTextActors_.setSize(cornerPts.size());
|
||||
forAll(cornerPts, pointi)
|
||||
{
|
||||
// Display either pointi as a number or with its name
|
||||
@ -556,7 +561,7 @@ void Foam::vtkPVblockMesh::renderPointNumbers
|
||||
blockVertex::write(os, pointi, blkMesh.meshDict());
|
||||
|
||||
// Into a list for later removal
|
||||
pointTextActorsPtrs_[pointi] = createTextActor
|
||||
pointTextActors_[pointi] = createTextActor
|
||||
(
|
||||
os.str(),
|
||||
cornerPts[pointi]*scaleFactor
|
||||
@ -565,9 +570,9 @@ void Foam::vtkPVblockMesh::renderPointNumbers
|
||||
}
|
||||
|
||||
// Add text to each renderer
|
||||
forAll(pointTextActorsPtrs_, actori)
|
||||
forAll(pointTextActors_, actori)
|
||||
{
|
||||
renderer->AddViewProp(pointTextActorsPtrs_[actori]);
|
||||
renderer->AddViewProp(pointTextActors_[actori]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -56,6 +56,8 @@ class vtkPolyData;
|
||||
class vtkUnstructuredGrid;
|
||||
class vtkIndent;
|
||||
|
||||
template<class T> class vtkSmartPointer;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
@ -110,21 +112,14 @@ class vtkPVblockMesh
|
||||
arrayRange rangeCorners_;
|
||||
|
||||
//- List of patch names for rendering to window
|
||||
List<vtkTextActor*> patchTextActorsPtrs_;
|
||||
List<vtkSmartPointer<vtkTextActor>> patchTextActors_;
|
||||
|
||||
//- List of point numbers for rendering to window
|
||||
List<vtkTextActor*> pointTextActorsPtrs_;
|
||||
List<vtkSmartPointer<vtkTextActor>> pointTextActors_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Create a text actor
|
||||
static vtkTextActor* createTextActor
|
||||
(
|
||||
const std::string& s,
|
||||
const point& pt
|
||||
);
|
||||
|
||||
//- Reset data counters
|
||||
void resetCounters();
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ License
|
||||
#include "vtkPoints.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkUnstructuredGrid.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
@ -99,7 +100,9 @@ void Foam::vtkPVblockMesh::convertMeshBlocks
|
||||
const blockDescriptor& blockDef = blkMesh[blockI];
|
||||
|
||||
// Convert OpenFOAM mesh vertices to VTK
|
||||
vtkPoints *vtkpoints = vtkPoints::New();
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->Allocate(blockDef.nPoints());
|
||||
const labelList& blockLabels = blockDef.blockShape();
|
||||
|
||||
@ -117,7 +120,9 @@ void Foam::vtkPVblockMesh::convertMeshBlocks
|
||||
nodeIds[ptI] = ptI;
|
||||
}
|
||||
|
||||
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh =
|
||||
vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
|
||||
vtkmesh->Allocate(1);
|
||||
vtkmesh->InsertNextCell
|
||||
(
|
||||
@ -127,7 +132,6 @@ void Foam::vtkPVblockMesh::convertMeshBlocks
|
||||
);
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
addToBlock
|
||||
(
|
||||
@ -135,7 +139,6 @@ void Foam::vtkPVblockMesh::convertMeshBlocks
|
||||
selection->GetArrayName(partId)
|
||||
);
|
||||
|
||||
vtkmesh->Delete();
|
||||
++datasetNo;
|
||||
}
|
||||
|
||||
@ -211,8 +214,11 @@ void Foam::vtkPVblockMesh::convertMeshEdges
|
||||
{
|
||||
const List<point>& edgePoints = edgesPoints[foundEdgeI];
|
||||
|
||||
vtkPolyData* vtkmesh = vtkPolyData::New();
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->Allocate( edgePoints.size() );
|
||||
vtkmesh->Allocate(1);
|
||||
@ -237,7 +243,6 @@ void Foam::vtkPVblockMesh::convertMeshEdges
|
||||
);
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
addToBlock
|
||||
(
|
||||
@ -245,7 +250,6 @@ void Foam::vtkPVblockMesh::convertMeshEdges
|
||||
selection->GetArrayName(partId)
|
||||
);
|
||||
|
||||
vtkmesh->Delete();
|
||||
datasetNo++;
|
||||
|
||||
break;
|
||||
@ -287,9 +291,14 @@ void Foam::vtkPVblockMesh::convertMeshCorners
|
||||
|
||||
if (true) // or some flag or other condition
|
||||
{
|
||||
vtkPolyData* vtkmesh = vtkPolyData::New();
|
||||
vtkPoints* vtkpoints = vtkPoints::New();
|
||||
vtkCellArray* vtkcells = vtkCellArray::New();
|
||||
vtkSmartPointer<vtkPolyData> vtkmesh =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkSmartPointer<vtkPoints> vtkpoints =
|
||||
vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkSmartPointer<vtkCellArray> vtkcells =
|
||||
vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
vtkpoints->Allocate( blockPoints.size() );
|
||||
vtkcells->Allocate( blockPoints.size() );
|
||||
@ -309,15 +318,15 @@ void Foam::vtkPVblockMesh::convertMeshCorners
|
||||
}
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkpoints->Delete();
|
||||
|
||||
vtkmesh->SetVerts(vtkcells);
|
||||
vtkcells->Delete();
|
||||
|
||||
addToBlock(output, vtkmesh, range, datasetNo, range.name());
|
||||
vtkmesh->Delete();
|
||||
|
||||
++datasetNo;
|
||||
}
|
||||
|
||||
// anything added?
|
||||
if (datasetNo)
|
||||
{
|
||||
++blockNo;
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ License
|
||||
#include "vtkDataSet.h"
|
||||
#include "vtkMultiBlockDataSet.h"
|
||||
#include "vtkInformation.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -54,7 +55,8 @@ void Foam::foamPvCore::addToBlock
|
||||
const int blockNo = selector.block();
|
||||
|
||||
vtkDataObject* dataObj = output->GetBlock(blockNo);
|
||||
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(dataObj);
|
||||
vtkSmartPointer<vtkMultiBlockDataSet> block =
|
||||
vtkMultiBlockDataSet::SafeDownCast(dataObj);
|
||||
|
||||
if (!block)
|
||||
{
|
||||
@ -66,9 +68,8 @@ void Foam::foamPvCore::addToBlock
|
||||
return;
|
||||
}
|
||||
|
||||
block = vtkMultiBlockDataSet::New();
|
||||
block = vtkSmartPointer<vtkMultiBlockDataSet>::New();
|
||||
output->SetBlock(blockNo, block);
|
||||
block->Delete();
|
||||
}
|
||||
|
||||
if (debug)
|
||||
|
||||
Reference in New Issue
Block a user