convert .stl fomat to .vtk format (XML VTU format and legacy ASCII format)

Hello,
I’m trying to visualize my .stl file using glvis library (for using mfem )
.stl format is not supported in mfem, so I tried converting it to .vtk format. (using the following code)

 vtkSmartPointer<vtkSTLReader> stlReader__ = vtkSmartPointer<vtkSTLReader>::New();
stlReader__->SetFileName("D:\\C3.stl");
stlReader__->Update();

vtkSmartPointer<vtkPolyDataWriter> vtkWriter = vtkSmartPointer<vtkPolyDataWriter>::New();
vtkWriter->SetFileName("D:\\c3.vtk");
vtkWriter-> SetInputData(stlReader__-> GetOutput());
vtkWriter->Update();

The vtk format conversion was successful, but when I run it in glvis, the following error occurs.

Verification failed: (major_vtk_version >= 2 && major_vtk_version <= 4) is false:
 --> Unsupported VTK format
 ... in function: void __cdecl mfem::Mesh::Loader(class std::basic_istream<char,struct std::char_traits<char> > &,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)
 ... in file: E:\mfem-master\mesh\mesh.cpp:4052

After searching, it says that I need to change my vtk file to ASCII VTK version 4, or XML VTK. Is there a way to change using vtk code without using ParaView? (I have to solve it inside vtk project without using Paraview.

related issue link

You can write older version of the file with this:

https://vtk.org/doc/nightly/html/classvtkDataWriter.html#a2e473c06cc1dc75bb63ff29c21933290acd12becdbb6a4dd1cd39930e28433000

1 Like