Commit ff54ef82 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

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.
parent 966fc4c5
......@@ -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<double>& requestTimes)
updateInfo();
}
if (debug)
{
Info<< "<end> setTime() - selectedTime="
<< Times[nearestIndex].name() << " index=" << timeIndex_
<< "/" << Times.size()
<< " meshUpdateState=" << updateStateName(meshState_) << nl;
}
DebugInfo
<< "<end> 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<< "<beg> updateInfo"
<< " [volMeshPtr=" << (volMeshPtr_ ? "set" : "nullptr")
<< "] timeIndex="
<< timeIndex_ << nl;
}
DebugInfo
<< "<beg> 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<< "<end> updateInfo" << nl;
}
DebugInfo << "<end> 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
......
......@@ -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<vtkUnstructuredGrid>,
public foamVtkMeshMaps
public vtk::vtuAdaptor
{
//- The vtk points for the mesh (and decomposition)
vtkSmartPointer<vtkPoints> points
(
const fvMesh& mesh
) const;
//- The vtk points for the mesh (and decomposition),
//- using the provided pointMap
vtkSmartPointer<vtkPoints> points
(
const fvMesh& mesh,
const labelUList& pointMap
) const;
//- Internal mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> internal
(
const fvMesh& mesh,
const bool decompPoly
);
//- Subsetted mesh as vtkUnstructuredGrid
vtkSmartPointer<vtkUnstructuredGrid> subset
(
const fvMeshSubset& subsetter,
const bool decompPoly
bool decompPoly = false
);
};
......@@ -348,14 +319,6 @@ class vtkPVFoam
const labelUList& faceLabels
) const;
//- Volume field
template<class Type>
vtkSmartPointer<vtkFloatArray> convertVolFieldToVTK
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const foamVtuData& vtuData
) const;
//- Convert finite volume fields
void convertVolFields();
......
......@@ -68,8 +68,7 @@ void Foam::vtkPVFoam::convertVolField
autoPtr<GeometricField<Type, pointPatchField, pointMesh>> 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<vtkFloatArray> cdata = convertVolFieldToVTK
dataset->GetCellData()->AddArray
(
fld,
vtuData
vtuData.convertField(fld)
);
dataset->GetCellData()->AddArray(cdata);
if (ptfPtr.valid())
{
vtkSmartPointer<vtkFloatArray> 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<class Type>
vtkSmartPointer<vtkFloatArray>
Foam::vtkPVFoam::convertVolFieldToVTK
(
const GeometricField<Type, fvPatchField, volMesh>& fld,
const foamVtuData& vtuData
) const
{
const labelUList& cellMap = vtuData.cellMap();
auto data = vtkSmartPointer<vtkFloatArray>::New();
data->SetName(fld.name().c_str());
data->SetNumberOfComponents(static_cast<int>(pTraits<Type>::nComponents));
data->SetNumberOfTuples(cellMap.size());
DebugInfo
<< "Convert volField: " << fld.name() << " size="
<< cellMap.size() << " (field "
<< fld.size() << ") nComp="
<< static_cast<int>(pTraits<Type>::nComponents) << nl;
float scratch[pTraits<Type>::nComponents];
vtkIdType celli = 0;
for (const label meshCelli : cellMap)
{
vtk::Tools::foamToVtkTuple(scratch, fld[meshCelli]);
data->SetTuple(celli++, scratch);
}
return data;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
......
......@@ -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;
}
......
......@@ -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 "