Commit 6e20e88b authored by Andrew Wilson's avatar Andrew Wilson 🐘
Browse files

ENH: Can now read LineMesh's from VTK files

parent 6fb6e835
......@@ -360,6 +360,12 @@ GeometryUtils::copyToLineMesh(vtkSmartPointer<vtkPolyData> vtkMesh)
std::shared_ptr<VecDataArray<double, 3>> vertices = copyToVecDataArray(vtkMesh->GetPoints());
std::shared_ptr<VecDataArray<int, 2>> cells = copyToVecDataArray<2>(vtkMesh->GetPolys());
// If polys is empty use lines instead
if (cells->size() == 0)
{
cells = copyToVecDataArray<2>(vtkMesh->GetLines());
}
auto mesh = std::make_unique<LineMesh>();
mesh->initialize(vertices, cells);
......
......@@ -250,7 +250,18 @@ VTKMeshIO::readVtkGenericFormatData(const std::string& filePath)
if (vtkSmartPointer<vtkPolyData> vtkMesh = reader->GetPolyDataOutput())
{
return GeometryUtils::copyToSurfaceMesh(vtkMesh);
// Try to convert to surface mesh, if no elements exist try reading as a line mesh
std::shared_ptr<SurfaceMesh> surfMesh = GeometryUtils::copyToSurfaceMesh(vtkMesh);
if (surfMesh->getNumTriangles() > 0)
{
return surfMesh;
}
std::shared_ptr<LineMesh> lineMesh = GeometryUtils::copyToLineMesh(vtkMesh);
if (lineMesh->getNumLines() > 0)
{
return lineMesh;
}
return GeometryUtils::copyToPointSet(vtkMesh);
}
if (vtkUnstructuredGrid* vtkMesh = reader->GetUnstructuredGridOutput())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment