[vtkusers] Fill in 2D vtkPolyData

Jonathan Morra jonmorra at gmail.com
Wed Apr 25 12:36:37 EDT 2012


So I think I have solved the issues for my situations.  I have attached my
modified file, but the basic change I made was changing your definition of
"largest" polygon for computation of the normal.  I'm not sure how you have
defined largest, but I changed largest to be the largest number of points.
 This seems to work for my test cases, however I think a better
generalization would be the largest area.

Let me know if this makes sense and passes your test cases

// if no normal specified, then compute one from largest contour

  // This change made by Jon on 4/25/2012.

  // It would appear that at least for my examples, the calculation of

  // "largest" is not correct.  I go ahead and define "largest" as that contour

  // with the largest number of points.  This seems to work for my test cases,

  // however a good generalization would be to define "largest" as the polygon

  // with the largest area.

  double computedNormal[3] = { 0.0, 0.0, 1.0 };

  if (normal == 0)

    {

    //double maxnorm2 = 0;

    double maxPoints = 0;

    size_t numNewPolys = newPolys.size();

    for (size_t i = 0; i < numNewPolys; i++)

      {

      vtkCTPFPoly &poly = newPolys[i];

      size_t numPoints = poly.size();

      double n[3] = { 0.0, 0.0, 0.0 };

      double v0[3], v1[3], v2[3];

      points->GetPoint(poly[numPoints-1], v1);

      points->GetPoint(poly[0], v2);

       for (size_t j = 1; j < numPoints; j++)

        {

        v0[0] = v1[0]; v0[1] = v1[1]; v0[2] = v1[2];

        v1[0] = v2[0]; v1[1] = v2[1]; v1[2] = v2[2];

        points->GetPoint(poly[j], v2);

         double ax = v2[0] - v1[0];

        double ay = v2[1] - v1[1];

        double az = v2[2] - v1[2];

        double bx = v0[0] - v1[0];

        double by = v0[1] - v1[1];

        double bz = v0[2] - v1[2];

         n[0] += (ay * bz - az * by);

        n[1] += (az * bx - ax * bz);

        n[2] += (ax * by - ay * bx);

        }

       double norm2 = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];

      if (numPoints > maxPoints)

        {

        computedNormal[0] = -n[0]/norm2;

        computedNormal[1] = -n[1]/norm2;

        computedNormal[2] = -n[2]/norm2;

        //maxnorm2 = norm2;

        maxPoints = numPoints;

        }

      }

    normal = computedNormal;

    }


On Tue, Apr 24, 2012 at 9:38 PM, Jonathan Morra <jonmorra at gmail.com> wrote:

> I've been looking at this all day, and I think the answer lies within
> the vtkCTPFCheckPolygonSense method.  It would appear that for complex
> drawings which are correctly filled in, this method returns a sense of 1
> for all but the outer contour and incorrectly filled in contours return a
> sense of 0 for all but the outer contour.  Before I continue down this
> road, I was wondering if there might be a more straightforward way to solve
> my problem.
>
> I have a 3D binary volume from which I am extracting a contour for
> visualization using vtkMarchingSquares and a 2D region.  I want to
> visualize the interior of this contour with varying levels of opacity.  Is
> there another way to do this other than
> 1.  Use vtkMarchingSquares to vtkStripper to generate a 2D mesh
> 2.  Run 2D mesh through vtkContourToPolygonFilter
> 3.  Visualize
>
> Is there someway to just tell vtkMarchingSquares to fill in the output, or
> maybe something else I haven't thought of?
>
>
> On Mon, Apr 23, 2012 at 9:20 AM, Jonathan Morra <jonmorra at gmail.com>wrote:
>
>> I'm just getting around to looking into this now.  I'll let you know if I
>> fix this for my case.  On a related note, does there exist a filter which
>> takes as input a specified 2D vtkPolyData, and a set of candidate 2D
>> vtkPolyDatas, and returns a list of those candidate vtkPolyDatas which are
>> wholly inside the specified input?  This seems to be related to this filter.
>>
>>
>> On Thu, Apr 19, 2012 at 11:03 AM, David Gobbi <david.gobbi at gmail.com>wrote:
>>
>>> Hi Jonathan,
>>>
>>> This is why I haven't added this filter to VTK yet.  When the input
>>> has multiple contours, the code doesn't yet have the necessary logic
>>> for determining which contours are holes.  In your case, it has
>>> incorrectly marked the large contour as a hole.
>>>
>>> Unfortunately I cannot provide you with a timeline for when I will
>>> finish this filter, lately I've been crazy busy on other projects.
>>> But if you want to give it a shot yourself, take a look at the code
>>> for vtkContourToPolygonFilter::MakePolysFromContours(). The
>>> section that needs to be modified is the block that starts with
>>> "if (normal == 0)".
>>>
>>>  - David
>>>
>>>
>>> On Thu, Apr 19, 2012 at 11:44 AM, Jonathan Morra <jonmorra at gmail.com>
>>> wrote:
>>> >
>>> > After using your filter for a little while, for the most part it works
>>> great, however I have discovered a few cases where it doesn't work.  I've
>>> attached a screen shot showing a failure,  The first image is the input
>>> vtkPolyData, and the second is the result of running through your filter.
>>>  Can you determine what is going on?  If not, I'd be happy to give you the
>>> poly data I'm using, just let me know how to export it to disk, and I can
>>> email it to you.
>>> >
>>> > Thanks
>>> >
>>> > PS The behavior seems unpredictable, as sometimes with shapes just as
>>> complicated it works fine, I can't seem to tell what makes it fail.
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > On Tue, Apr 10, 2012 at 12:26 PM, David Gobbi <david.gobbi at gmail.com>
>>> wrote:
>>> >>
>>> >> Use the PickableOff() method (on the actor, not the data).
>>> >>
>>> >> On Tue, Apr 10, 2012 at 1:17 PM, Jonathan Morra <jonmorra at gmail.com>
>>> wrote:
>>> >> > One more question along this same line.  Now that I have opaque
>>> vtkPolyData,
>>> >> > I'm noticing that my vtkPicker is no longer hitting the same data
>>> it was
>>> >> > before, it's hitting the now opaque poly data.  This makes sense to
>>> me, but
>>> >> > I don't want it to happen.  Is there a way to tell the vtkPicker to
>>> ignore
>>> >> > some vtkPolyData (ie always pick the underlying data).
>>> >> >
>>> >> > Thanks
>>> >
>>> >
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120425/7355e6f3/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkContourToPolygonFilter.cpp
Type: text/x-c++src
Size: 69691 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120425/7355e6f3/attachment.cpp>


More information about the vtkusers mailing list