Is Compound Empty

Hi, after using BRep_Builder::Add and Remove, how can I know a compound is empty or not? (has subshapes or not)

Hugues Delorme's picture

One way (maybe not very efficient) is to use a TopExp_Explorer like this :

TopoDS_Shape shape = ...;
TopExp_Explorer exp(shape, TopAbs_VERTEX); // If there are vertices do there are sub-shapes (faces, edges, ...)
if (!exp.More())
// shape is empty
// shape has sub-shapes

Roman Lygin's picture

if (!aCompound.IsNull() && TopoDS_Iterator(aCompound).More()) {
//aCompound has subshapes

Hugues' code will work just fine in most cases unless there are corner cases such as a tree of compounds where the leaves are empty. In this case there are no vertices but original compound is not truly empty.

Hope this helps.

--- - blog on Open CASCADE