[vtkusers] Clip ImageData with plane

laurent.paul at club-internet.fr laurent.paul at club-internet.fr
Thu Jul 7 05:35:30 EDT 2005


Hi users,

I'd want to clip image data (Volume) with a plane.
That's almost simple but that's not all.
I want the clipped away datas be displayed in the renderer window but with a "special" color.
I wrote a C++ program but it crashes at running time inside the callback, at EndInteractionEvent. I never can AddClippingPlane to the mapper. It crashes just here! In fact, I don't know which vtkClip and vtkMapper use. Since clipping data modify their type, I don't know if I can display both "good" and clipped away datas in the same renderer, same window....
This is my code (the skeleton, based on examples):

// Callback for the image plane widget Endinteraction
class EndCallback : public vtkCommand
{
public:
  static EndCallback *New()
    { return new EndCallback; }

  virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
 	  vtkDataSetMapper* selectmapper = reinterpret_cast<vtkDataSetMapper*>(caller);
      vtkImplicitPlaneWidget* planeWidget = reinterpret_cast<vtkImplicitPlaneWidget*>(caller);
      vtkActor* actor = reinterpret_cast<vtkActor*>(caller);
      vtkPlane* localplane = vtkPlane::New();
      planeWidget->GetPlane(localplane);
      actor->VisibilityOn();
      selectmapper->AddClippingPlane(localplane);
     }
};

int main(int argc, char *argv[])
{
vtkDICOMImageReader* reader = vtkDICOMImageReader::New();
vtkPiecewiseFunction* scalarOp = vtkPiecewiseFunction::New();
vtkColorTransferFunction* color= vtkColorTransferFunction::New();
vtkVolumeProperty* volumeproperty = vtkVolumeProperty::New();
vtkVolumeRayCastCompositeFunction* RayCastFct = vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper* mapper = vtkVolumeRayCastMapper::New();
  mapper->SetVolumeRayCastFunction(RayCastFct);
  mapper->SetInput(reader->GetOutput());
vtkVolume* volume = vtkVolume::New();
  volume->SetMapper(mapper);
  volume->SetProperty(volumeproperty);
  volume->VisibilityOn();
vtkRenderer* ren1 = vtkRenderer::New();
  ren1->AddVolume(volume);
vtkRenderWindow* renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

// Associate the plane widget with the interactor
vtkImplicitPlaneWidget* planeWidget = vtkImplicitPlaneWidget::New();
EndCallback* endcb = EndCallback::New();
  planeWidget->SetInteractor(iren);
  planeWidget->SetInput((vtkDataSet *)reader->GetOutput());
  planeWidget->PlaceWidget();
  planeWidget->AddObserver(vtkCommand::EndInteractionEvent, endcb);

// clip the data with vtkPlane implicit function
vtkPlane* plane = vtkPlane::New();
vtkClipVolume* clipper = vtkClipVolume::New();
  clipper->SetInput(reader->GetOutput());
  clipper->SetClipFunction(plane);
  clipper->GenerateClipScalarsOn();
  clipper->GenerateClippedOutputOn();

//property of clipped away datas
vtkProperty* selectproperty = vtkProperty::New();
//Mapper for clipped away datas
vtkDataSetMapper* selectmapper = vtkDataSetMapper::New();
  selectmapper->SetInput((vtkDataSet *)clipper->GetClippedOutput());

//Actor for clipped away datas
vtkActor* actor = vtkActor::New();
  actor->VisibilityOff();
  actor->SetMapper(selectmapper);
  actor->SetProperty(selectproperty);

//Start rendering
  ren1->AddActor(actor);
  iren->Initialize();
  iren->Start();

return 0;
}



I don't know:
- Which mapper and actor/volume for the clipped away datas.
- If I can display different types of datas in the same- RayCastMapper for the initial volume.
- Why I can't add clipping plane to the mapper.

I wrote the same program in Tcl. It works better than the C++ since I can add the clipping plane in the procedure. However, I can't no more view the clipped away datas .
What is the matter?


Thanks,

Laurent.




More information about the vtkusers mailing list