[vtkusers] Problems with vtkClipPolyData

Richard Whitehead richard.whitehead at vivosight.com
Wed Jun 11 11:30:35 EDT 2014


I'm having a couple of problems with clipping polygon data, which the
following code exposes:
 - Clipping a closed polygon, which should all be retained, it loses the
closing vertex
 - Clipping all the data so there is nothing left, various things then
crash because the clipper produces an array with one entry consisting of a
single null pointer

To reproduce these, in the first case define USE_CLIPPER but
not CLIP_TO_NOTHING in the following code, and in the second case define
them both.

This seems such ancient code; am I doing something wrong?  I'm using 6.1.

Many thanks,

Richard



#define USE_CLIPPER 1
#define CLIP_TO_NOTHING 1

// create circle of points, joined by lines into a closed loop, on the x,y
plane
vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
vtkIdType* lineIndices = new vtkIdType[21];
for (int i = 0; i< 20; i++)
{
const double angle = 2.0*vtkMath::Pi()*i/20.0;
points->InsertPoint(static_cast<vtkIdType>(i), 100*cos(angle),
100*sin(angle), 0.0 );
lineIndices[i] = static_cast<vtkIdType>(i);
}
lineIndices[20] = 0;
lines->InsertNextCell(21,lineIndices);
delete [] lineIndices;
pd->SetPoints(points);
pd->SetLines(lines);
 // clipping
#if USE_CLIPPER
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
#if CLIP_TO_NOTHING
plane->SetOrigin(0, 0, -1.0); // no data on this plane
#else
plane->SetOrigin(0, 0, 0.0); // all the data is on this plane
#endif
plane->SetNormal(0, 0, 1);
vtkSmartPointer<vtkClipPolyData> clipper =
vtkSmartPointer<vtkClipPolyData>::New();
clipper->SetInputData(pd);
clipper->SetClipFunction(plane);
clipper->GenerateClipScalarsOn();
clipper->InsideOutOn();
clipper->Update();
#endif

// windows and interactors
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->SetSize(600, 600);

// widget
vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red
vtkSmartPointer<vtkContourWidget> contourWidget =
vtkSmartPointer<vtkContourWidget>::New();
contourWidget->SetInteractor(renderWindowInteractor);
contourWidget->SetRepresentation(contourRep);
contourWidget->On();

#if USE_CLIPPER
contourWidget->Initialize(clipper->GetOutput());
#else
contourWidget->Initialize(pd);
#endif
 // run
contourWidget->Render();
renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
contourWidget->Off();





-- 

Richard Whitehead *–* Senior Imaging Engineer

*Michelson Diagnostics Ltd*

*M:* +44 (0)7905 955276   *T:* +44 (0)20 8308 1695

*E: *richard.whitehead at vivosight.com   *W:* www.vivosight.com


<http://www.vivosight.com/>


Michelson Diagnostics Ltd, 1 Grays Farm Production Village, Grays Farm
Road, Orpington, Kent  BR5 3BD, UK

Registered Office: 3 Shearwater, Maidstone, ME16 0DW.     Registered in
England No. 5732681
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140611/01981fa6/attachment.html>


More information about the vtkusers mailing list