[vtkusers] vtkImagePlaneWidget problem, (data thickness)

Dean Inglis dean.inglis at camris.ca
Fri Jan 21 20:58:44 EST 2011


hi,

looks like you might have specified the wrong zero-based slice index
on one of the widgets;

reader->SetDataDimensions(511,447);
reader->SetImageRange(88, 136);

so you only have 49 actual slices in the z-direction, but you are
trying to set the slice index to 80:

planeWidgetZ->SetSliceIndex(80);

so try setting the z widget to slice 8

As for slice thickness, you are already setting that in the reader with

reader->SetDataSpacing(0.78125,0.78125,5);

as you interact with the widgets, you will notice, especially the
planeWidgetZ, if you drag it along its unit normal, the image will
change in 5 mm increments smoothly, that is, you will drag it in
continuous space and it will appear to change every 5 mm.  Each widget
represents an "infinitely thin" cutting plane.  If you want to see slabs,
you may want to try doing 3D volume rendering with the interpolation
set to nearest.

regards
Dean



Dear ALL,

I have two questions about the 3D rendering from multiple slices of MRI
images. For this task, I am using vtkImagePlaneWidget, to show the sagittal,
coronal and axial plane from the constructed 3d rendering.
First question: MRI images have thickness, for my case, it is 5mm, how can I
set this thickness in the program? The SetDataSpacing is the only way to set
the spacing between the slices, but not the thickness. Anyone having ideas?
 Second question: The resultant images after 3D rendering seems like have
been stretch, as shown in figure below:

   http://vtk.1045678.n5.nabble.com/file/n3351486/Original.bmp
(a) Original


http://vtk.1045678.n5.nabble.com/file/n3351486/results_been_stretch.bmp
(b) the result been stretch, why?

What is the problem? Is that because of the camera setting? I showed my
codes below:

int main()
{
vtkVolume16Reader *reader = vtkVolume16Reader::New();
 reader->SetDataOrigin(0,0,0);
reader->SetFilePrefix("C:\\Users\\Khin
Wee\\Desktop\\P2_MRI\\data\\004\\MR.978");
reader->SetDataSpacing(0.78125,0.78125,5);
reader->SetDataDimensions(511,447);
reader->SetImageRange(88, 136);
reader->SetDataByteOrderToLittleEndian();
reader->Update();

vtkImageCast *readerImageCast = vtkImageCast::New();
 readerImageCast->SetInput((vtkDataObject *)reader->GetOutput());
 readerImageCast->SetOutputScalarTypeToUnsignedChar();
 readerImageCast->ClampOverflowOn();
 readerImageCast->Update();

  vtkRenderer* ren1 = vtkRenderer::New();
  vtkRenderWindow* renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

  vtkCellPicker* picker = vtkCellPicker::New();
    picker->SetTolerance(0.005);

  vtkProperty* ipwProp = vtkProperty::New();

  vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
    planeWidgetX->SetInteractor( iren);
    planeWidgetX->SetKeyPressActivationValue('x');
    planeWidgetX->SetPicker(picker);
    planeWidgetX->RestrictPlaneToVolumeOn();
    planeWidgetX->GetPlaneProperty()->SetColor(1,0,0);
    planeWidgetX->SetTexturePlaneProperty(ipwProp);
    planeWidgetX->TextureInterpolateOff();
    planeWidgetX->SetResliceInterpolateToNearestNeighbour();
    planeWidgetX->SetInput(readerImageCast->GetOutput());
    planeWidgetX->SetPlaneOrientationToXAxes();
 planeWidgetX->SetSlicePosition(150);
    planeWidgetX->DisplayTextOn();
    planeWidgetX->On();
    planeWidgetX->InteractionOn();

  vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
    planeWidgetY->SetInteractor( iren);
    planeWidgetY->SetKeyPressActivationValue('y');
    planeWidgetY->SetPicker(picker);
    planeWidgetY->GetPlaneProperty()->SetColor(1,1,0);
    planeWidgetY->SetTexturePlaneProperty(ipwProp);
    planeWidgetY->TextureInterpolateOn();
    planeWidgetY->SetResliceInterpolateToLinear();
    planeWidgetY->SetInput(readerImageCast->GetOutput());
    planeWidgetY->SetPlaneOrientationToYAxes();
    planeWidgetY->SetSlicePosition(140);
    planeWidgetY->DisplayTextOn();
    planeWidgetY->UpdatePlacement();
    planeWidgetY->On();

  vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
    planeWidgetZ->SetInteractor( iren);
    planeWidgetZ->SetKeyPressActivationValue('z');
    planeWidgetZ->SetPicker(picker);
    planeWidgetZ->GetPlaneProperty()->SetColor(0,0,1);
    planeWidgetZ->SetTexturePlaneProperty(ipwProp);
    planeWidgetZ->TextureInterpolateOn();
    planeWidgetZ->SetResliceInterpolateToCubic();
    planeWidgetZ->SetInput(readerImageCast->GetOutput());
    planeWidgetZ->SetPlaneOrientationToZAxes();
    planeWidgetZ->SetSliceIndex(80);
    planeWidgetZ->DisplayTextOn();
    planeWidgetZ->On();

  ren1->SetBackground( 0.1, 0.1, 0.2);
  renWin->SetSize( 600, 600);
  renWin->Render();
  iren->Initialize();
  iren->Start();
  renWin->Render();
  ipwProp->Delete();
  planeWidgetX->Delete();
  planeWidgetY->Delete();
  planeWidgetZ->Delete();
  picker->Delete();
  outlineActor->Delete();
  outlineMapper->Delete();
  outline->Delete();
  iren->Delete();
  renWin->Delete();
  ren1->Delete();
  reader->Delete();
  return 0;
}





More information about the vtkusers mailing list