computational-geometrycsg

Constructive Solid Geometry vs Boundary Representation


I want to implement boolean operations on nonconvex polyhedral objects and want to render them with OpenGL. I have read about the two predominant techniques to do boolean operations on polyhedra: Boundary Representation (BReps) and Constructive Solid Geometry (CSG). According to some papers, implementing booleans with CSG should be easer so I think about using CSG rather than BReps. I know that BReps describe geometry by vertices and polygons, whereas CSG uses basic primitive objects like cylinders or spheres that are getting combined within a tree structure. I know that performing booleans on BReps are implemented by cutting the polygons which are intersecting and removing those polygons which are not needed (depending if the operatins is union or difference or ...). But how are boolean operations implemented in terms of CSG? How can I implements CSG boolean operations? I've already looked on the internet and found this for example http://evanw.github.io/csg.js/ or https://www.andrew.cmu.edu/user/jackiey/resources/CSG/CSG_report.pdf The curious thing is that these algorithms just use BReps for their booleans. So I don't understand where the advantage of CSG should be or why CSG booleans should be easier to implement.


Solution

  • You are somehow talking apples and pears.

    CSG is a general way to describe complex solids from primitive ones, an "arithmetic" on solids if you want. This process is independent of the exact representation of these solids. Examples of alternative/complementary modeling techniques are free-from surface generation, generalized cylinders, algebraic methods...

    BRep is one of the possible representation of a solid, based on a vertex/edge/face graph structure. Some alternative representations are space-occupancy models such as voxels and octrees.

    Usually, a CSG expression is evaluated using the representation on hand; in some cases, the original CSG tree is kept as such, with basic primitives at the leaves.

    A polyhedral BRep model is conceptually simple to implement; anyway, CSG expression evaluation is arduous (polyhedron intersection raises uneasy numerical and topological problems).

    Rendering of a BRep requires the triangulation of the faces, which can then be handled by a standard rendering pipeline.

    A voxel model is both simple to implement and makes the CSG expressions trivial to process; on the other hand it gives a crude approximation of the shapes.

    A raw CSG tree can be used for direct rendering by the ray-tracing technique: after traversing all primitives by a ray, you combine the ray sections using the CSG expression. This approach combines a relatively simple implementation with accuracy, at the expense of a high computational cost (everything needs to be repeated on every pixel of the image, and for every view).