mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: consolidate some common methods for paraview + catalyst
This commit is contained in:
@ -2,6 +2,7 @@ sinclude $(GENERAL_RULES)/paraview
|
||||
|
||||
EXE_INC = \
|
||||
${c++LESSWARN} \
|
||||
-I$(LIB_SRC)/conversion/lnInclude \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-I$(ParaView_INCLUDE_DIR) \
|
||||
-I$(ParaView_INCLUDE_DIR)/vtkkwiml
|
||||
|
||||
@ -34,16 +34,6 @@ License
|
||||
#include "vtkInformation.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
#include "foamVtkAdaptors.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(foamPvCore, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::foamPvCore::printDataArraySelection
|
||||
@ -103,13 +93,14 @@ void Foam::foamPvCore::addToBlock
|
||||
output->SetBlock(blockNo, block);
|
||||
}
|
||||
|
||||
if (debug)
|
||||
#ifdef FULLDEBUG
|
||||
{
|
||||
Info<< "block[" << blockNo << "] has "
|
||||
<< block->GetNumberOfBlocks()
|
||||
<< " datasets prior to adding set " << datasetNo
|
||||
<< " with name: " << datasetName << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
block->SetBlock(datasetNo, dataset);
|
||||
|
||||
@ -192,9 +183,8 @@ Foam::foamPvCore::getSelectedArraySet
|
||||
}
|
||||
}
|
||||
|
||||
if (debug > 1)
|
||||
#ifdef FULLDEBUG
|
||||
{
|
||||
const int n = select->GetNumberOfArrays();
|
||||
Info<< "available(";
|
||||
for (int i=0; i < n; ++i)
|
||||
{
|
||||
@ -208,6 +198,7 @@ Foam::foamPvCore::getSelectedArraySet
|
||||
}
|
||||
Info<< " )\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
return enabled;
|
||||
}
|
||||
@ -238,7 +229,7 @@ Foam::word Foam::foamPvCore::getFoamName(const std::string& str)
|
||||
{
|
||||
if (str.size())
|
||||
{
|
||||
std::string::size_type beg = str.rfind('/');
|
||||
auto beg = str.rfind('/');
|
||||
if (beg == std::string::npos)
|
||||
{
|
||||
beg = 0;
|
||||
@ -248,7 +239,7 @@ Foam::word Foam::foamPvCore::getFoamName(const std::string& str)
|
||||
++beg;
|
||||
}
|
||||
|
||||
std::string::size_type end = beg;
|
||||
auto end = beg;
|
||||
|
||||
while (str[end] && word::valid(str[end]))
|
||||
{
|
||||
@ -274,29 +265,4 @@ void Foam::foamPvCore::printMemory()
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkCellArray> Foam::foamPvCore::identityVertices
|
||||
(
|
||||
const label size
|
||||
)
|
||||
{
|
||||
// VTK_VERTEX
|
||||
auto cells = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
UList<vtkIdType> cellsUL = vtkUList(cells, size, 2*size);
|
||||
|
||||
// Cell connectivity for vertex
|
||||
// [size, ids.., size, ids...]
|
||||
// which means
|
||||
// [1, id, 1, id, ...]
|
||||
label idx = 0;
|
||||
for (label id=0; id < size; ++id)
|
||||
{
|
||||
cellsUL[idx++] = 1;
|
||||
cellsUL[idx++] = id;
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -26,13 +26,13 @@ Description
|
||||
|
||||
SourceFiles
|
||||
foamPvCore.C
|
||||
foamPvCoreTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamPvCore_H
|
||||
#define foamPvCore_H
|
||||
|
||||
#include "className.H"
|
||||
#include "fileName.H"
|
||||
#include "stringList.H"
|
||||
#include "boolList.H"
|
||||
@ -167,25 +167,10 @@ public:
|
||||
}; // End class arrayRange
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
foamPvCore(const foamPvCore&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const foamPvCore&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Static data members
|
||||
ClassName("foamPvCore");
|
||||
|
||||
|
||||
//- Construct null
|
||||
foamPvCore() = default;
|
||||
constexpr foamPvCore() noexcept {}
|
||||
|
||||
|
||||
//- Print information about vtkDataArraySelection
|
||||
@ -308,13 +293,6 @@ public:
|
||||
static void printMemory();
|
||||
|
||||
|
||||
//- Return an identity list of VTK_VERTEX
|
||||
static vtkSmartPointer<vtkCellArray> identityVertices
|
||||
(
|
||||
const label size
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
}; // End class foamPvCore
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Helpers for OpenFOAM reader interfaces in ParaView.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamPvFields_H
|
||||
#define foamPvFields_H
|
||||
|
||||
#include "symmTensor.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class foamPvFields Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
struct foamPvFields
|
||||
{
|
||||
//- Remapping for some data types
|
||||
template<class Type>
|
||||
inline static void remapTuple(float vec[])
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Template specialization for symmTensor
|
||||
template<>
|
||||
inline void Foam::foamPvFields::remapTuple<Foam::symmTensor>(float vec[])
|
||||
{
|
||||
Foam::Swap(vec[1], vec[3]); // swap XY <-> YY
|
||||
Foam::Swap(vec[2], vec[5]); // swap XZ <-> ZZ
|
||||
}
|
||||
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,115 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkAdaptors_H
|
||||
#define foamVtkAdaptors_H
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "labelList.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkIdTypeArray.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkUnsignedCharArray.h"
|
||||
#include "vtkAOSDataArrayTemplate.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
//- Attach a smart pointer, or generate a non-null one.
|
||||
template<class T>
|
||||
inline vtkSmartPointer<T> nonNullSmartPointer(T* ptr)
|
||||
{
|
||||
return vtkSmartPointer<T>(ptr ? ptr : T::New());
|
||||
}
|
||||
|
||||
|
||||
//- Helper to wrap vtkUnsignedCharArray as a UList
|
||||
inline UList<uint8_t> vtkUList
|
||||
(
|
||||
vtkUnsignedCharArray* array,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
array->SetNumberOfComponents(1);
|
||||
array->SetNumberOfTuples(size);
|
||||
|
||||
UList<uint8_t> list
|
||||
(
|
||||
array->WritePointer(0, size),
|
||||
size
|
||||
);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
//- Helper to wrap vtkIdTypeArray as a UList
|
||||
inline UList<vtkIdType> vtkUList
|
||||
(
|
||||
vtkIdTypeArray* array,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
array->SetNumberOfComponents(1);
|
||||
array->SetNumberOfTuples(size);
|
||||
|
||||
UList<vtkIdType> list
|
||||
(
|
||||
array->WritePointer(0, size),
|
||||
size
|
||||
);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
//- Special helper to wrap vtkCellArray as a UList
|
||||
inline UList<vtkIdType> vtkUList
|
||||
(
|
||||
vtkCellArray* cells,
|
||||
const label nCells,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
cells->GetData()->SetNumberOfTuples(size);
|
||||
|
||||
UList<vtkIdType> list
|
||||
(
|
||||
cells->WritePointer(nCells, size),
|
||||
size
|
||||
);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -72,6 +72,7 @@ SourceFiles
|
||||
#include "PrimitivePatchInterpolation.H"
|
||||
#include "volPointInterpolation.H"
|
||||
#include "foamPvCore.H"
|
||||
#include "foamVtkTools.H"
|
||||
#include "foamVtkMeshMaps.H"
|
||||
|
||||
#include "vtkPoints.h"
|
||||
@ -115,112 +116,53 @@ template<class Type> class List;
|
||||
|
||||
class vtkPVFoam
|
||||
:
|
||||
private foamPvCore
|
||||
private foamPvCore,
|
||||
protected vtk::Tools
|
||||
{
|
||||
// Convenience typedefs
|
||||
typedef PrimitivePatchInterpolation<primitivePatch> patchInterpolator;
|
||||
|
||||
|
||||
// Private classes
|
||||
|
||||
//- Bookkeeping for internal caching.
|
||||
// Retain an original copy of the geometry as well as a shallow copy
|
||||
// with the output fields.
|
||||
// The original copy is reused for different timestep
|
||||
template<class DataType>
|
||||
struct foamVtkCaching
|
||||
{
|
||||
typedef DataType dataType;
|
||||
|
||||
//- The geometry, without any cell/point data
|
||||
vtkSmartPointer<dataType> vtkgeom;
|
||||
|
||||
//- The shallow-copy of geometry, plus additional data
|
||||
vtkSmartPointer<dataType> dataset;
|
||||
|
||||
//- Number of points associated with geometry
|
||||
inline uint64_t nPoints() const
|
||||
{
|
||||
return vtkgeom ? vtkgeom->GetNumberOfPoints() : 0;
|
||||
}
|
||||
|
||||
//- Clear geometry and dataset
|
||||
void clearGeom()
|
||||
{
|
||||
vtkgeom = nullptr;
|
||||
dataset = nullptr;
|
||||
}
|
||||
|
||||
//- Return a shallow copy of vtkgeom for manipulation
|
||||
vtkSmartPointer<dataType> getCopy() const
|
||||
{
|
||||
auto copy = vtkSmartPointer<dataType>::New();
|
||||
if (vtkgeom)
|
||||
{
|
||||
copy->ShallowCopy(vtkgeom);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
//- Make a shallow copy of vtkgeom into dataset
|
||||
void reuse()
|
||||
{
|
||||
dataset = vtkSmartPointer<dataType>::New();
|
||||
if (vtkgeom)
|
||||
{
|
||||
dataset->ShallowCopy(vtkgeom);
|
||||
}
|
||||
}
|
||||
|
||||
//- Set the geometry and make a shallow copy to dataset
|
||||
void set(vtkSmartPointer<dataType> geom)
|
||||
{
|
||||
vtkgeom = geom;
|
||||
reuse();
|
||||
}
|
||||
|
||||
//- Report basic information to output
|
||||
void PrintSelf(std::ostream& os) const
|
||||
{
|
||||
os << "geom" << nl;
|
||||
if (vtkgeom)
|
||||
{
|
||||
vtkgeom->PrintSelf(std::cout, vtkIndent(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "nullptr";
|
||||
}
|
||||
os << nl;
|
||||
|
||||
os << "copy" << nl;
|
||||
if (dataset)
|
||||
{
|
||||
dataset->PrintSelf(std::cout, vtkIndent(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "nullptr";
|
||||
}
|
||||
os << nl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- Bookkeeping for vtkPolyData
|
||||
struct foamVtpData
|
||||
:
|
||||
public foamVtkCaching<vtkPolyData>,
|
||||
public vtk::Caching<vtkPolyData>,
|
||||
public foamVtkMeshMaps
|
||||
{};
|
||||
|
||||
|
||||
//- Bookkeeping for vtkUnstructuredGrid
|
||||
struct foamVtuData
|
||||
:
|
||||
public foamVtkCaching<vtkUnstructuredGrid>,
|
||||
public vtk::Caching<vtkUnstructuredGrid>,
|
||||
public foamVtkMeshMaps
|
||||
{};
|
||||
{
|
||||
//- 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
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// Private Data
|
||||
@ -294,7 +236,7 @@ class vtkPVFoam
|
||||
//- Reset data counters
|
||||
void resetCounters();
|
||||
|
||||
// Update information helper functions
|
||||
// Update information helper functions
|
||||
|
||||
//- Internal mesh info
|
||||
void updateInfoInternalMesh(vtkDataArraySelection* select);
|
||||
@ -347,7 +289,7 @@ class vtkPVFoam
|
||||
void updateInfoLagrangianFields(vtkDataArraySelection* select);
|
||||
|
||||
|
||||
// Mesh conversion functions
|
||||
// Mesh conversion functions
|
||||
|
||||
//- Convert internalMesh
|
||||
void convertMeshVolume();
|
||||
@ -385,53 +327,7 @@ class vtkPVFoam
|
||||
void convertMeshPointSets();
|
||||
|
||||
|
||||
// Add mesh functions
|
||||
|
||||
//- Generate vtk points for the current mesh points/decomposition
|
||||
static vtkSmartPointer<vtkPoints> movePoints
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const foamVtuData& vtuData
|
||||
);
|
||||
|
||||
//- Generate vtk points for the current mesh points/decomposition,
|
||||
// using the provided pointMap
|
||||
static vtkSmartPointer<vtkPoints> movePoints
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const foamVtuData& vtuData,
|
||||
const labelUList& pointMap
|
||||
);
|
||||
|
||||
//- Volume mesh as vtkUnstructuredGrid
|
||||
static vtkSmartPointer<vtkUnstructuredGrid> volumeVTKMesh
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
foamVtuData& vtuData,
|
||||
const bool decompPoly
|
||||
);
|
||||
|
||||
//- Subsetted mesh as vtkUnstructuredGrid
|
||||
static vtkSmartPointer<vtkUnstructuredGrid> volumeVTKSubsetMesh
|
||||
(
|
||||
const fvMeshSubset& subsetter,
|
||||
foamVtuData& vtuData,
|
||||
const bool decompPoly
|
||||
);
|
||||
|
||||
//- Volume mesh as vtkUnstructuredGrid
|
||||
vtkSmartPointer<vtkUnstructuredGrid> volumeVTKMesh
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
foamVtuData& vtuData
|
||||
) const;
|
||||
|
||||
//- Subsetted mesh as vtkUnstructuredGrid
|
||||
vtkSmartPointer<vtkUnstructuredGrid> volumeVTKSubsetMesh
|
||||
(
|
||||
const fvMeshSubset& subsetter,
|
||||
foamVtuData& vtuData
|
||||
) const;
|
||||
// Add mesh functions
|
||||
|
||||
//- Lagrangian positions as vtkPolyData
|
||||
vtkSmartPointer<vtkPolyData> lagrangianVTKMesh
|
||||
@ -440,55 +336,8 @@ class vtkPVFoam
|
||||
const word& cloudName
|
||||
) const;
|
||||
|
||||
//- Patch points
|
||||
template<class PatchType>
|
||||
static vtkSmartPointer<vtkPoints> movePatchPoints
|
||||
(
|
||||
const PatchType& p
|
||||
);
|
||||
|
||||
//- Patch faces as vtk-cells
|
||||
template<class PatchType>
|
||||
static vtkSmartPointer<vtkCellArray> patchFacesVTKCells
|
||||
(
|
||||
const PatchType& p
|
||||
);
|
||||
|
||||
//- Patches (mesh or primitive) as vtkPolyData
|
||||
template<class PatchType>
|
||||
static vtkSmartPointer<vtkPolyData> patchVTKMesh
|
||||
(
|
||||
const PatchType& p
|
||||
);
|
||||
|
||||
|
||||
// Field conversion functions
|
||||
|
||||
//- Copy list to pre-allocated vtk array.
|
||||
// \return number of input items copied
|
||||
template<class Type>
|
||||
static label transcribeFloatData
|
||||
(
|
||||
vtkFloatArray* array,
|
||||
const UList<Type>& input,
|
||||
const label start = 0
|
||||
);
|
||||
|
||||
//- Create named field initialized to zero
|
||||
template<class Type>
|
||||
static vtkSmartPointer<vtkFloatArray> zeroVTKField
|
||||
(
|
||||
const word& name,
|
||||
const label size
|
||||
);
|
||||
|
||||
//- Convert float data to VTK field
|
||||
template<class Type>
|
||||
vtkSmartPointer<vtkFloatArray> convertFieldToVTK
|
||||
(
|
||||
const word& name,
|
||||
const UList<Type>& fld
|
||||
) const;
|
||||
// Field conversion functions
|
||||
|
||||
//- Face set/zone field
|
||||
template<class Type>
|
||||
@ -520,7 +369,7 @@ class vtkPVFoam
|
||||
void convertLagrangianFields();
|
||||
|
||||
|
||||
// Convert OpenFOAM fields
|
||||
// Convert OpenFOAM fields
|
||||
|
||||
//- Volume field - all types
|
||||
template<class Type>
|
||||
@ -599,7 +448,7 @@ class vtkPVFoam
|
||||
);
|
||||
|
||||
|
||||
// GUI selection helper functions
|
||||
// GUI selection helper functions
|
||||
|
||||
//- Get the first word from the reader 'parts' selection
|
||||
word getReaderPartName(const int partId) const;
|
||||
@ -607,10 +456,10 @@ class vtkPVFoam
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
//- No copy construct
|
||||
vtkPVFoam(const vtkPVFoam&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
//- No copy assignment
|
||||
void operator=(const vtkPVFoam&) = delete;
|
||||
|
||||
|
||||
@ -684,12 +533,6 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "vtkPVFoamTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -37,7 +37,6 @@ InClass
|
||||
#include "volPointInterpolation.H"
|
||||
#include "zeroGradientFvPatchField.H"
|
||||
#include "interpolatePointToCell.H"
|
||||
#include "foamPvFields.H"
|
||||
#include "areaFaMesh.H"
|
||||
#include "areaFields.H"
|
||||
|
||||
@ -119,7 +118,7 @@ void Foam::vtkPVFoam::convertVolField
|
||||
// To improve code reuse, we allocate the CellData as a zeroed-field
|
||||
// ahead of time.
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> cdata = zeroVTKField<Type>
|
||||
vtkSmartPointer<vtkFloatArray> cdata = zeroField<Type>
|
||||
(
|
||||
fld.name(),
|
||||
dataset->GetNumberOfPolys()
|
||||
@ -662,7 +661,7 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
||||
{
|
||||
vec[d] = component(t, d);
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(vec);
|
||||
remapTuple<Type>(vec);
|
||||
|
||||
data->SetTuple(pointi++, vec);
|
||||
}
|
||||
@ -676,7 +675,7 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
||||
{
|
||||
vec[d] = component(t, d);
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(vec);
|
||||
remapTuple<Type>(vec);
|
||||
|
||||
data->SetTuple(pointi++, vec);
|
||||
}
|
||||
@ -693,7 +692,7 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
||||
{
|
||||
vec[d] = component(t, d);
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(vec);
|
||||
remapTuple<Type>(vec);
|
||||
|
||||
data->SetTuple(pointi++, vec);
|
||||
}
|
||||
@ -707,7 +706,7 @@ vtkSmartPointer<vtkFloatArray> Foam::vtkPVFoam::convertPointField
|
||||
{
|
||||
vec[d] = component(t, d);
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(vec);
|
||||
remapTuple<Type>(vec);
|
||||
|
||||
data->SetTuple(pointi++, vec);
|
||||
}
|
||||
@ -758,119 +757,6 @@ void Foam::vtkPVFoam::convertLagrangianFields
|
||||
// low-level conversions
|
||||
//
|
||||
|
||||
template<class Type>
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtkPVFoam::zeroVTKField
|
||||
(
|
||||
const word& name,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
data->SetName(name.c_str());
|
||||
data->SetNumberOfComponents(int(pTraits<Type>::nComponents));
|
||||
data->SetNumberOfTuples(size);
|
||||
|
||||
data->Fill(0);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::label Foam::vtkPVFoam::transcribeFloatData
|
||||
(
|
||||
vtkFloatArray* array,
|
||||
const UList<Type>& input,
|
||||
const label start
|
||||
)
|
||||
{
|
||||
const int nComp(pTraits<Type>::nComponents);
|
||||
|
||||
if (array->GetNumberOfComponents() != nComp)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "vtk array '" << array->GetName()
|
||||
<< "' has mismatch in number of components for type '"
|
||||
<< pTraits<Type>::typeName
|
||||
<< "' : target array has " << array->GetNumberOfComponents()
|
||||
<< " components instead of " << nComp
|
||||
<< nl;
|
||||
}
|
||||
|
||||
const vtkIdType maxSize = array->GetNumberOfTuples();
|
||||
const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size());
|
||||
|
||||
if (start < 0 || vtkIdType(start) >= maxSize)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "vtk array '" << array->GetName()
|
||||
<< "' copy with out-of-range (0-" << long(maxSize-1) << ")"
|
||||
<< " starting location"
|
||||
<< nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (endPos > maxSize)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "vtk array '" << array->GetName()
|
||||
<< "' copy ends out-of-range (" << long(maxSize) << ")"
|
||||
<< " using sizing (start,size) = ("
|
||||
<< start << "," << input.size() << ")"
|
||||
<< nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
float scratch[nComp];
|
||||
forAll(input, idx)
|
||||
{
|
||||
const Type& t = input[idx];
|
||||
for (direction d=0; d<nComp; ++d)
|
||||
{
|
||||
scratch[d] = component(t, d);
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(scratch);
|
||||
|
||||
array->SetTuple(start+idx, scratch);
|
||||
}
|
||||
|
||||
return input.size();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtkPVFoam::convertFieldToVTK
|
||||
(
|
||||
const word& name,
|
||||
const UList<Type>& fld
|
||||
) const
|
||||
{
|
||||
const int nComp(pTraits<Type>::nComponents);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "convert UList<" << pTraits<Type>::typeName << "> "
|
||||
<< name
|
||||
<< " size=" << fld.size()
|
||||
<< " nComp=" << nComp << nl;
|
||||
}
|
||||
|
||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
data->SetName(name.c_str());
|
||||
data->SetNumberOfComponents(nComp);
|
||||
data->SetNumberOfTuples(fld.size());
|
||||
|
||||
transcribeFloatData(data, fld);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtkPVFoam::convertFaceFieldToVTK
|
||||
@ -923,7 +809,7 @@ Foam::vtkPVFoam::convertFaceFieldToVTK
|
||||
scratch[d] = component(t, d);
|
||||
}
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(scratch);
|
||||
remapTuple<Type>(scratch);
|
||||
|
||||
data->SetTuple(idx, scratch);
|
||||
}
|
||||
@ -966,7 +852,7 @@ Foam::vtkPVFoam::convertVolFieldToVTK
|
||||
{
|
||||
scratch[d] = component(t, d);
|
||||
}
|
||||
foamPvFields::remapTuple<Type>(scratch);
|
||||
remapTuple<Type>(scratch);
|
||||
|
||||
data->SetTuple(idx, scratch);
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -81,14 +81,14 @@ void Foam::vtkPVFoam::convertMeshVolume()
|
||||
Info<< "move points " << longName << nl;
|
||||
}
|
||||
vtkgeom = vtuData.getCopy();
|
||||
vtkgeom->SetPoints(movePoints(mesh, vtuData));
|
||||
vtkgeom->SetPoints(vtuData.points(mesh));
|
||||
}
|
||||
}
|
||||
|
||||
if (!vtkgeom)
|
||||
{
|
||||
// Nothing usable from cache - create new geometry
|
||||
vtkgeom = volumeVTKMesh(mesh, vtuData);
|
||||
vtkgeom = vtuData.internal(mesh, this->decomposePoly_);
|
||||
}
|
||||
|
||||
vtuData.set(vtkgeom);
|
||||
@ -176,7 +176,10 @@ void Foam::vtkPVFoam::convertMeshPatches()
|
||||
if (patchIds.size() == 1)
|
||||
{
|
||||
vtkgeom = vtpData.getCopy();
|
||||
vtkgeom->SetPoints(movePatchPoints(patches[patchIds[0]]));
|
||||
vtkgeom->SetPoints
|
||||
(
|
||||
vtk::Tools::Patch::points(patches[patchIds[0]])
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -234,7 +237,7 @@ void Foam::vtkPVFoam::convertMeshPatches()
|
||||
mesh.points()
|
||||
);
|
||||
|
||||
vtkgeom = patchVTKMesh(pp);
|
||||
vtkgeom = vtk::Tools::Patch::mesh(pp);
|
||||
}
|
||||
|
||||
faceLabels.clear(); // Unneeded
|
||||
@ -256,7 +259,7 @@ void Foam::vtkPVFoam::convertMeshPatches()
|
||||
// Store good patch id as additionalIds
|
||||
vtpData.additionalIds() = {patchId};
|
||||
|
||||
vtkgeom = patchVTKMesh(patches[patchId]);
|
||||
vtkgeom = vtk::Tools::Patch::mesh(patches[patchId]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,7 +346,7 @@ void Foam::vtkPVFoam::convertMeshArea()
|
||||
vtpData.clear(); // Remove any old mappings
|
||||
|
||||
// Nothing usable from cache - create new geometry
|
||||
vtkgeom = patchVTKMesh(mesh.patch());
|
||||
vtkgeom = vtk::Tools::Patch::mesh(mesh.patch());
|
||||
}
|
||||
|
||||
vtpData.set(vtkgeom);
|
||||
@ -414,10 +417,7 @@ void Foam::vtkPVFoam::convertMeshCellZones()
|
||||
Info<< "move points " << longName << nl;
|
||||
}
|
||||
vtkgeom = vtuData.getCopy();
|
||||
vtkgeom->SetPoints
|
||||
(
|
||||
movePoints(mesh, vtuData, vtuData.pointMap())
|
||||
);
|
||||
vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,7 +426,7 @@ void Foam::vtkPVFoam::convertMeshCellZones()
|
||||
fvMeshSubset subsetter(mesh);
|
||||
subsetter.setLargeCellSubset(zMesh[zoneId]);
|
||||
|
||||
vtkgeom = volumeVTKSubsetMesh(subsetter, vtuData);
|
||||
vtkgeom = vtuData.subset(subsetter, this->decomposePoly_);
|
||||
}
|
||||
|
||||
vtuData.set(vtkgeom);
|
||||
@ -484,10 +484,7 @@ void Foam::vtkPVFoam::convertMeshCellSets()
|
||||
Info<< "move points " << longName << nl;
|
||||
}
|
||||
vtkgeom = vtuData.getCopy();
|
||||
vtkgeom->SetPoints
|
||||
(
|
||||
movePoints(mesh, vtuData, vtuData.pointMap())
|
||||
);
|
||||
vtkgeom->SetPoints(vtuData.points(mesh, vtuData.pointMap()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -496,7 +493,7 @@ void Foam::vtkPVFoam::convertMeshCellSets()
|
||||
fvMeshSubset subsetter(mesh);
|
||||
subsetter.setLargeCellSubset(cellSet(mesh, partName));
|
||||
|
||||
vtkgeom = volumeVTKSubsetMesh(subsetter, vtuData);
|
||||
vtkgeom = vtuData.subset(subsetter, this->decomposePoly_);
|
||||
}
|
||||
|
||||
vtuData.set(vtkgeom);
|
||||
@ -571,7 +568,7 @@ void Foam::vtkPVFoam::convertMeshFaceZones()
|
||||
vtpData.clear(); // No additional ids, maps
|
||||
|
||||
const primitiveFacePatch& pp = zMesh[zoneId]();
|
||||
vtkgeom = patchVTKMesh(pp);
|
||||
vtkgeom = vtk::Tools::Patch::mesh(pp);
|
||||
}
|
||||
|
||||
vtpData.set(vtkgeom);
|
||||
@ -644,7 +641,7 @@ void Foam::vtkPVFoam::convertMeshFaceSets()
|
||||
mesh.points()
|
||||
);
|
||||
|
||||
vtkgeom = patchVTKMesh(pp);
|
||||
vtkgeom = vtk::Tools::Patch::mesh(pp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::lagrangianVTKMesh
|
||||
|
||||
vtkmesh = vtkSmartPointer<vtkPolyData>::New();
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkmesh->SetVerts(foamPvCore::identityVertices(parcels.size()));
|
||||
vtkmesh->SetVerts(vtk::Tools::identityVertices(parcels.size()));
|
||||
}
|
||||
|
||||
if (debug)
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -29,96 +29,91 @@ License
|
||||
// OpenFOAM includes
|
||||
#include "fvMesh.H"
|
||||
#include "fvMeshSubset.H"
|
||||
#include "foamVtkAdaptors.H"
|
||||
#include "foamVtkTools.H"
|
||||
#include "foamVtuSizing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkUnstructuredGrid.h"
|
||||
#include <vtkUnstructuredGrid.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::movePoints
|
||||
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::foamVtuData::points
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const foamVtuData& vtuData
|
||||
)
|
||||
const fvMesh& mesh
|
||||
) const
|
||||
{
|
||||
// Convert OpenFOAM mesh vertices to VTK
|
||||
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
// Normal points
|
||||
const pointField& points = mesh.points();
|
||||
const pointField& pts = mesh.points();
|
||||
|
||||
// Additional cell centres
|
||||
const labelList& addPoints = vtuData.additionalIds();
|
||||
const labelList& addPoints = this->additionalIds();
|
||||
|
||||
vtkpoints->SetNumberOfPoints(points.size() + addPoints.size());
|
||||
vtkpoints->SetNumberOfPoints(pts.size() + addPoints.size());
|
||||
|
||||
// Normal points
|
||||
label pointi = 0;
|
||||
forAll(points, i)
|
||||
label pointId = 0;
|
||||
for (const point& p : pts)
|
||||
{
|
||||
vtkpoints->SetPoint(pointi++, points[i].v_);
|
||||
vtkpoints->SetPoint(pointId, p.v_);
|
||||
++pointId;
|
||||
}
|
||||
|
||||
// Cell centres
|
||||
forAll(addPoints, i)
|
||||
for (const label ptId : addPoints)
|
||||
{
|
||||
vtkpoints->SetPoint(pointi++, mesh.C()[addPoints[i]].v_);
|
||||
vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_);
|
||||
++pointId;
|
||||
}
|
||||
|
||||
return vtkpoints;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::movePoints
|
||||
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::foamVtuData::points
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const foamVtuData& vtuData,
|
||||
const labelUList& pointMap
|
||||
)
|
||||
) const
|
||||
{
|
||||
// Convert OpenFOAM mesh vertices to VTK
|
||||
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
// Normal points
|
||||
const pointField& points = mesh.points();
|
||||
const pointField& pts = mesh.points();
|
||||
|
||||
// Additional cell centres
|
||||
const labelList& addPoints = vtuData.additionalIds();
|
||||
const labelList& addPoints = this->additionalIds();
|
||||
|
||||
vtkpoints->SetNumberOfPoints(pointMap.size() + addPoints.size());
|
||||
|
||||
// Normal points
|
||||
label pointi = 0;
|
||||
forAll(pointMap, i)
|
||||
label pointId = 0;
|
||||
for (const label ptId : pointMap)
|
||||
{
|
||||
vtkpoints->SetPoint(pointi++, points[pointMap[i]].v_);
|
||||
vtkpoints->SetPoint(pointId, pts[ptId].v_);
|
||||
++pointId;
|
||||
}
|
||||
|
||||
// Cell centres
|
||||
forAll(addPoints, i)
|
||||
for (const label ptId : addPoints)
|
||||
{
|
||||
vtkpoints->SetPoint(pointi++, mesh.C()[addPoints[i]].v_);
|
||||
vtkpoints->SetPoint(pointId, mesh.C()[ptId].v_);
|
||||
++pointId;
|
||||
}
|
||||
|
||||
return vtkpoints;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::foamVtuData::internal
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
foamVtuData& vtuData,
|
||||
const bool decompPoly
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "<beg> " << FUNCTION_NAME << nl;
|
||||
printMemory();
|
||||
}
|
||||
|
||||
vtk::vtuSizing sizing(mesh, decompPoly);
|
||||
|
||||
auto cellTypes = vtkSmartPointer<vtkUnsignedCharArray>::New();
|
||||
@ -130,14 +125,14 @@ vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
auto faceLocations = vtkSmartPointer<vtkIdTypeArray>::New();
|
||||
|
||||
UList<uint8_t> cellTypesUL =
|
||||
vtkUList
|
||||
vtk::Tools::asUList
|
||||
(
|
||||
cellTypes,
|
||||
sizing.nFieldCells()
|
||||
);
|
||||
|
||||
UList<vtkIdType> cellsUL =
|
||||
vtkUList
|
||||
vtk::Tools::asUList
|
||||
(
|
||||
cells,
|
||||
sizing.nFieldCells(),
|
||||
@ -145,21 +140,21 @@ vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
);
|
||||
|
||||
UList<vtkIdType> cellLocationsUL =
|
||||
vtkUList
|
||||
vtk::Tools::asUList
|
||||
(
|
||||
cellLocations,
|
||||
sizing.sizeInternal(vtk::vtuSizing::slotType::CELLS_OFFSETS)
|
||||
);
|
||||
|
||||
UList<vtkIdType> facesUL =
|
||||
vtkUList
|
||||
vtk::Tools::asUList
|
||||
(
|
||||
faces,
|
||||
sizing.sizeInternal(vtk::vtuSizing::slotType::FACES)
|
||||
);
|
||||
|
||||
UList<vtkIdType> faceLocationsUL =
|
||||
vtkUList
|
||||
vtk::Tools::asUList
|
||||
(
|
||||
faceLocations,
|
||||
sizing.sizeInternal(vtk::vtuSizing::slotType::FACES_OFFSETS)
|
||||
@ -174,7 +169,7 @@ vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
cellLocationsUL,
|
||||
facesUL,
|
||||
faceLocationsUL,
|
||||
static_cast<foamVtkMeshMaps&>(vtuData)
|
||||
static_cast<foamVtkMeshMaps&>(*this)
|
||||
);
|
||||
|
||||
auto vtkmesh = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
@ -182,7 +177,7 @@ vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
// 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(movePoints(mesh, vtuData));
|
||||
vtkmesh->SetPoints(this->points(mesh));
|
||||
|
||||
if (facesUL.size())
|
||||
{
|
||||
@ -207,58 +202,27 @@ vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
);
|
||||
}
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "<end> " << FUNCTION_NAME << nl;
|
||||
printMemory();
|
||||
}
|
||||
|
||||
return vtkmesh;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKSubsetMesh
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::foamVtuData::subset
|
||||
(
|
||||
const fvMeshSubset& subsetter,
|
||||
foamVtuData& vtuData,
|
||||
const bool decompPoly
|
||||
)
|
||||
{
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh = volumeVTKMesh
|
||||
(
|
||||
subsetter.subMesh(),
|
||||
vtuData,
|
||||
decompPoly
|
||||
);
|
||||
vtkSmartPointer<vtkUnstructuredGrid> vtkmesh =
|
||||
this->internal(subsetter.subMesh(), decompPoly);
|
||||
|
||||
// Convert cellMap, addPointCellLabels to global cell ids
|
||||
vtuData.renumberCells(subsetter.cellMap());
|
||||
this->renumberCells(subsetter.cellMap());
|
||||
|
||||
// Copy pointMap as well, otherwise pointFields fail
|
||||
vtuData.pointMap() = subsetter.pointMap();
|
||||
this->pointMap() = subsetter.pointMap();
|
||||
|
||||
return vtkmesh;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKMesh
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
foamVtuData& vtuData
|
||||
) const
|
||||
{
|
||||
return volumeVTKMesh(mesh, vtuData, this->decomposePoly_);
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> Foam::vtkPVFoam::volumeVTKSubsetMesh
|
||||
(
|
||||
const fvMeshSubset& subsetter,
|
||||
foamVtuData& vtuData
|
||||
) const
|
||||
{
|
||||
return volumeVTKSubsetMesh(subsetter, vtuData, this->decomposePoly_);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -1,119 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "vtkPVFoam.H"
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "polyPatch.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "foamVtkAdaptors.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkPoints.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class PatchType>
|
||||
vtkSmartPointer<vtkPoints> Foam::vtkPVFoam::movePatchPoints
|
||||
(
|
||||
const PatchType& p
|
||||
)
|
||||
{
|
||||
// Convert OpenFOAM mesh vertices to VTK
|
||||
const pointField& points = p.localPoints();
|
||||
|
||||
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->SetNumberOfPoints(points.size());
|
||||
forAll(points, i)
|
||||
{
|
||||
vtkpoints->SetPoint(i, points[i].v_);
|
||||
}
|
||||
|
||||
return vtkpoints;
|
||||
}
|
||||
|
||||
|
||||
template<class PatchType>
|
||||
vtkSmartPointer<vtkCellArray> Foam::vtkPVFoam::patchFacesVTKCells
|
||||
(
|
||||
const PatchType& p
|
||||
)
|
||||
{
|
||||
// Faces as polygons
|
||||
const faceList& faces = p.localFaces();
|
||||
|
||||
label nAlloc = faces.size();
|
||||
for (const face& f : faces)
|
||||
{
|
||||
nAlloc += f.size();
|
||||
}
|
||||
|
||||
auto cells = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
UList<vtkIdType> cellsUL =
|
||||
vtkUList
|
||||
(
|
||||
cells,
|
||||
faces.size(),
|
||||
nAlloc
|
||||
);
|
||||
|
||||
// Cell connectivity for polygons
|
||||
// [size, verts..., size, verts... ]
|
||||
label idx = 0;
|
||||
for (const face& f : faces)
|
||||
{
|
||||
cellsUL[idx++] = f.size();
|
||||
|
||||
for (const label verti : f)
|
||||
{
|
||||
cellsUL[idx++] = verti;
|
||||
}
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
|
||||
template<class PatchType>
|
||||
vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::patchVTKMesh
|
||||
(
|
||||
const PatchType& p
|
||||
)
|
||||
{
|
||||
auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkmesh->SetPoints(movePatchPoints(p));
|
||||
vtkmesh->SetPolys(patchFacesVTKCells(p));
|
||||
|
||||
return vtkmesh;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -3,6 +3,7 @@ sinclude $(GENERAL_RULES)/paraview
|
||||
EXE_INC = \
|
||||
${c++LESSWARN} \
|
||||
-I$(LIB_SRC)/fileFormats/lnInclude \
|
||||
-I$(LIB_SRC)/conversion/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/mesh/blockMesh/lnInclude \
|
||||
-I$(ParaView_INCLUDE_DIR) \
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -29,6 +29,7 @@ License
|
||||
// OpenFOAM includes
|
||||
#include "blockMesh.H"
|
||||
#include "Time.H"
|
||||
#include "foamVtkTools.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellArray.h"
|
||||
@ -255,7 +256,7 @@ void Foam::vtkPVblockMesh::convertMeshCorners
|
||||
auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkmesh->SetPoints(vtkpoints);
|
||||
vtkmesh->SetVerts(foamPvCore::identityVertices(blkPoints.size()));
|
||||
vtkmesh->SetVerts(vtk::Tools::identityVertices(blkPoints.size()));
|
||||
|
||||
addToBlock(output, vtkmesh, range, datasetNo, range.name());
|
||||
++datasetNo;
|
||||
|
||||
285
src/conversion/vtk/adaptor/foamVtkTools.H
Normal file
285
src/conversion/vtk/adaptor/foamVtkTools.H
Normal file
@ -0,0 +1,285 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::vtk::Tools
|
||||
|
||||
Description
|
||||
A collection of static methods to assist converting OpenFOAM data
|
||||
structures into VTK internal data structures.
|
||||
|
||||
Note
|
||||
The class is implemented as headers-only.
|
||||
|
||||
SourceFiles
|
||||
foamVtkToolsI.H
|
||||
foamVtkToolsTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkTools_H
|
||||
#define foamVtkTools_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "faceList.H"
|
||||
#include "pointField.H"
|
||||
#include "symmTensor.H"
|
||||
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkFloatArray.h>
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkIdTypeArray.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkUnsignedCharArray.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace vtk
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class vtk::Caching Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
//- Bookkeeping for internal caching.
|
||||
// Retain an original copy of the geometry as well as a shallow copy
|
||||
// with the output fields.
|
||||
// The original copy is reused for different timesteps etc.
|
||||
template<class DataType>
|
||||
struct Caching
|
||||
{
|
||||
typedef DataType dataType;
|
||||
|
||||
//- The geometry, without any cell/point data
|
||||
vtkSmartPointer<dataType> vtkgeom;
|
||||
|
||||
//- The shallow-copy of geometry, plus additional data
|
||||
vtkSmartPointer<dataType> dataset;
|
||||
|
||||
//- Number of points associated with the geometry
|
||||
inline uint64_t nPoints() const
|
||||
{
|
||||
return vtkgeom ? vtkgeom->GetNumberOfPoints() : 0;
|
||||
}
|
||||
|
||||
//- Clear geometry and dataset
|
||||
void clearGeom()
|
||||
{
|
||||
vtkgeom = nullptr;
|
||||
dataset = nullptr;
|
||||
}
|
||||
|
||||
//- Return a shallow copy of vtkgeom for manipulation
|
||||
vtkSmartPointer<dataType> getCopy() const
|
||||
{
|
||||
auto copy = vtkSmartPointer<dataType>::New();
|
||||
if (vtkgeom)
|
||||
{
|
||||
copy->ShallowCopy(vtkgeom);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
//- Make a shallow copy of vtkgeom into dataset
|
||||
void reuse()
|
||||
{
|
||||
dataset = vtkSmartPointer<dataType>::New();
|
||||
if (vtkgeom)
|
||||
{
|
||||
dataset->ShallowCopy(vtkgeom);
|
||||
}
|
||||
}
|
||||
|
||||
//- Set the geometry and make a shallow copy to dataset
|
||||
void set(vtkSmartPointer<dataType> geom)
|
||||
{
|
||||
vtkgeom = geom;
|
||||
reuse();
|
||||
}
|
||||
|
||||
//- Report basic information to output
|
||||
void PrintSelf(std::ostream& os) const
|
||||
{
|
||||
os << "geom" << nl;
|
||||
if (vtkgeom)
|
||||
{
|
||||
vtkgeom->PrintSelf(std::cout, vtkIndent(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "nullptr";
|
||||
}
|
||||
os << nl;
|
||||
|
||||
os << "copy" << nl;
|
||||
if (dataset)
|
||||
{
|
||||
dataset->PrintSelf(std::cout, vtkIndent(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "nullptr";
|
||||
}
|
||||
os << nl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class vtk::Tools Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Tools
|
||||
{
|
||||
public:
|
||||
|
||||
//- Wrap vtkUnsignedCharArray as a UList
|
||||
inline static UList<uint8_t> asUList
|
||||
(
|
||||
vtkUnsignedCharArray* array,
|
||||
const label size
|
||||
);
|
||||
|
||||
//- Wrap vtkIdTypeArray as a UList
|
||||
inline static UList<vtkIdType> asUList
|
||||
(
|
||||
vtkIdTypeArray* array,
|
||||
const label size
|
||||
);
|
||||
|
||||
//- Wrap vtkCellArray as a UList
|
||||
inline static UList<vtkIdType> asUList
|
||||
(
|
||||
vtkCellArray* cells,
|
||||
const label nCells,
|
||||
const label size
|
||||
);
|
||||
|
||||
|
||||
//- Convert OpenFOAM patch to vtkPolyData
|
||||
struct Patch
|
||||
{
|
||||
//- Convert local patch points to vtkPoints
|
||||
template<class PatchType>
|
||||
static vtkSmartPointer<vtkPoints> points(const PatchType& p);
|
||||
|
||||
//- Convert patch faces to vtk polygon cells
|
||||
template<class PatchType>
|
||||
static vtkSmartPointer<vtkCellArray> faces(const PatchType& p);
|
||||
|
||||
//- Convert patch points/faces to vtkPolyData
|
||||
template<class PatchType>
|
||||
static vtkSmartPointer<vtkPolyData> mesh(const PatchType& p);
|
||||
};
|
||||
|
||||
|
||||
//- Remapping for some OpenFOAM data types
|
||||
template<class Type>
|
||||
inline static void remapTuple(float vec[]) {}
|
||||
|
||||
//- Remapping for some OpenFOAM data types
|
||||
template<class Type>
|
||||
inline static void remapTuple(double vec[]) {}
|
||||
|
||||
// Field Conversion Functions
|
||||
|
||||
//- Copy list to pre-allocated vtk array.
|
||||
// \return number of input items copied
|
||||
template<class Type>
|
||||
static label transcribeFloatData
|
||||
(
|
||||
vtkFloatArray* array,
|
||||
const UList<Type>& input,
|
||||
const label start = 0
|
||||
);
|
||||
|
||||
//- Create named field initialized to zero
|
||||
template<class Type>
|
||||
static vtkSmartPointer<vtkFloatArray> zeroField
|
||||
(
|
||||
const word& name,
|
||||
const label size
|
||||
);
|
||||
|
||||
//- Convert field data to a vtkFloatArray
|
||||
template<class Type>
|
||||
static vtkSmartPointer<vtkFloatArray> convertFieldToVTK
|
||||
(
|
||||
const word& name,
|
||||
const UList<Type>& fld
|
||||
);
|
||||
|
||||
//- An identity list of VTK_VERTEX
|
||||
static inline vtkSmartPointer<vtkCellArray> identityVertices
|
||||
(
|
||||
const label size
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
//- Template specialization for symmTensor
|
||||
template<>
|
||||
inline void Foam::vtk::Tools::remapTuple<Foam::symmTensor>(float vec[])
|
||||
{
|
||||
std::swap(vec[1], vec[3]); // swap XY <-> YY
|
||||
std::swap(vec[2], vec[5]); // swap XZ <-> ZZ
|
||||
}
|
||||
|
||||
|
||||
//- Template specialization for symmTensor
|
||||
template<>
|
||||
inline void Foam::vtk::Tools::remapTuple<Foam::symmTensor>(double vec[])
|
||||
{
|
||||
std::swap(vec[1], vec[3]); // swap XY <-> YY
|
||||
std::swap(vec[2], vec[5]); // swap XZ <-> ZZ
|
||||
}
|
||||
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace vtk
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "foamVtkToolsI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "foamVtkToolsTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
90
src/conversion/vtk/adaptor/foamVtkToolsI.H
Normal file
90
src/conversion/vtk/adaptor/foamVtkToolsI.H
Normal file
@ -0,0 +1,90 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::UList<uint8_t> Foam::vtk::Tools::asUList
|
||||
(
|
||||
vtkUnsignedCharArray* array,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
array->SetNumberOfComponents(1);
|
||||
array->SetNumberOfTuples(size);
|
||||
|
||||
return UList<uint8_t>(array->WritePointer(0, size), size);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::UList<vtkIdType> Foam::vtk::Tools::asUList
|
||||
(
|
||||
vtkIdTypeArray* array,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
array->SetNumberOfComponents(1);
|
||||
array->SetNumberOfTuples(size);
|
||||
|
||||
return UList<vtkIdType>(array->WritePointer(0, size), size);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::UList<vtkIdType> Foam::vtk::Tools::asUList
|
||||
(
|
||||
vtkCellArray* cells,
|
||||
const label nCells,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
cells->GetData()->SetNumberOfTuples(size);
|
||||
|
||||
return UList<vtkIdType>(cells->WritePointer(nCells, size), size);
|
||||
}
|
||||
|
||||
|
||||
inline vtkSmartPointer<vtkCellArray> Foam::vtk::Tools::identityVertices
|
||||
(
|
||||
const label size
|
||||
)
|
||||
{
|
||||
// VTK_VERTEX: need 2 values (size=1 and index=id) per vertex
|
||||
auto cells = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
UList<vtkIdType> list = asUList(cells, size, 2*size);
|
||||
|
||||
// Cell connectivity for vertex
|
||||
// [size, ids.., size, ids...] -> therefore [1, id, 1, id, ...]
|
||||
auto iter = list.begin();
|
||||
for (label id=0; id < size; ++id)
|
||||
{
|
||||
*(iter++) = 1;
|
||||
*(iter++) = id;
|
||||
}
|
||||
|
||||
return cells;
|
||||
};
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
229
src/conversion/vtk/adaptor/foamVtkToolsTemplates.C
Normal file
229
src/conversion/vtk/adaptor/foamVtkToolsTemplates.C
Normal file
@ -0,0 +1,229 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017-2018 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
InClass
|
||||
Foam::vtk::Tools
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef foamVtkToolsTemplates_C
|
||||
#define foamVtkToolsTemplates_C
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "error.H"
|
||||
|
||||
// VTK includes
|
||||
#include <vtkFloatArray.h>
|
||||
#include <vtkCellData.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class PatchType>
|
||||
vtkSmartPointer<vtkPoints>
|
||||
Foam::vtk::Tools::Patch::points(const PatchType& p)
|
||||
{
|
||||
// Local patch points to vtkPoints
|
||||
const pointField& pts = p.localPoints();
|
||||
|
||||
auto vtkpoints = vtkSmartPointer<vtkPoints>::New();
|
||||
|
||||
vtkpoints->SetNumberOfPoints(pts.size());
|
||||
vtkIdType pointId = 0;
|
||||
|
||||
for (const point& p : pts)
|
||||
{
|
||||
vtkpoints->SetPoint(pointId, p.v_);
|
||||
++pointId;
|
||||
}
|
||||
|
||||
return vtkpoints;
|
||||
}
|
||||
|
||||
|
||||
template<class PatchType>
|
||||
vtkSmartPointer<vtkCellArray>
|
||||
Foam::vtk::Tools::Patch::faces(const PatchType& p)
|
||||
{
|
||||
// Faces as polygons
|
||||
const faceList& fcs = p.localFaces();
|
||||
|
||||
label nAlloc = fcs.size();
|
||||
for (const face& f : fcs)
|
||||
{
|
||||
nAlloc += f.size();
|
||||
}
|
||||
|
||||
auto vtkcells = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
UList<vtkIdType> list = asUList(vtkcells, fcs.size(), nAlloc);
|
||||
|
||||
// Cell connectivity for polygons
|
||||
// [size, verts..., size, verts... ]
|
||||
auto iter = list.begin();
|
||||
for (const face& f : fcs)
|
||||
{
|
||||
*(iter++) = f.size();
|
||||
|
||||
for (const label verti : f)
|
||||
{
|
||||
*(iter++) = verti;
|
||||
}
|
||||
}
|
||||
|
||||
return vtkcells;
|
||||
}
|
||||
|
||||
|
||||
template<class PatchType>
|
||||
vtkSmartPointer<vtkPolyData>
|
||||
Foam::vtk::Tools::Patch::mesh(const PatchType& p)
|
||||
{
|
||||
auto vtkmesh = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
vtkmesh->SetPoints(points(p));
|
||||
vtkmesh->SetPolys(faces(p));
|
||||
|
||||
return vtkmesh;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
//
|
||||
// Low-Level conversions
|
||||
//
|
||||
|
||||
template<class Type>
|
||||
Foam::label Foam::vtk::Tools::transcribeFloatData
|
||||
(
|
||||
vtkFloatArray* array,
|
||||
const UList<Type>& input,
|
||||
const label start
|
||||
)
|
||||
{
|
||||
const int nComp(pTraits<Type>::nComponents);
|
||||
|
||||
if (array->GetNumberOfComponents() != nComp)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "vtk array '" << array->GetName()
|
||||
<< "' has mismatch in number of components for type '"
|
||||
<< pTraits<Type>::typeName
|
||||
<< "' : target array has " << array->GetNumberOfComponents()
|
||||
<< " components instead of " << nComp
|
||||
<< nl;
|
||||
}
|
||||
|
||||
const vtkIdType maxSize = array->GetNumberOfTuples();
|
||||
const vtkIdType endPos = vtkIdType(start) + vtkIdType(input.size());
|
||||
|
||||
if (!maxSize)
|
||||
{
|
||||
// no-op
|
||||
return 0;
|
||||
}
|
||||
else if (start < 0 || vtkIdType(start) >= maxSize)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "vtk array '" << array->GetName()
|
||||
<< "' copy with out-of-range [0," << long(maxSize) << ")"
|
||||
<< " starting at " << start
|
||||
<< nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if (endPos > maxSize)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "vtk array '" << array->GetName()
|
||||
<< "' copy ends out-of-range (" << long(maxSize) << ")"
|
||||
<< " using sizing (start,size) = ("
|
||||
<< start << "," << input.size() << ")"
|
||||
<< nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
float scratch[nComp];
|
||||
forAll(input, idx)
|
||||
{
|
||||
const Type& t = input[idx];
|
||||
for (direction d=0; d<nComp; ++d)
|
||||
{
|
||||
scratch[d] = component(t, d);
|
||||
}
|
||||
remapTuple<Type>(scratch);
|
||||
|
||||
array->SetTuple(start+idx, scratch);
|
||||
}
|
||||
|
||||
return input.size();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtk::Tools::zeroField
|
||||
(
|
||||
const word& name,
|
||||
const label size
|
||||
)
|
||||
{
|
||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
data->SetName(name.c_str());
|
||||
data->SetNumberOfComponents(int(pTraits<Type>::nComponents));
|
||||
data->SetNumberOfTuples(size);
|
||||
|
||||
data->Fill(0);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
vtkSmartPointer<vtkFloatArray>
|
||||
Foam::vtk::Tools::convertFieldToVTK
|
||||
(
|
||||
const word& name,
|
||||
const UList<Type>& fld
|
||||
)
|
||||
{
|
||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
data->SetName(name.c_str());
|
||||
data->SetNumberOfComponents(int(pTraits<Type>::nComponents));
|
||||
data->SetNumberOfTuples(fld.size());
|
||||
|
||||
transcribeFloatData(data, fld);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user