[vtkusers] Cut 3d object with vtkPlaneSource

madz madaramh at gmail.com
Wed Feb 5 02:01:01 EST 2014


I have a 3D graph in which I have to show a horizontal plain at a given YZ
point which should look like the following.

  <http://vtk.1045678.n5.nabble.com/file/n5725758/Plot3Dsurfaces_07.png> 

I have used vtkcutter but it does not give a plane like feature. Is there
any way to make it display like a plane.
I also tried positioning a vtkPlaneSource but could not get it to position
correctly.
Here is an example program,


#include <vtkSmartPointer.h>
#include <vtkCubeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkPlane.h>
#include <vtkCutter.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPlaneSource.h>
 
int main(int, char *[])
{ 
  vtkSmartPointer<vtkCubeSource> cube =
    vtkSmartPointer<vtkCubeSource>::New();
  cube->SetXLength(40);
  cube->SetYLength(30);
  cube->SetZLength(20);
  vtkSmartPointer<vtkPolyDataMapper> cubeMapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  cubeMapper->SetInputConnection(cube->GetOutputPort());
 
  // Create a plane to cut,here it cuts in the XZ direction (xz
normal=(1,0,0);XY =(0,0,1),YZ =(0,1,0)
  vtkSmartPointer<vtkPlane> plane =
    vtkSmartPointer<vtkPlane>::New();
  plane->SetOrigin(10,0,0);
  plane->SetNormal(1,0,0);
 
  // Create cutter
  vtkSmartPointer<vtkCutter> cutter =
    vtkSmartPointer<vtkCutter>::New();
  cutter->SetCutFunction(plane);
  cutter->SetInputConnection(cube->GetOutputPort());
  cutter->Update();
 
  vtkSmartPointer<vtkPolyDataMapper> cutterMapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  cutterMapper->SetInputConnection( cutter->GetOutputPort());
 
  // Create plane actor
  vtkSmartPointer<vtkActor> planeActor =
    vtkSmartPointer<vtkActor>::New();
  planeActor->GetProperty()->SetColor(1.0,1,0);
  planeActor->GetProperty()->SetLineWidth(2);
  planeActor->SetMapper(cutterMapper);

  
  vtkSmartPointer<vtkPlaneSource> planeSource =
	  vtkSmartPointer<vtkPlaneSource>::New();
  planeSource->SetNormal(1,0,0);
  planeSource->SetOrigin(10,0,0);
  planeSource->Update();

  // Create a mapper and actor.
  vtkSmartPointer<vtkPolyDataMapper> planeSourceMapper = 
	  vtkSmartPointer<vtkPolyDataMapper>::New();
  planeSourceMapper->SetInput(planeSource->GetOutput());

  vtkSmartPointer<vtkActor> planeSourceActor = 
	  vtkSmartPointer<vtkActor>::New();
  planeSourceActor->SetMapper(planeSourceMapper);
 
  // Create cube actor
  vtkSmartPointer<vtkActor> cubeActor =
    vtkSmartPointer<vtkActor>::New();
  cubeActor->GetProperty()->SetColor(0.5,1,0.5);
  cubeActor->GetProperty()->SetOpacity(0.5);
  cubeActor->SetMapper(cubeMapper);
 
  // Create renderers and add actors of plane and cube
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(planeActor); //display the rectangle resulting from the
cut
  renderer->AddActor(cubeActor); //display the cube
  renderer->AddActor(planeSourceActor);
 
  // Add renderer to renderwindow and render
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  renderWindow->SetSize(600, 600);
 
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  interactor->SetRenderWindow(renderWindow);
  renderer->SetBackground(0,0,0);
  renderWindow->Render();
 
  interactor->Start();
 
  return EXIT_SUCCESS;
}

How can I get the plane to appear exactly where the cutter is displayed.

Thanks.



--
View this message in context: http://vtk.1045678.n5.nabble.com/Cut-3d-object-with-vtkPlaneSource-tp5725758.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list