# Boolean Expressions on shapes

The version 7.0 of Open CASCADE Technology features the new General Fuse (GF) based algorithm - Cells Builder. The algorithm can be very useful if you have to perform several standard Boolean operations such as CUT, COMMON and FUSE on the same shapes to obtain the final result.

Due to the possibility to get any split parts of the arguments (parts of the input shapes split in the places of intersection with other input shapes), which are called Cells (that’s where the name for the algorithm comes from), the Cells Builder may significantly simplify and speed up these operations as all intersections will be performed in a single run. In effect, the Cells Builder allows executing the Boolean expressions on the shapes, i.e. performing a sequence of standard Boolean operations in one operation.

The first version of the algorithm (available since OCCT 7.0) had limited capabilities. It worked only with the shapes of the same dimension - only VERTICES, or only EDGES, etc. Recently, the algorithm has been extended to also work with multi-dimensional input shapes. The next version of Open CASCADE (7.2) will feature this extension.

# Application

The Cells Builder algorithm has a very wide application - from building the result of General Fuse and any Boolean operations to building the result of your own application-specific operation. Cells Builder extends the idea of General Fuse algorithm by providing the means to specify uniquely any cell (split part of the arguments) to be taken into the result.
The result of General Fuse is a collection of all split parts of all arguments. See the example of three circular faces C1(red), C2(green) and C3 (blue) on the image below:

Most often, however, you need to take into the result the split parts of only some of the arguments (as an example of partition operation):

Sometimes the split parts of one argument should be taken and the splits of other shapes should be avoided, and then vice versa:

Or may be you need to take into the result only the parts of arguments not contained in any other argument:

Using the Cells Builder allows getting all these results of Boolean Expressions in one operation.

As you can see the Cells Builder can also be useful when you need to perform many different Boolean operations on the same input shapes. For instance, you need to cut the material from the object and to get the part that has been removed, i.e. you need to perform two subsequent operations CUT and then COMMON, or, as in Case 3 of Gluing options, you need to CUT the two objects and then to FUSE the result with the tool. Even for these simple operations using the Cells Builder will be beneficial. The Cells Builder improves the performance by avoiding constant rebuilding of the splits of the arguments as it is done in Boolean operations. All splits are built only once and then reused for getting the new results. Such approach allows both saving time and adding robustness to the whole process.

Another useful feature of the algorithm is the possibility to remove any internal boundaries between splits. In other words it gives the possibility to fuse any parts added to the result and to keep any other parts separate. For that, the approach with materials IDs has been implemented. When you add cells into the result, you can set the material for each cell, and the boundaries between cells with the same material will be removed:

Note that the internal boundaries between parts of different dimensions will not be removed. Thus the result of the algorithm can be finely tuned by appropriate assignment of material IDs..
Additionally there is a possibility to produce containers from the parts added into the result (Wires, Shells, Compsolids), even if the arguments are not containers.

# Usage

The usage of the algorithm is fully described in the OCCT on-line documentation - Cells Builder algorithm description.

# Examples

#### 1. Same-dimensional arguments

The following simple example demonstrates the usage and possibilities of the algorithm on three spheres:

```psphere s1 15
psphere s2 15
psphere s3 15
ttranslate s1 0 0 10
ttranslate s2 20 0 10
ttranslate s3 10 0 0
bclearobjects; bcleartools
bfillds
bcbuild rx
```

Note, that it is not needed to rebuild splits in order to build all these results. Once built, they are just reused for obtaining new results.

#### 2. Multi-dimensional arguments

The following simple example demonstrates the possibilities of the algorithm on a box and an intersecting face. In this example we will perform the Boolean operations, which cannot be performed using the standard Boolean Operations algorithm.
Input shapes:

```box b 20 10 10
plane p 10 5 5 1 0 0
mkface f p -10 10 -10 10
bclearobjects
bcleartools
bfillds
bcbuild rx
```

