Comparing shapes


If I make two spheres:
TopoDS_Shape Shape1 = BRepPrimAPI_MakeSphere(10);
TopoDS_Shape Shape2 = BRepPrimAPI_MakeSphere(10);

Shape1 == Shape2 returns false.

Is there a method that compares two shapes to determine if they are equivalent?

Thank you for any help,

Lee Sangsu's picture


the == operator don't take care of the content, but only take care of the pointers of TShape, and Location,etc inside the TopoDS_Shape.
So, if you build two shapes by builder API, they are totally different shapes, even though they have same geometry, because they have different memory allocations.

If you want to know they have equivalent geometry, I think you should go inside the geometries of the shape, and compare them one by one.

If anyone have a better solution, please let me know.

I hope this helps you...

mriley's picture

That's the only solution I see, too.

angel's picture

Maybe your can find out the Sphere Center and Radius and then compare them.

TopoDS_Face F;
for (TopExp_Explorer exp(Shape1,TopAbs_FACE); exp.More(); exp.Next()) {
F = TopoDS::Face(exp.Current());
Handle(Geom_Surface) S = BRep_Tool::Surface (F);
gp_Pnt Center1 = (Handle Geom_SphericalSurface)::DownCast(S))->Sphere().Location();

Standard_Real Radius1=Handle Geom_SphericalSurface)::DownCast(S))->Radisu();


mriley's picture

That would probably work for the spheres, but I'm afraid I mislead you with the way I worded the question. I'm actually inquiring about a method to compare two TopoDS_Shape objects of arbitrary shape. I used the spheres only to demonstrate the problem.


angel's picture

I'm sorry, my suggestion focus on sphere.

Jérome Dufaure's picture

to compare two shapes you can use the IsPartner() or IsSame() methods from TopoDS_Shape.
good luck

mriley's picture

Since Shape1 and Shape2 do not share the same underlying shape, these methods return false.

Ming's picture

Have you solved this problem? I also have the same problem. If so, would you let me pls? email:

Ryan Mohr's picture

Why not use boolean operations to compare the two? Subtract one from the other and if you're left with nothing they're equal. I've never tried it, but shouldn't that work?

Ming's picture

They might be of the same geometric expression equation but of different U,V parameters.

rudie.visser_144331's picture

Was there ever something made for this problem? I want to compare shapes too and see if they are equal. I need this to remove all duplicate items in big assemblies so I only have to process them once.

Please help I've tried everything I could find but nothing worked so far.

Sergey Slyadnev's picture

I need this to remove all duplicate items in big assemblies so I only have to process them once.

Hi Rudie,

You may want to try out hunting down duplicates function in CAD Processor software ( Free trial is available for downloading. Just select the root assembly item, then click "Assembly", then "Duplicates".

Kind regards,

rudie.visser_144331's picture

Hi Sergey,

Yes that function does exactly what I need only I want to do it automated via the open source library is that possible or is this only possible with the CAD Processor SDK? Thanks for the help.

Sergey Slyadnev's picture

Rudie, this function is a part of our commercial software package. CAD Processor is based on OCCT and, of course, this function operates with topological and geometric data structures of the kernel. But the algorithm itself is entirely custom. Also, to optimize assemblies, we use a dedicated data framework (XDE) which represents those assemblies with preserved instancing. Whenever you optimize duplicates, you should usually care about associated metadata (colors, PMIs), so this feature is not 100% geometric.

CAD Processor can be used not only as SDK but also as a batch utility if you consider converting your files all at once in a separate process. The most affordable option will be to use STEP format as input, STEP format as an output and scripting (Tcl) for automation of the logic. If you ever consider using our commercial offer like this, please, contact our sales via the contact form.

Hope this helps,

Giovanni Bettega's picture

Hi, this is a very old post. This is a working solution

TopoDS_Shape boltShape = <...taken from somewhere...>;

for(myCTX->InitSelected();myCTX->MoreSelected(); myCTX->NextSelected())
    TopoDS_Shape curSelectedShape = myCTX->SelectedShape();
    TopLoc_Location curLoc = curSelectedShape.Location();
    TopoDS_Shape aShape = boltShape.Located(curLoc);
    if(!aShape.IsEqual(boltShape)) continue;
    cout<<"____found identical____"<<endl;