Shape ID

Someone know if there is a way to identify a shape, and all subshapes, through save and load operations without OCAF or XDE ?
I need a transient ID that don't change if I do, for example, boolean operations.

Note that:

1) hash code change through save and load operations
2) I don't want to rebuild all ID's if I make a little modification on a complex shape
3) I don't know if TopExp_Explorer takes care of shapes order through save and load operations

Thanks for reply,

Filippo.

Patrik Mueller's picture

Hi Filippo,

if I understand you correct you want to save/load the CSG history?
If so I think you have to build functions for doing CSG. With these functions and the labels for NamedShapes you could do it perhaps (I'm on holiday without OCC - so I can't say it exactly - especially the class names).

Hope this was a hint,

Patrik

Filippo Bottega's picture

Hi Patrik,

please note that I don't want to use OCAF or XDE. The reason is that when you trace faces and edges of 50 kbyte brep file, you get a 2000 kbyte XDE file .

Regards,
Filippo.

Andrey Pozdeev's picture

Hi Filippo,

as others have pointed, the TopoDS_Shape stores only the topological data structure, attributes such as ID or color must be implemented separately by a class which uses a TopoDS_Shape as an internal member.

however you can always dump the contents of a Topods_shape into a string/binary using
BRepTools::dump()

or you could also send the contents to a file by using either read or write for serializing or deserializing a topods_shape:
BRepTools::Read/Write

this is if you don't want to use OCAF, which takes care of serializing/deserializing all the data in your document + cross links across multiple documents.

alternatively you could use a shapemap or hashmap where you place a topodshape using a string id as the key, this way you can place and retrieve a topods_shape using a key or viceversa get a key by providing a topods_shape to the map:

NCollection_DataMap

Regards,

Alex

Ugo Capeto's picture

Yeah, I need the exact same thing !!!

Basically need a permanent ID attached to topological entities.

Alexander Luger's picture

This is a hot topic for me too. Is there something new since 2009? Can I attach a permanent ID to a TopoDS_Shape without using OCAF?

Regards,
Alex

Benjamin Bihler's picture

Hi!

I guess there will never be something like that! This has nothing to do with topological data.

There is a certain hierarchy for every shape type: gp_Pnt -> TopoDS_Vertex -> AIS_Shape/TNaming_NamedShape/...

gp_Pnt contains the basic geometric information, TopoDS_Vertex contains also topological information and the other types contain additional information for visualization, storage, ...

Not adding a permanent (unique?) ID to the more basic types is important to be quick and tidy. For example a TopoDS_Vertex may be created quickly, used for some computation and deleted afterwards without messing around with globally unique IDs. If one added IDs to TopoDS_Shape, the next one would demand names, others would ask for colors, textures, bounding volumes, ...

Therefore you have to create your own classes to handle additional data, perhaps by using composition. Or just use OCAF, it is not that complicated!

Benjamin