Asumed I have a compound off lots off faces. What would be the cheapest way to find two identical faces? What would be best to check for during iteration through all the faces ?

First, you have to define what you consider an identical face. In OCC if the two shapes reference the same TShape you can use one of these methods:

If you have two faces that only look identical but don't share a common TShape you must implement some geometrical matching function if you want that too.Standard_Boolean IsPartner(const TopoDS_Shape& other) const;

//! Returns True if two shapes are same, i.e. if they <br>

//! share the same TShape with the same Locations. <br>

//! Orientations may differ. <br>

Standard_Boolean IsSame(const TopoDS_Shape& other) const;

//! Returns True if two shapes are equal, i.e. if they <br>

//! share the same TShape with the same Locations and <br>

//! Orientations. <br>

//! <br>

Standard_Boolean IsEqual(const TopoDS_Shape& other) const;

I'm playing with compsolids (viewtopic.php?f=8&t=13830) I just would like to test by python if I had success or not in building c compsolid by iterating through all faces and find duplicates which indicates a non valid compsolid.

That was my question about. But may be bad written down. What is the best geometrical matching function to compare faces. First idea was compare the cound of edges, vertexes and the centre of mass and the area. But surely there are much better geometrical matches.wmayer wrote:First, you have to define what you consider an identical face ...

If you have two faces that only look identical but don't share a common TShape you must implement some geometrical matching function if you want that too.

I assume there is no python function implemented in FreeCAD to check if two faces use the same TShape ?!wmayer wrote: In OCC if the two shapes reference the same TShape you can use one of these methods:Standard_Boolean IsPartner(const TopoDS_Shape& other) const;

//! Returns True if two shapes are same, i.e. if they <br>

//! share the same TShape with the same Locations. <br>

//! Orientations may differ. <br>

Standard_Boolean IsSame(const TopoDS_Shape& other) const;

//! Returns True if two shapes are equal, i.e. if they <br>

//! share the same TShape with the same Locations and <br>

//! Orientations. <br>

//! <br>

Standard_Boolean IsEqual(const TopoDS_Shape& other) const;

If you are creating them with code something like thisbernd wrote:I'm playing with compsolids (viewtopic.php?f=8&t=13830) I just would like to test by python if I had success or not in building c compsolid by iterating through all faces and find duplicates which indicates a non valid compsolid.

Code: Select all

`compSolid = Part.CompSolid([solid1, solid2])`

e.g. Two cubes 6 face each = 12 and the compsolid would have 11.

Of course since this would only work in cases like above where you know how many face to expect in the compsolid, I don't know if it would help much?

Jim

Code: Select all

```
box=Part.makeBox(10,10,10)
sphere=Part.makeSphere(3,App.Vector(5,5,5))
cut=box.cut(sphere)
compSolid = Part.CompSolid([cut.Solids[0],sphere])
Part.show(compSolid)
# -----------------------------------------------
s1=compSolid.Solids[0] # 7 faces
s2=compSolid.Solids[1] # 1 face
for i in s1.Faces:
for j in s2.Faces:
print("Is same: %s" % (i.isSame(j)))
```

Thanks werner and jim for your help. A compsolid really is what it says a container for solids sharing the same face. If the solids do not share the same face the compsolid is invalid

The two boxes have contact faces which have the same geometry, but they do not share the same geometry. Am i right?

(it is difficault in englich in german there are two words. It would be: Die faces haben die Gleiche geometrie, aber nicht dieselbe geometrie. http://www.selbe-gleiche.de/ Thus it is no CompSolid.)

Code: Select all

```
import Part
box=Part.makeBox(10,10,10)
sphere=Part.makeSphere(3,App.Vector(5,5,5))
cut=box.cut(sphere)
s1 = cut.Solids[0]
has_same_faces = False
for i in s1.Faces:
for j in sphere.Faces:
print("Is same: %s" % (i.isSame(j)))
if i.isSame(j):
Part.show(j)
has_same_faces = True
if has_same_faces:
print "Found same faces in the solids, the CompSolid could be valid!"
compSolid = Part.CompSolid([s1,sphere])
docobj = App.ActiveDocument.addObject("Part::Feature","Sphere_in_Box")
docobj.Shape = compSolid
box2=Part.makeBox(10,10,10,App.Vector(10,0,0))
has_same_faces = False
for i in s1.Faces:
for j in box2.Faces:
print("Is same: %s" % (i.isSame(j)))
if i.isSame(j):
Part.show(j)
has_same_faces = True
if has_same_faces:
print "Found same faces in the solids, the CompSolid could be valid!"
else:
print "Found no same faces in the solids, the CompSolid will not be valid!"
compSolid = Part.CompSolid([box,box2])
docobj = App.ActiveDocument.addObject("Part::Feature","Box_on_Box")
docobj.Shape = compSolid
```

(it is difficault in englich in german there are two words. It would be: Die faces haben die Gleiche geometrie, aber nicht dieselbe geometrie. http://www.selbe-gleiche.de/ Thus it is no CompSolid.)

The two boxes have contact faces which have theThe two boxes have contact faces which have the same geometry, but they do not share the same geometry. Am i right?

Exact ! The code you provided earlier (isSame) shows it very well.wmayer wrote:The two boxes have contact faces which have theThe two boxes have contact faces which have the same geometry, but they do not share the same geometry. Am i right?equalgeometry, but they do not share the same geometry. Am i right?

I have tried to rebuild the solids by shape builder gui and by python but I'm not able to make them sharing the same geometry for the contact face.

BTW: the boolean cut works like a charm for compsolids ... viewtopic.php?f=8&t=13830&p=111039#p111039

If you want to check if there are equal but not shared faces in a compsolid, you can try to fuse all faces together, and check if the fusion has the same number of faces as the input. It's going to be slow, I guess..