[vtkusers] vtkPolyData output of vtkImplicitBoolean and proper use of SafeDownCast.
Amanda Lind
mandalin147 at gmail.com
Mon Apr 11 01:03:16 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
//define Polygons - select points
vtkPolygon *plane1=vtkPolygon::New();
vtkPolygon *plane2=vtkPolygon::New();
vtkSmartPointer<vtkPoints> points1 = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkPoints> points2 = vtkSmartPointer<vtkPoints>::New();
for(int index=0; index<numcorners1 ; index++)
{
points1->InsertNextPoint ( 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 );
}
//define vtkPolyData - declare polygons
// vtkPolyData *polydata1 = vtkPolyData::New();
// vtkPolyData *polydata2 = vtkPolyData::New();
// polydata1->SetPoints ( points1 );
// polydata2->SetPoints ( points2 );
//2 set PolyLine from Cells
vtkPolyLine *polyline1 =vtkPolyLine::New();
vtkPolyLine *polyline2 =vtkPolyLine::New();
for(int index; index<numcorners1 ; index++)
{ polyline1->GetPointIds()->SetId(index,index);
}
for(int index=numcorners1; index<numcorners1+numcorners2 ; index++)
{ polyline2->GetPointIds()->SetId(index,index);
}
//3 set PolyPlane from PolyLine
vtkPolyPlane *polyplane1 =vtkPolyPlane::New();
vtkPolyPlane *polyplane2 =vtkPolyPlane::New();
polyplane1->SetPolyLine(polyline1);
polyplane2->SetPolyLine(polyline2);
//calculate the union
vtkImplicitBoolean *theIntersection = vtkImplicitBoolean::New();
theIntersection->SetOperationTypeToUnion();
theIntersection->AddFunction(polyplane1);
theIntersection->AddFunction(polyplane2);
//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.
More information about the vtkusers
mailing list