Home › Forum › SOFA › Using SOFA › [SOLVED] import a vtk file
Tagged: meshing, tetrahedra, triangles
- This topic has 8 replies, 3 voices, and was last updated 8 years, 10 months ago by Hugo.
-
AuthorPosts
-
2 February 2016 at 09:40 #5507francescaBlocked
Hi,I would like to know if you I can import an vtk file obtained by a segmentation process through Modeler in order to build a model of deformation of the organ represented in vtk.
2 February 2016 at 10:16 #5508RosalieBlockedHi Francesca,
First it depends if your vtk file is an image or a mesh. As you say the file is the result of a segmentation I guess it is an image. Thus, to be able to deform it in SOFA you need to convert this segmented map into a mesh. This can be done with the CGAL plugin:
1) Load the CGAL plugin
2) Create the component MeshGenerationFromImage (I give you the xml syntax):<MeshGenerationFromImage filename = "input.vtk" name = "meshGen" template = "Vec3d" facetAngle = "30" facetSize = "30" facetApproximation = "1" cellRatio = "2" cellSize = "20.0 " odt = "true" odt_max_it = "2" perturb = "true" perturb_max_time = "20.0" />
You may need to change the parameters facetAngle, facetSize, facetApproximation and cellSize depending on the size of your mesh (the values are in millimeter). I advise you to keep the other parameters (cellRatio, odt, odt_max_it, perturb, perturb_max_time) unchanged for the moment (these parameters are linked to the shape of the tetrahedra).
3) Create a mesh with the result of the previous component:
<Mesh name="mesh" points="@meshGen.outputPoints" tetras="@meshGen.outputTetras"/>
Afterwards you can create a mechanical object and a force field (TetrahedronFEMForceField for instance).
If you do it like that, the mesh will be generated each time you launch the scene (and the mesh will not be exactly the same because the mesh generation algorithm uses random seeds). To alleviate this problem you can delete the force field and use a VTKExporter:
<VTKExporter name="export_vol_mesh" exportAtBegin="1" exportAtEnd="0" triangles="true" tetras="true" filename="output" />
Then in another scene you can load your mesh with a MeshVTKLoader, create a mechanical object, a force field …
Hope this will help,
Rosalie
2 February 2016 at 13:51 #5510francescaBlockedWell…thank you! Now I can load the mesh of my organ.
Now I have a root whit MeshVtkloader OglModel and VisualStyle node in the Modeler tree.I can run this scene in Sofa and visualize my organ.
I would like to know how to make my organ deformable whit a spring mass model or finite element simulation.Sorry I’m a beginner and I don’t know how to create these simple steps using the Modeler.2 February 2016 at 14:57 #5511RosalieBlockedOk (just to know did you use the CGAL plugin, or your vtk file was already a mesh and thus you used only MeshVTKLoader?)
I think the best way to know how to deform a mesh in sofa is to follow the tutorials. If your mesh is composed of tetrahedra, try ForceFields/Tetrahedon FEM and “Edit in Modeler”.
Tell us if you have any problem with the tutorial.
Rosalie
2 February 2016 at 18:00 #5516francescaBlockedmy vtk file described a triangular mesh. I visualize it on SOFA following the instructions in the tutorial StepByStep / Visualization / Meshloading and rendering (2/7) ,that is:
Clear the scene to start with just a root node.
Add a MeshVTKLoader node component and rename it “loader”.
Change the filename of the object to the path name of my organ.vtk
Add a OglModel.
Save my scene file by Selecting File> Save. We will refer to this file as myTutorial.scn.
In my XML editor, open myTutorial.scn. Look for the line:
OglModel template = “ExtVec3f” name = “oglModel8”
After the property name, add src = “@ loader”.
Save the file. Re-open myTutorial.scn in the Modeler.Now I would like to do something similar to the deformable model of the tongue for my organ…but when I edit the deformable tongue tutorial in modeler if I try to run it on SOFA I receive an error message: “Error running sofa,error code”.
INFO(SofaGUI): lastUsedGUI.ini not found; using default GUI.
INFO(SofaGUI): lastUsedGUI.ini not found; using default GUI.
FROM SOFA [ERR] >> 2016-02-02 18:59:08.328 runSofa[802:507] invalid drawableFROM SOFA [ERR] >>
3 February 2016 at 08:37 #5519HugoKeymasterDear Francesca,
If you want to have a deformable 3D object (like the tongue), you need to have a 3D deformation model. Therefore, you will need a 3D representation of your object: a triangle mesh only represents the surface (2 dimensions) of the object.
You need to convert your 2D organ into a 3D one, i.e. use tetrehedra instead of triangles. To do so:
- either you can use the component MeshTetraStuffing in SofaMisc (example here: examples/Components/misc/MeshTetraStuffing.scn)
- or you can use the CGAL plugin. The MeshGenerationFromPolyhedron allows to generate a tetrahedral mesh from a triangulated surface.
Hope this helps.
Hugo
3 February 2016 at 09:04 #5521francescaBlockedThanks I will follow your instructions…but I have some problem with the visualization of some tutorial in Modeler…when I run some of them in Sofa I receive an error message: “Error running sofa,error code”.
Any idea?3 February 2016 at 11:24 #5523HugoKeymasterHi Francesca,
I’m afraid there is some bugs in the Modeler itself.
We are working on it.
When you work on a scene in the Modeler, you can still export it (.scn) and use it in runSofa directly.
Sorry for the inconvenience.Hugo
4 February 2016 at 12:54 #5534HugoKeymasterHi Francesca (again),
I think we answered the question about how to import vtk files in SOFA.
If you have any further questions, do not hesitate to create a new topic!Cheers,
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.