59 mBoundaryFacesRead(0),
60 mBoundaryFacesSkipped(0),
61 mCableElementsRead(0),
62 mNumElementAttributes(0),
63 mNumFaceAttributes(0),
64 mNumCableElementAttributes(0),
67 mVtkCellType(VTK_TETRA)
69 vtkXMLUnstructuredGridReader* vtk_xml_unstructured_grid_reader;
75 EXCEPTION(
"Could not open VTU file: " + pathBaseName);
80 vtk_xml_unstructured_grid_reader = vtkXMLUnstructuredGridReader::New();
81 vtk_xml_unstructured_grid_reader->SetFileName( pathBaseName.c_str() );
82 vtk_xml_unstructured_grid_reader->Update();
85 vtk_xml_unstructured_grid_reader->Delete();
92 mNumNodes = mpVtkUnstructuredGrid->GetNumberOfPoints();
93 unsigned num_cells = mpVtkUnstructuredGrid->GetNumberOfCells();
95 if (ELEMENT_DIM == 2u)
98 mVtkCellType = VTK_TRIANGLE;
100 else if (ELEMENT_DIM == 1u)
102 mNodesPerElement = 2;
103 mVtkCellType = VTK_LINE;
106#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 2)
107 const auto num_distinct_cell_types =
static_cast<unsigned>(mpVtkUnstructuredGrid->GetDistinctCellTypesArray()->GetNumberOfTuples());
109 vtkCellTypes* cell_types = vtkCellTypes::New();
110 mpVtkUnstructuredGrid->GetCellTypes(cell_types);
111 const auto num_distinct_cell_types =
static_cast<unsigned>(cell_types->GetNumberOfTypes());
112 cell_types->Delete();
115 if (num_distinct_cell_types > 1u)
117 mNumCableElementAttributes = 1;
118 for (
unsigned cell_id = 0; cell_id < num_cells; ++cell_id)
120 if (mpVtkUnstructuredGrid->GetCellType(cell_id) == mVtkCellType)
123 assert(mNumCableElements == 0);
125 else if (mpVtkUnstructuredGrid->GetCellType(cell_id) == VTK_LINE)
138 mNumElements = num_cells;
142 if (ELEMENT_DIM == 2u)
144 vtkDataSetSurfaceFilter* p_surface = vtkDataSetSurfaceFilter::New();
145 mpVtkFilterEdges = vtkFeatureEdges::New();
146#if VTK_MAJOR_VERSION >= 6
147 p_surface->SetInputData(mpVtkUnstructuredGrid);
148 mpVtkFilterEdges->SetInputConnection(p_surface->GetOutputPort());
150 p_surface->SetInput(mpVtkUnstructuredGrid);
151 mpVtkFilterEdges->SetInput(p_surface->GetOutput());
153 mpVtkFilterEdges->Update();
154 mNumFaces = mpVtkFilterEdges->GetOutput()->GetNumberOfCells();
157 else if (ELEMENT_DIM == 3u)
159 mpVtkGeometryFilter = vtkGeometryFilter::New();
160#if VTK_MAJOR_VERSION >= 6
161 mpVtkGeometryFilter->SetInputData(mpVtkUnstructuredGrid);
163 mpVtkGeometryFilter->SetInput(mpVtkUnstructuredGrid);
166#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1)
168 mpVtkGeometryFilter->SetPassThroughPointIds(1);
170 mpVtkGeometryFilter->Update();
172 mNumFaces = mpVtkGeometryFilter->GetOutput()->GetNumberOfCells();
173 if (mNumCableElements > 0)
176 unsigned num_all_cells = mNumFaces;
177 for (
unsigned i=0; i<num_all_cells; i++)
179 if (mpVtkGeometryFilter->GetOutput()->GetCellType(i) == VTK_LINE)
186 else if (ELEMENT_DIM == 1u)
189 vtkSmartPointer<vtkIdList> enclosing_cells = vtkSmartPointer<vtkIdList>::New();
190 assert(mNumNodes == (
unsigned) mpVtkUnstructuredGrid->GetNumberOfPoints());
191 for (
unsigned point_index = 0; point_index < mNumNodes; ++point_index)
193 mpVtkUnstructuredGrid->GetPointCells(point_index, enclosing_cells);
195 if (enclosing_cells->GetNumberOfIds() == 1u)
352 if (mCableElementsRead >= mNumCableElements)
354 EXCEPTION(
"Trying to read data for a cable element that doesn't exist" );
357 unsigned next_index = mNumElements + mCableElementsRead;
358 assert(mpVtkUnstructuredGrid->GetCellType(next_index)==VTK_LINE);
362 for (
unsigned i = 0; i < 2; i++)
364 next_element_data.
NodeIndices.push_back(mpVtkUnstructuredGrid->GetCell(next_index)->GetPointId(i));
367 vtkDataArray *p_scalars = mpVtkUnstructuredGrid->GetCellData()->GetArray(
"Cable radius" );
368 next_element_data.
AttributeValue = p_scalars->GetTuple(next_index)[0];
370 mCableElementsRead++;
371 return next_element_data;
378 if (mBoundaryFacesRead >= mNumFaces)
380 EXCEPTION(
"Trying to read data for a boundary element that doesn't exist");
384 if (ELEMENT_DIM == 3u)
386#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1)
388 vtkDataArray *original_ids = mpVtkGeometryFilter->GetOutput()->GetPointData()->GetArray(
"vtkOriginalPointIds");
390 while (mpVtkGeometryFilter->GetOutput()->GetCellType(mBoundaryFacesRead + mBoundaryFacesSkipped) == VTK_LINE)
392 mBoundaryFacesSkipped++;
394 for (
unsigned i = 0; i < (mNodesPerElement-1); i++)
396 unsigned id = mpVtkGeometryFilter->GetOutput()->GetCell(mBoundaryFacesRead + mBoundaryFacesSkipped)->GetPointId(i);
397#if (VTK_MAJOR_VERSION >= 9 && VTK_MINOR_VERSION >= 1)
399 next_face_data.
NodeIndices.push_back(original_ids->GetTuple1(
id));
405 else if (ELEMENT_DIM == 2u)
407 for (
unsigned i = 0; i < (mNodesPerElement-1); i++)
409 next_face_data.
NodeIndices.push_back(mpVtkFilterEdges->GetOutput()->GetCell(mBoundaryFacesRead)->GetPointId(i));
412 else if (ELEMENT_DIM == 1u)
414 vtkSmartPointer<vtkIdList> enclosing_cells = vtkSmartPointer<vtkIdList>::New();
415 assert(mNumNodes == (
unsigned) mpVtkUnstructuredGrid->GetNumberOfPoints());
416 for (
unsigned point_index = mBoundaryFacesSkipped; point_index < mNumNodes; ++point_index)
418 mBoundaryFacesSkipped++;
419 mpVtkUnstructuredGrid->GetPointCells(point_index, enclosing_cells);
421 if (enclosing_cells->GetNumberOfIds() == 1u)
433 mBoundaryFacesRead++;
434 return next_face_data;
441 vtkCellData *p_cell_data = mpVtkUnstructuredGrid->GetCellData();
443 if (!p_cell_data->HasArray(dataName.c_str()))
445 EXCEPTION(
"No cell data '" + dataName +
"'");
448 vtkDataArray *p_scalars = p_cell_data->GetArray( dataName.c_str() );
449 if (p_scalars->GetNumberOfComponents() != 1)
451 EXCEPTION(
"The cell data '" + dataName +
"' is not scalar data.");
455 for (
unsigned i = 0; i < mNumElements; i++)
457 dataPayload.push_back( p_scalars->GetTuple(i)[0] );
464 vtkCellData *p_cell_data = mpVtkUnstructuredGrid->GetCellData();
466 if (!p_cell_data->HasArray(dataName.c_str()))
468 EXCEPTION(
"No cell data '" + dataName +
"'");
471 vtkDataArray *p_scalars = p_cell_data->GetArray( dataName.c_str() );
472 if (p_scalars->GetNumberOfComponents() != 3)
474 EXCEPTION(
"The cell data '" + dataName +
"' is not 3-vector data.");
478 for (
unsigned i = 0; i < mNumElements; i++)
480 c_vector <double, SPACE_DIM> data;
481 for (
unsigned j = 0; j < SPACE_DIM; j++)
483 data[j]= p_scalars->GetTuple(i)[j];
485 dataPayload.push_back(data);
493 vtkPointData *p_point_data = mpVtkUnstructuredGrid->GetPointData();
495 if (!p_point_data->HasArray(dataName.c_str()))
497 EXCEPTION(
"No point data '" + dataName +
"'");
500 vtkDataArray *p_scalars = p_point_data->GetArray( dataName.c_str() );
501 if (p_scalars->GetNumberOfComponents() != 1)
503 EXCEPTION(
"The point data '" + dataName +
"' is not scalar data.");
508 for (
unsigned i = 0; i < mNumNodes; i++)
510 dataPayload.push_back( p_scalars->GetTuple(i)[0] );
517 vtkPointData *p_point_data = mpVtkUnstructuredGrid->GetPointData();
519 if (!p_point_data->HasArray(dataName.c_str()))
521 EXCEPTION(
"No point data '" + dataName +
"'");
524 vtkDataArray *p_scalars = p_point_data->GetArray( dataName.c_str() );
526 if (p_scalars->GetNumberOfComponents() != 3)
528 EXCEPTION(
"The point data '" + dataName +
"' is not 3-vector data.");
531 for (
unsigned i = 0; i < mNumNodes; i++)
533 c_vector<double, SPACE_DIM> data;
534 for (
unsigned j = 0; j< SPACE_DIM; j++)
536 data[j] = p_scalars->GetTuple(i)[j];
538 dataPayload.push_back( data );