[vtkusers] Using vtkMarchingCubes3D with vtkContourWidget

Jonathan Morra jonmorra at gmail.com
Tue Nov 16 19:25:11 EST 2010


I have been working on this some more and realized that I've overlooked a
major issue.  When I cut a mesh in a different plane I might not get only 1
contour.  This has lead me to do the following in the hopes of returning N
vtkPoints, and creating a new contour with each.  Unfortunately this still
doesn't work.  It would appear that some of the cells from strippedData need
to be connected and some do not, however, I'm still not sure how to
determine which ones should be connected and which ones should be different
contours.

The frustrating thing for me is that I know the code to do this is buried
somewhere in VTK because when I render the output of vtkCutter, it looks
totally reasonable, but I just can't seem to flush out the logic.

Any ideas?

        vtkStripper stripper = new vtkStripper();
        stripper.SetInput(unorderedData);
        stripper.Update();
        vtkPolyData strippedData = stripper.GetOutput();

        HashSet<vtkPoints> pointsSet = new HashSet<vtkPoints>();
        // Here, we're trying to mimic the suggestion given here
        //
http://vtk.1045678.n5.nabble.com/question-about-vtkContourWidget-vtkContourRepresentation-td1255118.html#a3247766

        for (int i=0; i<strippedData.GetNumberOfCells(); i++) {
            vtkCell cell = strippedData.GetCell(i);
            vtkPoints points = new vtkPoints();
            for (int j=0; j<cell.GetNumberOfPoints(); j++)
                points.InsertNextPoint(cell.GetPoints().GetPoint(j));
            pointsSet.add(points);
        }

        return pointsSet;

On Mon, Nov 15, 2010 at 11:08 AM, Jonathan Morra <jonmorra at gmail.com> wrote:

> So I've found out some more info.  It would appear that I am in fact
> ordering the points in each cell correctly.  The following code will output
> a part of the total points in order.  However, if I uncomment the outer for
> loop and change strippedData.GetCell(0) to strippedData.GetCell(i) the
> points are again out of order (like my last message).  It would appear that
> the cells of stripped data have an order that is not 0, 1, 2,...
>
> Does anyone know if this is correct, or if I'm on the right track?
>
>         vtkStripper stripper = new vtkStripper();
>         stripper.SetInput(unorderedData);
>         stripper.Update();
>         vtkPolyData strippedData = stripper.GetOutput();
>
>         vtkPoints points = new vtkPoints();
>         // Here, we're trying to mimic the suggestion given here
>         //
> http://vtk.1045678.n5.nabble.com/question-about-vtkContourWidget-vtkContourRepresentation-td1255118.html#a3247766
>
>         //for (int i=0; i<strippedData.GetNumberOfCells(); i++) {
>             vtkCell cell = strippedData.GetCell(0);
>             for (int j=0; j<cell.GetPoints().GetNumberOfPoints()-1; j++) {
>                 points.InsertNextPoint(cell.GetPoints().GetPoint(j));
>             }
>         //}
>         return points;
>
> On Thu, Nov 11, 2010 at 12:24 PM, Jonathan Morra <jonmorra at gmail.com>wrote:
>
>> So after struggling with this for a while, I've come up with the following
>> code, which kinda does the job.
>>
>>     public vtkPoints reorderPoints(vtkPolyData unorderedData) {
>>         vtkStripper stripper = new vtkStripper();
>>         stripper.SetInput(unorderedData);
>>         stripper.Update();
>>         vtkPolyData strippedData = stripper.GetOutput();
>>
>>         vtkPoints points = new vtkPoints();
>>         // Here, we're trying to mimic the suggestion given here
>>         //
>> http://vtk.1045678.n5.nabble.com/question-about-vtkContourWidget-vtkContourRepresentation-td1255118.html#a3247766
>>         for (int i=0; i<strippedData.GetNumberOfCells(); i++) {
>>             vtkCell cell = strippedData.GetCell(i);
>>             for (int j=0; j<cell.GetPoints().GetNumberOfPoints()-1; j++) {
>>                 points.InsertNextPoint(cell.GetPoints().GetPoint(j));
>>             }
>>         }
>>         return points;
>>     }
>> The points that are returned are in "better" order than having not run
>> this method, but it's still not the correct order.  It turns out that I
>> cannot upgrade to the newest version of VTK because we're using GDCM which
>> isn't yet integrated into the newest version of VTK, so I'm stuck with 5.6
>> for now.  However, I did do a test on the head of GIT and I tried to use
>> Karthik's code suggested above, but I still couldn't get that working.  I
>> attempted to follow internally what vtkCellArray.GetNextCell() was doing,
>> and that's how I came up with the above function.
>>
>> Can someone tell me why the above function isn't returning the vtkPoints
>> in the correct order for vtkContourWidget?
>>
>> Thanks
>>
>> On Sat, Nov 6, 2010 at 10:12 PM, Karthik Krishnan <
>> karthik.krishnan at kitware.com> wrote:
>>
>>> Ah.. yes.. This method was added on May 19, 2010. Perhaps you are
>>> using a version of VTK prior to that.
>>>
>>> Please see :
>>>
>>> http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=068a064cea7ba0fc7a4c4f9d2f7dfed6eb093674
>>>
>>> Update your VTK.
>>>
>>>
>>> On Sat, Nov 6, 2010 at 10:54 PM, Jonathan Morra <jonmorra at gmail.com>
>>> wrote:
>>> > I couldn't find GetNextCell() at all in Java. I'm currently using
>>> version
>>> > 5.6. Do you have any other suggestions?
>>> >
>>> > On Nov 6, 2010 9:05 AM, "Karthik Krishnan" <
>>> karthik.krishnan at kitware.com>
>>> > wrote:
>>> >
>>> > Jonathan:
>>> >
>>> > Use the other signature of the method GetNextCell. [ int
>>> > GetNextCell(vtkIdList *pts) ]That should be wrapped...
>>> >
>>> > The code to re-order the points based on the connectivity information
>>> > would be written in java as :
>>> >
>>> >  vtkIdList idlist = new vtkIdList();
>>> >  unorderedPolyData.GetLines().GetNextCell(idlist);
>>> >  npts = idlist.GetNumberOfIds();
>>> >  for ( int i = 0;  i < ( npts-1 );  i ++)
>>> >    {
>>> >    points.InsertPoint(i,
>>> unorderedPolyData.GetPoints().GetPoint(pts[i]));
>>> >    }
>>> >
>>> > --
>>> > karthik
>>> >
>>> > On Wed, Nov 3, 2010 at 7:29 AM, Jonathan Morra <jonmorra at gmail.com>
>>> wrote:
>>> >> I have a 3D vtkPolyDat...
>>> >
>>> >> _______________________________________________
>>> >> Powered by www.kitware.com
>>> >>
>>> >> Visit other Kitwa...
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101116/8bc45940/attachment.htm>


More information about the vtkusers mailing list