58 mBoundaryFacesRead(0),
59 mBoundaryFacesSkipped(0),
60 mCableElementsRead(0),
61 mNumElementAttributes(0),
62 mNumFaceAttributes(0),
63 mNumCableElementAttributes(0),
66 mVtkCellType(VTK_TETRA)
68 vtkXMLUnstructuredGridReader* vtk_xml_unstructured_grid_reader;
74 EXCEPTION(
"Could not open VTU file: " + pathBaseName);
79 vtk_xml_unstructured_grid_reader = vtkXMLUnstructuredGridReader::New();
80 vtk_xml_unstructured_grid_reader->SetFileName( pathBaseName.c_str() );
81 vtk_xml_unstructured_grid_reader->Update();
84 vtk_xml_unstructured_grid_reader->Delete();
91 mNumNodes = mpVtkUnstructuredGrid->GetNumberOfPoints();
92 unsigned num_cells = mpVtkUnstructuredGrid->GetNumberOfCells();
94 if (ELEMENT_DIM == 2u)
97 mVtkCellType = VTK_TRIANGLE;
99 else if (ELEMENT_DIM == 1u)
101 mNodesPerElement = 2;
102 mVtkCellType = VTK_LINE;
105#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 2)
106 const auto num_distinct_cell_types =
static_cast<unsigned>(mpVtkUnstructuredGrid->GetDistinctCellTypesArray()->GetNumberOfTuples());
108 vtkCellTypes* cell_types = vtkCellTypes::New();
109 mpVtkUnstructuredGrid->GetCellTypes(cell_types);
110 const auto num_distinct_cell_types =
static_cast<unsigned>(cell_types->GetNumberOfTypes());
111 cell_types->Delete();
114 if (num_distinct_cell_types > 1u)
116 mNumCableElementAttributes = 1;
117 for (
unsigned cell_id = 0; cell_id < num_cells; ++cell_id)
119 if (mpVtkUnstructuredGrid->GetCellType(cell_id) == mVtkCellType)
122 assert(mNumCableElements == 0);
124 else if (mpVtkUnstructuredGrid->GetCellType(cell_id) == VTK_LINE)
137 mNumElements = num_cells;
141 if (ELEMENT_DIM == 2u)
143 vtkDataSetSurfaceFilter* p_surface = vtkDataSetSurfaceFilter::New();
144 mpVtkFilterEdges = vtkFeatureEdges::New();
145 p_surface->SetInputData(mpVtkUnstructuredGrid);
146 mpVtkFilterEdges->SetInputConnection(p_surface->GetOutputPort());
147 mpVtkFilterEdges->Update();
148 mNumFaces = mpVtkFilterEdges->GetOutput()->GetNumberOfCells();
151 else if (ELEMENT_DIM == 3u)
153 mpVtkGeometryFilter = vtkGeometryFilter::New();
154 mpVtkGeometryFilter->SetInputData(mpVtkUnstructuredGrid);
156#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1)
158 mpVtkGeometryFilter->SetPassThroughPointIds(1);
160 mpVtkGeometryFilter->Update();
162 mNumFaces = mpVtkGeometryFilter->GetOutput()->GetNumberOfCells();
163 if (mNumCableElements > 0)
166 unsigned num_all_cells = mNumFaces;
167 for (
unsigned i=0; i<num_all_cells; i++)
169 if (mpVtkGeometryFilter->GetOutput()->GetCellType(i) == VTK_LINE)
176 else if (ELEMENT_DIM == 1u)
179 vtkSmartPointer<vtkIdList> enclosing_cells = vtkSmartPointer<vtkIdList>::New();
180 assert(mNumNodes == (
unsigned) mpVtkUnstructuredGrid->GetNumberOfPoints());
181 for (
unsigned point_index = 0; point_index < mNumNodes; ++point_index)
183 mpVtkUnstructuredGrid->GetPointCells(point_index, enclosing_cells);
185 if (enclosing_cells->GetNumberOfIds() == 1u)
342 if (mCableElementsRead >= mNumCableElements)
344 EXCEPTION(
"Trying to read data for a cable element that doesn't exist" );
347 unsigned next_index = mNumElements + mCableElementsRead;
348 assert(mpVtkUnstructuredGrid->GetCellType(next_index)==VTK_LINE);
352 for (
unsigned i = 0; i < 2; i++)
354 next_element_data.
NodeIndices.push_back(mpVtkUnstructuredGrid->GetCell(next_index)->GetPointId(i));
357 vtkDataArray *p_scalars = mpVtkUnstructuredGrid->GetCellData()->GetArray(
"Cable radius" );
358 next_element_data.
AttributeValue = p_scalars->GetTuple(next_index)[0];
360 mCableElementsRead++;
361 return next_element_data;
368 if (mBoundaryFacesRead >= mNumFaces)
370 EXCEPTION(
"Trying to read data for a boundary element that doesn't exist");
374 if (ELEMENT_DIM == 3u)
376#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1)
378 vtkDataArray *original_ids = mpVtkGeometryFilter->GetOutput()->GetPointData()->GetArray(
"vtkOriginalPointIds");
380 while (mpVtkGeometryFilter->GetOutput()->GetCellType(mBoundaryFacesRead + mBoundaryFacesSkipped) == VTK_LINE)
382 mBoundaryFacesSkipped++;
384 for (
unsigned i = 0; i < (mNodesPerElement-1); i++)
386 unsigned id = mpVtkGeometryFilter->GetOutput()->GetCell(mBoundaryFacesRead + mBoundaryFacesSkipped)->GetPointId(i);
387#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1)
389 next_face_data.
NodeIndices.push_back(original_ids->GetTuple1(
id));
395 else if (ELEMENT_DIM == 2u)
397 for (
unsigned i = 0; i < (mNodesPerElement-1); i++)
399 next_face_data.
NodeIndices.push_back(mpVtkFilterEdges->GetOutput()->GetCell(mBoundaryFacesRead)->GetPointId(i));
402 else if (ELEMENT_DIM == 1u)
404 vtkSmartPointer<vtkIdList> enclosing_cells = vtkSmartPointer<vtkIdList>::New();
405 assert(mNumNodes == (
unsigned) mpVtkUnstructuredGrid->GetNumberOfPoints());
406 for (
unsigned point_index = mBoundaryFacesSkipped; point_index < mNumNodes; ++point_index)
408 mBoundaryFacesSkipped++;
409 mpVtkUnstructuredGrid->GetPointCells(point_index, enclosing_cells);
411 if (enclosing_cells->GetNumberOfIds() == 1u)
423 mBoundaryFacesRead++;
424 return next_face_data;
431 vtkCellData *p_cell_data = mpVtkUnstructuredGrid->GetCellData();
433 if (!p_cell_data->HasArray(dataName.c_str()))
435 EXCEPTION(
"No cell data '" + dataName +
"'");
438 vtkDataArray *p_scalars = p_cell_data->GetArray( dataName.c_str() );
439 if (p_scalars->GetNumberOfComponents() != 1)
441 EXCEPTION(
"The cell data '" + dataName +
"' is not scalar data.");
445 for (
unsigned i = 0; i < mNumElements; i++)
447 dataPayload.push_back( p_scalars->GetTuple(i)[0] );
454 vtkCellData *p_cell_data = mpVtkUnstructuredGrid->GetCellData();
456 if (!p_cell_data->HasArray(dataName.c_str()))
458 EXCEPTION(
"No cell data '" + dataName +
"'");
461 vtkDataArray *p_scalars = p_cell_data->GetArray( dataName.c_str() );
462 if (p_scalars->GetNumberOfComponents() != 3)
464 EXCEPTION(
"The cell data '" + dataName +
"' is not 3-vector data.");
468 for (
unsigned i = 0; i < mNumElements; i++)
470 c_vector <double, SPACE_DIM> data;
471 for (
unsigned j = 0; j < SPACE_DIM; j++)
473 data[j]= p_scalars->GetTuple(i)[j];
475 dataPayload.push_back(data);
483 vtkPointData *p_point_data = mpVtkUnstructuredGrid->GetPointData();
485 if (!p_point_data->HasArray(dataName.c_str()))
487 EXCEPTION(
"No point data '" + dataName +
"'");
490 vtkDataArray *p_scalars = p_point_data->GetArray( dataName.c_str() );
491 if (p_scalars->GetNumberOfComponents() != 1)
493 EXCEPTION(
"The point data '" + dataName +
"' is not scalar data.");
498 for (
unsigned i = 0; i < mNumNodes; i++)
500 dataPayload.push_back( p_scalars->GetTuple(i)[0] );
507 vtkPointData *p_point_data = mpVtkUnstructuredGrid->GetPointData();
509 if (!p_point_data->HasArray(dataName.c_str()))
511 EXCEPTION(
"No point data '" + dataName +
"'");
514 vtkDataArray *p_scalars = p_point_data->GetArray( dataName.c_str() );
516 if (p_scalars->GetNumberOfComponents() != 3)
518 EXCEPTION(
"The point data '" + dataName +
"' is not 3-vector data.");
521 for (
unsigned i = 0; i < mNumNodes; i++)
523 c_vector<double, SPACE_DIM> data;
524 for (
unsigned j = 0; j< SPACE_DIM; j++)
526 data[j] = p_scalars->GetTuple(i)[j];
528 dataPayload.push_back( data );