The primary advantage of dual contouring is that it is able to reproduce sharp features, which is something that most other implicit surface meshing algorithms are unable to do. I also consider Dual Contouring to be simpler to implement from scratch than Marching Cubes, since you don't need to form large tables of stencils.
The overall algorithm is very simple. First the region to be meshed is divided into convex non-overlapping cells (like uniform cubes or tetrahedra). The scalar function that is being meshed is then evaluated at the vertices of those cells, and each vertex is labeled as being either inside or outside of the surface to be meshed.
Those cells that have a mix of inside and outside vertices must then contain a portion of the surface. It is this point where Dual Contouring begins to differ from Marching Cubes: instead of applying a stencil based on which vertices are inside or outside, Dual Contouring generates a single 'dual' vertex per cell straddling the surface. It then connects every dual vertex with it's neighboring dual vertices to form the final mesh. The only difficultly arises in choosing the location of the dual vertices to best represent the underlying surface being meshed.
To choose where to place vertices, dual contouring uses not only the intersection of the surface with the edges of the mesh, but also the surface normals at those locations. It then solves for the dual vertex location which minimizes the error in satisfying planes that pass through the edge intersections with the same normals as at the intersections. This corresponds to minimizing the following error:
where is the dual vertex position, is the location of the i'th (of n) edge intersection and is the corresponding normal for the i'th intersection. This is just a least squares system
which can be solved using a QR decomposition, or by forming the normal equations. One tricky aspect of this is that although there are always at least as many intersected edges as unknowns, it may not be the case that the row contributed by each edge is linearly independent from the other rows. In flat regions of the surface the normals will be nearly if not exactly the same, and the set of equations will be (nearly) singular.
One way to handle this is to add special-case code to check that the system is not singular, and if it is, solve a different system in 1D for the offset of the dual vertex in the normal direction that minimizes the fitting error. It is also possible to add a regularization term with low weight that prevents the system from being singular, but does not affect the results too badly in the event the system is well conditioned. I have done this by adding a (small) multiple of identity to the normal equations coefficient matrix, and the same small multiple of the original dual vertex position (i.e. the cell centroid) to the right hand side.
The image above shows an example of this in action. I generated an isosurface representation of the fandisk model, then ran it through dual contouring to produce the result you see above. Note that the method faithfully reproduces the sharp edges of this CAD model. I appear to have some minor bugs in the implementation however, as there are some artifacts on concave sharp edges.
The regularization approach seems to work well and eliminates the need for special case code. It also provides a knob to trade off mesh quality for approximation error: if the regularization term is small, then the method will try to reproduce the underlying surface faithfully. On the other hand, if the regularization term is large, dual vertices will be placed close to the centroid of the cells that generate them, producing a high quality mesh, but with staircasing artifacts where approximation error has been introduced.
5 comments:
Hi, i'm trying to create a fully destructible environment and i noticed that, soon or late, i'll have to demolish structures with sharp edges like walls. Now... i've already implemented dual marching cubes and it works fine, but i just can't understand the error function thing. Any help, please?
Hey James, appreciate the write up. I'm following the logic but falling down on the QEF, and you lost me completely on your regularization term approach. :)
I'm tackling getting my head around the math because that's obviously what's throwing me. Least Squares is a regression technique I recall from statistics I believe but I can't pair the two.
If you do any follow up or have any links or concepts to share it would be appreciated.
I'm going to join this comments train :) What on earth is QR Decomposition and how do I do it? I've search many sites and haven't understood how it applies to Dual contouring and how to "calculate" anything using it.
There are definitely a lot of particulars like that to take into consideration. That may be a great point to convey up. I provide the ideas above as normal inspiration but clearly there are questions like the one you convey up where an important factor might be working in honest good faith. I don?t know if finest practices have emerged around issues like that, but I am positive that your job is clearly identified as a fair game. Both boys and girls feel the influence of just a second’s pleasure, for the remainder of their lives. gsn casino games
I can set up my new idea from this post. It gives in depth information. Thanks for this valuable download obs studio full crack 64-bit windows 10 kuyhaa topic for all,..
Post a Comment