[vtkusers] Check if point is inside convex hull

David Doria daviddoria+vtk at gmail.com
Tue Nov 17 15:41:35 EST 2009


On Tue, Nov 17, 2009 at 3:23 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> David,
>
> Here is an alternative to your original example. As you noted, sphere
> source produces triangles. If you delaunay the points from sphere
> source you can produce a volume.
>
> Your original example had other flaws.
> 1) You never called update on the sphere source.
> 2) You did not provide a weights array.
>
> #include <vtkPolyData.h>
> #include <vtkSphereSource.h>
> #include <vtkSmartPointer.h>
> #include <vtkDelaunay3D.h>
> #include <vtkUnstructuredGrid.h>
>
> int main(int argc, char **argv)
> {
>  vtkSmartPointer<vtkSphereSource> SphereSource =
> vtkSmartPointer<vtkSphereSource>::New();
>  SphereSource->SetCenter(0.0, 0.0, 0.0);
>  SphereSource->SetRadius(1.0);
>  SphereSource->Update();
>
>  vtkSmartPointer<vtkDelaunay3D> Sphere = vtkSmartPointer<vtkDelaunay3D>::New();
>  Sphere->SetInput(SphereSource->GetOutput());
>  Sphere->Update();
>
>  double TestInside[3] = {.5, 0.0, 0.0};
>  double TestOutside[3] = {10.0, 0.0, 0.0};
>
>  double pcoords[3], weights[3];
>
>  vtkIdType cellId;
>
>  int subId;
>
>  //should be inside
>  cellId = Sphere->GetOutput()->FindCell(TestInside, NULL, 0, .1,
> subId, pcoords, weights);
>  if (cellId>=0)
>    {
>    cout << "In cell " << cellId << endl;
>    std::cout << "inside" << std::endl;
>    }
>  else
>  {
>    std::cout << "outside" << std::endl;
>  }
>
>  //should be outside
>  cellId = Sphere->GetOutput()->FindCell(TestOutside, NULL, 0, 0.1,
> subId, pcoords, weights);
>  if (cellId>=0)
>  {
>    cout << "In cell " << cellId << endl;
>    std::cout << "inside" << std::endl;
>  }
>  else
>  {
>    std::cout << "outside" << std::endl;
>  }
>
>  return 0;
> }
>


Thanks Bill. Since this uses a 3D Delaunay triangulation, it will
actually return true for points inside the convex hull of the original
object, correct? I.e. if the object is concave, some points that were
not actually inside the original object will say they are "inside"
using this method.

Thanks,

David



More information about the vtkusers mailing list