34 m_mesh(vtkSmartPointer<vtkDataSet>())
37 "Implemented vtk mesh reader is not compatible with extension "
39 <<
" Valid extenstions are vtk and pvtu."
69 vtkIdType cellType, nbCellsTotal =
m_mesh->GetNumberOfCells();
71 vtkIdType cellNbPoints;
72 vtkIdList *cellPoints = vtkIdList::New();
73 for (vtkIdType i = 0; i < nbCellsTotal; ++i)
75 cellType =
m_mesh->GetCellType(i);
111 m_mesh->GetCellPoints(i, cellPoints);
112 cellNbPoints = cellPoints->GetNumberOfIds ();
113 if ((cellNbPoints == 3 and not
m_quads) or (cellNbPoints == 4 and
m_quads))
134 "No cells or boundary cells found in file " <<
m_fileName <<
" for mesh of dimension "
161 vtkPointSet *p = vtkPointSet::SafeDownCast(
m_mesh);
167 if (i>=indexStart and i<indexEnd)
169 coords[3*nodeId ] =
static_cast<CepsReal>(pt[0]);
170 coords[3*nodeId+1] =
static_cast<CepsReal>(pt[1]);
171 coords[3*nodeId+2] =
static_cast<CepsReal>(pt[2]);
201 cellOffset+
m_cellsRead,i,nodeOffset,nodeIndices,nodeIndicesPtr,
202 cellAttr,cellAttrPtr,isBoundaryCell,
false
208 cellAttr,cellAttrPtr,isBoundaryCell,
true
218 return (extension ==
"vtk" or extension ==
"pvtu");
234 vtkIdList *ptIds = vtkIdList::New();
235 m_mesh->GetCellPoints(fileCellId,ptIds);
240 if (nbPoints == ptIds->GetNumberOfIds())
242 for (
CepsUInt i = 0U; i < nbPoints; i++)
243 nodeIndices[nodeIndicesPtr[cellId]+i] = ptIds->GetId(i)+nodeOffset;
250 nodeIndicesPtr[cellId+1] = nodeIndicesPtr[cellId] + nbPoints;
251 isBoundaryCell[cellId ] = boundaryFlag;
265 vtkXMLPUnstructuredGridReader *reader = vtkXMLPUnstructuredGridReader::New();
266 reader->SetFileName (fileName.c_str());
269 reader->GetOutput()->Register(reader);
270 m_mesh = vtkDataSet::SafeDownCast(reader->GetOutput());
277 vtkNew<vtkDataSetReader> reader;
279 reader->SetFileName (fileName.c_str());
280 reader->SetReadAllScalars(1);
281 reader->SetReadAllVectors(1);
282 reader->SetReadAllNormals(1);
283 reader->SetReadAllTensors(1);
284 reader->SetReadAllFields (1);
288 reader->GetOutput()->Register(reader);
289 m_mesh = vtkDataSet::SafeDownCast(reader->GetOutput());
296 vtkCellData *cellData =
m_mesh->GetCellData();
297 vtkDataArray *array =
nullptr;
301 for (i = 0; i < cellData->GetNumberOfArrays(); ++i)
303 array = cellData->GetArray(i);
305 switch (array->GetDataType())
307 case VTK_UNSIGNED_SHORT:
308 case VTK_UNSIGNED_CHAR:
309 case VTK_UNSIGNED_LONG:
310 case VTK_UNSIGNED_INT:
317 if ((array->GetNumberOfComponents()==1) and (array->GetNumberOfTuples() == nbCells))
323 CEPS_SAYS(
" Detected attributes array \"" << array->GetName() <<
"\" on cells");
337 vtkPointData *data =
m_mesh->GetPointData();
338 vtkDataArray *array =
nullptr;
341 for (i = 0; i < data->GetNumberOfArrays(); ++i)
343 array = data->GetArray(i);
345 switch (array->GetDataType())
347 case VTK_UNSIGNED_SHORT:
348 case VTK_UNSIGNED_CHAR:
349 case VTK_UNSIGNED_LONG:
350 case VTK_UNSIGNED_INT:
355 if ((array->GetNumberOfComponents() == 1) and ((
CepsUInt)(array->GetNumberOfTuples()) ==
m_nbNodes))
360 CEPS_SAYS(
" Detected attributes array \"" << array->GetName() <<
"\" on points");
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
int32_t CepsInt
Need 32 bit integer.
CepsString m_fileName
file to open
Abstract base class that encapsulates primary functionalities of each mesh reader.
CepsUInt m_nbAttrPerCell
attributes per cell
CepsBool m_initialized
Flag to ensure call of initializeReader()
void checkCanReadNodes(CepsUInt indexStart, CepsUInt indexEnd) const
Aborts if passed indices are wrong.
CepsUInt m_nbNodesPerBdryCell
nb nodes per boundary cell
CepsBool m_quads
Reader for quadratic cells.
CepsUInt m_bdryCellsRead
Keeps track of already read boundary cells.
CepsUInt m_nbNodesPerCell
nb nodes per cell
CepsUInt m_nbBdryCells
number of boundary cells in mesh, appropriate for dimension
CepsUInt m_nbAttrPerBdryCell
attributes per boundary cell
CepsUInt m_cellsRead
Keeps track of already read cells.
CepsUInt m_nbAttrPerNode
attributes per node
CepsUInt m_expectedDim
Expected dimension of mesh.
CepsUInt m_nbCellsTotal
number of all cells in file
CepsUInt m_nbNodes
number of nodes in mesh
CepsUInt m_nbCells
number of cells in mesh, appropriate for dimension
void checkCanReadCells(CepsUInt indexStart, CepsUInt indexEnd) const
Aborts if passed indices are wrong.
~VtkMeshReader() override
Destructor.
void getNextCell(CepsUInt cellId, CepsUInt fileCellId, CepsUInt nodeOffset, CepsVector< CepsNodeGlobalIndex > &nodeIndices, CepsVector< CepsUInt > &nodeIndicesPtr, CepsVector< CepsAttribute > &cellAttr, CepsVector< CepsUInt > &cellAttrPtr, CepsVector< CepsChar > &isBoundaryCell, CepsBool boundaryFlag) override
Reads a single cell in mesh file.
void readNodes(CepsUInt indexStart, CepsUInt indexEnd, CepsUInt nodeOffset, CepsVector< CepsReal > &coords, CepsVector< CepsAttribute > &attr, CepsVector< CepsUInt > &attrPtr) override
Reads several nodes in mesh file.
void determinePointDataToRead()
Selects the integer array that should be present, which contains node attributes.
CepsVector< vtkDataArray * > m_cellArrayToRead
Arrays of data defined on cells.
void readCells(CepsUInt indexStart, CepsUInt indexEnd, CepsUInt nodeOffset, CepsUInt cellOffset, CepsVector< CepsNodeGlobalIndex > &nodeIndices, CepsVector< CepsUInt > &nodeIndicesPtr, CepsVector< CepsAttribute > &cellAttr, CepsVector< CepsUInt > &cellAttrPtr, CepsVector< CepsChar > &isBoundaryCell) override
Reads several cells in mesh file.
VtkMeshReader(const CepsString &fileName, const CepsUInt &dim, CepsBool quads=false)
Constructor with full file name.
void determineCellDataToRead()
Selects the integer array that should be present, which contains cell attributes.
void initializePvtu(const CepsString &fileName)
Reads global information for parallel unstructured grids.
vtkSmartPointer< vtkDataSet > m_mesh
VTK mesh structure.
CepsVector< vtkDataArray * > m_pointArrayToRead
Arrays of data defined on points.
void initializeLegacy(const CepsString &fileName)
Reads global information for legacy files.
void initialize() override
Read nodes from indexStart to indexEnd, filling the arrays of coordinates and attributes.
CepsBool isVtkFile(const CepsString &fileName) const
Test if file is legacy file .vtk or .pvtu.
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
CepsString getFilename(const CepsString &str)
Returns a substring corresponding to the string after the last '/' character. Example: "/home/someone...
CepsString getExtension(const CepsString &str)
Returns the extension of a file, if any.