From ff54ef8299d93a9680def9b69963706b823e30cc Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 3 Feb 2019 17:24:26 +0100 Subject: [PATCH] ENH: additional vtk::Tools methods for handling faces, points etc. - includes initial relocation of low-level vtu handling. Extracted, refactored from the Catalyst function object. --- .../graphics/PVReaders/vtkPVFoam/vtkPVFoam.C | 89 +++----- .../graphics/PVReaders/vtkPVFoam/vtkPVFoam.H | 47 +---- .../vtkPVFoam/vtkPVFoamFieldTemplates.C | 53 +---- .../PVReaders/vtkPVFoam/vtkPVFoamFields.C | 7 +- .../PVReaders/vtkPVFoam/vtkPVFoamMesh.C | 119 +++-------- .../vtkPVFoam/vtkPVFoamMeshLagrangian.C | 7 +- .../PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C | 185 +---------------- .../PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C | 107 +++------- .../vtkPVFoam/vtkPVFoamUpdateTemplates.C | 19 +- .../PVReaders/vtkPVblockMesh/vtkPVblockMesh.C | 69 ++----- .../vtkPVblockMesh/vtkPVblockMeshConvert.C | 26 +-- src/conversion/vtk/adaptor/foamVtkTools.H | 32 ++- src/conversion/vtk/adaptor/foamVtkToolsI.H | 57 +++++- .../vtk/adaptor/foamVtkToolsTemplates.C | 70 ++++--- .../vtk/adaptor/foamVtkVtuAdaptor.H | 167 +++++++++++++++ .../vtk/adaptor/foamVtkVtuAdaptorI.H | 192 ++++++++++++++++++ .../vtk/adaptor/foamVtkVtuAdaptorTemplates.C | 105 ++++++++++ 17 files changed, 731 insertions(+), 620 deletions(-) create mode 100644 src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H create mode 100644 src/conversion/vtk/adaptor/foamVtkVtuAdaptorI.H create mode 100644 src/conversion/vtk/adaptor/foamVtkVtuAdaptorTemplates.C diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C index 57562b8e7a..01b7a5ff42 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2005-2010, 2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -251,13 +251,11 @@ int Foam::vtkPVFoam::setTime(const std::vector& requestTimes) updateInfo(); } - if (debug) - { - Info<< " setTime() - selectedTime=" - << Times[nearestIndex].name() << " index=" << timeIndex_ - << "/" << Times.size() - << " meshUpdateState=" << updateStateName(meshState_) << nl; - } + DebugInfo + << " setTime() - selectedTime=" + << Times[nearestIndex].name() << " index=" << timeIndex_ + << "/" << Times.size() + << " meshUpdateState=" << updateStateName(meshState_) << nl; return nearestIndex; } @@ -376,13 +374,11 @@ Foam::vtkPVFoam::vtkPVFoam } } - if (debug) - { - Info<< "fullCasePath=" << fullCasePath << nl - << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl - << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl - << "region=" << meshRegion_ << nl; - } + DebugInfo + << "fullCasePath=" << fullCasePath << nl + << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl + << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl + << "region=" << meshRegion_ << nl; // Create time object dbPtr_.reset @@ -405,10 +401,7 @@ Foam::vtkPVFoam::vtkPVFoam Foam::vtkPVFoam::~vtkPVFoam() { - if (debug) - { - Info<< "~vtkPVFoam" << nl; - } + DebugInfo << "~vtkPVFoam" << nl; delete volMeshPtr_; delete areaMeshPtr_; @@ -419,13 +412,11 @@ Foam::vtkPVFoam::~vtkPVFoam() void Foam::vtkPVFoam::updateInfo() { - if (debug) - { - Info<< " updateInfo" - << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "nullptr") - << "] timeIndex=" - << timeIndex_ << nl; - } + DebugInfo + << " updateInfo" + << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "nullptr") + << "] timeIndex=" + << timeIndex_ << nl; resetCounters(); @@ -475,10 +466,7 @@ void Foam::vtkPVFoam::updateInfo() // Lagrangian fields - includes save/restore of selected updateInfoLagrangianFields(reader_->GetLagrangianFieldSelection()); - if (debug) - { - Info<< " updateInfo" << nl; - } + DebugInfo << " updateInfo" << nl; } @@ -584,11 +572,9 @@ void Foam::vtkPVFoam::Update // Check to see if the OpenFOAM mesh has been created if (!volMeshPtr_) { - if (debug) - { - Info<< "Creating OpenFOAM mesh for region " << meshRegion_ - << " at time=" << dbPtr_().timeName() << nl; - } + DebugInfo + << "Creating OpenFOAM mesh for region " << meshRegion_ + << " at time=" << dbPtr_().timeName() << nl; volMeshPtr_ = new fvMesh ( @@ -605,10 +591,7 @@ void Foam::vtkPVFoam::Update } else { - if (debug) - { - Info<< "Using existing OpenFOAM mesh" << nl; - } + DebugInfo << "Using existing OpenFOAM mesh" << nl; } if (rangeArea_.intersects(selectedPartIds_)) @@ -684,10 +667,7 @@ void Foam::vtkPVFoam::Update rangeClouds_ ); - if (debug) - { - Info<< "done reader part" << nl << nl; - } + DebugInfo << "done reader part" << nl << nl; reader_->UpdateProgress(0.95); meshState_ = polyMesh::UNCHANGED; @@ -902,19 +882,14 @@ void Foam::vtkPVFoam::renderPatchNames displayZoneI += min(MAXPATCHZONES, nZones[patchi]); } - if (debug) - { - Info<< "displayed zone centres = " << displayZoneI << nl - << "zones per patch = " << nZones << nl; - } + DebugInfo + << "displayed zone centres = " << displayZoneI << nl + << "zones per patch = " << nZones << nl; // Set the size of the patch labels to max number of zones patchTextActors_.setSize(displayZoneI); - if (debug) - { - Info<< "constructing patch labels" << nl; - } + DebugInfo << "constructing patch labels" << nl; // Actor index displayZoneI = 0; @@ -934,12 +909,10 @@ void Foam::vtkPVFoam::renderPatchNames label globalZoneI = 0; for (label i = 0; i < nDisplayZones; ++i, globalZoneI += increment) { - if (debug) - { - Info<< "patch name = " << pp.name() << nl - << "anchor = " << zoneCentre[patchi][globalZoneI] << nl - << "globalZoneI = " << globalZoneI << nl; - } + DebugInfo + << "patch name = " << pp.name() << nl + << "anchor = " << zoneCentre[patchi][globalZoneI] << nl + << "globalZoneI = " << globalZoneI << nl; // Into a list for later removal patchTextActors_[displayZoneI++] = createTextActor diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H index 58d60103a1..01c05108e6 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2005-2010, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -74,13 +74,7 @@ SourceFiles #include "PrimitivePatchInterpolation.H" #include "volPointInterpolation.H" #include "foamPvCore.H" -#include "foamVtkTools.H" -#include "foamVtkMeshMaps.H" - -#include "vtkPoints.h" -#include "vtkPolyData.h" -#include "vtkSmartPointer.h" -#include "vtkUnstructuredGrid.h" +#include "foamVtkVtuAdaptor.H" // * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // @@ -89,7 +83,6 @@ class vtkDataArraySelection; class vtkDataSet; class vtkFloatArray; class vtkIndent; -class vtkMultiBlockDataSet; class vtkPVFoamReader; class vtkRenderer; class vtkTextActor; @@ -99,7 +92,7 @@ class vtkTextActor; namespace Foam { -// OpenFOAM class forward declarations +// Forward declarations (OpenFOAM) class argList; class Time; class faMesh; @@ -133,35 +126,13 @@ class vtkPVFoam //- Bookkeeping for vtkUnstructuredGrid struct foamVtuData : - public vtk::Caching, - public foamVtkMeshMaps + public vtk::vtuAdaptor { - //- The vtk points for the mesh (and decomposition) - vtkSmartPointer points - ( - const fvMesh& mesh - ) const; - - //- The vtk points for the mesh (and decomposition), - //- using the provided pointMap - vtkSmartPointer points - ( - const fvMesh& mesh, - const labelUList& pointMap - ) const; - - //- Internal mesh as vtkUnstructuredGrid - vtkSmartPointer internal - ( - const fvMesh& mesh, - const bool decompPoly - ); - //- Subsetted mesh as vtkUnstructuredGrid vtkSmartPointer subset ( const fvMeshSubset& subsetter, - const bool decompPoly + bool decompPoly = false ); }; @@ -348,14 +319,6 @@ class vtkPVFoam const labelUList& faceLabels ) const; - //- Volume field - template - vtkSmartPointer convertVolFieldToVTK - ( - const GeometricField& fld, - const foamVtuData& vtuData - ) const; - //- Convert finite volume fields void convertVolFields(); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C index a9a6f20694..aa4b12545c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -68,8 +68,7 @@ void Foam::vtkPVFoam::convertVolField autoPtr> ptfPtr; if (interpField) { - DebugInfo - << "convertVolField interpolating:" << fld.name() << nl; + DebugInfo << "convertVolField interpolating:" << fld.name() << nl; ptfPtr.reset ( @@ -415,22 +414,17 @@ void Foam::vtkPVFoam::convertVolFieldBlock foamVtuData& vtuData = iter.val(); auto dataset = vtuData.dataset; - vtkSmartPointer cdata = convertVolFieldToVTK + dataset->GetCellData()->AddArray ( - fld, - vtuData + vtuData.convertField(fld) ); - dataset->GetCellData()->AddArray(cdata); if (ptfPtr.valid()) { - vtkSmartPointer pdata = convertPointField + dataset->GetPointData()->AddArray ( - ptfPtr(), - fld, - vtuData + convertPointField(*ptfPtr, fld, vtuData) ); - dataset->GetPointData()->AddArray(pdata); } } } @@ -547,8 +541,7 @@ void Foam::vtkPVFoam::convertPointFields continue; } - DebugInfo - << "convertPointFields : " << fieldName << nl; + DebugInfo << "convertPointFields : " << fieldName << nl; // Throw FatalError, FatalIOError as exceptions const bool throwingError = FatalError.throwExceptions(); @@ -899,40 +892,6 @@ Foam::vtkPVFoam::convertFaceFieldToVTK } -template -vtkSmartPointer -Foam::vtkPVFoam::convertVolFieldToVTK -( - const GeometricField& fld, - const foamVtuData& vtuData -) const -{ - const labelUList& cellMap = vtuData.cellMap(); - - auto data = vtkSmartPointer::New(); - data->SetName(fld.name().c_str()); - data->SetNumberOfComponents(static_cast(pTraits::nComponents)); - data->SetNumberOfTuples(cellMap.size()); - - DebugInfo - << "Convert volField: " << fld.name() << " size=" - << cellMap.size() << " (field " - << fld.size() << ") nComp=" - << static_cast(pTraits::nComponents) << nl; - - float scratch[pTraits::nComponents]; - - vtkIdType celli = 0; - for (const label meshCelli : cellMap) - { - vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]); - data->SetTuple(celli++, scratch); - } - - return data; -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C index 62c382a898..b6b445a019 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2005-2010, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -130,10 +130,7 @@ void Foam::vtkPVFoam::convertPointFields() if (selectedFields.empty()) { - if (debug) - { - Info<< "no point fields selected" << nl; - } + DebugInfo << "no point fields selected" << nl; return; } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C index ba360a3b47..5dab7c04fe 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2005-2010, 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -69,19 +69,13 @@ void Foam::vtkPVFoam::convertMeshVolume() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo << "reuse " << longName << nl; vtuData.reuse(); // reuse continue; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo << "move points " << longName << nl; vtkgeom = vtuData.getCopy(); vtkgeom->SetPoints(vtuData.points(mesh)); } @@ -163,10 +157,7 @@ void Foam::vtkPVFoam::convertMeshPatches() if (meshState_ == polyMesh::UNCHANGED) { // Without movement is easy. - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo << "reuse " << longName << nl; vtpData.reuse(); continue; } @@ -196,11 +187,9 @@ void Foam::vtkPVFoam::convertMeshPatches() const labelList& patchIds = patches.groupPatchIDs().lookup(partName, labelList()); - if (debug) - { - Info<< "Creating VTK mesh for patches [" << patchIds <<"] " - << longName << nl; - } + DebugInfo + << "Creating VTK mesh for patches [" << patchIds <<"] " + << longName << nl; // Store good patch ids as additionalIds vtpData.additionalIds().reserve(patchIds.size()); @@ -250,11 +239,9 @@ void Foam::vtkPVFoam::convertMeshPatches() const label patchId = patches.findPatchID(partName); - if (debug) - { - Info<< "Creating VTK mesh for patch [" << patchId <<"] " - << partName << nl; - } + DebugInfo + << "Creating VTK mesh for patch [" << patchId <<"] " + << partName << nl; if (patchId >= 0) { @@ -324,19 +311,13 @@ void Foam::vtkPVFoam::convertMeshArea() // { // if (meshState_ == polyMesh::UNCHANGED) // { -// if (debug) -// { -// Info<< "reuse " << longName << nl; -// } +// DebugInfo << "reuse " << longName << nl; // vtpData.reuse(); // reuse // continue; // } // else if (meshState_ == polyMesh::POINTS_MOVED) // { -// if (debug) -// { -// Info<< "move points " << longName << nl; -// } +// DebugInfo << "move points " << longName << nl; // vtkgeom = vtpData.getCopy(); // vtkgeom->SetPoints(movePoints(mesh, vtpData)); // } @@ -392,11 +373,9 @@ void Foam::vtkPVFoam::convertMeshCellZones() continue; } - if (debug) - { - Info<< "Creating VTK mesh for cellZone[" << zoneId << "] " - << zoneName << nl; - } + DebugInfo + << "Creating VTK mesh for cellZone[" << zoneId << "] " + << zoneName << nl; foamVtuData& vtuData = cachedVtu_(longName); @@ -405,19 +384,13 @@ void Foam::vtkPVFoam::convertMeshCellZones() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo << "reuse " << longName << nl; vtuData.reuse(); continue; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo << "move points " << longName << nl; vtkgeom = vtuData.getCopy(); vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap())); } @@ -459,10 +432,7 @@ void Foam::vtkPVFoam::convertMeshCellSets() const auto& longName = selectedPartIds_[partId]; const word partName = getFoamName(longName); - if (debug) - { - Info<< "Creating VTK mesh for cellSet=" << partName << nl; - } + DebugInfo << "Creating VTK mesh for cellSet=" << partName << nl; foamVtuData& vtuData = cachedVtu_(longName); @@ -471,19 +441,13 @@ void Foam::vtkPVFoam::convertMeshCellSets() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reuse " << longName << nl; - } + DebugInfo << "reuse " << longName << nl; vtuData.reuse(); continue; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo << "move points " << longName << nl; vtkgeom = vtuData.getCopy(); vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap())); } @@ -536,11 +500,9 @@ void Foam::vtkPVFoam::convertMeshFaceZones() { continue; } - if (debug) - { - Info<< "Creating VTKmesh for faceZone[" << zoneId << "] " - << zoneName << nl; - } + DebugInfo + << "Creating VTKmesh for faceZone[" << zoneId << "] " + << zoneName << nl; foamVtpData& vtpData = cachedVtp_(longName); @@ -550,10 +512,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones() if (meshState_ == polyMesh::UNCHANGED) { // Without movement is easy. - if (debug) - { - Info<<"reuse " << longName << nl; - } + DebugInfo <<"reuse " << longName << nl; vtpData.reuse(); continue; } @@ -600,10 +559,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets() const auto& longName = selectedPartIds_[partId]; const word partName = getFoamName(longName); - if (debug) - { - Info<< "Creating VTK mesh for faceSet=" << partName << nl; - } + DebugInfo << "Creating VTK mesh for faceSet=" << partName << nl; foamVtpData& vtpData = cachedVtp_(longName); @@ -613,10 +569,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets() if (meshState_ == polyMesh::UNCHANGED) { // Without movement is easy. - if (debug) - { - Info<<"reuse " << longName << nl; - } + DebugInfo <<"reuse " << longName << nl; vtpData.reuse(); continue; } @@ -700,19 +653,13 @@ void Foam::vtkPVFoam::convertMeshPointZones() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reusing " << longName << nl; - } + DebugInfo << "reusing " << longName << nl; vtpData.reuse(); continue; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo << "move points " << longName << nl; vtkgeom = vtpData.getCopy(); } } @@ -772,19 +719,13 @@ void Foam::vtkPVFoam::convertMeshPointSets() { if (meshState_ == polyMesh::UNCHANGED) { - if (debug) - { - Info<< "reusing " << longName << nl; - } + DebugInfo << "reusing " << longName << nl; vtpData.reuse(); continue; } else if (meshState_ == polyMesh::POINTS_MOVED) { - if (debug) - { - Info<< "move points " << longName << nl; - } + DebugInfo << "move points " << longName << nl; vtkgeom = vtpData.getCopy(); } } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C index 7b78e15f17..e2a6cbecf5 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshLagrangian.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011, 2017-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -73,10 +73,7 @@ vtkSmartPointer Foam::vtkPVFoam::lagrangianVTKMesh { Cloud parcels(mesh, cloudName, false); - if (debug) - { - Info<< "cloud with " << parcels.size() << " parcels" << nl; - } + DebugInfo << "cloud with " << parcels.size() << " parcels" << nl; auto vtkpoints = vtkSmartPointer::New(); vtkpoints->SetNumberOfPoints(parcels.size()); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C index 28d304f51c..5c6656c6c1 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,198 +24,23 @@ License \*---------------------------------------------------------------------------*/ #include "vtkPVFoam.H" -#include "vtkPVFoamReader.h" - -// OpenFOAM includes -#include "fvMesh.H" #include "fvMeshSubset.H" -#include "foamVtkTools.H" -#include "foamVtuSizing.H" - -// VTK includes -#include // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points -( - const fvMesh& mesh -) const -{ - // Convert OpenFOAM mesh vertices to VTK - auto vtkpoints = vtkSmartPointer::New(); - - // Normal points - const pointField& pts = mesh.points(); - - // Additional cell centres - const labelUList& addPoints = this->additionalIds(); - - vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size()); - - // Normal points - vtkIdType pointId = 0; - for (const point& p : pts) - { - vtkpoints->SetPoint(pointId++, p.v_); - } - - // Cell centres - for (const label meshCelli : addPoints) - { - vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); - } - - return vtkpoints; -} - - -vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points -( - const fvMesh& mesh, - const labelUList& pointMap -) const -{ - // Convert OpenFOAM mesh vertices to VTK - auto vtkpoints = vtkSmartPointer::New(); - - // Normal points - const pointField& pts = mesh.points(); - - // Additional cell centres - const labelUList& addPoints = this->additionalIds(); - - vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size()); - - // Normal points - vtkIdType pointId = 0; - for (const label meshPointi : pointMap) - { - vtkpoints->SetPoint(pointId++, pts[meshPointi].v_); - } - - // Cell centres - for (const label meshCelli : addPoints) - { - vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); - } - - return vtkpoints; -} - - -vtkSmartPointer Foam::vtkPVFoam::foamVtuData::internal -( - const fvMesh& mesh, - const bool decompPoly -) -{ - vtk::vtuSizing sizing(mesh, decompPoly); - - auto cellTypes = vtkSmartPointer::New(); - - auto cells = vtkSmartPointer::New(); - auto faces = vtkSmartPointer::New(); - - auto cellLocations = vtkSmartPointer::New(); - auto faceLocations = vtkSmartPointer::New(); - - UList cellTypesUL = - vtk::Tools::asUList - ( - cellTypes, - sizing.nFieldCells() - ); - - UList cellsUL = - vtk::Tools::asUList - ( - cells, - sizing.nFieldCells(), - sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS) - ); - - UList cellLocationsUL = - vtk::Tools::asUList - ( - cellLocations, - sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS) - ); - - UList facesUL = - vtk::Tools::asUList - ( - faces, - sizing.sizeInternal(vtk::vtuSizing::slotType::FACES) - ); - - UList faceLocationsUL = - vtk::Tools::asUList - ( - faceLocations, - sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS) - ); - - - sizing.populateInternal - ( - mesh, - cellTypesUL, - cellsUL, - cellLocationsUL, - facesUL, - faceLocationsUL, - static_cast(*this) - ); - - auto vtkmesh = vtkSmartPointer::New(); - - // Convert OpenFOAM mesh vertices to VTK - // - can only do this *after* populating the decompInfo with cell-ids - // for any additional points (ie, mesh cell-centres) - vtkmesh->SetPoints(this->points(mesh)); - - if (facesUL.size()) - { - vtkmesh->SetCells - ( - cellTypes, - cellLocations, - cells, - faceLocations, - faces - ); - } - else - { - vtkmesh->SetCells - ( - cellTypes, - cellLocations, - cells, - nullptr, - nullptr - ); - } - - return vtkmesh; -} - - vtkSmartPointer Foam::vtkPVFoam::foamVtuData::subset ( const fvMeshSubset& subsetter, - const bool decompPoly + bool decompPoly ) { - vtkSmartPointer vtkmesh = - this->internal(subsetter.subMesh(), decompPoly); + auto vtkmesh = internal(subsetter.subMesh(), decompPoly); // Convert cellMap, addPointCellLabels to global cell ids - this->renumberCells(subsetter.cellMap()); + renumberCells(subsetter.cellMap()); // Copy pointMap as well, otherwise pointFields fail - this->pointMap() = subsetter.pointMap(); + pointMap() = subsetter.pointMap(); return vtkmesh; } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C index 6ea2fcec04..e1ea02a4e6 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C @@ -148,20 +148,14 @@ void Foam::vtkPVFoam::updateInfoInternalMesh vtkDataArraySelection* select ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; // Determine mesh parts (internalMesh, patches...) // Add internal mesh as first entry rangeVolume_.reset(select->GetNumberOfArrays(), 1); select->AddArray("internalMesh"); - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -170,10 +164,7 @@ void Foam::vtkPVFoam::updateInfoAreaMesh vtkDataArraySelection* select ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; rangeArea_.reset(select->GetNumberOfArrays(), 0); @@ -198,10 +189,7 @@ void Foam::vtkPVFoam::updateInfoAreaMesh select->AddArray("areaMesh"); } - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -210,11 +198,9 @@ void Foam::vtkPVFoam::updateInfoLagrangian vtkDataArraySelection* select ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl - << " " << dbPtr_->timePath()/cloud::prefix << nl; - } + DebugInfo + << " " << FUNCTION_NAME << nl + << " " << dbPtr_->timePath()/cloud::prefix << nl; // Use the db directly since this might be called without a mesh, // but the region must get added back in @@ -245,10 +231,7 @@ void Foam::vtkPVFoam::updateInfoLagrangian rangeClouds_.reset(select->GetNumberOfArrays()); rangeClouds_ += addToArray(select, "lagrangian/", names.sortedToc()); - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -258,11 +241,9 @@ void Foam::vtkPVFoam::updateInfoPatches HashSet& enabledEntries ) { - if (debug) - { - Info<< " " << FUNCTION_NAME - << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl; - } + DebugInfo + << " " << FUNCTION_NAME + << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl; rangePatches_.reset(select->GetNumberOfArrays()); @@ -436,10 +417,7 @@ void Foam::vtkPVFoam::updateInfoPatches } } - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -453,11 +431,9 @@ void Foam::vtkPVFoam::updateInfoZones return; } - if (debug) - { - Info<< " " << FUNCTION_NAME - << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl; - } + DebugInfo + << " " << FUNCTION_NAME + << " [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" << nl; // cellZones { @@ -498,10 +474,7 @@ void Foam::vtkPVFoam::updateInfoZones rangePointZones_ += addToArray(select, "pointZone/", names); } - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -515,10 +488,7 @@ void Foam::vtkPVFoam::updateInfoSets return; } - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; // Add names of sets. Search for last time directory with a sets // subdirectory. Take care not to search beyond the last mesh. @@ -540,11 +510,9 @@ void Foam::vtkPVFoam::updateInfoSets const IOobjectList objects(dbPtr_(), setsInstance, meshDir_/"sets"); - if (debug) - { - Info<< " updateInfoSets read " - << objects.names() << " from " << setsInstance << nl; - } + DebugInfo + << " updateInfoSets read " + << objects.names() << " from " << setsInstance << nl; rangeCellSets_.reset(select->GetNumberOfArrays()); @@ -571,10 +539,7 @@ void Foam::vtkPVFoam::updateInfoSets objects ); - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -583,10 +548,7 @@ void Foam::vtkPVFoam::updateInfoContinuumFields vtkDataArraySelection* select ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; // Preserve the enabled selections HashSet enabled; @@ -618,10 +580,7 @@ void Foam::vtkPVFoam::updateInfoContinuumFields setSelectedArrayEntries(select, enabled); // Adjust/restore selected - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -630,10 +589,7 @@ void Foam::vtkPVFoam::updateInfoPointFields vtkDataArraySelection* select ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; // Preserve the enabled selections HashSet enabled = getSelectedArraySet(select); @@ -655,10 +611,7 @@ void Foam::vtkPVFoam::updateInfoPointFields setSelectedArrayEntries(select, enabled); // Adjust/restore selected - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } @@ -667,10 +620,7 @@ void Foam::vtkPVFoam::updateInfoLagrangianFields vtkDataArraySelection* select ) { - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; // Preserve the enabled selections HashSet enabled = getSelectedArraySet(select); @@ -733,10 +683,7 @@ void Foam::vtkPVFoam::updateInfoLagrangianFields // Restore the enabled selections setSelectedArrayEntries(select, enabled); - if (debug) - { - Info<< " " << FUNCTION_NAME << nl; - } + DebugInfo << " " << FUNCTION_NAME << nl; } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateTemplates.C index fb02cbdd30..baf0396f07 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamUpdateTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -40,13 +40,11 @@ void Foam::vtkPVFoam::updateInfoFields const IOobjectList& objects ) { - if (debug) - { - Info<< " updateInfoFields <" - << meshType::Mesh::typeName - << "> [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" - << nl; - } + DebugInfo + << " updateInfoFields <" + << meshType::Mesh::typeName + << "> [volMeshPtr=" << (volMeshPtr_ ? "set" : "null") << "]" + << nl; // Add geometric fields (volume/area) to GUI addToSelection> @@ -102,10 +100,7 @@ void Foam::vtkPVFoam::updateInfoFields objects ); - if (debug) - { - Info<< " updateInfoFields" << nl; - } + DebugInfo << " updateInfoFields" << nl; } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMesh.C index 5a1b8b8dd1..08ea9cfe98 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMesh.C @@ -101,11 +101,9 @@ void Foam::vtkPVblockMesh::updateInfoBlocks vtkDataArraySelection* select ) { - if (debug) - { - Info<< " updateInfoBlocks" - << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; - } + DebugInfo + << " updateInfoBlocks" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; rangeBlocks_.reset(select->GetNumberOfArrays()); @@ -132,10 +130,7 @@ void Foam::vtkPVblockMesh::updateInfoBlocks ++rangeBlocks_; } - if (debug) - { - Info<< " updateInfoBlocks" << endl; - } + DebugInfo << " updateInfoBlocks" << endl; } @@ -144,11 +139,9 @@ void Foam::vtkPVblockMesh::updateInfoEdges vtkDataArraySelection* select ) { - if (debug) - { - Info<< " updateInfoEdges" - << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; - } + DebugInfo + << " updateInfoEdges" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "]" << endl; rangeEdges_.reset(select->GetNumberOfArrays()); @@ -168,10 +161,7 @@ void Foam::vtkPVblockMesh::updateInfoEdges ++rangeEdges_; } - if (debug) - { - Info<< " updateInfoEdges" << endl; - } + DebugInfo << " updateInfoEdges" << endl; } @@ -192,10 +182,7 @@ Foam::vtkPVblockMesh::vtkPVblockMesh rangeEdges_("edges"), rangeCorners_("corners") { - if (debug) - { - Info<< "vtkPVblockMesh - " << FileName << endl; - } + DebugInfo << "vtkPVblockMesh - " << FileName << endl; // avoid argList and get rootPath/caseName directly from the file fileName fullCasePath(fileName(FileName).path()); @@ -256,12 +243,10 @@ Foam::vtkPVblockMesh::vtkPVblockMesh } } - if (debug) - { - Info<< "fullCasePath=" << fullCasePath << nl - << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl - << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << endl; - } + DebugInfo + << "fullCasePath=" << fullCasePath << nl + << "FOAM_CASE=" << getEnv("FOAM_CASE") << nl + << "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << endl; // Create time object dbPtr_.reset @@ -284,10 +269,7 @@ Foam::vtkPVblockMesh::vtkPVblockMesh Foam::vtkPVblockMesh::~vtkPVblockMesh() { - if (debug) - { - Info<< "~vtkPVblockMesh" << endl; - } + DebugInfo << "~vtkPVblockMesh" << endl; delete meshPtr_; } @@ -297,11 +279,9 @@ Foam::vtkPVblockMesh::~vtkPVblockMesh() void Foam::vtkPVblockMesh::updateInfo() { - if (debug) - { - Info<< " updateInfo" - << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "] " << endl; - } + DebugInfo + << " updateInfo" + << " [meshPtr=" << (meshPtr_ ? "set" : "null") << "] " << endl; resetCounters(); @@ -339,19 +319,13 @@ void Foam::vtkPVblockMesh::updateInfo() setSelectedArrayEntries(edgeSelection, enabledEdges); } - if (debug) - { - Info<< " updateInfo" << endl; - } + DebugInfo << " updateInfo" << endl; } void Foam::vtkPVblockMesh::updateFoamMesh() { - if (debug) - { - Info<< " updateFoamMesh" << endl; - } + DebugInfo << " updateFoamMesh" << endl; // Check to see if the OpenFOAM mesh has been created if (!meshPtr_) @@ -398,10 +372,7 @@ void Foam::vtkPVblockMesh::updateFoamMesh() } - if (debug) - { - Info<< " updateFoamMesh" << endl; - } + DebugInfo << " updateFoamMesh" << endl; } diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C index d685eec7aa..bae85c2f86 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVblockMesh/vtkPVblockMeshConvert.C @@ -51,10 +51,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks int& blockNo ) { - if (debug) - { - Info<< " convertMeshBlocks" << endl; - } + DebugInfo << " convertMeshBlocks" << endl; const Map blockStatus = getSelectedArrayMap ( @@ -118,10 +115,7 @@ void Foam::vtkPVblockMesh::convertMeshBlocks ++blockNo; } - if (debug) - { - Info<< " convertMeshBlocks" << endl; - } + DebugInfo << " convertMeshBlocks" << endl; } @@ -220,11 +214,7 @@ void Foam::vtkPVblockMesh::convertMeshEdges ++blockNo; } - if (debug) - { - Info<< " convertMeshEdges" << endl; - } - + DebugInfo << " convertMeshEdges" << endl; } @@ -240,10 +230,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners const pointField blkPoints(meshPtr_->vertices() * meshPtr_->scaleFactor()); - if (debug) - { - Info<< " " << FUNCTION_NAME << endl; - } + DebugInfo << " " << FUNCTION_NAME << endl; if (true) // Or some flag or other condition { @@ -270,10 +257,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners ++blockNo; } - if (debug) - { - Info<< " " << FUNCTION_NAME << endl; - } + DebugInfo << " " << FUNCTION_NAME << endl; } diff --git a/src/conversion/vtk/adaptor/foamVtkTools.H b/src/conversion/vtk/adaptor/foamVtkTools.H index 935c75801d..f9cb5c7bcd 100644 --- a/src/conversion/vtk/adaptor/foamVtkTools.H +++ b/src/conversion/vtk/adaptor/foamVtkTools.H @@ -48,6 +48,7 @@ SourceFiles #include "faceList.H" #include "pointField.H" #include "symmTensor.H" +#include "MinMax.H" // VTK includes #include "vtkCellArray.h" @@ -63,7 +64,7 @@ SourceFiles // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Forward declarations +// Forward Declarations class vtkDataSet; class vtkCellData; class vtkPointData; @@ -192,6 +193,27 @@ namespace Tools ); + //- Return a list of points as vtkPoints + inline vtkSmartPointer Points + ( + const UList& pts + ); + + //- Return an indirect list of points as vtkPoints + inline vtkSmartPointer Points + ( + const UList& pts, + const labelUList& addr + ); + + //- Convert a list of faces (or triFaces) to vtk polygon cells + template + vtkSmartPointer Faces(const UList& faces); + + //- Min/Max of scalar, or mag() of non-scalars. Includes nullptr check. + inline scalarMinMax rangeOf(vtkDataArray* data); + + //- Convert OpenFOAM patch to vtkPolyData struct Patch { @@ -214,6 +236,14 @@ namespace Tools //- Return patch face centres as vtkPoints template static vtkSmartPointer faceCentres(const PatchType& p); + + //- Convert points/faces component to vtkPolyData + template + static vtkSmartPointer mesh + ( + const UList& pts, + const UList& fcs + ); }; diff --git a/src/conversion/vtk/adaptor/foamVtkToolsI.H b/src/conversion/vtk/adaptor/foamVtkToolsI.H index e151f1a7d1..2be7434d1d 100644 --- a/src/conversion/vtk/adaptor/foamVtkToolsI.H +++ b/src/conversion/vtk/adaptor/foamVtkToolsI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -64,6 +64,61 @@ inline Foam::UList Foam::vtk::Tools::asUList } +inline vtkSmartPointer +Foam::vtk::Tools::Points(const UList& pts) +{ + auto vtkpoints = vtkSmartPointer::New(); + + vtkpoints->SetNumberOfPoints(pts.size()); + + vtkIdType pointId = 0; + for (const point& pt : pts) + { + vtkpoints->SetPoint(pointId++, pt.v_); + } + + return vtkpoints; +} + + +inline vtkSmartPointer +Foam::vtk::Tools::Points(const UList& pts, const labelUList& addr) +{ + auto vtkpoints = vtkSmartPointer::New(); + + vtkpoints->SetNumberOfPoints(addr.size()); + + vtkIdType pointId = 0; + for (const label pointi : addr) + { + vtkpoints->SetPoint(pointId++, pts[pointi].v_); + } + + return vtkpoints; +} + + +inline Foam::scalarMinMax Foam::vtk::Tools::rangeOf(vtkDataArray* data) +{ + double range[2]{GREAT, -GREAT}; + + if (data) + { + if (data->GetNumberOfComponents() == 1) + { + data->GetRange(range); + } + else + { + // Mag + data->GetRange(range, -1); + } + } + + return scalarMinMax(range[0], range[1]); +} + + inline vtkSmartPointer Foam::vtk::Tools::identityVertices ( const label size diff --git a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C index 0032964635..062ef09782 100644 --- a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C +++ b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C @@ -37,48 +37,24 @@ InNamespace // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template -vtkSmartPointer -Foam::vtk::Tools::Patch::points(const PatchType& p) -{ - // Local patch points to vtkPoints - const pointField& pts = p.localPoints(); - - auto vtkpoints = vtkSmartPointer::New(); - - vtkpoints->SetNumberOfPoints(pts.size()); - - vtkIdType pointId = 0; - for (const point& pt : pts) - { - vtkpoints->SetPoint(pointId++, pt.v_); - } - - return vtkpoints; -} - - -template +template vtkSmartPointer -Foam::vtk::Tools::Patch::faces(const PatchType& p) +Foam::vtk::Tools::Faces(const UList& faces) { - // List of faces or triFaces - const auto& fcs = p.localFaces(); - - label nAlloc = fcs.size(); - for (const auto& f : fcs) + label nAlloc = faces.size(); + for (const auto& f : faces) { nAlloc += f.size(); } auto vtkcells = vtkSmartPointer::New(); - UList list = asUList(vtkcells, fcs.size(), nAlloc); + UList list = asUList(vtkcells, faces.size(), nAlloc); // Cell connectivity for polygons // [size, verts..., size, verts... ] auto iter = list.begin(); - for (const auto& f : fcs) + for (const auto& f : faces) { *(iter++) = f.size(); @@ -92,6 +68,23 @@ Foam::vtk::Tools::Patch::faces(const PatchType& p) } +template +vtkSmartPointer +Foam::vtk::Tools::Patch::points(const PatchType& p) +{ + // Local patch points to vtkPoints + return Tools::Points(p.localPoints()); +} + + +template +vtkSmartPointer +Foam::vtk::Tools::Patch::faces(const PatchType& p) +{ + return Tools::Faces(p.localFaces()); +} + + template vtkSmartPointer Foam::vtk::Tools::Patch::mesh(const PatchType& p) @@ -105,6 +98,23 @@ Foam::vtk::Tools::Patch::mesh(const PatchType& p) } +template +vtkSmartPointer +Foam::vtk::Tools::Patch::mesh +( + const UList& pts, + const UList& fcs +) +{ + auto vtkmesh = vtkSmartPointer::New(); + + vtkmesh->SetPoints(Tools::Points(pts)); + vtkmesh->SetPolys(Tools::Faces(fcs)); + + return vtkmesh; +} + + template vtkSmartPointer Foam::vtk::Tools::Patch::faceNormals(const PatchType& p) diff --git a/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H b/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H new file mode 100644 index 0000000000..4d3e74177f --- /dev/null +++ b/src/conversion/vtk/adaptor/foamVtkVtuAdaptor.H @@ -0,0 +1,167 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::vtk::vtuAdaptor + +Description + A low-level backend adaptor for converting OpenFOAM volume meshes/fields + to VTK internal representation. + The output is a single piece vtkUnstructuredGrid dataset. + Multiblock composition is done by the caller. + +Note + This was originally part of the catalystFvMesh function object backend, + which was prototyped in the ParaView reader module. + This adaptor unifies many common elements of both. + +SourceFiles + foamVtkVtuAdaptorI.H + foamVtkVtuAdaptorTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef foamVtk_vtuAdaptor_H +#define foamVtk_vtuAdaptor_H + +#include "fvMesh.H" +#include "volFieldsFwd.H" +#include "foamVtkTools.H" +#include "foamVtkMeshMaps.H" +#include "foamVtuSizing.H" + +#include "vtkSmartPointer.h" +#include "vtkPoints.h" +#include "vtkPolyData.h" +#include "vtkUnstructuredGrid.h" +#include "vtkMultiBlockDataSet.h" + +// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * // + +class vtkCellArray; +class vtkDataSet; +class vtkFloatArray; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace vtk +{ + +/*---------------------------------------------------------------------------*\ + Class vtk::vtuAdaptor Declaration +\*---------------------------------------------------------------------------*/ + +//- Bookkeeping for vtkUnstructuredGrid +struct vtuAdaptor +: + public vtk::Caching, + public foamVtkMeshMaps +{ + // Member Functions + + // Mesh Conversion + + //- The vtk points for the mesh (and decomposition) + inline vtkSmartPointer points + ( + const fvMesh& mesh + ) const; + + //- The vtk points for the mesh (and decomposition) + //- using the provided pointMap + inline vtkSmartPointer points + ( + const fvMesh& mesh, + const labelUList& pointMap + ) const; + + //- Internal mesh as vtkUnstructuredGrid. + // Calling this automatically populates the sizing and vtk::Caching + inline vtkSmartPointer internal + ( + const fvMesh& mesh, + const bool decompPoly = false + ); + + + // Field Conversion + + //- Convert internal volume field (CellData) + template + static vtkSmartPointer + convertField + ( + const DimensionedField& fld, + const vtuAdaptor& vtuData + ); + + //- Convert internal volume field (CellData) + template + static vtkSmartPointer + convertField + ( + const GeometricField& fld, + const vtuAdaptor& vtuData + ); + + + //- Convert internal volume field (CellData) + template + vtkSmartPointer + convertField + ( + const DimensionedField& fld + ) const; + + //- Convert internal volume field (CellData) + template + vtkSmartPointer + convertField + ( + const GeometricField& fld + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace vtk +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "foamVtkVtuAdaptorI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "foamVtkVtuAdaptorTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkVtuAdaptorI.H b/src/conversion/vtk/adaptor/foamVtkVtuAdaptorI.H new file mode 100644 index 0000000000..a86041396d --- /dev/null +++ b/src/conversion/vtk/adaptor/foamVtkVtuAdaptorI.H @@ -0,0 +1,192 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +inline vtkSmartPointer +Foam::vtk::vtuAdaptor::points +( + const fvMesh& mesh +) const +{ + // Convert OpenFOAM mesh vertices to VTK + auto vtkpoints = vtkSmartPointer::New(); + + // Normal points + const pointField& pts = mesh.points(); + + // Additional cell centres + const labelUList& addPoints = this->additionalIds(); + + vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size()); + + // Normal points + vtkIdType pointId = 0; + for (const point& p : pts) + { + vtkpoints->SetPoint(pointId++, p.v_); + } + + // Cell centres + for (const label meshCelli : addPoints) + { + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); + } + + return vtkpoints; +} + + +inline vtkSmartPointer +Foam::vtk::vtuAdaptor::points +( + const fvMesh& mesh, + const labelUList& pointMap +) const +{ + // Convert OpenFOAM mesh vertices to VTK + auto vtkpoints = vtkSmartPointer::New(); + + // Normal points + const pointField& pts = mesh.points(); + + // Additional cell centres + const labelUList& addPoints = this->additionalIds(); + + vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size()); + + // Normal points + vtkIdType pointId = 0; + for (const label meshPointi : pointMap) + { + vtkpoints->SetPoint(pointId++, pts[meshPointi].v_); + } + + // Cell centres + for (const label meshCelli : addPoints) + { + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); + } + + return vtkpoints; +} + + +inline vtkSmartPointer +Foam::vtk::vtuAdaptor::internal +( + const fvMesh& mesh, + const bool decompPoly +) +{ + vtk::vtuSizing sizing(mesh, decompPoly); + + auto cellTypes = vtkSmartPointer::New(); + + auto cells = vtkSmartPointer::New(); + auto faces = vtkSmartPointer::New(); + + auto cellLocations = vtkSmartPointer::New(); + auto faceLocations = vtkSmartPointer::New(); + + UList cellTypesUL = + vtk::Tools::asUList(cellTypes, sizing.nFieldCells()); + + UList cellsUL = + vtk::Tools::asUList + ( + cells, + sizing.nFieldCells(), + sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS) + ); + + UList cellLocationsUL = + vtk::Tools::asUList + ( + cellLocations, + sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS) + ); + + UList facesUL = + vtk::Tools::asUList + ( + faces, + sizing.sizeInternal(vtk::vtuSizing::slotType::FACES) + ); + + UList faceLocationsUL = + vtk::Tools::asUList + ( + faceLocations, + sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS) + ); + + + sizing.populateInternal + ( + mesh, + cellTypesUL, + cellsUL, + cellLocationsUL, + facesUL, + faceLocationsUL, + static_cast(*this) + ); + + auto vtkmesh = vtkSmartPointer::New(); + + // Convert OpenFOAM mesh vertices to VTK + // - can only do this *after* populating the decompInfo with cell-ids + // for any additional points (ie, mesh cell-centres) + vtkmesh->SetPoints(this->points(mesh)); + + if (facesUL.size()) + { + vtkmesh->SetCells + ( + cellTypes, + cellLocations, + cells, + faceLocations, + faces + ); + } + else + { + vtkmesh->SetCells + ( + cellTypes, + cellLocations, + cells, + nullptr, + nullptr + ); + } + + return vtkmesh; +} + + +// ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkVtuAdaptorTemplates.C b/src/conversion/vtk/adaptor/foamVtkVtuAdaptorTemplates.C new file mode 100644 index 0000000000..9452ec97fa --- /dev/null +++ b/src/conversion/vtk/adaptor/foamVtkVtuAdaptorTemplates.C @@ -0,0 +1,105 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +// VTK includes +#include "vtkFloatArray.h" +#include "vtkCellData.h" +#include "vtkPointData.h" +#include "vtkSmartPointer.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +vtkSmartPointer +Foam::vtk::vtuAdaptor::convertField +( + const DimensionedField& fld, + const vtuAdaptor& vtuData +) +{ + const int nComp(pTraits::nComponents); + const labelUList& cellMap = vtuData.cellMap(); + + auto data = vtkSmartPointer::New(); + data->SetName(fld.name().c_str()); + data->SetNumberOfComponents(nComp); + data->SetNumberOfTuples(cellMap.size()); + + // DebugInfo + // << "Convert field: " << fld.name() + // << " size=" << cellMap.size() + // << " (" << fld.size() << " + " + // << (cellMap.size() - fld.size()) + // << ") nComp=" << nComp << endl; + + + float scratch[pTraits::nComponents]; + + vtkIdType celli = 0; + for (const label meshCelli : cellMap) + { + vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]); + data->SetTuple(celli++, scratch); + } + + return data; +} + + +template +vtkSmartPointer +Foam::vtk::vtuAdaptor::convertField +( + const GeometricField& fld, + const vtuAdaptor& vtuData +) +{ + return convertField(fld.internalField(), vtuData); +} + + +template +vtkSmartPointer +Foam::vtk::vtuAdaptor::convertField +( + const DimensionedField& fld +) const +{ + return convertField(fld, *this); +} + + +template +vtkSmartPointer +Foam::vtk::vtuAdaptor::convertField +( + const GeometricField& fld +) const +{ + return convertField(fld, *this); +} + + +// ************************************************************************* //