[vtkusers] Example of PointInPolygon

rakesh patil prakeshofficial at gmail.com
Wed Sep 29 07:23:37 EDT 2010


hi,

Below is the sample code what i was trying.

int num = polyPd->GetNumberOfPoints();
// polyPd is a polydata containing points that forms a polygon

vtkPoints* points = this->del->GetOutput()->GetPoints();
// del is an instance of vtkDelaunay2d class. Out of this object is used to
display
// scattered points

vtkPoints *newPoints = vtkPoints::New();
// To store selected points

double bnds[6], n[3];

// Get the bounds in 'bnds'
polyPd->GetPoints()->GetBounds(bnds);

// To get normal direction in 'n'
vtkPolygon::ComputeNormal(num,
  static_cast<double *>(polyPd->GetPoints()->GetData()->GetVoidPointer(0)),
n);

for( int id = 0; id < points->GetNumberOfPoints(); id++ )
{
  if( vtkPolygon::PointInPolygon( points->GetPoint(id), num,
      static_cast<double
*>(polyPd->GetPoints()->GetData()->GetVoidPointer(0)), n) == 1 )
       newPoints->InsertNextPoint(points->GetPoint(id));
}

// code to create a mapper and actor with
// the help of newPoints

I hope there is no difficulty in understanding the other part of code. I got
this logic from the mailing list when i searched for PoinInPolygon here

http://public.kitware.com/pipermail/vtkusers/2010-April/107974.html

Thanks

Warm Regards
Rakesh Patil


On Wed, Sep 29, 2010 at 3:49 PM, Jothy <jothybasu at gmail.com> wrote:

> Could you please post your code?
>
> Jothy
>
> On Wed, Sep 29, 2010 at 11:09 AM, rakesh patil <prakeshofficial at gmail.com>wrote:
>
>> Hi,
>>
>> I have been trying to find whether a given point is within a polygon or
>> not. I have been doing this using,
>>
>> vtkPolygon::PointInPolygon()
>>
>> function. But out of 10 runs, in 1 run, i get only few points inside, the
>> polygon. Others just fails and shows 0 points selected.
>>
>> Can anyone come up with a small example, for this?
>>
>> Thanks
>>
>> Warm Regards
>> Rakesh Patil
>>
>> _______________________________________________
>> 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
>>
>>
>
>
> --
> PhD Student
> Dept. of Medical Physics
> Clatterbridge Centre for Oncology
> UK
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100929/a766160d/attachment.htm>


More information about the vtkusers mailing list