44 #include "VtkMeshReader.hpp" 47 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
57 mBoundaryFacesRead(0),
58 mBoundaryFacesSkipped(0),
59 mCableElementsRead(0),
60 mNumElementAttributes(0),
61 mNumFaceAttributes(0),
62 mNumCableElementAttributes(0),
65 mVtkCellType(VTK_TETRA)
67 vtkXMLUnstructuredGridReader* vtk_xml_unstructured_grid_reader;
73 EXCEPTION(
"Could not open VTU file: " + pathBaseName);
78 vtk_xml_unstructured_grid_reader = vtkXMLUnstructuredGridReader::New();
79 vtk_xml_unstructured_grid_reader->SetFileName( pathBaseName.c_str() );
80 vtk_xml_unstructured_grid_reader->Update();
83 vtk_xml_unstructured_grid_reader->Delete();
86 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
93 if (ELEMENT_DIM == 2u)
98 else if (ELEMENT_DIM == 1u)
105 vtkCellTypes* cell_types = vtkCellTypes::New();
108 if (cell_types->GetNumberOfTypes() > 1)
111 for (
unsigned cell_id = 0; cell_id < num_cells; ++cell_id)
134 cell_types->Delete();
138 if (ELEMENT_DIM == 2u)
140 vtkDataSetSurfaceFilter* p_surface = vtkDataSetSurfaceFilter::New();
142 #if VTK_MAJOR_VERSION >= 6 153 else if (ELEMENT_DIM == 3u)
156 #if VTK_MAJOR_VERSION >= 6 168 for (
unsigned i=0; i<num_all_cells; i++)
177 else if (ELEMENT_DIM == 1u)
180 vtkSmartPointer<vtkIdList> enclosing_cells = vtkSmartPointer<vtkIdList>::New();
182 for (
unsigned point_index = 0; point_index <
mNumNodes; ++point_index)
186 if (enclosing_cells->GetNumberOfIds() == 1u)
198 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
222 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
225 if (ELEMENT_DIM == 3u)
229 else if (ELEMENT_DIM == 2u)
235 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
241 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
247 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
253 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
259 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
265 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
271 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
277 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
283 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
294 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
299 EXCEPTION(
"Trying to read data for a node that doesn't exist" );
302 std::vector<double> next_node;
304 for (
unsigned i = 0; i < 3; i++)
313 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
318 EXCEPTION(
"Trying to read data for an element that doesn't exist" );
323 EXCEPTION(
"Element is not of expected type (vtkTetra/vtkTriangle)");
337 return next_element_data;
340 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
345 EXCEPTION(
"Trying to read data for a cable element that doesn't exist" );
353 for (
unsigned i = 0; i < 2; i++)
359 next_element_data.AttributeValue = p_scalars->GetTuple(next_index)[0];
361 mCableElementsRead++;
362 return next_element_data;
366 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
371 EXCEPTION(
"Trying to read data for a boundary element that doesn't exist");
376 if (ELEMENT_DIM == 3u)
387 else if (ELEMENT_DIM == 2u)
394 else if (ELEMENT_DIM == 1u)
396 vtkSmartPointer<vtkIdList> enclosing_cells = vtkSmartPointer<vtkIdList>::New();
403 if (enclosing_cells->GetNumberOfIds() == 1u)
416 return next_face_data;
420 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
425 if (!p_cell_data->HasArray(dataName.c_str()))
427 EXCEPTION(
"No cell data '" + dataName +
"'");
430 vtkDataArray *p_scalars = p_cell_data->GetArray( dataName.c_str() );
431 if (p_scalars->GetNumberOfComponents() != 1)
433 EXCEPTION(
"The cell data '" + dataName +
"' is not scalar data.");
439 dataPayload.push_back( p_scalars->GetTuple(i)[0] );
443 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
448 if (!p_cell_data->HasArray(dataName.c_str()))
450 EXCEPTION(
"No cell data '" + dataName +
"'");
453 vtkDataArray *p_scalars = p_cell_data->GetArray( dataName.c_str() );
454 if (p_scalars->GetNumberOfComponents() != 3)
456 EXCEPTION(
"The cell data '" + dataName +
"' is not 3-vector data.");
462 c_vector <double, SPACE_DIM> data;
463 for (
unsigned j = 0; j < SPACE_DIM; j++)
465 data[j]= p_scalars->GetTuple(i)[j];
467 dataPayload.push_back(data);
472 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
477 if (!p_point_data->HasArray(dataName.c_str()))
479 EXCEPTION(
"No point data '" + dataName +
"'");
482 vtkDataArray *p_scalars = p_point_data->GetArray( dataName.c_str() );
483 if (p_scalars->GetNumberOfComponents() != 1)
485 EXCEPTION(
"The point data '" + dataName +
"' is not scalar data.");
492 dataPayload.push_back( p_scalars->GetTuple(i)[0] );
496 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
501 if (!p_point_data->HasArray(dataName.c_str()))
503 EXCEPTION(
"No point data '" + dataName +
"'");
506 vtkDataArray *p_scalars = p_point_data->GetArray( dataName.c_str() );
508 if (p_scalars->GetNumberOfComponents() != 3)
510 EXCEPTION(
"The point data '" + dataName +
"' is not 3-vector data.");
515 c_vector<double, SPACE_DIM> data;
516 for (
unsigned j = 0; j< SPACE_DIM; j++)
518 data[j] = p_scalars->GetTuple(i)[j];
520 dataPayload.push_back( data );
525 template <
unsigned ELEMENT_DIM,
unsigned SPACE_DIM>
unsigned GetNumCableElementAttributes() const
unsigned mBoundaryFacesSkipped
#define EXCEPTION(message)
unsigned GetNumEdges() const
unsigned mNumFaceAttributes
void GetPointData(std::string dataName, std::vector< double > &dataPayload)
unsigned GetNumFaceAttributes() const
unsigned mOrderOfElements
vtkGeometryFilter * mpVtkGeometryFilter
ElementData GetNextFaceData()
unsigned GetNumElementAttributes() const
ElementData GetNextElementData()
unsigned mNumElementAttributes
std::vector< unsigned > NodeIndices
unsigned mNumCableElements
unsigned GetNumElements() const
unsigned mNodesPerElement
ElementData GetNextCableElementData()
unsigned mCableElementsRead
unsigned GetNumCableElements() const
unsigned mBoundaryFacesRead
vtkFeatureEdges * mpVtkFilterEdges
void GetCellData(std::string dataName, std::vector< double > &dataPayload)
unsigned mNumCableElementAttributes
unsigned GetNumFaces() const
unsigned GetNumNodes() const
vtkUnstructuredGrid * OutputMeshAsVtkUnstructuredGrid()
std::vector< double > GetNextNode()
vtkSmartPointer< vtkUnstructuredGrid > mpVtkUnstructuredGrid
VtkMeshReader(std::string pathBaseName)