[vtkusers] Check if point is inside convex hull
Bill Lorensen
bill.lorensen at gmail.com
Tue Nov 17 15:23:42 EST 2009
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;
}
On Tue, Nov 17, 2009 at 3:01 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> On Tue, Nov 17, 2009 at 2:37 PM, <lynx.abraxas at freenet.de> wrote:
>>
>> On 17/11/09 12:41:19, David Doria wrote:
>> > I broke your example into two parts:
>> >
>> > http://www.vtk.org/Wiki/Convex_hull
>> >
>> > http://www.vtk.org/Wiki/Check_if_a_point_is_inside_an_object
>> >
>> > The convex hull part works fine. However, the "point inside object" part I
>> > am having trouble with. It compiles, but it says both points are outside the
>> > sphere. Can someone take a look?
>>
>> Hi David,
>>
>> I see You're exampling again even with pics, that's great!
>> I'm not sure but when I was looking for a function checking if a point is
>> inside a closed surface I found vtkSelectEnclosedPoints. However I haven't
>> found the time yet to implement the code using it.
>> Looking at Your example I would guess that Sphere->FindCell checks if a point
>> is inside the cell's polygon (eg lying on the polygon surface). I'm not sure
>> about this but that's what FindCell sounds to me. It would explain why both
>> points are "outside" since they are not inside a polygon plane.
>>
>> Thanks,
>> Lynx
>>
>>
>
> I see... so originally Dirk (he is to thank for the images, by the
> way!) was testing if a point was inside the convex hull produced by
> delaunay3d. As I understand it, this produces tetrahedra - so that's
> why the "point inside" test worked because there were actually
> volumetric cells in the polydata?
>
> I tried to use vtkSelectEnclosedPoints here -
> http://www.vtk.org/Wiki/Check_if_a_point_is_inside_an_object - (take a
> look Lynx)
>
> It works (the IsInside function works properly) but I was getting a
> segfault probably due to a data type problem when I tried to get the
> whole array of 0/1 labels of inside outside. It was actually crashing
> on
>
> InsideArray->GetNumberOfTuples()
>
> Does anyone know how to get the length of a vtkDataArray?
>
> Thanks,
>
> David
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list