[vtkusers] Problem with cutter

Philipp Staempfli ph_staempfli at hotmail.com
Tue Nov 21 04:24:32 EST 2000


Hi

I have the following problem: I'd like to slice a cone with a plane. So I 
defined a cutter, a cut-function, and I tried to render the output of the 
cutter. All I get is an empty window....

Thanks

Ph. Staempfli

My c++ code:

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkPlane.h"
#include "SaveImage.h"
#include "vtkCutter.h"
#include "vtkLODActor.h"
#include "vtkOutlineFilter.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkPlaneSource.h"

void main( int argc, char *argv[] )
{
  // create a rendering window and renderer
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWindow = vtkRenderWindow::New();
    renWindow->AddRenderer(ren);

vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWindow1 = vtkRenderWindow::New();
renWindow1->AddRenderer(ren1);
renWindow1->SetSize(300,300);
renWindow1->SetPosition(0,330);

  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWindow);
  renWindow->SetSize( 300, 300 );

  // create an actor and give it cone geometry
  vtkConeSource *cone = vtkConeSource::New();
    cone->SetResolution(8);
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
    coneMapper->SetInput(cone->GetOutput());
  vtkActor *coneActor = vtkActor::New();
    coneActor->SetMapper(coneMapper);


	vtkPlane *plane = vtkPlane::New();
    plane->SetOrigin(1,1,1);
    plane->SetNormal(1,2,3);
	vtkCutter *planeCut = vtkCutter::New();
    planeCut->SetInput(cone->GetOutput());
    planeCut->SetCutFunction(plane);

	vtkPolyDataMapper *cutMapper = vtkPolyDataMapper::New();

    cutMapper->SetInput(planeCut->GetOutput());

    vtkLODActor *cutActor=vtkLODActor::New();
	cutActor->SetMapper(cutMapper);


//just for testing if they intersect really....
	vtkPlaneSource *plane1 = vtkPlaneSource::New();
	plane1->SetOrigin(1,1,1);
	plane1->SetNormal(1,2,3);
    vtkPolyDataMapper *plane1Mapper = vtkPolyDataMapper::New();


	plane1Mapper->SetInput(plane1->GetOutput());
    vtkActor *plane1Actor = vtkActor::New();
    plane1Actor->SetMapper(plane1Mapper);


	vtkOutlineFilter *outline = vtkOutlineFilter::New();
    outline->SetInput(cone->GetOutput());
	vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
    outlineMapper->SetInput(outline->GetOutput());
	vtkActor *outlineActor= vtkActor::New();
    outlineActor->SetMapper(outlineMapper);



  // add the actors to the renderers
ren1->AddActor (cutActor);
ren1->SetBackground(1,1,1);
ren->AddActor (plane1Actor);
ren->AddActor(coneActor);
ren->AddActor(outlineActor);

  // draw the resulting scene
  renWindow->Render();
  renWindow1->Render();

  SAVEIMAGE(renWindow );
  SAVEIMAGE(renWindow1);
  //  Begin mouse interaction
  iren->Start();

  // Clean up


  outline->Delete();
  outlineMapper->Delete();
  outlineActor->Delete();
  ren1->Delete();
  cutActor->Delete();
  plane->Delete();
  planeCut->Delete();
  cutMapper->Delete();
  plane1Mapper->Delete();
  plane1->Delete();
  plane1Mapper->Delete();
  plane1Actor->Delete();

  ren->Delete();
  renWindow->Delete();
  iren->Delete();
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
}

_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com





More information about the vtkusers mailing list