[vtkusers] Extracted cross-section from vtkCutter cannot be displayed
ochampao
ochampao at hotmail.com
Wed Jul 11 06:00:16 EDT 2018
Here is the method which adds the sphere on the right view and then cuts the
cross-section to be displayed on the left view.
void addPickedPoint(const double x, const double y, const double z)
{
// sphere source
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetCenter(x, y, z);
sphereSource->SetRadius(1.0);
sphereSource->SetThetaResolution(50);
sphereSource->SetPhiResolution(50);
// sphere polygonal mapper
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
// actor for displaying sphere in 3D
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper);
sphereActor->GetProperty()->SetDiffuseColor(1, 0, 0);
sphereActor->GetProperty()->SetOpacity(0.7);
// setup cut plane for extracting cross-sections of polygonal models.
// Cutplane is the plane defined by the focal point and the view plane
// normal of the Left View.
vtkNew<vtkPlane> cutPlane;
cutPlane->SetOrigin(
this->leftRenderer->GetActiveCamera()->GetFocalPoint());
cutPlane->SetNormal(
this->leftRenderer->GetActiveCamera()->GetViewPlaneNormal());
// setup cutter and attach cutplane
vtkNew<vtkCutter> cutter;
cutter->SetCutFunction(cutPlane);
cutter->SetInputConnection(sphereSource->GetOutputPort());
cutter->Update();
// crossection mapper
vtkNew<vtkPolyDataMapper> cutterMapper;
cutterMapper->SetInputConnection(cutter->GetOutputPort());
// actor for displaying the extracted cross-section from the sphere
vtkNew<vtkActor> cutterActor;
cutterActor->SetMapper(cutterMapper);
cutterActor->GetProperty()->SetDiffuseColor(0.2, .49, 1);
cutterActor->GetProperty()->SetColor(1.0, 0.55, 0.2);
cutterActor->GetProperty()->SetLineWidth(1.0f);
cutterActor->GetProperty()->SetOpacity(1.0);
// add all actors to the Renderers
this->leftRenderer->AddActor(cutterActor);
this->rightRenderer->AddActor(sphereActor);
// reset camera
this->leftRenderer->ResetCamera();
this->rightRenderer->ResetCamera();
// render views
this->leftRenderer->GetRenderWindow()->Render();
this->rightRenderer->GetRenderWindow()->Render();
}
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list