Sat, 12/14/2024 - 12:02
Hello,
I have been struggling with a problem for a while regarding retaining relationship between a TopoDS_Shape and its corresponding TopoDS_Edge's, after I have extracted the edges from the shape through explore.
If I convert the shape and the edges to BREP's and then convert them back to Shape and Edge entities, the relationship between the edge and the shape is lost, and I cannot fillet the shape anymore using the edge.
I have UUID's assigned to each edge externally, and I want to be able to reference each edge directly without having to explore the shape and find the edge geometrically each time.
Is there a more elegant way to do this in OCC? Is there a way to rebuild relationships between BREP's of shape objects and their corresponding edges?
Sat, 12/14/2024 - 14:54
Hello.
TopoDS_Shape is a wrapper around any TopoDS_TShape objects. It means TopoDS_Shape can be casted to specific TopoDS object accroding TopAbs type defined.
As for a relation, it is not clear for me your goal. Originally the TopoDS_Edge was designed to store only TopoDS_TEdge pointer + orientation and location.
On BRep Level here are no direct mapping. All elements are connected only as a part of Child list on one direction. For example, Wire have as a childs 5 edges. Edges have no relation with Wire. But they know that edge have 2 childs (2 vertexes). At the same time these vertexes don't know that they are a part of Edge. The relation is only single direction.
You can once iterate by your graph and create a map, where a key TopoDS_Shape and value your UUID. Be caraful, please use the hasher that do not care about location or orientation. You need to create your own hasher, you can use the sample from TopTools_ShapeMapHasher. But please use "IsPartner" instead of "IsSame". And hash must be "return opencascade::hash(theShape.TShape().get())"
Best regards, Dmitrii.
Sat, 12/14/2024 - 15:09
Hi Dimitrii, thanks for your reply.
My problem is basically in web scenario. I am using REST API to share information between front-end and back-end. Front-end is based on Three.js, and back-end is Flask with OpenCASCADE set up.
Now when I want to do a fillet operation, I get the UUID from the front-end and pass it to back-end. In the back-end, I am using simple SQL database to store TopoDS_Shape by pickling it within Python, and also its TopoDS_Edge's by also pickling them. Using UUID, I then get my edge from the edge's table in the database. But when I try to use this edge along with the shape to perform a fillet operation in OCC, it gives me an error that edge is not valid.
Now I cannot store TopoDS_Edge or TopoDS_Solid objects in-memory in web based environment, so I have to use some database. One solution I tried was to get the edge from the database, then use Topo_Explore on the shape again, and then compare the position of the vertices of the edge from database with the new edge I get from explorer. This is very slow and not a reliable solution.
I hope the problem is much clearer now. Basically I just want to get an edge from an object very quickly using some edge ID.
Sat, 12/14/2024 - 16:02
If you re-create the object all the time by re-reading it then it is not possible like these for mapping in map. In you case only recommended solution - once iterate under object and then create a mapping between iteration index and the element itself. All the objects in shape are indexed under their structure. You can keep the index under iteration or iteration list in your side and then make fast iteration by extraction iteration index and iterate it back.
OCCT shapes do not have extra functionality inside. Any tools needs to be developed by your.
Best regards, Dmitrii