[vtkusers] Example of PointInPolygon
rakesh patil
prakeshofficial at gmail.com
Thu Sep 30 02:28:12 EDT 2010
Hello,
The problem is solved.. The problem was in the code, I was using,
vtkPolyData object directly..
When I changed it to vtkPolygon, everything worked fine..:-)
Thanks
Warm Regards
Rakesh Patil
On Thu, Sep 30, 2010 at 7:11 AM, rakesh patil <prakeshofficial at gmail.com>wrote:
> Hello,
>
> Now the things are going more weird. If I load the scatter file in UTM
> format, then it shows all the points in the bounding box. If i load data in
> Geographic format(lat/long) then, it doesnt show any point within the
> polygon..
>
> Any clues, or suggestions whats going wrong here?
>
>
> Thanks
>
> Warm Regards
> Rakesh Patil
>
> On Wed, Sep 29, 2010 at 5:25 PM, rakesh patil <prakeshofficial at gmail.com>wrote:
>
>> Hi
>>
>> I am using points and not vertex points. Also the example given by David,
>> is instructing me the similar method to use.
>>
>> In the above code i made a small change. Instead of.
>>
>> newPoints->InsertNextPoint( points->GetPoint(id));
>>
>> I wrote
>>
>> double pt[3];
>> points->GetPoint(id, pt);
>> newPoints->InsertNextPoint(pt);
>>
>> After this change i am getting strange result. The result in "newPoints"
>> is all the points that fall inside a region defined by bounds. i.e. a
>> rectangular region which is formed by the bounds.
>>
>> This is really getting interesting and strange.. :-)
>>
>> Thanks
>>
>> Warm Regards
>> Rakesh Patil
>>
>>
>> On Wed, Sep 29, 2010 at 5:09 PM, Jothy <jothybasu at gmail.com> wrote:
>>
>>> Are you using vertex points instead of points inside the polygon. I mean,
>>> in case of a sphere, are using surface points rather than points inside the
>>> sphere.
>>>
>>> I think there is some difficulty in accurately calculating whether a
>>> point is inside or outside a polygon, if you submit a point which lies on or
>>> very close to the surface due to round-off errors in the ray-tracing used.
>>>
>>>
>>> Jothy
>>>
>>>
>>> On Wed, Sep 29, 2010 at 12:23 PM, rakesh patil <
>>> prakeshofficial at gmail.com> wrote:
>>>
>>>> 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
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> 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/20100930/cecd5a7b/attachment.htm>
More information about the vtkusers
mailing list