3 January 2017 at 6 h 47 min #8255
Recently, I’ve been working on trying to find the best way to convert some STLs (I had converted from DICOM files), to tetrahedral meshes for simulation in SOFA.
Thankfully, a nice little CGAL plugin and tutorials from the SOFA guys helped me set up a pipeline for the same.
After having generated the VTU Files using an XML script I wrote (very similar to the python script in the link above), I was unable to load them in SOFA for visualization.
Therefore, I had a few questions about this process (I’m sorry, the questions may not be limited to SOFA, but I feel like answers to these will help me generate better models for my SOFA simulations in the future):
- What’s the best way to visualize the generated VTU file, so I know that my tetrahedralization has worked sufficiently?
- Is there a better pipeline that you guys use to get to a volumetric mesh from a DICOM file? I felt like going through the STLs was sort of tedious, but at the same time, allowed me to clean up my meshes very intuitively in the intermediate steps.
Currently, I’ve written the following script to visualize my mesh, but I think I’ve made some mistake in parsing in the VTU file.
<?xml version="1.0" ?> <Node name="root" dt="0.01" gravity="0 -9.81 0" > <VisualStyle displayFlags="showForceFields showBehaviorModels" /> <DefaultPipeline name="CollisionPipeline" verbose="0" /> <BruteForceDetection name="N2" /> <DefaultContactManager name="collision response" response="default" /> <DiscreteIntersection /> <Node name="Bone" gravity="0 -9.81 0"> <EulerImplicitSolver name="cg_odesolver" printLog="0" /> <CGLinearSolver name="linear solver" iterations="25" tolerance="1e-09" threshold="1e-09" /> <MeshVTKLoader name="MeshLoader" filename="bone.vtu" /> <Mesh src="@MeshLoader" /> <TetrahedronSetTopologyContainer name="topo" src="@MeshLoader" /> <TetrahedronSetGeometryAlgorithms drawEdges="0" /> <MechanicalObject name="dofs" src="@MeshLoader" rotation="45 0 0" translation="0.0 10 7.5" scale = "0.1"/> <TetrahedronFEMForceField template="Vec3d" name="FEM" youngModulus="50" poissonRatio="0.45" /> <UniformMass name="mass" totalmass="1" /> </Node> </Node>
And executing the above in SOFA gives me the following error:
ERROR(TetrahedronFEMForceField): object must have a tetrahedric BaseMeshTopology
I’m not sure where I’m going wrong here, and a visualization would really help. Please let me know if you need any other details.
Thanks a lot! 🙂3 January 2017 at 9 h 01 min #8256
CGAL is also able to convert a 3d image into a tetrahedral mesh (see http://doc.cgal.org/latest/Mesh_3/index.html#title23). There is a SOFA component for that in the CGALPlugin. It’s called MeshGenerationFromImage. You will need to use the image plugin as well. You would have to convert your input DICOM image first with an image processing program.
The input image must be segmented. You can set labels to subdomains and mesh them with different parameters.
If you want to visualize VTU files, I would advise Paraview. It is also possible with Sofa with a scene. In your scene, the trick is to use the visualization tool of the FEM force field, but it means you need to setup a scene with mechanical stuff whereas you only want visualization. I didn’t try your scene but I think it will work by removing the Mesh component. Also check the number of tets in the MeshVTKLoader component in case you have a problem with your mesh.
Hope it helped4 January 2017 at 17 h 07 min #8274
Thanks a lot for that. Yes, I was trying to use MeshGenerationFromPolyhedron, but just following the basic syntax for my STL wasn’t working very well. The resulting model wasn’t showing up in Paraview, and resulted in the aforementioned error in SOFA.
I think I’ll try to go the 3D-Image route, which seems more direct. Would you say this is usually the route you guys take to go from a CT-Scan to a SOFA Simulation?
Thanks again!4 January 2017 at 22 h 40 min #8276RosalieParticipant
- CRCHUM & Polytechnique Montréal
If you want to use MeshGenerationFromImage maybe my first answer to this post can be useful:
And if you want to know how to properly set the parameters of this component you can refer to the CGAL manual:
To answer your question, given that a volume mesh generator always approximates the input surface, it is better to give directly the segmented image and not a surface mesh which is already an approximation of the segmented surface.
Also, be careful with the quality of your volume mesh. SOFA will not warn you if you use a poor quality mesh to perform the simulation. You must test you mesh to ensure that it is suitable for your simulation (for instance the result of the simulation should not be dependent of your mesh resolution, large dihedral angles in tetrahedra lead to discretization errors, etc.).
Hope this will help,
Rosalie4 January 2017 at 23 h 05 min #8277
Thanks a lot Rosalie. I have actually been using your previous post to aid in my Mesh Generation from a 3D Image.
I agree, going through a surface mesh would lower the quality of the generated volume mesh.
I’ll try to work on this and get a preliminary output. 🙂
Thanks again!5 January 2017 at 0 h 51 min #8281
I tried segmenting a section of my DICOMS into a VTK, that I tried to tetrahedralize using the sample script you had suggested in the previous forum post, like so:
<?xml version="1.0"?> <Node name="root" gravity="0 0 0" dt="1" > <RequiredPlugin pluginName="CGALPlugin"/> <RequiredPlugin pluginName="image"/> <BackgroundSetting color="0 0.16862745098 0.21176470588"/> <VisualStyle displayFlags="showVisual" /> <OglGrid/> <OglSceneFrame/> <OglLineAxis/> <!-- <ImageViewer template="ImageUC" src="@image"/> --> <MeshGenerationFromImage filename = "path/to/image.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" /> <Mesh name="volume" points="@meshGen.outputPoints" tetras="@meshGen.outputTetras"/> <VTKExporter name="export_vol_mesh" exportAtBegin="1" exportAtEnd="0" triangles="true" tetras="true" filename="output_ken_bone.vtu" /> </Node>
I got the following error on running the above:
_readImageHeaderAndGetError: does not find image format for 'path/to/image.vtk'
Looking a bit more into the error, I see that the error is thrown in ImageIO.h in CGAL. Going through this file, I wasn’t sure if the VTK format was even accepted as a valid 3D Image format by it.
Am I missing something here. Can you give me any tips about how to go on investigating?
Thanks! 🙂5 January 2017 at 14 h 57 min #8283
If I remember correctly, CGAL can load only .inr image files. But you can link the CGAL component with an ImageContainer from the image plugin (like in https://github.com/sofa-framework/sofa/blob/master/applications/plugins/CGALPlugin/scenes/MeshGenerationFromImage.scn). It uses the cimg library http://cimg.eu/. Check the supported files and convert your image with another program.5 January 2017 at 17 h 31 min #8285
I had tried this yesterday, by exporting my 3D Slicer Segmented DICOM files as HDR Files, and gathering the same through an ImageContainer, like so:
<ImageContainer name="image" template="ImageUC" filename="C:\path\to\image.hdr"/> <MeshGenerationFromImage template="Vec3d" name="meshGen" printLog="true" drawTetras="true" image="@image.image" transform="@image.transform" cellSize="0.5" facetAngle="30" facetSize="1" cellRatio="3" facetApproximation="1" ordering="0" label="1 2 3" labelCellSize="0.2 0.5 0.1" labelCellData="100 200 300"/>
but got a CImg IOException, saying it had failed to recognize the file. Is there a page that demonstrates the process of going from a DICOM to a format easily accepted by SOFA (that would be really helpful)?5 January 2017 at 18 h 04 min #8286
I don’t know how to do that, but if you manage to do this, a description of the method could be very helpful for everyone.
If you look at the code of ImageContainer, you can see the file extensions supported by Sofa: https://github.com/sofa-framework/sofa/blob/master/applications/plugins/image/ImageContainer.h
According to the documentation, Slicer can deal with these formats: https://www.slicer.org/wiki/Documentation/4.0/SlicerApplication/SupportedDataFormat
Try to find a common format (mhd for example).
Good luck25 March 2017 at 13 h 14 min #8829
I saw some messages about ur successful use of CGAL. Can I ask some questions about it?
I met some problems when i tried to test CGAL by using MeshGenerationFromImage in ..\SOFA16.12\sofaproject\sofasrc\applications\plugins\CGALPlugin\scenes. But it informed me:
`[INFO] [SofaPython] Added ‘F:/SOFA16.12/sofaproject/sofasrc/applications/plugins/image/python’ to sys.path
[INFO] [SofaPython] Added ‘F:/SOFA16.12/sofaproject/sofasrc/applications/plugins/SofaPython/python’ to sys.path
[INFO] [PluginManager] Loaded plugin: F:/SOFA16.12/sofaproject/sofabuild/bin/Release/SofaPython.dll
0殑!W] [PluginManager] Plugin loading failed (F:/SOFA16.12/sofaproject/sofabuild/bin/Release/CGALPlugin.dll): ~
[INFO] [PluginManager] Loaded plugin: F:/SOFA16.12/sofaproject/sofabuild/bin/Release/image.dll
[INFO] [PluginManager] Loaded plugin: F:/SOFA16.12/sofaproject/sofabuild/bin/Release/image_gui.dll
[WARNING] [MeshTopology] Could not setup Data link between @generator.outputPoints and points.
[WARNING] [MeshTopology] Could not setup Data link between @generator.outputTetras and tetras.
[ERROR] [DAGNode “root”] Object type “MeshGenerationFromImage” creation Failed
[ERROR] [SceneLoaderXML] Node initialization failed.
[WARNING] [VTKExporter] File data/output.vtu NOT FOUND in :F:/SOFA16.12/sofaproject/sofasrc/examples:F:/SOFA16.12/sofaproject/sofasrc/share
File data/output.vtu NOT FOUND in :F:/SOFA16.12/sofaproject/sofasrc/examples:F:/SOFA16.12/sofaproject/sofasrc/share
Error creating file data/output.vtu
Have you ever met this kind of problem? And how to fix it?
Thanks in advance.28 March 2017 at 8 h 42 min #8836
I think you should have started another post instead of continuing on this post.
Anyway, your problem is that sofa failed to load the CGAL plugin. If the plugin is not loaded, the other components in the scene cannot work with the CGAL component.
Have you compiled sofa or just downloaded the executable? Here is the documentation on the CGAL plugin: https://www.sofa-framework.org/community/doc/using-sofa/optional-features/cgal-library/
Alex28 March 2017 at 9 h 05 min #8837
I have already compiled sofa, as the link shown.
And cgal4.9 has some problems to compile so i changed cgal4.7.
But for bad luck it still can’t work.21 April 2017 at 22 h 00 min #8975HugoKeymaster
- SOFA Consortium
So, 4.7 is working for you Lujain, right?
Shall we close the topic?22 April 2017 at 3 h 47 min #8983
- You must be logged in to reply to this topic.