compound made up of 2 solids, shared face

I create 2 adjacent boxes (solids)
then create a compound containing those 2 solids using a Builder and Add.
When i do a faceMap, I get 12 faces, shouldn't i get 11 faces, one being shared by the 2 solids ?
Do you need to tell OCC that the face is supposed to be shared ? How does that work ?

Roman Lygin's picture

Ugo, are you creating them independently (e.g. two different calls to BRepPrimAPI_MakeBox) ? If so, there is no sharing inside.
'Sharing' is a topological notion, i.e. an object is 'shared' if it is exactly one memory location pointed to by different objects.

TopTools_MapOfShape (or any other container using TopTools_ShapeMapHasher for key generation) uses TopoDS_Shape::IsSame() which returns true for shape with:
- the same TopoDS_TShapes
- the same TopLoc_Locations
- (same or different orientations)

If you really need to have boxes with a shared face, you need to create them bottom-up. Or perhaps try the following:
- create first box
- explore by faces and find the right one (order is always predefined)
- create 2nd box
- find the face which corresponds to one to be shared
- use BRepTools_ReShape to record substitution of face2 with face1
- BRepTools_ReShape::Apply (box2) will return you a box with face1 inside.
- create a compound.

Hope this helps.
Roman
---
opencascade.blogspot.com - the Open CASCADE blog
www.cadexchanger.com - CAD Exchanger, your 3D data translator

Ugo Capeto's picture

Hi Roman:
yes, that's exactly it. thanks for the answer.
to be honest, i'd rather have non shared faces so that modification of 1 solid doesn't affect the neighboring solid.
Also, thanks for clarifying the shape indexing and the meaning of IsSame.

Ugo Capeto's picture

oh yeah, the 2 boxes are created independently with primitive call (MakeBox). and lo and behold, i totally understand what you are saying :)

Tiberiu Chelcea's picture

I've tried to use this approach to building a shared face, but it did not seem to work (I've exported the resulting shapes in a meshing program, and could see easily that the two faces were not shared).

The code is this:
BRepTools_ReShape aReshp;
TopoDS_Face face1 = ... // find it in box1
TopoDS_Face face2 = ... // find it in box2
aReshp->Replace(face2, face1, false);
box2 = aReshp->Apply(box2, TopAbs_SHAPE);
// build the compound and write it for the mesher

Is this the way to do it? Should I manually replace each vertex and each edge of face2 with the corresponding vertices and edges of face1 (i.e. recursive calls to BRepTools_ReShape::Apply)?

There's this strange warning in the documentation for BRepTools_ReShape::Apply :

virtual Standard_EXPORT TopoDS_Shape Apply (const TopoDS_Shape &shape, const TopAbs_ShapeEnum until, const Standard_Integer buildmode)

Applies the substitutions requests to a shape
gives the level of type until which requests are taken into account. For subshapes of the type no rebuild and futher exploring are done.
ACTUALLY, NOT IMPLEMENTED BELOW TopAbs_FACE

says how to do on a SOLID,SHELL ... if one of its sub-shapes has been changed:
0: at least one Replace or Remove -> COMPOUND, else as such
1: at least one Remove (Replace are ignored) -> COMPOUND
2: Replace and Remove are both ignored
If Replace/Remove are ignored or absent, the result as same
type as the starting shape

The other Apply method (that's only missing the buildmode parameter and which I've used in my code) does not have this warning, but given that the code's not working for faces, it worries me.

Tiberiu Chelcea's picture

I'm sorry, this was a false alarm. I was writing the result in STEP format to be used in Gmsh for meshing. However, when the result is written in BRP format, the faces are shared, but in STEP format they are not. What could the problem be that the STEP format does not show these two faces as shared? Is STEP saving more information that could confuse Gmsh?