The color problem of Boolean operation

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?

Kirill Gavrilov's picture

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.