[vtkusers] Slice out of dataset

Christian Mol christianmol at gmail.com
Wed Jan 7 16:24:49 EST 2015


Hi,

Currently I am trying to display a dataset using VTK. It seems to work
pretty well. A small problem though, is that using the code given
below, scrolling beyond the actual data seems to be possible. When I
use <ctrl> + right mouse button to scroll through the data it does not
clip at the boundary of the data. Am I doing something wrong here, or
is there more involved to accomplish the desired situation?

int main(int, char *[])
{
  vtkSmartPointer<vtkMetaImageReader> r =
vtkSmartPointer<vtkMetaImageReader>::New();
  r->SetFileName("00000000.mhd");
  r->Update();

  vtkSmartPointer<vtkImageResliceMapper> im =
vtkSmartPointer<vtkImageResliceMapper>::New();
  im->SetInputConnection(r->GetOutputPort());
  im->SliceFacesCameraOn();
  im->SliceAtFocalPointOn();
  im->BorderOn();
  im->UpdateInformation();

  vtkSmartPointer<vtkImageProperty> ip =
vtkSmartPointer<vtkImageProperty>::New();
  ip->SetColorWindow(2000);
  ip->SetColorLevel(1000);
  ip->SetAmbient(0.0);
  ip->SetDiffuse(1.0);
  ip->SetOpacity(1.0);
  ip->SetInterpolationTypeToLinear();

  vtkSmartPointer<vtkImageSlice> ia = vtkSmartPointer<vtkImageSlice>::New();
  ia->SetMapper(im);
  ia->SetProperty(ip);

  vtkSmartPointer<vtkImageStack> stack = vtkSmartPointer<vtkImageStack>::New();
  stack->AddImage(ia);
  stack->SetActiveLayer(0);

  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddViewProp(stack);
  renderer->SetBackground(0.0, 1.0, 0.0);

  vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);

  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  vtkSmartPointer<vtkInteractorStyleImage> style =
vtkSmartPointer<vtkInteractorStyleImage>::New();

  renderWindow->GetInteractor()->SetInteractorStyle(style);

  style->SetInteractionModeToImage3D();

  renderer->GetActiveCamera()->ParallelProjectionOn();

  renderer->ResetCameraClippingRange();
  renderer->ResetCamera();

  renderWindow->Render();

  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

Kind regards,

Christian Mol


More information about the vtkusers mailing list