
Tue, 11/17/2020 - 17:42
Forums:
In the Open Cascade, the Boolean operation Class need to input Topods_Shape. However the TopoDS_Shape doesn't contain color information. If the two topoDS_shape have differnt color, Can OCC keep the color after boolean operation? For example, I want to do boolean union of a red box and a green box. In the end, the union box will be red on one side, green on the other side. Can Open Cascade do that? Which class do I need to use?
Thu, 11/19/2020 - 16:01
As you have been mentioned, TopoDS_Shape is only geometry placeholder - it does not define any attributes like color, material, text or similar.
Such attributes can be stored in different ways like simple data map in AIS_ColoredShape, XCAF document or application-specific data model based on TObj/different kind.
OCCT algorithms (Boolean operations and similar) operate on geometry/topology level - e.g. work with TopoDS_Shape and do not deal with application-specific attributes stored elsewhere.
This separation is robust and clear - therefore, it is a responsibility of application-level modification operation to preserve necessary attributes attached to shapes, when it is necessary and actually possible.
While preserving entire shape attributes is more or less straightforward, dealing with sub-shape attributes involves some complexity (and ambiguity in some cases).
This kind of functionality is normally relies on a Shape modification History, which is provided by all topological API algorithms in OCCT.
So that basically application should re-map shape attributes from old shapes in history to new ones in some way defined by application itself.
Fri, 04/18/2025 - 14:32
Hey, digging up some old bones here :)
As the OP above, I am trying to keep track of colors during geometry creation. The application is receiving a csg tree to create a solid. Each node of the csg tree (i.e. box, torus, extrude, etc...) has a color. My strategy was to use the XCAF document as you mentioned above. It works well with basic csg tree such as a unique box node with color blue. However, the tricky part comes with boolean operations (again, as the OP mentioned).
Here is the method to register a shape in the XCAF document:
The boolean operation history is great when it comes to identify the shape that were generated, deleted or modified. But I didn't see any functionality to see which face was. Did I missed it?
For reference, this is my operation node (cut, fuse and common) main method:
The way I see it, OCCT is just not suitable for color tracking during geometry construction. I might have to live with that. If you have any example proving otherwise, I'd me more than happy to look at them.
Have a good one!
Sat, 04/19/2025 - 13:29
Thomas Delorme wrote:
I guess you are trying to put several complex things together - Boolean operations, colors on Solids, colors on Faces, XCAF document... Implementing a final solution will require handling a plenty of various options.
For instance, if you allow assigning colors to Solids, then you'll to explode modified Solids into Faces if you'll want to merge colors of both originating Solids... And then you'll need to maintain list of subshapes in XCAF document in a way as it is expected to work in XCAF.
Lets localize one of the problem and try to solve a particular step. For instance, we have 2 simple Solids with different colors and we want to propagate original colors to new Faces in result of Boolean operation. In this Draw Harness sample we will avoid using XCAF and instead assign colors to subshapes via
AIS_ColoredShape
class (by the wayXCAFPrs_AISObject
inherits this class and dispatches colors from XCAF document):In this particular sample every Face from original Solids is either 'modified' or 'deleted'. Here we iterate over Faces in original Solids (via
TopExp_Explorer(theSolid, TopAbs_FACE)
), check if Face has been deleted (BRepTools_History::IsRemoved()
) or get modified Face (BRepTools_History::Modified()
).Then we display result of Boolean operations via
AIS_ColoredShape
and assign colorsAIS_ColoredShape::SetCustomColor()
to each Face. For simplicity, I use colors of original Solids, but the logic could be improved to maintain original per-Face colors.The 'generated' (
BRepTools_History::Generated()
) output of original Faces will be Edges, which we are probably not interested in our case. In real case we will need to also handle unmodified Faces and keep their colors.Sat, 04/19/2025 - 13:40
2Thomas Delorme
There is also an OCAF mechanism called Topological Naming which is supposed to aim to track such kind of shape modifications in the document.
You may also find some insights about the topological naming problem within FreeCAD wiki.