[vtkusers] Problems cutting polygons, bug?

Lodron, Gerald Gerald.Lodron at joanneum.at
Wed Nov 24 02:22:39 EST 2010


Hi

I wrote an application where a user can paint 2d polygons in 3D space. Then the user can define a cutting plane and i display the resulting lines.
The problem is that SOMETIMES the cutting does not work, so if anyone replys i will send him the Test1.vtk file which contains 4 Polygons whereby only three are cutted. (Yes the cutting plane defenetly cuts all polygons and there are 4 Polygons in the input file, see first visualization).

here my code:


vtkSmartPointer<vtkPolyDataReader> oReader = vtkPolyDataReader::New();

oReader->SetFileName("C:\\Test1.vtk");

oReader->Update();

vtkSmartPointer<vtkPolyData> oPolyData = oReader->GetOutput();

//Display input data, not important

{

vtkSmartPointer<vtkPolyDataMapper> oMapper = vtkPolyDataMapper::New();

oMapper->SetInputConnection(oReader->GetOutputPort());

vtkSmartPointer<vtkActor> oActor = vtkActor::New();

oActor->SetMapper( oMapper );

vtkSmartPointer<vtkRenderer> oRenderer = vtkRenderer::New();

vtkSmartPointer<vtkRenderWindow> oRenderWindow = vtkRenderWindow::New();

oRenderWindow->AddRenderer(oRenderer);

vtkSmartPointer<vtkRenderWindowInteractor> oIRen = vtkRenderWindowInteractor::New();

oIRen->SetRenderWindow(oRenderWindow);

oRenderer->AddActor(oActor);

// Render and interact

oRenderWindow->Render();

oIRen->Initialize();

oIRen->Start();

}

oPolyData->Print(std::cout); //containing 4 polygons

//Cut 2D polygons in 3D space with a plane

vtkSmartPointer<vtkPlane> oPlane = vtkPlane::New();

vtkSmartPointer<vtkCutter> oCutter = vtkCutter::New();

oCutter->SetCutFunction(oPlane);

oCutter->GenerateValues(1,0,1); //i am not sure why i do that

oPlane->SetOrigin(8.5, -72, -1177.0);

oPlane->SetNormal(1,0,0);

oCutter->SetInput(oPolyData);

oCutter->Update();

vtkSmartPointer<vtkPolyData> oCuttedPolyData = oCutter->GetOutput();

//Display cutting data, not important

{

vtkSmartPointer<vtkPolyDataMapper> oMapper = vtkPolyDataMapper::New();

oMapper->SetInputConnection(oCutter->GetOutputPort());

vtkSmartPointer<vtkActor> oActor = vtkActor::New();

oActor->SetMapper( oMapper );

vtkSmartPointer<vtkRenderer> oRenderer = vtkRenderer::New();

vtkSmartPointer<vtkRenderWindow> oRenderWindow = vtkRenderWindow::New();

oRenderWindow->AddRenderer(oRenderer);

vtkSmartPointer<vtkRenderWindowInteractor> oIRen = vtkRenderWindowInteractor::New();

oIRen->SetRenderWindow(oRenderWindow);

oRenderer->AddActor(oActor);

// Render and interact

oRenderWindow->Render();

oIRen->Initialize();

oIRen->Start();

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101124/ce7a17ca/attachment.htm>


More information about the vtkusers mailing list