As some already noticed, there is an issue with this algorithm. In some particular cases of vertices positions, the resulting set of triangles might create concave structure. The cause of such behaviour is the initial supertriangle. In this implementation, it is reduced to the size that is just enough to enclose all vertices. This makes it highly probable to have a significant triangles formed with the supertriangle vertices, and have them deleted in the finalizing step. If the supertriangle was much bigger than the spread of the input vertces (dx, dy), the algorithm would create the triangles in a convex fashion.
Simple solution found in Gilles Dumoulin's implementation is to initialize the supertriangle as follows:
REAL dMax = (dx dy) ? dx : dy;
REAL xMid = (xMax + xMin) / 2.0;
REAL yMid = (yMax + yMin) / 2.0;
vSuper = Vertex(xMid - 20 * dMax, yMid - dMax);
vSuper = Vertex(xMid, yMid + 20 * dMax);
vSuper = Vertex(xMid + 20 * dMax,yMid - dMax);
This mod should sort out the convexity issue.
I implemented the algorithm just to test how the Delaunay algorithm works and it seems to work perfectly. The only small issue is the need for the "super triangle(s)". You do not always have those bounding triangles when you start.
Anyway, the visualization is really great and made it absolutely trivial to implement!
Real great and so fast.
I compile it with Visual Studio and it worked
But I want to integrate Delaunay.cpp with a project in QT
I am using the QT4.8 sdk by nokia and compiling with minGW
Everything goes well but for 2 lines using the same function remove_if
in you code around line 273:
tIterator itEnd = remove_if(workset.begin(), workset.end(),
triangleIsCompleted(itVertex, output, vSuper));
I get this message from minGW:
function '_FIter std::remove_if(_FIter, _FIter, _Predicate) [with _FIter =
std::_Rb_tree_const_iterator, _Predicate = triangleIsCompleted]':
: passing 'const triangle' as 'this' argument of 'triangle
Problem with VIsual Studio 2010
Posted by PabloLiberman
on 08/18/2011 02:34am
Hi, I try to use this demo in VIsual Studio 2010 and the remove_if makes bugs, somebody try to run it in vs2010? (it makes compilation bug)
I solved a problem.
Posted by Becky
on 01/28/2013 11:10pm
I solved a problem.
This problem occurred because that VC2010's and VC2008 are differ.
so, we should add some code that operator '=' overriding in class triangle.
const triangle& operator=(const triangle &tri;) const
if (this != &tri;)
memcpy ((void*)this, &tri;, sizeof(tri));
have a good time :)
Hello, same problem with QT and minGW
microsoft does not use original algorithm.h
As a way around, modify the code like this:
/* FB */ tIterator itEnd;
/* FB */ for ( itEnd = workset.begin(); itEnd != workset.end(); itEnd++)
/* FB */ triangleIsCompleted(itVertex, output, vSuper);
/* FB */ -- itEnd;
//FB tIterator itEnd = remove_if(workset.begin(), workset.end(), triangleIsCompleted(itVertex, output, vSuper));
// A triangle is 'hot' if the current vertex v is inside the circumcircle.
// Remove all hot triangles, but keep their edges.
// FB itEnd = remove_if(workset.begin(), itEnd, vertexIsInCircumCircle(itVertex, edges));
/* FB */ tIterator itAt;
/* FB */ for ( itAt = workset.begin(); itAt != itEnd; itAt++)
/* FB */ vertexIsInCircumCircle(itVertex, edges);
/* FB */ itEnd = --itAt;
workset.erase(itEnd, workset.end()); // remove_if doesn't actually remove; we have to do this explicitly.
It might be, I don't understand anything (then forget this comment), but...
then you reliably get 7 triangles, instead of 8
regards from germany
polygon with points inside
Posted by Oliver Neuse
on 09/18/2010 11:28am
sorry, points were wrong, too late:
I noticed that your result surface may not have a convex boundary. Could you tell me how to modify the algorithm to make the surface have a convex boundary?
I wish you can understand me.:-)
love from China
Steve wrote a nice article on Delauney tesselation and included a source fortran code with it. I still use it as a first step in a three step program. Second step is smoothing the triangle via Clough-Tocher finite element plates (Salkauskus in his book about 1980 used it), then a brute force contouring. I still have the source and executables, produces autocad dfx output files. Rich Ray (firstname.lastname@example.org)