[vtkusers] Display filled contour of a cut sphere

Hortense KIRISLI hortense.kirisli at aquilab.com
Mon May 4 10:09:39 EDT 2015


Hi all,

Here is what I would like to do:
I have a sphere that I cut with a plane. I succeeded to display the intersection of the sphere with the plane as a contour, but do not succeed to display it filled. Also, I do not want the sphere itself to be visible, only its intersection in plane, filled (so I cant use
I have been looking into other vtk posts and example (capSphere.tcl), which are supposed to perform what I want, but could not make it works.

Here is my code; the issue I see is that boundaryStrips seems to be empty.

  // Plane
  vtkSmartPointer<vtkPlane> cutterPlane = vtkSmartPointer<vtkPlane>::New();
  cutterPlane = vtkSmartPointer<vtkPlane>::New();
  cutterPlane->SetOrigin(0., 0., 0.);
  cutterPlane->SetNormal(normal[0], normal[1], normal[2]);

  // Sphere center
  vtkSmartPointer<vtkSphereSource> sphereCenter = vtkSmartPointer<vtkSphereSource>::New();
  sphereCenter = vtkSmartPointer<vtkSphereSource>::New();
  sphereCenter->SetCenter(0., 0., 0.);
  sphereCenter->SetRadius(20.0);
  sphereCenter->SetThetaResolution(16);
  sphereCenter->SetPhiResolution(16);

  //// Cutter sphere center
  //vtkSmartPointer<vtkCutter> cutterSphereCenter = vtkSmartPointer<vtkCutter>::New();
  //cutterSphereCenter->SetCutFunction(cutterPlane);
  //cutterSphereCenter->SetInputConnection(sphereCenter->GetOutputPort());

  // TODO: fill in the cutted sphere
  vtkSmartPointer<vtkClipPolyData> clipper = vtkSmartPointer<vtkClipPolyData>::New();
  clipper->SetInputConnection(sphereCenter->GetOutputPort());
  clipper->SetClipFunction(cutterPlane);
  //clipper->GenerateClipScalarsOn();
  //clipper->GenerateClippedOutputOn();
  //clipper->SetValue(0);

 // FeatureEdges
  vtkSmartPointer<vtkFeatureEdges> boundaryEdges = vtkSmartPointer<vtkFeatureEdges>::New();
  boundaryEdges->SetInputConnection(clipper->GetOutputPort());
  boundaryEdges->BoundaryEdgesOn();
  boundaryEdges->FeatureEdgesOff();
  boundaryEdges->NonManifoldEdgesOff();

  // Stripper
  vtkSmartPointer<vtkStripper> boundaryStrips = vtkSmartPointer<vtkStripper>::New();
  boundaryStrips->SetInputConnection(boundaryEdges->GetOutputPort());
  std::cout << "Nb points : " << (boundaryStrips->GetOutput())->GetNumberOfPoints() << std::endl;
  std::cout << "Nb lines : " << (boundaryStrips->GetOutput())->GetNumberOfLines() << std::endl;

  // PolyData
  vtkSmartPointer<vtkPolyData> boundaryPoly = vtkSmartPointer<vtkPolyData>::New();
  boundaryPoly->SetPoints((boundaryStrips->GetOutput())->GetPoints());
  boundaryPoly->SetPolys((boundaryStrips->GetOutput())->GetLines());

  // Triangle
  vtkSmartPointer<vtkTriangleFilter> boundaryTriangles = vtkSmartPointer<vtkTriangleFilter>::New();
  boundaryTriangles->SetInputData(boundaryPoly);

  //Mapper sphere center
  vtkSmartPointer<vtkPolyDataMapper> sphereCenterClipMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  sphereCenterClipMapper->SetInputConnection(boundaryTriangles->GetOutputPort());

  // Actor sphere center
  vtkSmartPointer<vtkActor> sphereCenterActor = vtkSmartPointer<vtkActor>::New();
  sphereCenterActor->SetMapper(sphereCenterClipMapper);
  sphereCenterActor->GetProperty()->SetColor(sphericalVOIData.colorSphere.redF(), sphericalVOIData.colorSphere.greenF(), sphericalVOIData.colorSphere.blueF());
  sphereCenterActor->GetProperty()->SetEdgeColor(sphericalVOIData.colorSphere.redF(), sphericalVOIData.colorSphere.greenF(), sphericalVOIData.colorSphere.blueF());
  sphereCenterActor->GetProperty()->EdgeVisibilityOn();
  sphereCenterActor->VisibilityOff();

  // TODO fin


Any hints about what I might be doing wrong would be welcome,

Regards,
Hortense
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150504/72bfb1de/attachment.html>


More information about the vtkusers mailing list