diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C index 40802fdb7c..6cb7a81cde 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFieldTemplates.C @@ -40,11 +40,11 @@ InClass #include "areaFaMesh.H" #include "areaFields.H" -// vtk includes -#include "vtkFloatArray.h" -#include "vtkCellData.h" -#include "vtkPointData.h" -#include "vtkSmartPointer.h" +// VTK includes +#include +#include +#include +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // @@ -68,10 +68,8 @@ void Foam::vtkPVFoam::convertVolField autoPtr> ptfPtr; if (interpField) { - if (debug) - { - Info<< "convertVolField interpolating:" << fld.name() << nl; - } + DebugInfo + << "convertVolField interpolating:" << fld.name() << nl; ptfPtr.reset ( @@ -102,7 +100,7 @@ void Foam::vtkPVFoam::convertVolField foamVtpData& vtpData = iter.object(); auto dataset = vtpData.dataset; - const labelList& patchIds = vtpData.additionalIds(); + const labelUList& patchIds = vtpData.additionalIds(); if (patchIds.empty()) { @@ -291,13 +289,13 @@ void Foam::vtkPVFoam::convertVolFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -373,13 +371,13 @@ void Foam::vtkPVFoam::convertDimFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -501,13 +499,13 @@ void Foam::vtkPVFoam::convertAreaFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -545,10 +543,8 @@ void Foam::vtkPVFoam::convertPointFields continue; } - if (debug) - { - Info<< "convertPointFields : " << fieldName << nl; - } + DebugInfo + << "convertPointFields : " << fieldName << nl; // Throw FatalError, FatalIOError as exceptions const bool throwingError = FatalError.throwExceptions(); @@ -581,7 +577,7 @@ void Foam::vtkPVFoam::convertPointFields foamVtpData& vtpData = iter.object(); auto dataset = vtpData.dataset; - const labelList& patchIds = vtpData.additionalIds(); + const labelUList& patchIds = vtpData.additionalIds(); if (patchIds.size() != 1) { continue; @@ -645,13 +641,13 @@ void Foam::vtkPVFoam::convertPointFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -706,7 +702,6 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField const foamVtuData& vtuData ) { - const int nComp(pTraits::nComponents); const labelUList& addPointCellLabels = vtuData.additionalIds(); const labelUList& pointMap = vtuData.pointMap(); @@ -714,7 +709,7 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField const label nPoints = (pointMap.size() ? pointMap.size() : pfld.size()); auto data = vtkSmartPointer::New(); - data->SetNumberOfComponents(nComp); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(nPoints + addPointCellLabels.size()); // Note: using the name of the original volField @@ -729,75 +724,54 @@ vtkSmartPointer Foam::vtkPVFoam::convertPointField data->SetName(pfld.name().c_str()); } - if (debug) - { - Info<< "convert Point field: " - << pfld.name() - << " size=" << (nPoints + addPointCellLabels.size()) - << " (" << nPoints << " + " << addPointCellLabels.size() - << ") nComp=" << nComp << nl; - } + DebugInfo + << "Convert point field: " << pfld.name() + << " size=" << (nPoints + addPointCellLabels.size()) + << " (" << nPoints << " + " << addPointCellLabels.size() + << ") nComp=" << static_cast(pTraits::nComponents) << nl; - float vec[nComp]; - label pointi = 0; + float scratch[pTraits::nComponents]; + + vtkIdType pointi = 0; if (pointMap.size()) { - forAll(pointMap, i) + for (const label meshPointi : pointMap) { - const Type& t = pfld[pointMap[i]]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple(scratch, pfld[meshPointi]); + data->SetTuple(pointi++, scratch); } } else { - forAll(pfld, i) + for (const Type& val : pfld) { - const Type& t = pfld[i]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple(scratch, val); + data->SetTuple(pointi++, scratch); } } // Continue with additional points + // - correspond to cell centres if (notNull(vfld)) { - forAll(addPointCellLabels, apI) + for (const label meshCelli : addPointCellLabels) { - const Type& t = vfld[addPointCellLabels[apI]]; - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple(scratch, vfld[meshCelli]); + data->SetTuple(pointi++, scratch); } } else { - forAll(addPointCellLabels, apI) + for (const label meshCelli : addPointCellLabels) { - Type t = interpolatePointToCell(pfld, addPointCellLabels[apI]); - for (direction d=0; d(vec); - - data->SetTuple(pointi++, vec); + vtk::Tools::foamToVtkTuple + ( + scratch, + interpolatePointToCell(pfld, meshCelli) + ); + data->SetTuple(pointi++, scratch); } } @@ -846,13 +820,13 @@ void Foam::vtkPVFoam::convertLagrangianFields catch (Foam::IOerror& ioErr) { ioErr.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } catch (Foam::error& err) { // Bit of trickery to get the original message err.write(Warning, false); - Info << nl << endl; + Info<< nl << endl; } // Restore previous exception throwing state @@ -876,53 +850,44 @@ Foam::vtkPVFoam::convertFaceFieldToVTK const labelUList& faceLabels ) const { - if (debug) - { - Info<< "convert face field: " - << fld.name() - << " size=" << faceLabels.size() - << " nComp=" << int(pTraits::nComponents) << nl; - } + DebugInfo + << "Convert face field: " << fld.name() + << " size=" << faceLabels.size() + << " nComp=" << static_cast(pTraits::nComponents) << nl; const fvMesh& mesh = fld.mesh(); - const int nComp(pTraits::nComponents); const label nInternalFaces = mesh.nInternalFaces(); - const labelList& faceOwner = mesh.faceOwner(); - const labelList& faceNeigh = mesh.faceNeighbour(); + const labelUList& faceOwner = mesh.faceOwner(); + const labelUList& faceNeigh = mesh.faceNeighbour(); auto data = vtkSmartPointer::New(); data->SetName(fld.name().c_str()); - data->SetNumberOfComponents(nComp); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(faceLabels.size()); - float scratch[nComp]; - // Interior faces: average owner/neighbour // Boundary faces: the owner value - forAll(faceLabels, idx) - { - const label faceNo = faceLabels[idx]; - if (faceNo < nInternalFaces) - { - Type t = 0.5*(fld[faceOwner[faceNo]] + fld[faceNeigh[faceNo]]); - for (direction d=0; d::nComponents]; + + vtkIdType faceId = 0; + for (const label meshFacei : faceLabels) + { + if (meshFacei < nInternalFaces) + { + Type val = + 0.5*(fld[faceOwner[meshFacei]] + fld[faceNeigh[meshFacei]]); + + vtk::Tools::foamToVtkTuple(scratch, val); } else { - const Type& t = fld[faceOwner[faceNo]]; - for (direction d=0; d(scratch); - data->SetTuple(idx, scratch); + data->SetTuple(faceId++, scratch); } return data; @@ -937,35 +902,26 @@ Foam::vtkPVFoam::convertVolFieldToVTK const foamVtuData& vtuData ) const { - const int nComp(pTraits::nComponents); const labelUList& cellMap = vtuData.cellMap(); auto data = vtkSmartPointer::New(); data->SetName(fld.name().c_str()); - data->SetNumberOfComponents(nComp); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(cellMap.size()); - if (debug) - { - Info<< "convert volField: " - << fld.name() - << " size=" << cellMap.size() - << " (" << fld.size() << " + " - << (cellMap.size() - fld.size()) - << ") nComp=" << nComp << nl; - } + DebugInfo + << "Convert volField: " << fld.name() << " size=" + << cellMap.size() << " (field " + << fld.size() << ") nComp=" + << static_cast(pTraits::nComponents) << nl; - float scratch[nComp]; - forAll(cellMap, idx) - { - const Type& t = fld[cellMap[idx]]; - for (direction d=0; d(scratch); + float scratch[pTraits::nComponents]; - data->SetTuple(idx, scratch); + vtkIdType celli = 0; + for (const label meshCelli : cellMap) + { + vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]); + data->SetTuple(celli++, scratch); } return data; diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C index 7a29072240..eeb3bfab1e 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMesh.C @@ -172,7 +172,7 @@ void Foam::vtkPVFoam::convertMeshPatches() { // Point movement on single patch is OK - const labelList& patchIds = vtpData.additionalIds(); + const labelUList& patchIds = vtpData.additionalIds(); if (patchIds.size() == 1) { vtkgeom = vtpData.getCopy(); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C index 7ef9e570ff..28d304f51c 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamMeshVolume.C @@ -49,23 +49,21 @@ vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = this->additionalIds(); + const labelUList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size()); // Normal points - label pointId = 0; + vtkIdType pointId = 0; for (const point& p : pts) { - vtkpoints->SetPoint(pointId, p.v_); - ++pointId; + vtkpoints->SetPoint(pointId++, p.v_); } // Cell centres - for (const label ptId : addPoints) + for (const label meshCelli : addPoints) { - vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); } return vtkpoints; @@ -85,23 +83,21 @@ vtkSmartPointer Foam::vtkPVFoam::foamVtuData::points const pointField& pts = mesh.points(); // Additional cell centres - const labelList& addPoints = this->additionalIds(); + const labelUList& addPoints = this->additionalIds(); vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size()); // Normal points - label pointId = 0; - for (const label ptId : pointMap) + vtkIdType pointId = 0; + for (const label meshPointi : pointMap) { - vtkpoints->SetPoint(pointId, pts[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, pts[meshPointi].v_); } // Cell centres - for (const label ptId : addPoints) + for (const label meshCelli : addPoints) { - vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_); - ++pointId; + vtkpoints->SetPoint(pointId++, mesh.cellCentres()[meshCelli].v_); } return vtkpoints; diff --git a/src/conversion/vtk/adaptor/foamVtkTools.H b/src/conversion/vtk/adaptor/foamVtkTools.H index e73dd87832..f52d3f1905 100644 --- a/src/conversion/vtk/adaptor/foamVtkTools.H +++ b/src/conversion/vtk/adaptor/foamVtkTools.H @@ -49,6 +49,7 @@ SourceFiles #include "pointField.H" #include "symmTensor.H" +// VTK includes #include #include #include @@ -209,13 +210,36 @@ public: //- Remapping for some OpenFOAM data types (eg, symmTensor) + // \param data[in,out] The data to be remapped in-place template inline static void remapTuple(float data[]) {} //- Remapping for some OpenFOAM data types (eg, symmTensor) + // \param data[in,out] The data to be remapped in-place template inline static void remapTuple(double data[]) {} + //- Copy/transcribe OpenFOAM data types to VTK format + // This allows a change of data type (float vs double) as well as + // addressing any swapping issues (eg, symmTensor) + // + // \param output[out] The output scratch space. Must be long enough + // to hold the result. + // \param val[in] The input data to copy/transcribe + template + inline static void foamToVtkTuple(float output[], const Type& val); + + //- Copy/transcribe OpenFOAM data types to VTK format + // This allows a change of data type (float vs double) as well as + // addressing any swapping issues (eg, symmTensor) + // + // \param output[out] The output scratch space. Must be long enough + // to hold the result. + // \param val[in] The input data to copy/transcribe + template + inline static void foamToVtkTuple(double output[], const Type& val); + + // Field Conversion Functions //- Copy list to pre-allocated vtk array. @@ -225,7 +249,7 @@ public: ( vtkFloatArray* array, const UList& input, - const label start = 0 + vtkIdType start = 0 //!< The write offset into output array ); //- Create named field initialized to zero @@ -270,7 +294,6 @@ inline void Foam::vtk::Tools::remapTuple(double data[]) } - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace vtk diff --git a/src/conversion/vtk/adaptor/foamVtkToolsI.H b/src/conversion/vtk/adaptor/foamVtkToolsI.H index f93b2c7d55..e151f1a7d1 100644 --- a/src/conversion/vtk/adaptor/foamVtkToolsI.H +++ b/src/conversion/vtk/adaptor/foamVtkToolsI.H @@ -87,4 +87,34 @@ inline vtkSmartPointer Foam::vtk::Tools::identityVertices }; +template +inline void Foam::vtk::Tools::foamToVtkTuple +( + float output[], + const Type& val +) +{ + for (direction cmpt=0; cmpt < pTraits::nComponents; ++cmpt) + { + output[cmpt] = component(val, cmpt); + } + remapTuple(output); +} + + +template +inline void Foam::vtk::Tools::foamToVtkTuple +( + double output[], + const Type& val +) +{ + for (direction cmpt=0; cmpt < pTraits::nComponents; ++cmpt) + { + output[cmpt] = component(val, cmpt); + } + remapTuple(output); +} + + // ************************************************************************* // diff --git a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C index 3a7b653869..5049e67ff8 100644 --- a/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C +++ b/src/conversion/vtk/adaptor/foamVtkToolsTemplates.C @@ -50,12 +50,11 @@ Foam::vtk::Tools::Patch::points(const PatchType& p) auto vtkpoints = vtkSmartPointer::New(); vtkpoints->SetNumberOfPoints(pts.size()); - vtkIdType pointId = 0; + vtkIdType pointId = 0; for (const point& p : pts) { - vtkpoints->SetPoint(pointId, p.v_); - ++pointId; + vtkpoints->SetPoint(pointId++, p.v_); } return vtkpoints; @@ -127,8 +126,7 @@ Foam::vtk::Tools::Patch::faceNormals(const PatchType& p) vtkIdType faceId = 0; for (const vector& n : norms) { - array->SetTuple(faceId, n.v_); - ++faceId; + array->SetTuple(faceId++, n.v_); } return array; @@ -145,7 +143,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData ( vtkFloatArray* array, const UList& input, - const label start + vtkIdType start ) { const int nComp(pTraits::nComponents); @@ -162,7 +160,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData } const vtkIdType maxSize = array->GetNumberOfTuples(); - const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size()); + const vtkIdType endPos = start + vtkIdType(input.size()); if (!maxSize) { @@ -174,7 +172,7 @@ Foam::label Foam::vtk::Tools::transcribeFloatData WarningInFunction << "vtk array '" << array->GetName() << "' copy with out-of-range [0," << long(maxSize) << ")" - << " starting at " << start + << " starting at " << long(start) << nl; return 0; @@ -185,23 +183,18 @@ Foam::label Foam::vtk::Tools::transcribeFloatData << "vtk array '" << array->GetName() << "' copy ends out-of-range (" << long(maxSize) << ")" << " using sizing (start,size) = (" - << start << "," << input.size() << ")" + << long(start) << "," << input.size() << ")" << nl; return 0; } - float scratch[nComp]; - forAll(input, idx) - { - const Type& t = input[idx]; - for (direction d=0; d(scratch); + float scratch[pTraits::nComponents]; - array->SetTuple(start+idx, scratch); + for (const Type& val : input) + { + foamToVtkTuple(scratch, val); + array->SetTuple(start++, scratch); } return input.size(); @@ -219,7 +212,7 @@ Foam::vtk::Tools::zeroField auto data = vtkSmartPointer::New(); data->SetName(name.c_str()); - data->SetNumberOfComponents(int(pTraits::nComponents)); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(size); data->Fill(0); @@ -239,7 +232,7 @@ Foam::vtk::Tools::convertFieldToVTK auto data = vtkSmartPointer::New(); data->SetName(name.c_str()); - data->SetNumberOfComponents(int(pTraits::nComponents)); + data->SetNumberOfComponents(static_cast(pTraits::nComponents)); data->SetNumberOfTuples(fld.size()); transcribeFloatData(data, fld);