In this post, the use of TetGen for 3D Voronoi tesselation has been briefly discussed. However there is still no info about the use of TetGen to generate a 3D Voronoi diagram. The TetGen documentation is very brief about this feature, and there is no example how to generate the voronoi diagram shown in the documentation. I found out that one needs to use the "v" switch (in contrary to the documentation which claims this switches on the verbose mode), based on some quotes on the Web. However if I try the Mathematica interface TetGenLink I fail to get any information on the 3D Voronoi diagram. I tried out the following sequence.
First I loaded the TetGen Link and generated 8 3D points to keep the graphical output simple.
Needs["TetGenLink`"];
RandomSeed[12345];
pts = RandomReal[{-1, 1}, {8, 3}];
Then I generated an TetGen Instance
inInst = TetGenCreate[]
To automatically generate an boundary for a potential Voronoi diagram (even if I do not know this would work) I extracted the ConvexHull of the point set and assigned all points and the convex hull faces to the instance
{ptshull2, surfacehull2} = TetGenConvexHull[pts];
TetGenSetPoints[inInst, ptshull2]
TetGenSetFacets[inInst, {#} & /@ surfacehull2]
please note that the face indices have to be enclosed into additional list brackets, otherwise you'll get an TetGen error.
Then I define a Wireframe visualization function to display tetrahedrons.
TetrahedraWireframe[i_] :=
Line[ Flatten[
i[[All, #]] & /@ {{1, 2}, {2, 3}, {3, 1}, {1, 4}, {2, 4}, {3, 4}}, 1]]
Finally I fire TetGen by doing
outInst = TetGenTetrahedralize[inInst, "v"]
extract the results from the TetGen run by doing
coords = TetGenGetPoints[outInst];
elements = TetGenGetElements[outInst];
And visualize the resulting Tetrahedrons
Graphics3D[{GraphicsComplex[coords, TetrahedraWireframe[elements]],
PointSize[Large], Point /@ coords, Red, Point /@ pts}]
which yields the following graphical output
I naively hoped that somehow by using this procedure I would get the Voronoi diagram, but it seems that this is not available in Mathematica. Furthermore the "v" switch does not have any effect it seems.
Any ideas about convincing Mathematica to return the Voronoi diagram are most welcome.
Already upfront: I'm aware that there are other solutions possible, mentioned in the above post, like using mPower to link to QHull for instance. However I would like to use the TetGen link since it is well integrated into Mathematica.
Another option would be to get QHULL integrated into Mathematica in a similiar fashion like TetGen, but for whatever reason this has not been done yet. The mPower approach lacks significant performance (since it is firing qhull through the run command) compared to the speed of the TetGen implementation.