[vtkusers] PointInPolygon of vtkPolygon class

長尾 佐市 nagao-saichi at jcom.home.ne.jp
Wed May 17 10:18:47 EDT 2006


I check,  a point is inner or outer of polygon.
 I use PointInPolygon method of vtkPloygon calss.

 This method returns  invalid result, out of polygon point is
 innner one. I think this  is a BUG.

 I debugging this routine, I get solution,

   //   Fire the ray and compute the number of intersections.  Be careful
   //   of degenerate cases (e.g., ray intersects at vertex).
   //

     for (numInts=0, testResult=VTK_POLYGON_CERTAIN, i=0; i<numPts; i++)
       {
       x1 = pts + 3*i;
       x2 = pts + 3*((i+1)%numPts);

       //   Fire the ray and compute the number of intersections.  Becareful
       //   of degenerate cases (e.g., ray intersects at vertex).
       //
       if ((status=vtkLine::Intersection(x,xray,x1,x2,u,v)) ==
VTK_POLYGON_INTERSECTION)
         {
         if ( (VTK_POLYGON_RAY_TOL < v) && (v < 1.0-VTK_POLYGON_RAY_TOL) &&
         (VTK_POLYGON_RAY_TOL < u) && (u < 1.0-VTK_POLYGON_RAY_TOL) )
           {
           numInts++;
           }
         else
           {
       testResult = VTK_POLYGON_UNCERTAIN;
           }
         }
       else if ( status == VTK_POLYGON_ON_LINE )
         {
 //        testResult = VTK_POLYGON_UNCERTAIN;
 // At this point, testResult is UNCERTAIN,-> this is invalid rusult.
 // comment out of this line then get ture rusult.
         }
       }

  please check it,  thanks.




More information about the vtkusers mailing list