Search code examples
c++vtk

vtkDelaunay3D::SetAlpha() does not accept values below 0


I'm trying to use VTK's Delaunay3D() to get a minimal bounding surface on my data using the alphaShapes algorithm. The particular dataset I'm working on is generally toroidally- or cylindrically-shaped, so by my understanding I should be trying to find a value < 0 for alpha. The class, however, does not seem to be able to handle negative floats. This can be confirmed by this minimal example:

#include <iostream>
#include <vtkSmartPointer>
#include <vtkDelaunay3D>

void test() {
    vtkSmartPointer<vtkDelaunay3D> dataMesh = vtkSmartPointer<vtkDelaunay3D>::New();
    dataMesh->SetAlpha(-.1);
    std::cout << dataMesh->GetAlpha() << std::endl;
}

int main(void) {
    test();
}

I get an output of 0, and this is reflected in visualizations of my actual data -- I get a big ugly diamond instead of a beautiful donut. If SetAlpha() is given a positive value, VTK responds as expected.

Is this a known issue? Are there workarounds?

SYSTEM: Ubuntu 20.04, using gcc version 9.4.0 with CMake. VTK 9.1 for c++.


Solution

  • It looks like your code is doing 3D Delaunay triangulation, not alpha shapes.

    From the documentation for Delaunay3D:

    For a non-zero alpha value, only verts, edges, faces, or tetra contained within the circumsphere (of radius alpha) will be output.

    In this implementation of Delaunay triangulation, alpha is a radius that can't be negative.

    Looks like VTK is silently changing it to 0 right here in the code: https://github.com/Kitware/VTK/blob/01f5cc18fd9f0c8e34a5de313d53d2178ff6e325/Filters/Core/vtkDelaunay3D.h#L129

    The documentation also mentions explicitly that the "alpha" is not the same as the alpha in alpha shapes, it's merely means something similar.

    (The notion of alpha value is derived from Edelsbrunner's work on "alpha shapes".) Note that a modification to alpha shapes enables output of combinations of tetrahedra, triangles, lines, and/or verts (see the boolean ivars AlphaTets, AlphaTris, AlphaLines, AlphaVerts).

    I'm not a PhD in CS/Geometry so maybe I'm missing something, but it seems like that class is not really what you want.

    So try setting alpha as something small and positive and if your data is toroidal it will probably give you what you want.