
Tue, 12/08/2015 - 14:15
Forums:
Hello,
I have just started using OpenCascade. I have the following problem:
- I have read an stl file (mesh of a surface) into an object of type TopoDS_Shape.
I wanted to know if OpenCascade provides a way to find the points on the boundary of this TopoDS_Shape object?
I have seen BRepTools::OuterWire, is this the class to use? In which case could any one suggest how could one cast a TopoDS_Shape object to TopoDS_Face?
Any help would be much appreciated.
Thanks
Sunayana
Wed, 12/09/2015 - 11:15
Hello Sunayana,
if you have a TopoDS_Shape, you can extract the vertices by exploring the vertices of the shape. This function for example takes the shape, extracts the vertices into gp_Pnt - s and returns them in an array.
22 Handle_TColgp_HArray1OfPnt StlPointsExtractor::extractVerticesFromTopoDSShape(const TopoDS_Shape& shape)
23 {
24 TopTools_IndexedMapOfShape vertices;
25 TopExp::MapShapes(shape,TopAbs_VERTEX,vertices);
26
27 Handle_TColgp_HArray1OfPnt result = new TColgp_HArray1OfPnt(1,vertices.Extent());
28
29 for(Standard_Integer i = 1;i<=vertices.Extent();i++)
30 {
31 TopoDS_Vertex vertex = TopoDS::Vertex(vertices.FindKey(i));
32 gp_Pnt currentGeometricPoint = BRep_Tool::Pnt(vertex);
33 result->SetValue(i,currentGeometricPoint);
34 }
35
36 return result;
37
38 }
I hope this helps.
László
Wed, 12/09/2015 - 11:34
If you are interested, I have a small example here:
https://github.com/lvk88/OccTutorial/blob/master/OtherExamples/runners/extractStlPoints.cpp
This program takes an stl file, extracts the points and writes them out in a text file.
Let me know if it works out!
Mon, 12/14/2015 - 14:00
Hello Laszlo,
Thanks a lot for your reply. I tried your method and it works, but it extracts all the vertices of the shape, I just wanted to extract the boundary vertices of the shape, I will now try using
BRepTools::OuterWire and let you know if it works.
Sunayana
Mon, 12/14/2015 - 21:01
Hi Sunayana,
Is it a non-closed STL surface? I mean, in STL all the vertices kind of lie on thw boundary of the shape, don't they?
Can you upload a small figure of what you would like to achieve? Maybe I could help you further with that.
László
Tue, 12/15/2015 - 16:07
Hello László,
Thanks for your help. What I want to do is given a triangular mesh of a non-closed surface, I would like to extract the points on the four boundary curves of the STL surface.
A simple example is a meshed plane where I would like only the points on the four boundary lines. In the attached jpeg it would be the marked points.
Is there a way to extract this information from an STL file?
Thanks and Regards,
Sunayana
Wed, 12/23/2015 - 12:47
Hello Sunayana,
Alright, I understand what you would like to do. Here is how I would do it:
The STL file consists of faces, each bounded by edges. You can check for each edge if it has one or two parent faces. If the edge is connected to two faces, it is an internal edge (assuming that the STL file is a manifold mesh). If the edge is connected to only one face (one triangle), then it lies on the boundary of the mesh.
To do this, you could use TopExp::MapShapesAndAncestors, which would create you a map, where the key of each element are the edges in your mesh, and the value is a list of faces, the parents of a given edge.
I created you an example that you can check at the following link:
https://github.com/lvk88/OccTutorial/blob/master/OtherExamples/runners/extractStlManifoldBoundaries.cpp
This creates a curved plate with a hole in the middle and generates an STL file out of it. Then reads it in again and finds the boundary edges of the mesh. It is pretty slow, but I guess I was not using the most optimal containers, and not in the most optimal way.
Have a look on the attached pictures also!
Best regards
László
Mon, 01/11/2016 - 19:06
Hello László,
Sorry for the delayed response and thanks a lot for the piece of code, it works on the stl meshes I have.
With Regards,
Sunayana
Fri, 04/13/2018 - 21:17
Hey,
Could you tell me how did you read an STL file into a TopoDs_Shape??
Thanks
Mon, 07/09/2018 - 15:26
To read an stl file into TopoDS_Shape do the following: