Search code examples
pythonvtkmayavi

Where is vtkSphere::ComputeBoundingSphere in in VTK's Python bindings


I'm using Anaconda 64-bit on Windows with VTK version 5.10.1 and MayaVi version 4.3.1. Is vtkSphere::ComputeBoundingSphere available from VTK's Python bindings? I have a set of 3D points for which I want the minimum bounding sphere. As far as I can see, vtkSphere::ComputeBoundingSphere does this in C++ but I can't find this function in the Python bindings for VTK.

I have found the class vtk.vtkSphere and the output of help(vtk.vtkSphere) mentions "Additional methods are available for sphere-related computations, such as computing bounding spheres for a set of points, or set of spheres.". So, where is this function though?


Solution

  • I still haven't found evidence that VTK's Python bindings expose vtkSphere::ComputeBoundingSphere, but I have found the CGAL library which has Python bindings that do expose N-dimensional bounding sphere calculations. The C++ function documentation is at http://doc.cgal.org/latest/Bounding_volumes/classCGAL_1_1Min__sphere__d.html.

    I used the outdated bindings at http://cgal-python.gforge.inria.fr/ (because there is a Windows installer available at http://www.lfd.uci.edu/~gohlke/pythonlibs/#cgal-python) but there are newer bindings available at https://code.google.com/p/cgal-bindings/ if anyone wants to give them a try.

    Assuming you have a list of vertices called verts, the following code constructs a Min_sphere_3 object from which one can get the centre and radius of the bounding sphere.

    import CGAL
    
    min_sphere = CGAL.Geometric_Optimisation.Min_sphere_3()
    
    for pt in verts:
        min_sphere.insert(CGAL.Point_3(pt[0], pt[1], pt[2]))
    
    # Sphere properties: min_sphere.center(), min_sphere.squared_radius().