Results:

 Example Usage Image of the result Common operation API: aLSToTake.Clear(); aLSToTake.Append(aBox); aLSToTake.Append(aFace); aLSToAvoid.Clear(); aCBuilder.AddToResult(aLSToTake,aLSToAvoid); DRAW: bcremoveall bcadd result b 1 f 1 Fuse operation API: aLSToTake.Clear(); aLSToTake.Append(aBox); aLSToAvoid.Clear(); aCBuilder.AddToResult(aLSToTake,aLSToAvoid, 1, Standard_True); aLSToTake.Clear(); aLSToTake.Append(aFace); aLSToAvoid.Clear(); aLSToAvoid.Append(aBox); aCBuilder.AddToResult(aLSToTake, aLSToAvoid); DRAW: bcremoveall bcadd result b 1 -m 1 -u bcadd result f 1 b 0 CUT box from the face API: aLSToTake.Clear(); aLSToTake.Append(aFace); aLSToAvoid.Clear(); aLSToAvoid.Append(aBox); aCBuilder.AddToResult(aLSToTake,aLSToAvoid); DRAW: bcremoveall bcadd result f 1 b 0 CUT face from the box API: aLSToTake.Clear(); aLSToTake.Append(aBox); aLSToAvoid.Clear(); aLSToAvoid.Append(aFace); aCBuilder.AddToResult(aLSToTake,aLSToAvoid); DRAW: bcremoveall bcadd result b 1 f 0

Again, the splits are built only once and just reused for building new results.

# Tests on performance

The following environment has been used to measure the performance:

 Processor Intel(R) Core(TM) i5-4460 CPU @ 3.20 GHz System type 64-bit Operating System Installed memory (RAM) 16GB Operating System Windows 10 Pro Compiler Microsoft Visual Studio Professional 2013, Version 12.0.31101.00 Update 4 Open CASCADE 7.1.0 development (master from 01/06/2017), optimized mode

Since we use the same intersection part (Pave Filler) for BOPs and Cells Builder, only the performance of the building part will be measured. The set of 21x21 cylinders on a plate is used as a sample:

```box b1 100 100 1
compound cylinders
for {set i 0} {\$i < 101} {incr i 5} {
for {set j 0} {\$j < 101} {incr j 5} {
pcylinder p 1 5;
ttranslate p \$i \$j -2;
}
}
bclearobjects; bcleartools
bfillds
```
 Operations Standard BOPs script Cells Builder script Standard BOPs, sec Cells Builder, sec Performance gain, times CUT and then COMMON ``` bbop r1 2 bbop r2 0 ``` ``` bcbuild rx bcremoveall bcadd r1 b1 1 cylinders 0 bcremoveall bcadd r2 b1 1 cylinders 1 ``` 3.46 1.93 1.79 CUT and then FUSE ``` bbop r1 2 bbop r2 1 ``` ``` bcbuild rx bcremoveall bcadd r1 b1 1 cylinders 0 bcremoveall bcaddall r2 -m 1 -u ``` 3.71 2.17 1.71 CUT, COMMON and then opposite CUT ``` bbop r1 2 bbop r2 0 bbop r3 3 ``` ``` bcbuild rx bcremoveall bcadd r1 b1 1 cylinders 0 bcremoveall bcadd r2 b1 1 cylinders 1 bcremoveall bcadd r3 b1 0 cylinders 1 ``` 5.6 1.93 2.9

# Conclusion

The Cells Builder algorithm is a very useful and flexible tool for computing Boolean expressions on any number of shapes. It allows performing complex operations with minimal effort; it is just necessary to define the rules in terms of Cells - which ones to be taken and which to be excluded.

### Pictures

All the pictures are empty. Could you fix this problem to help understanding ?
TIA

### Pictures

Sorry for that. It's now fixed - the pictures have been added.

Thanks.

### CUT face from the box

As we can see: In "CUT face from the box" the box now has two shapes. How can I access them independently?

-Pravin

### They are not two shapes. It

They are not two shapes. It is one shape with internal face inside it.

### Any way to divide a shape into two?

Thanks for the response.
I am looking for a way to divide a shape into two (using a plane or face) and access them separately.
It would be great if you suggest any ideas.