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

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();

vtkSmartPointer<vtkPolyDataWriter> vtkWriter = vtkSmartPointer<vtkPolyDataWriter>::New();
vtkWriter-> SetInputData(stlReader__-> GetOutput());

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:

1 Like