If you want to get the best out of your products, our Technical Support Team is available to assist you in any question, request, or technical issue that you may have.

Open Inventor 9.5

Home › Open Inventor Mentor, 2nd Edition - Volume I › Chapter 9. Rendering Features › 9.6. CSG Rendering

- About This Book
- Chapter 1. Overview
- Chapter 2. An Inventor Sampler
- Chapter 3. Nodes and Groups
- Chapter 4. Cameras and Lights
- Chapter 5. Shapes, Properties, and Binding
- Chapter 6. Text
- Chapter 7. Textures
- Chapter 8. Applying Actions
- Chapter 9. Rendering Features
- Chapter 10. Handling Events and Selection
- Chapter 11. Touch and Gesture Events
- Chapter 12. Importing data
- Chapter 13. Exporting Data
- Chapter 14. Sensors
- Chapter 15. Engines
- Chapter 16. Node Kits
- Chapter 17. Draggers and Manipulators
- Chapter 18. Inventor Component Library
- Chapter 19. Stereo Viewing
- Chapter 20. Curves and Surfaces
- Chapter 21. Shaders
- Chapter 22. VRML97/ X3D Extensions
- Chapter 23. Collision Detection
- Chapter 24. Multithreading
- Chapter 25. Open Inventor Computing framework
- Chapter 26. Immersive Virtual Reality
- Chapter 27. Remote Rendering
- Chapter 28. Using Inventor with OpenGL
- Chapter 29. Portable User Interface - DialogViz
- Chapter 30. Optimizing Applications
- Appendix A. Error Handling
- Appendix B. Color Plates
- Legal Notice
- List of Examples
- List of Figures
- List of Tables

After reading this section, you’ll know how to use the CSG module to make Constructive Solid Geometry (**CSG** ).

The CSG extension provides solid modeling nodes for describing 3D shapes as combinations of other shapes using Boolean operations such as merge, intersection, and subtraction.

CSG stands for **Constructive Solid Geometry**.
It is a powerful method for describing a 3D shape as a combination of simpler 3D shapes using
the Boolean operations merge (union), intersection, and subtraction. For instance, the
expression "(A-B)+C" means remove B from A, then merge the result with C. This is called a
*CSG expression*, describing a *CSG tree*.

Actual computation of the geometry resulting from a CSG expression can be a slow process, at least not fast enough for real-time updates in interactive applications. However a visual simulation of a CSG shape can be achieved in many cases at interactive speed by using a special rendering method taking advantage of accelerated OpenGL rendering and the stencil buffer.

SolidViz implements a visual simulation of CSG shapes. A new group node,
**SoCSGGroup** **SoCSGGroup** **SoCSGGroup** , allows the specification of a CSG
expression.

**SoSolidViz** **SoSolidViz** **SoSolidViz**

Initialization class used to initialize and get information about the CSG module.

**SoCSGGroup** **SoCSGGroup** **SoCSGGroup**

Group node for interactive CSG rendering which performs a Constructive Solid Geometry (CSG) renderingThis group node performs a Constructive Solid Geometry (CSG) rendering. The children of this group define the solids that are involved in the CSG rendering. It is important to know that all children of this group are assumed to be solid (i.e., having a closed surface). Otherwise the results may be incorrect.

An expression is a character string which specifies the operations between solids. The operations can be *intersection* (indicated as “.” in the expression), union (“+”), or *subtraction* (“-”).

A solid is identified by a letter in the expression and corresponds to the child number of the **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** as follows: “A” corresponds to child 0, “B” corresponds to child 1, and so forth. The expression is not case sensitive.

Thus a CSG expression could be: “A . B - C + A” which means *compute the intersection of A and B, then remove C, then merge with A * and corresponds to the CSG tree in Figure 9.22, “ An example CSG tree”.

A letter in the CSG expression can be followed by a number to indicate the convexity of the solid. The convexity of a solid is defined as the maximum numbers of pairs of front and back surfaces. For instance, the convexity of a cube is 1 whereas the convexity of a torus is 2. The convexity of a solid is assumed to be 1 if no digit follows the corresponding letter in the expression. The maximum allowable convexity value is 128.

The CSG tree defined by *expression* is assumed to be in normal form (normalized). A CSG tree is in normal form when all intersection and subtraction operators have a left subtree that contains no union operator and a right subtree that is simply a shape. For example, the tree shown in Figure 9.22, “ An example CSG tree”, is in normal form.

A CSG tree can be converted to normal form by repeatedly applying the following set of production rules to the tree and then its subtrees:

** Step 1: Initialize SolidViz module.**

This initialization must be called after initializing Open Inventor.

SoSolidViz::init();

** Step 2: Create an SoCSGGroup object.**

