[vtkusers] vtkClipVolume and sphere, plane, box

Laurent Paul Laurent.Paul at orto.ucl.ac.be
Mon Nov 28 05:34:41 EST 2005


Hi users,

I want to clip a volume with plane, box and sphere. The entire volume is
on the left, while the clipped one is on the right (two differents
mappers).

I manage to clip the volume with plane and box, but not using a classical
way (I think).
I use vtkImplicitPlaneWidget and BoxWidget to clip the volume. For each
interaction, I add a clipping plane to the mapper. So, I can view the
result. It works.
But, I never connect the output of my vtkClipVolume filter. That's why I
think I'm doing bad.
I understand that when I tried to clip with a sphere.... How to add a
clipping plane when you use a sphere?!

So, I connected the clipper output to an UnstructuredGridVolumeMapper but
with very few results. My program grows up (memory size goes up to 1300 Mo
RAM for a very ridiculous volume, only 3 slices). I can't interact with
it.

This is my code:

reader = vtkDICOMImageReader::New();
  reader->SetDirectoryName(inputFilename);

vtkImageCast *caster = vtkImageCast::New();
  caster->SetInput((vtkDataObject *)reader->GetOutput());
  caster->SetOutputScalarTypeToUnsignedShort();
  caster->ClampOverflowOn();

vtkPlane *plane = vtkPlane::New();
vtkClipVolume *clipper = vtkClipVolume::New();
  clipper->SetInput((vtkDataObject *)caster->GetOutput());
  clipper->SetClipFunction(plane);  //or sphere or box
//  clipper->SetValue(0.2);  What does this function means??

vtkVolumeRayCastCompositeFunction* RayCastFct =
vtkVolumeRayCastCompositeFunction::New();
  RayCastFct->SetCompositeMethodToInterpolateFirst();

vtkVolumeRayCastMapper* mapper2 = vtkVolumeRayCastMapper::New();
  mapper2->SetVolumeRayCastFunction(RayCastFct);
  mapper2->SetInput(caster->GetOutput());

vtkVolumeProperty *volumeproperty = vtkVolumeProperty::New();
  ...

volume = vtkVolume::New();
  volume->SetMapper(mapper2 );
  volume->SetProperty(volumeproperty);

vtkRenderer *ren1 = vtkRenderer::New();
  ren1->AddVolume(volume);
  ren1->SetViewport(0.0,0.0,0.5,1.0);
vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

vtkImplicitPlaneWidget *planeWidget = vtkImplicitPlaneWidget::New();
PlaneCallback *cb = PlaneCallback::New();
  planeWidget->SetInput((vtkDataSet *)caster->GetOutput());
  planeWidget->SetInteractor(iren);
  planeWidget->PlaceWidget();
  planeWidget->On();
  planeWidget->AddObserver(vtkCommand::InteractionEvent, cb);

UGRightMapper = vtkUnstructuredGridVolumeRayCastMapper::New();
  UGRightMapper->SetInput(clipper->GetOutput());

UGvolume = vtkVolume::New();
  UGvolume->SetMapper( UGRightMapper );
  UGvolume->SetProperty(volumeproperty);

vtkRenderer *ren2 = vtkRenderer::New();
  ren2->AddVolume(UGvolume);
  ren2->SetViewport(0.5,0.0,1.0,1.0);
  ren2->SetBackground( 0.05, 0.05, 0.05 );
  renWin->SetSize(600,300);
  renWin->AddRenderer(ren2);
  iren->Initialize();
  iren->Start();

Callback code:

  virtual void Execute(vtkObject *caller, unsigned long, void*)
{
  vtkImplicitPlaneWidget *planeWidget =
reinterpret_cast<vtkImplicitPlaneWidget *>(caller);
  planeWidget->GetPlane(clippingplane);
  rightMapper->AddClippingPlane(clippingplane);
  std::cout << "item: " <<
rightMapper->GetClippingPlanes()->GetNumberOfItems() <<std::endl;
}

rightMapper and clippingplane are passed thru 2 functions called SetMapper
and SetPlane which arguments are "plane" and "UGRightMapper".

I can see the left volume, buty I have to wait for a long time... and
cannot interact with the volume. Make the plane appears is very time and
memory consuming for a bad result....

What is wrong?
Is UnstructureGdridMapper able to display a clipped volume (in a
reasonnable memory consumption)?
What's the problem with memory?

I still don't understand what means the clipper->SetValue() function... My
english is too basic!!

Thanks for your answer.

Laurent.




More information about the vtkusers mailing list