How to make two TopoDS_Shapes equal after deserializing with BRepTools::Read?

I have two solids that were processed with BRepAlgoAPI_MakeConnected. After the operation, some of their faces should be topologically identical—i.e., they should compare as IsEqual (or at least IsSame).

However, when I serialize each solid separately using BRepTools::Write and then deserialize them back with BRepTools::Read, the corresponding faces are no longer IsEqual—even though they originated from the same connected geometry.

I understand that deserialization creates new TShape instances, so pointer-based identity is lost. But is there a way to preserve or restore the topological equivalence so that IsEqual (or IsSame) returns true for the matching faces?

Or, more generally: what’s the recommended approach to reliably identify “the same” sub-shapes across independently deserialized copies of a shape?

Dmitrii Pasukhin's picture

Hello, IsEqual or IsSame or any "fast" operation will not help you.

There is only option to use "deep" comparing. At the moment, OCCT do not provide open-source version of that algo. You need to check all the geometry, all the pcurves, all the topology and locations by values. It is complex iteration, but there is no other options with files extracted from BRep.

The basic idea, you can check with new package GeomHash and GeomHash2d in latest master branch to deep checking of geometry. That package is a part of new features coming soon.

We are working on more modern approach with UUID, but it will be not a part of BRep files in any cases and not directly a part of basic TopoDS_Shapes.

Best regards, Dmitrii.