Home › Forum › SOFA › Using SOFA › [SOLVED] reading STL file vertices from my own component
Tagged: 64_bits, Linux_ubuntu, SOFA_1608
- This topic has 4 replies, 2 voices, and was last updated 7 years, 9 months ago by Dalia.
-
AuthorPosts
-
1 February 2017 at 13:55 #8484DaliaBlocked
Hello,
Being a new user to SOFA. I’m trying to get around.
As I understood from some scenes, “MeshSTLLoader” is a component to load a “.stl” mesh.
OK, now I want to load stl file thourgh C++ code (in my own test component), I do not intend to do anything specific, nor to visualize the mesh. I just want to access to the vertices,edges, etc… and to output their coordiantes.
To this end, I noticed that there exist two related classes: “MeshSTL” which inherits from sofa::helper::io::Mesh and “MeshSTLLoader” which inherits from sofa::core::loader::MeshLoader
My first question is what is the basic difference between these two classes? maybe what is a helper? which one I should use in my case?
The second question is that when I tried the helper, I used the init function to pass the file name, and SOFA crashs. and when I tried the loader, I used the setFilename function (to do the same thing as it is in the scenes) and SOFA crashs as well.I would be grateful for any hint in my primary steps in SOFA.
Dalia
2 February 2017 at 11:54 #8491epernodBlockedHi Dalia,
first you are right there is a duplication of API for the mesh loaders in SOFA. Cleaning this is an ongoing work (tracked in issue 42).
So to answer to that part you should use the MeshSTLLoader.Then to help you, there is an example using that component here: examples/Components/loader/MeshSTLLoader.scn
As I understand you are not using a scene but directly working in c++, then to help you could you show how you set up your scene in c++.regards,
Erik
2 February 2017 at 14:31 #8498DaliaBlockedThanks Erik!
OK, I’ll use the loader.
I have a basic scene in which I included a component defined by myself let say myComponent.
In the myComponent handle event “updateOnBeginStep” I have the following code:std::cout<<"MyComponent updateOnBeginStep!"<<std::endl;
which is working fine which means that I can handle the event, and sofa does not crash.
Now when I add :
std::cout<<"MyComponent updateOnBeginStep!"<<std::endl; sofa::core::loader::MeshLoader *my_mesh; my_mesh->setFilename("/mesh_models/test_mesh.stl"); sofa::helper::vector< Vector3 > my_vertices; my_vertices = my_mesh->getVertices ();
Sofa crashes at the setFilename line!
In the debug mode the heap is :
0 sofa::core::objectmodel::DDGNode::updateIfDirty DDGNode.h 192 0x7ffff7b3ba8c 1 sofa::core::objectmodel::Data<std::__cxx11::string>::beginEdit Data.h 437 0x7ffff4726757 2 sofa::core::objectmodel::DataFileName::setValue DataFileName.h 91 0x7ffff6782d07 3 sofa::core::loader::BaseLoader::setFilename BaseLoader.h 117 0x7fff9fdd98c3 4 sofa::component::controller::MyComponent<int>::updateOnBeginStep MyComponent.cpp 167 0x7fff9fdeb62a 5 sofa::component::controller::MyComponent<int>::handleEvent MyComponent.cpp 115 0x7fff9fdeb0ab
I hope that this description is clear? What should I do to load the file and access to its vertices?
Dalia
3 February 2017 at 12:09 #8509epernodBlockedHi,
it looks like an init is missing in your component. Look at the tutorial:
application/tutorials/chainHybrid/chainHybrid.cpp it does exactly what you want using a MeshGmshLoader.looking at the lines I bet this is missing:
my_mesh->load();
Erik
7 February 2017 at 18:42 #8518DaliaBlockedYour hint and the tutorial example was very useful!
I could make what I wanted to do.
Thanks Erik!Dalia
-
AuthorPosts
- You must be logged in to reply to this topic.