[vtkusers] vtkPolyData output of vtkImplicitBoolean and proper use of SafeDownCast.

mandalin mandalin147 at gmail.com
Mon Apr 11 01:04:57 EDT 2011


Hello good people of the vtk forum,

Given two finite, co-planar, planes (essentially 2 2D Polygons), I am
trying to calculate their union. Both planes are defined with vertices
(vtkPoints). I hope to get a new set of vertices as a result, and I hope
that array of vertices is empty if there is no overlap.

Below is my code. I have proceeded as follows
defined vtkpoints
defined vtkpolylines with those vtkpoints
defined vtkpolyplanes with those vtkpolylines
used vtkimplicitboolean to calculate their intersection
am attempting to extract the polydata defining the intersection-> Here
is where I get stuck.

I have clumsily tried to work around this by transforming the PolyData
into a vtkDataArray, and made some attempts with GetTuple. There must be
a more direct way I am missing.

It currently runs, however I have not been able to affirm the values of
anything.
Most importantly, I have not figured out the proper syntax to extract
the polydata with.

If I don't figure this out i suppose I'll go compile a library dedicated
to this task.

Thank you in advance,
~Amanda Lind


//define Polygons - select points
    vtkPolygon *plane1=vtkPolygon::New();
    vtkPolygon *plane2=vtkPolygon::New();

    vtkSmartPointer points1 = vtkSmartPointer::New();
    vtkSmartPointer points2 = vtkSmartPointer::New();


    for(int index=0; indexInsertNextPoint ( rotated_corners1[index].x,
rotated_corners1[index].y, rotated_corners1[index].z );
    }

    for(int index=numcorners1 ; index< numcorners1+numcorners2 ; index++)
    {
        points1->InsertNextPoint ( rotated_corners2[index].x,
rotated_corners2[index].y, rotated_corners2[index].z );
    }

//2 set PolyLine from Cells
    vtkPolyLine *polyline1 =vtkPolyLine::New();
    vtkPolyLine *polyline2 =vtkPolyLine::New();

    for(int index; indexGetPointIds()->SetId(index,index);
    }

    for(int index=numcorners1; index&lt;numcorners1+numcorners2 ; index++)
    { polyline2-&gt;GetPointIds()->SetId(index,index);
    }


//3 set PolyPlane from PolyLine
    vtkPolyPlane *polyplane1 =vtkPolyPlane::New();
    vtkPolyPlane *polyplane2 =vtkPolyPlane::New();

    polyplane1->SetPolyLine(polyline1);
    polyplane2->SetPolyLine(polyline2);


//4 calculate the union
    vtkImplicitBoolean *theIntersection = vtkImplicitBoolean::New();
    theIntersection->SetOperationTypeToUnion();
    theIntersection->AddFunction(polyplane1);
    theIntersection->AddFunction(polyplane2);


//5 extract the vertices
    vtkExtractPolyDataGeometry * unionplane
=vtkExtractPolyDataGeometry::New ();
    unionplane->SetImplicitFunction(theIntersection);
    unionplane->ExtractInsideOn();
    unionplane->ExtractBoundaryCellsOn();
    unionplane->Update();

	
    vtkCellArray *newverts= vtkCellArray::New();
    newverts=newpoly->GetVerts();

    vtkIdTypeArray * pts;
    pts=newverts->GetData();


//On another forum I have been told that the data array has the format...
    /*
     You can call GetData() on the cell array to access the IDs as a
     regular vtkDataArray.  The layout of the data array will be:

     [cell0_npts cell0_pt0 cell0_pt1 ... cell1_npts cell1_pt0 cell1_pt1 ...
     cell2_npts ... ]

     */
//However I am at a loss on how to access. I have attempted GetTuple to
no avail.


--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPolyData-output-of-vtkImplicitBoolean-and-proper-use-of-SafeDownCast-tp4295185p4295185.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list