Create the group node which will contain the shapes of the CSG model.

SoCSGGroup *myCSGGroup =newSoCSGGroup;

SoCSGGroup myCSGGroup =newSoCSGGroup();

SoCSGGroup myCSGGroup =newSoCSGGroup();

** Step 3: Add the solid shapes to the SoCSGGroup.**

Add as many children to the **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** as there are solid shapes.

SoCube *myShapeA =newSoCube; SoSphere *myShapeB =newSoSphere; myCSGGroup->addChild(myShapeA);// The first child is interpreted as the solid AmyCSGGroup->addChild(myShapeB);// The second child is interpreted as the solid B

SoCube myShapeA =newSoCube(); SoSphere myShapeB =newSoSphere(); myCSGGroup.AddChild(myShapeA);// The first child is interpreted as the solid AmyCSGGroup.AddChild(myShapeB);// The second child is interpreted as the solid B

SoCube myShapeA =newSoCube(); SoSphere myShapeB =newSoSphere(); myCSGGroup.addChild(myShapeA);// The first child is interpreted as the solid AmyCSGGroup.addChild(myShapeB);// The second child is interpreted as the solid B

Each child of the **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** must correspond to a solid shape. If your solid shape is composed of several nodes (e.g., transformation nodes, property nodes, shape nodes,…), add all these nodes as children of an **SoSeparator** **SoSeparator** **SoSeparator** , then add this separator as a child of **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** .

Each shape added under an **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** must be solid (i.e., a closed shape) to obtain correct results.

** Step 4: Specify the expression of the SoCSGGroup.**

The CSG expression relating the solid shapes of **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** must be specified though the **expression** field. The expression for subtracting shape B from shape A is: “A-B”.

myCSGGroup->expression.setValue("A-B");// The sphere (solid B)// is subtracted from the cube (solid A)

myCSGGroup.expression.SetValue("A-B");// The sphere (solid B)// is subtracted from the cube (solid A)

myCSGGroup.expression.setValue("A-B");// The sphere (solid B)// is subtracted from the cube (solid A)

The expression must be normalized.

** Step 5: Add the SoCSGGroup to the scene graph.**

root->addChild(myCSGGroup);

root.AddChild(myCSGGroup);

root.addChild(myCSGGroup);

The example program:

$OIVHOME/src/SolidViz/examples/csgGroup.cxx

illustrates these steps.

Picking on a CSG rendering may not work as expected. **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** produces the visual effect of the specified CSG operations, but the actual geometry is not modified. Open Inventor picking operates on the actual geometry. For example, if a cube has a cylindrical “hole” cut out of it using CSG rendering, picking on the “hole” will return a pick path to the geometry used to cut out the hole.

CSG rendering (i.e., **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** ) *
requires* that an OpenGL stencil buffer exist for the Open Inventor drawing window.
For best performance, the graphics accelerator should do stencil buffer operations in hardware.

On Microsoft Windows, you can “hint” to the Pixel Format chooser that
stencil buffer support is very important by setting the environment variable **OIV_REQUIRE_STENCIL**.

CSG rendering requires two or (potentially many) more rendering passes, which will reduce performance. The number of passes is related to the complexity of the CSG expression and to the convexity of the geometry. Consequently, a good graphics accelerator is highly recommended.

You must also be aware that the more complex the CSG expression is, the
slower the performance. The same holds true for the convexity of an object – greater convexity
implies slower performance. Furthermore, if the CSG expression exceeds a certain length, a
save/restore of the depth is needed and this operation is time consuming. The environment
variable **OIV_CSG_BUFFER_REGION** on Windows allows you to speed
up this task (see the **SoCSGGroup** **SoCSGGroup** **SoCSGGroup** reference manual text for more
information).

/Inventor_Mentor/Rendering_Features/Bump_Mapping/FXViz_Bump_Mapping.html

/Inventor_Mentor/Rendering_Features/Rendering_Features.html

/Inventor_Mentor/Rendering_Features/Shaders_Rendering_Features.html

Hotline & support

If you want to get the best out of your products, our Technical Support Team is available to assist you in any question, request, or technical issue that you may have.

Contact us

FEI Visualization Sciences Group operates at a worldwide level through offices in the United States, United Kingdom, France and distributors. Feel free to contact us.

Trial Versions

Request an evaluation version of Open Inventor. Evaluation versions include full access to our technical support and product experts.

Website

FEI Visualization Sciences Group is the leading provider of advanced 3D visualization and analysis software tools for developers, engineers and scientists in natural resources, medical and life sciences, and engineering.

©2015 FEI. FEI, the FEI logo, and Open Inventor are trademarks of FEI Company or its affiliates. All other trademarks belong to their respective owners.