Skip to content

Commit ccc94ba

Browse files
szellmanntarcila
authored andcommitted
If VTU reader fails parsing file as XML, try with legacy reader
1 parent 17e1dbe commit ccc94ba

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tsd/src/tsd/io/importers/import_VTU.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <vtkPointData.h>
1818
#include <vtkSmartPointer.h>
1919
#include <vtkUnstructuredGrid.h>
20+
#include <vtkUnstructuredGridReader.h>
2021
#include <vtkXMLUnstructuredGridReader.h>
2122
#endif
2223
// std
@@ -47,13 +48,26 @@ static ArrayRef makeFloatArray1D(
4748

4849
SpatialFieldRef import_VTU(Scene &scene, const char *filepath)
4950
{
51+
vtkUnstructuredGrid *grid{nullptr};
52+
5053
// Read .vtu file
5154
vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
5255
vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
53-
reader->SetFileName(filepath);
54-
reader->Update();
5556

56-
vtkUnstructuredGrid *grid = reader->GetOutput();
57+
vtkSmartPointer<vtkUnstructuredGridReader> legacyReader =
58+
vtkSmartPointer<vtkUnstructuredGridReader>::New();
59+
60+
if (reader->CanReadFile(filepath)) {
61+
reader->SetFileName(filepath);
62+
reader->Update();
63+
grid = reader->GetOutput();
64+
} else {
65+
// legacy reader has no CanReadFile
66+
legacyReader->SetFileName(filepath);
67+
legacyReader->Update();
68+
grid = legacyReader->GetOutput();
69+
}
70+
5771
if (!grid) {
5872
logError("[import_VTU] failed to load .vtu file '%s'", filepath);
5973
return {};

0 commit comments

Comments
 (0)