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.

Ben Pieters-Hawke's picture

"At the moment, OCCT do not provide open-source version of that algo."

Is that to say that there's a closed/proprietary part of the tech stack that does this? I was under the impression that OCCT followed an "IP controlled, FOSS model". If there are parts of the tech stack that are closed/proprietary, where might I find more info on this? A quick search didn't ping anything obvious.

Dmitrii Pasukhin's picture

OpenCascade provide OCCT (LGPL 2.1) and Added-Value components which is commercial extensions. Also we provide custom development, where we have used our advanced algos, which not always available as separated components. The comparison is one of them. If you are interested or have more quastion, please visit https://occt3d.com or use contact us form.

Best regards, Dmitrii.