From b842eda439f0a66a3e565aa2ff0b0e8aae0fa118 Mon Sep 17 00:00:00 2001 From: henry <henry@dm.opencfd.co.uk> Date: Thu, 1 May 2008 15:39:17 +0100 Subject: [PATCH] Updated PV3Foam reader --- .../PV3FoamReader/vtkPV3FoamReader.cxx | 2 +- .../PV3FoamReader/vtkPV3FoamReader.h | 4 +- .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C | 74 +++++++++++++++++-- .../PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H | 30 +++++++- .../vtkPV3Foam/vtkPV3FoamAddFields.H | 4 +- .../vtkPV3FoamConvertLagrangianFields.H | 8 +- .../vtkPV3Foam/vtkPV3FoamConvertMesh.C | 21 +++--- .../vtkPV3FoamConvertPatchFaceField.H | 8 +- .../vtkPV3FoamConvertPatchPointField.H | 8 +- .../vtkPV3Foam/vtkPV3FoamConvertPointFields.H | 8 +- .../vtkPV3Foam/vtkPV3FoamConvertVolFields.H | 10 +-- .../vtkPV3Foam/vtkPV3FoamInsertNextPoint.H | 4 +- .../vtkPV3FoamUpdateInformationFields.H | 4 +- 13 files changed, 140 insertions(+), 45 deletions(-) diff --git a/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx b/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx index 3c9570c..12872d6 100644 --- a/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx +++ b/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.cxx @@ -210,7 +210,7 @@ int vtkPV3FoamReader::RequestData if ( (UpdateGUIOld == GetUpdateGUI()) - || (output->GetNumberOfDataSets(0) == 0) + || (output->GetNumberOfBlocks() == 0) ) { foamData_->Update(output); diff --git a/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h b/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h index 318016f..c9875f9 100644 --- a/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h +++ b/src/paraview-plugins/PV3FoamReader/PV3FoamReader/vtkPV3FoamReader.h @@ -41,7 +41,9 @@ class vtkDataArraySelection; class vtkCallbackCommand; -class VTK_IO_EXPORT vtkPV3FoamReader : public vtkMultiBlockDataSetAlgorithm +class VTK_IO_EXPORT vtkPV3FoamReader +: + public vtkMultiBlockDataSetAlgorithm { public: diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C index 3e3d2af..61e33a5 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.C @@ -37,6 +37,7 @@ License // VTK includes #include "vtkCharArray.h" #include "vtkDataArraySelection.h" +#include "vtkDataSet.h" #include "vtkFieldData.h" #include "vtkMultiBlockDataSet.h" #include "vtkRenderer.h" @@ -55,6 +56,69 @@ defineTypeNameAndDebug(Foam::vtkPV3Foam, 0); #include "vtkPV3FoamUpdateInformationFields.H" +void Foam::vtkPV3Foam::AddToBlock +( + vtkMultiBlockDataSet* output, + unsigned int blockNo, + unsigned int datasetNo, + vtkDataSet* dataset +) +{ + vtkDataObject* blockDO = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + if (blockDO && !block) + { + FatalErrorIn("Foam::vtkPV3Foam::AddToBlock") + << "Block already has a vtkDataSet assigned to it" << nl << endl; + return; + } + + if (!block) + { + block = vtkMultiBlockDataSet::New(); + output->SetBlock(blockNo, block); + block->Delete(); + } + + block->SetBlock(datasetNo, dataset); +} + + +vtkDataSet* Foam::vtkPV3Foam::GetDataSetFromBlock +( + vtkMultiBlockDataSet* output, + unsigned int blockNo, + unsigned int datasetNo +) +{ + vtkDataObject* blockDO = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + if (block) + { + return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo)); + } + + return 0; +} + + +Foam::label Foam::vtkPV3Foam::GetNumberOfDataSets +( + vtkMultiBlockDataSet* output, + unsigned int blockNo +) +{ + vtkDataObject* blockDO = output->GetBlock(blockNo); + vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO); + if (block) + { + return block->GetNumberOfBlocks(); + } + + return 0; +} + + void Foam::vtkPV3Foam::resetCounters() { // Reset data size counts @@ -481,11 +545,11 @@ void Foam::vtkPV3Foam::Update if (debug) { Info<< "Number of data sets after update" << nl - << " VOLUME = " << output->GetNumberOfDataSets(VOLUME) << nl - << " LAGRANGIAN = " << output->GetNumberOfDataSets(LAGRANGIAN) - << nl << " CELLSET = " << output->GetNumberOfDataSets(CELLSET) - << nl << " FACESET = " << output->GetNumberOfDataSets(FACESET) - << nl << " POINTSET = " << output->GetNumberOfDataSets(POINTSET) + << " VOLUME = " << GetNumberOfDataSets(output, VOLUME) << nl + << " LAGRANGIAN = " << GetNumberOfDataSets(output, LAGRANGIAN) + << nl << " CELLSET = " << GetNumberOfDataSets(output, CELLSET) + << nl << " FACESET = " << GetNumberOfDataSets(output, FACESET) + << nl << " POINTSET = " << GetNumberOfDataSets(output, POINTSET) << endl; } } diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H index 21d02e4..8657a9b 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3Foam.H @@ -23,7 +23,7 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::vtkPV3Foam + vtkPV3Foam Description @@ -65,6 +65,7 @@ SourceFiles // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // class vtkDataArraySelection; +class vtkDataSet; class vtkMultiBlockDataSet; class vtkPoints; class vtkPV3FoamReader; @@ -188,6 +189,33 @@ class vtkPV3Foam // Private Member Functions + // Convenience method use to convert the readers from VTK 5 + // multiblock API to the current composite data infrastructure + void AddToBlock + ( + vtkMultiBlockDataSet* output, + unsigned int blockNo, + unsigned int datasetNo, + vtkDataSet* dataset + ); + + // Convenience method use to convert the readers from VTK 5 + // multiblock API to the current composite data infrastructure + vtkDataSet* GetDataSetFromBlock + ( + vtkMultiBlockDataSet* output, + unsigned int blockNo, + unsigned int datasetNo + ); + + // Convenience method use to convert the readers from VTK 5 + // multiblock API to the current composite data infrastructure + label GetNumberOfDataSets + ( + vtkMultiBlockDataSet* output, + unsigned int blockNo + ); + //- Reset data counters void resetCounters(); diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddFields.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddFields.H index 357e260..4cf4829 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddFields.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamAddFields.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertLagrangianFields.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertLagrangianFields.H index c52e3d6..9de17ee 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertLagrangianFields.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertLagrangianFields.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ @@ -102,7 +102,7 @@ void Foam::vtkPV3Foam::convertLagrangianField { vtkUnstructuredGrid* lagrangianMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(LAGRANGIAN, 0) + GetDataSetFromBlock(output, LAGRANGIAN, 0) ); vtkFloatArray *pointTypes = vtkFloatArray::New(); @@ -144,7 +144,7 @@ void Foam::vtkPV3Foam::convertLagrangianField { vtkUnstructuredGrid* lagrangianMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(LAGRANGIAN, 0) + GetDataSetFromBlock(output, LAGRANGIAN, 0) ); vtkFloatArray *pointScalars = vtkFloatArray::New(); diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertMesh.C b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertMesh.C index 95a0797..2edace9 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertMesh.C +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertMesh.C @@ -65,7 +65,8 @@ void Foam::vtkPV3Foam::convertMeshVolume vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New(); SetName(ugrid, "internalMesh"); addVolumeMesh(mesh, ugrid, superCells_); - output->SetDataSet(VOLUME, 0, ugrid); + AddToBlock(output, VOLUME, 0, ugrid); +// reader_->SetBlock(output->GetNumberOfBlocks(), ugrid); selectedRegionDatasetIds_[VOLUME] = 0; ugrid->Delete(); } @@ -96,7 +97,7 @@ void Foam::vtkPV3Foam::convertMeshLagrangian vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New(); addLagrangianMesh(mesh, ugrid); - output->SetDataSet(LAGRANGIAN, 0, ugrid); + AddToBlock(output, LAGRANGIAN, 0, ugrid); selectedRegionDatasetIds_[LAGRANGIAN] = 0; ugrid->Delete(); } @@ -141,8 +142,8 @@ void Foam::vtkPV3Foam::convertMeshPatches const label patchId = mesh.boundaryMesh() .findPatchID(regionName); addPatchMesh(patches[patchId], ugrid); - const label nextId = output->GetNumberOfDataSets(VOLUME); - output->SetDataSet(VOLUME, nextId, ugrid); + const label nextId = GetNumberOfDataSets(output, VOLUME); + AddToBlock(output, VOLUME, nextId, ugrid); selectedRegionDatasetIds_[i] = nextId; ugrid->Delete(); } @@ -188,14 +189,14 @@ void Foam::vtkPV3Foam::convertMeshCellSet vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New(); SetName(ugrid, cSetName.c_str()); - const label nextId = output->GetNumberOfDataSets(CELLSET); + const label nextId = GetNumberOfDataSets(output, CELLSET); addVolumeMesh ( subsetter.subMesh(), ugrid, superCellSetCells_[nextId] ); - output->SetDataSet(CELLSET, nextId, ugrid); + AddToBlock(output, CELLSET, nextId, ugrid); selectedRegionDatasetIds_[i] = nextId; ugrid->Delete(); } @@ -245,8 +246,8 @@ void Foam::vtkPV3Foam::convertMeshFaceSet fSet, ugrid ); - const label nextId = output->GetNumberOfDataSets(FACESET); - output->SetDataSet(FACESET, nextId, ugrid); + const label nextId = GetNumberOfDataSets(output, FACESET); + AddToBlock(output, FACESET, nextId, ugrid); selectedRegionDatasetIds_[i] = nextId; ugrid->Delete(); } @@ -296,8 +297,8 @@ void Foam::vtkPV3Foam::convertMeshPointSet pSet, ugrid ); - const label nextId = output->GetNumberOfDataSets(POINTSET); - output->SetDataSet(POINTSET, nextId, ugrid); + label nextId = GetNumberOfDataSets(output, POINTSET); + AddToBlock(output, POINTSET, nextId, ugrid); selectedRegionDatasetIds_[i] = nextId; ugrid->Delete(); } diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchFaceField.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchFaceField.H index 938455e..db24e17 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchFaceField.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchFaceField.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ @@ -49,7 +49,7 @@ void Foam::vtkPV3Foam::convertPatchFaceField { vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, regioni) + GetDataSetFromBlock(output, VOLUME, regioni) ); vtkFloatArray *cellTypes = vtkFloatArray::New(); @@ -87,7 +87,7 @@ void Foam::vtkPV3Foam::convertPatchFaceField { vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, regioni) + GetDataSetFromBlock(output, VOLUME, regioni) ); vtkFloatArray *cellScalars = vtkFloatArray::New(); diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchPointField.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchPointField.H index 50c258d..2ec93df 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchPointField.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPatchPointField.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ @@ -46,7 +46,7 @@ void Foam::vtkPV3Foam::convertPatchPointField { vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, regioni) + GetDataSetFromBlock(output, VOLUME, regioni) ); vtkFloatArray *pointTypes = vtkFloatArray::New(); @@ -83,7 +83,7 @@ void Foam::vtkPV3Foam::convertPatchPointField { vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, regioni) + GetDataSetFromBlock(output, VOLUME, regioni) ); vtkFloatArray *pointScalars = vtkFloatArray::New(); diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPointFields.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPointFields.H index 19777cc..4e6fe75 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPointFields.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertPointFields.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ @@ -130,7 +130,7 @@ void Foam::vtkPV3Foam::convertPointField { vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, 0) + GetDataSetFromBlock(output, VOLUME, 0) ); vtkFloatArray *pointTypes = vtkFloatArray::New(); @@ -197,7 +197,7 @@ void Foam::vtkPV3Foam::convertPointField { vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, 0) + GetDataSetFromBlock(output, VOLUME, 0) ); vtkFloatArray *pointScalars = vtkFloatArray::New(); diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertVolFields.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertVolFields.H index f4520f0..e27af75 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertVolFields.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamConvertVolFields.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ @@ -177,10 +177,10 @@ void Foam::vtkPV3Foam::convertVolField { vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, 0) + GetDataSetFromBlock(output, VOLUME, 0) ); - vtkFloatArray *cellTypes = vtkFloatArray::New(); + vtkFloatArray* cellTypes = vtkFloatArray::New(); cellTypes->SetNumberOfTuples(superCells_.size()); cellTypes->SetNumberOfComponents(Type::nComponents); cellTypes->Allocate(Type::nComponents*superCells_.size()); @@ -220,7 +220,7 @@ void Foam::vtkPV3Foam::convertVolField { vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast ( - output->GetDataSet(VOLUME, 0) + GetDataSetFromBlock(output, VOLUME, 0) ); vtkFloatArray *cellScalars = vtkFloatArray::New(); diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamInsertNextPoint.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamInsertNextPoint.H index 307fc81..107296e 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamInsertNextPoint.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamInsertNextPoint.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ diff --git a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInformationFields.H b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInformationFields.H index fc32fc2..da6f766 100644 --- a/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInformationFields.H +++ b/src/paraview-plugins/PV3FoamReader/vtkPV3Foam/vtkPV3FoamUpdateInformationFields.H @@ -22,8 +22,8 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -InClass - Foam::vtkPV3Foam +Class + vtkPV3Foam \*---------------------------------------------------------------------------*/ -- GitLab