Boolean Operation on Bodies

The function

MbResultType BooleanResult( const c3d::SolidSPtr &           solid1,
                                  MbeCopyMode                sameShell1,
                            const c3d::SolidSPtr &           solid2,
                                  MbeCopyMode                sameShell2,
                            const MbBooleanOperationParams & params,
                                  c3d::SolidSPtr &           result );

constructs a new body by executing a Boolean operation on two solids with the ability to control face and edge merging.

The function input parameters are:

  • solid1 — the first solid for the Boolean operation;

  • sameShell1 — the copy mode for the first solid;

  • solid2 — the second solid for the Boolean operation;

  • sameShell2 — the copy mode for the second solid;

  • params — the parameters of the Boolean operation.

The function output parameter is the result object containing the constructed solid.

The function returns a result code from the MbResultType enumeration (see mb_operation_result.h).

The function is declared in the file action_solid.h.

The function performs union, intersection and difference operations on two solids solid1 and solid2.

The parameters sameShell1 and sameShell2 control the transfer of faces, edges and vertices from the source solids solid1 and solid2 to the constructed solid result, and can take one of four values:

  • cm_Same = 0 (the shell is not copied);

  • cm_KeepHistory (the source shell and its copy share common base surfaces, vertices, and faces unchanged by the operation);

  • cm_KeepSurface (the source shell and its copy share common base surfaces);

  • cm_Copy (the source shell and its copy do not share any common data).

A detailed description of the MbeCopyMode enumeration is provided in section Copying a Set of Faces.

The class MbBooleanOperationParams contains parameters for executing the Boolean operation. When creating an object of class MbBooleanOperationParams, one of the following constructors is used:

MbBooleanOperationParams(      OperationType       oType,
                         const MbBooleanFlags &    flags,
                         const MbSNameMaker &      operNames,
                               ProgressIndicator * progress = nullptr )

MbBooleanOperationParams(      OperationType        oType,
                               bool                 closed,
                         const MbSNameMaker &       operNames,
                               IProgressIndicator * progress = nullptr )

where

  • oType — the type of Boolean operation;

  • flags — control flags for the Boolean operation;

  • operNames — name maker;

  • closed — indicator of closure of the operand shells;

  • progress — progress indicator for operation execution.

The variant of MbBooleanOperationParams object with the closed parameter works only for non-closed solids and specifies the need to check the result for closure.

The parameter oType defines the type of Boolean operation and can take three values: bo_Union, bo_Intersect, bo_Difference:

  • when oType = bo_Union, the function performs union of solids solid1 and solid2;

  • when oType = bo_Intersect, the function performs intersection of solids solid1 and solid2;

  • when oType = bo_Difference, the function performs subtraction of solid2 from solid1.

The parameter operNames is used for naming resulting objects of the Boolean operation.

The parameter flags contains control flags for the Boolean operation.

The object has the following flags, which can be set in the constructor when creating the object, or using separate setter functions:

bool mergeFaces — merge similar faces;

bool mergeEdges — merge similar edges;

bool closed — closure of the operand shells;

bool enclosureCheck — check shells for nesting;

bool allowNonIntersecting — output the resulting shell if there are no intersections;

bool cutting — shell cutting flag when building cuts and sections;

bool repairShellEdges — shell edge repair flag for source shells.

Figure 1 shows the source solids solid1 and solid2:

../../../../_images/M.2.1.1.png

Рис. 1

Figure 2 shows the result of the Boolean union operation on solids solid1 and solid2 shown in Fig. 1:

../../../../_images/M.2.1.2.png

Рис. 2

Figure 3 shows the result of the Boolean intersection operation on solids solid1 and solid2 shown in Fig. 1:

../../../../_images/M.2.1.3.png

Рис. 3

Figure 4 shows the result of the Boolean difference operation (subtracting solid2 from solid1) on the solids shown in Fig. 1:

../../../../_images/M.2.1.4.png

Рис. 4

Figure 5 shows the result of the Boolean difference operation (subtracting solid solid1 from solid solid2) on the solids shown in Fig. 1:

../../../../_images/M.2.1.5.png

Рис. 5

To demonstrate the function’s operation with an MbBooleanFlags object with different values of the mergeFaces flag, consider Boolean operations on source solids solid1 and solid2 shown in Fig. 6:

../../../../_images/M.2.1.6.png

Рис. 6

Figure 7 shows the result of the union of solids solid1 and solid2 when the function operates with the flag mergeFaces = true:

../../../../_images/M.2.1.7.png

Рис. 7

Figure 8 shows the result of the union of solids solid1 and solid2 when the function operates with the flag mergeFaces = false. Coinciding faces in Fig. 8 are not merged:

../../../../_images/M.2.1.8.png

Рис. 8

Figure 9 shows the result of the difference operation (subtracting solid2 from solid1) when the function operates with the parameter mergeFaces = true (merge similar faces):

../../../../_images/M.2.1.9.png

Рис. 9

Figure 10 shows the result of the difference operation (subtracting solid2 from solid1) when the function operates with the parameter mergeFaces = false. Coinciding faces in Fig. 10 are not merged:

../../../../_images/M.2.1.10.png

Рис. 10

The function BooleanResult() adds to the constructed solid’s history log a builder MbBooleanSolid, which contains all the necessary data to execute the operation. The builder MbBooleanSolid is declared in the file cr_boolean_solid.h.

Test.exe application executes Boolean operations on bodies using Create→Solid→As union with a solid→Solid, Create→Solid→As subtraction with a solid→Solid, Create→Solid→As intersection with a solid→Solid menu commands.