vtkClipPolyData basic problems
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
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 plane = vtkSmartPointer::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 clipper = vtkSmartPointer::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();