[vtkusers] Extract on slice from a volume then display it

Nicolas RANNOU nrannou at bwh.harvard.edu
Fri May 29 16:37:09 EDT 2009


Hello,

I'm currently trying to extract a slice from a 3d volume then to display it
in a window but it doesn't work.
I proceed exactly the same way as in
VTK/Example/ImageProcessing/Cxx/ImageSliceing.cxx .
In my window, I just get a black background.
(my input image is in grey levels)
If I add a color to the background, my window stays black.
So I assume that the actor is there but is not well displayed.

Does anybody have any idea?

Thanks for the help,
Nicolas

My code:
/--------------------------------------------------------------------------------/

  vtkEMSegmentMRMLManager *mrmlManager = this->GetGUI()->GetMRMLManager();

  vtkMRMLVolumeNode* volumeNode =
mrmlManager->GetVolumeNode(target_vol_id);

  vtkImageData* inputImage = volumeNode->GetImageData();

  int extent[6];
  double spacing[3];
  double origin[3];
  inputImage->GetWholeExtent(extent);
  inputImage->GetSpacing(spacing);
  inputImage->GetOrigin(origin);

  double center[3];
  center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
  center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
  center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);

  // Matrices for axial, coronal, sagittal, oblique view orientations

  static double coronalElements[16] = {
           1, 0, 0, 0,
           0, 0, 1, 0,
           0,-1, 0, 0,
           0, 0, 0, 1 };

  // Set the slice orientation
  vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();
  resliceAxes->DeepCopy(coronalElements);

  // Set the point through which to slice
  resliceAxes->SetElement(0, 3, center[0]);
  resliceAxes->SetElement(1, 3, center[1]);
  resliceAxes->SetElement(2, 3, center[2]);

  // Extract a slice in the desired orientation
  vtkImageReslice *reslice = vtkImageReslice::New();
  reslice->SetInput(volumeNode->GetImageData());
  reslice->SetOutputDimensionality(2);
  reslice->SetResliceAxes(resliceAxes);
  reslice->SetInterpolationModeToLinear();

  // Create a greyscale lookup table
  vtkLookupTable *table = vtkLookupTable::New();
  table->SetRange(0, 2000); // image intensity range
  table->SetValueRange(0.0, 1.0); // from black to white
  table->SetSaturationRange(0.0, 0.0); // no color saturation
  table->SetRampToLinear();
  table->Build();

  // Map the image through the lookup table
  vtkImageMapToColors *color = vtkImageMapToColors::New();
  color->SetLookupTable(table);
  color->SetInput(inputImage);//reslice->GetOutput());

  // Display the image
  vtkImageActor *actor = vtkImageActor::New();
  actor->SetInput(color->GetOutput());

  vtkRenderer *renderer = vtkRenderer::New();
  renderer->AddActor(actor);

  vtkRenderWindow *window = vtkRenderWindow::New();
  window->AddRenderer(renderer);
  window->Render();

/--------------------------------------------------------------------------------/




More information about the vtkusers mailing list