Home › Forum › SOFA › Using SOFA › [SOLVED] Getting VTU File?
Tagged: I
- This topic has 8 replies, 3 voices, and was last updated 3 years, 3 months ago by Hugo.
-
AuthorPosts
-
27 July 2021 at 12:50 #20085MABlocked
Hello,
I have a hard time to get vtu file format, the basic scenes arenot working in SOFA, also I am trying to convert vtk to vtu in paraview, but it seems vtu files arenot compatible for SOFA. Can you please advise how can I get vtu files?
27 July 2021 at 15:43 #20086jnbrunetModeratorHi,
Are you using python scene? If so, you can use meshio to import meshes. For example:
import meshio mesh = meshio.read('/path/to/mesh.vtu') def createScene(root): root.addObject('MechanicalObject', position=mesh.points.tolist()) root.addObject('TetrahedronSetTopologyContainer', name='topology', tetrahedra=mesh.cells_dict['tetra'].tolist()) # (...)
You can read more about using python with SOFA here.
J-N
28 July 2021 at 13:21 #20088MABlockedHi,
Thanks! Yes, I am using python scene, my questions precisely how I can export Obj file to VTU files? I know how to get VTK files, but in some examples it gives error and it requires vtu format, which I am not able to get or it give error, for example I use paraviw for conversion vtk to vtu, but still in SOFA doesnot work it seems I guess vtu files obtained by paraview isnot okay, I tried other vtu files examples in SOFA and works perfectly and thats make me wonder how I can get vtu files “export vtk/obj to vtu?”
28 July 2021 at 17:20 #20090jnbrunetModeratorThat’s probably because VTK/VTU loader/exporter in SOFA haven’t been updated for a while. That’s why I suggest loading/exporting your meshes using an external tool such as
meshio
and fill-up the loaded vertex positions and indices directly into SOFA’s data field in python.28 July 2021 at 17:29 #20091MABlockedHere is the code
import Sofa import os path = os.path.dirname(os.path.abspath(__file__))+'/mesh/' def createScene(rootNode): rootNode.createObject('VisualStyle', displayFlags='showForceFields showBehaviorModels') rootNode.createObject('RequiredPlugin', pluginName='SofaExporter') rootNode.createObject('RequiredPlugin', pluginName='SoftRobots') rootNode.createObject('RequiredPlugin', name='SofaPython') rootNode.createObject('RequiredPlugin', pluginName='CGALPlugin') rootNode.createObject('RequiredPlugin', pluginName='SofaExporter') rootNode.createObject('RequiredPlugin', name='SofaSparseSolver') rootNode.createObject('RequiredPlugin', name='SofaBoundaryCondition') rootNode.findData('gravity').value='-9810 0 0'; rootNode.createObject('BackgroundSetting', color=[0, 0.168627, 0.211765, 1]); rootNode.createObject('OglSceneFrame', style="Arrows", alignment="TopRight"); ############################### ## MECHANICAL MODEL ############################### node = rootNode.createChild('node') node.createObject('MeshObjLoader',name='mesh',filename=path+'Hollow_Bunny_Body_Cavity.obj') node.createObject('MeshGenerationFromPolyhedron', inputPoints='@mesh.position', inputTriangles='@mesh.triangles', drawTetras='1', facetSize='0.35', facetApproximation='0.1', cellRatio='2', cellSize='0.5' ) node.createObject('Mesh', position='@gen.outputPoints', tetrahedra='@gen.outputTetras') node.createObject('VTKExporter', filename=path+'bunny.vtu', edges='0', tetras='1', exportAtBegin='1', listening='true') return rootNode
I press ctrl+E to export at the beginning, and the result is exporting VTU files that is empty, I am confused.
[INFO] [VTKExporter(VTKExporter)] ### VTKExporter[VTKExporter] ### Nb points: 0 Nb edges: 0 Nb triangles: 0 Nb quads: 0 Nb tetras: 0 Nb hexas: 0 ### ### Total nb cells: 0
I tried different meshes and I dont know what is missing, I cannot view it in paraview
28 July 2021 at 17:32 #20092MABlockedBTW, I tried meshio and also in vain, the vtu generated by meshio leads the scene crashing, all the examples files in SOFA in vtu works except the ones I generate from meshio for example,I dont know what I am missing to create a vtu file
28 July 2021 at 18:33 #20094MABlockedimport meshio mesh = meshio.read('dogbone.vtk') mesh.write("dogbone.vtu")
I really dont know what to do else to get a vtu file working in SOFA like vtu file example, after getting multiple files in VTU all of them crash… I am really confused.
29 July 2021 at 16:47 #20097MABlockedIt worked, I think the problem is the vtu file generated from paraview is different from the one at SOFA, although I made sure the data mode is ascii. Anyway, I used VTK format which can be generated from freecad and GMSH
1- Import STL file in Freecad
2- Then go to part, select: create shape from mesh
3- then click on the new generated shape and select: convert to solid
4-Select the new generated shape, and the export in STEP format.
5- Open Gmsh, merge, and then go to mesh, select 3D, that should give volumetric mesh
6- To refine mesh, go down in gmsh list, refine mesh by spliting, that would make it finer.For those who maybe interested in generating vtu, simply in Paraview, save data as vtu and select data mode ASCII.
In SOFA scenes, sometimes it doesnot work for vtu, but you can import VTK and visualize using two commands below”
`bunnyVisu = finger.createChild(‘visu’)
bunnyVisu.createObject(‘OglModel’, color=[0.3, 0.2, 0.2, 0.6])
bunnyVisu.createObject(‘IdentityMapping’)”`I hope there will be more documentation on these steps as it sometimes not easy to figure things out 😉
Thanks
30 July 2021 at 11:33 #20101HugoKeymasterHey @ma1991
Sorry for the delay of the reply, I was away due baby arrival!
Exactly, as Jean Nico said, latest VTK formats from Paraview are maybe not supported in SOFA. It would be a nice contribution btw!Jean Nicolas’ suggestion was to read the vtk mesh with meshio (as you are doing on your second line) but then to fill the SOFA topology data from the information loaded in meshio in python. Without trying to generate a vtu.
Do you see the difference ?
Anyway, glad it worked.Best wishes,
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.