NMO
NMO

Reputation: 766

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.

Upvotes: 2

Views: 9660

Answers (3)

user1196549
user1196549

Reputation:

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).

Upvotes: 3

fang
fang

Reputation: 3633

A CSG model just represents the desired operations (unions, intersections,...etc) applied onto transformed prmitives. It does not really modify the primitives (such as trimming the corner of a cube). The reason you can see a complex model being displayed on the screen is because the rendering engine is doing the trick. When displaying a CSG model, there are typically two ways: the first way is to convert it to a Brep model on the fly and the 2nd way is to use a CSG direct display algorithm, which is often based on scanline algorithim.

So, if you already have a good CSG rendering engine, then you don't have to worry about trimming the Brep model and your life is indeed easier. But if you have to write the rendering engine yourself, you will not save as much time by going with CSG.

Upvotes: 1

Spektre
Spektre

Reputation: 51873

in mine opinion CSG is not easier at all

  • but it is more precise
  • there are not used cylinders,spheres,...
  • instead there are used rotation surfaces of curves

Operations on CSG

  • if you do (bool)operations on rotation surfaces with the same axis
  • then just you do the operation on the curves ... (this is where the CSG is better then BRep)
  • when the axises are not the same then you have to create new entry in the CSG tree
  • also operations on compatible object (like boxes join/cut with same joining/intersecting surface) can be done by simply updating the size of them ...
  • but most implementation do not do such things and instead every operation is stored into tree
  • which makes the rendering slow after any change in the tree
  • also the render must do all the operations not during the operations it self but in rendering or pre-rendering stage
  • which makes the CSG implementation more complicated.
  • the only advantage I see in it is that the model can have analytic representation
  • which is far more accurate especially if multiple operations are on top of it...

Upvotes: 0

Related Questions