[vtkusers] ImagePlaneWidget

dean.inglis at on.aibn.com dean.inglis at on.aibn.com
Thu Mar 27 09:02:47 EST 2003


Hi,

I have done this in C++, not tcl, for an app with
two render windows, wherein one has 3 vtkImagePlaneWidgets
and the other has a vtkImageActor showing one of the
slices currently being pushed/controlled by a scroll bar.
render window 1) contains:

  vtkCellPicker* sharedPicker = vtkCellPicker::New();
    sharedPicker->SetTolerance(0.01);

  vtkRenderWindowInteractor* iren = RenderWindow3D->GetInteractor();

  planeWidgetX = vtkImagePlaneWidget::New();
    planeWidgetX->TextureInterpolateOff();
    planeWidgetX->SetResliceInterpolateToNearestNeighbour();
    planeWidgetX->SetKeyPressActivationValue('x');
    planeWidgetX->SetInteractor(iren);
    planeWidgetX->SetPicker(sharedPicker);
    planeWidgetX->GetPlaneProperty()->SetColor(1,0,0);
    planeWidgetX->DisplayTextOff();
    planeWidgetX->Off();
    SliceInterpolationMode[0] = 0;


  planeWidgetY = vtkImagePlaneWidget::New();
    planeWidgetY->TextureInterpolateOff();
    planeWidgetY->SetResliceInterpolateToNearestNeighbour();
    planeWidgetY->SetKeyPressActivationValue('y');
    planeWidgetY->SetInteractor(iren);
    planeWidgetY->SetPicker(sharedPicker);
    planeWidgetY->GetPlaneProperty()->SetColor(1,1,0);
    planeWidgetY->DisplayTextOff();
    planeWidgetY->Off();
    SliceInterpolationMode[1] = 0;


  planeWidgetZ = vtkImagePlaneWidget::New();
    planeWidgetZ->TextureInterpolateOff();
    planeWidgetZ->SetResliceInterpolateToNearestNeighbour();
    planeWidgetZ->SetKeyPressActivationValue('z');
    planeWidgetZ->SetInteractor(iren);
    planeWidgetZ->SetPicker(sharedPicker);
    planeWidgetZ->GetPlaneProperty()->SetColor(0,0,1);
    planeWidgetZ->DisplayTextOff();
    planeWidgetZ->Off();

Now, init the objects for three separate 2D slice represenations:

  colorMap1 = vtkImageMapToColors::New();
    colorMap1->PassAlphaToOutputOff();
    colorMap1->SetActiveComponent(0);
    colorMap1->SetOutputFormatToLuminance();

  colorMap2 = vtkImageMapToColors::New();
    colorMap2->PassAlphaToOutputOff();
    colorMap2->SetActiveComponent(0);
    colorMap2->SetOutputFormatToLuminance();

  colorMap3 = vtkImageMapToColors::New();
    colorMap3->PassAlphaToOutputOff();
    colorMap3->SetActiveComponent(0);
    colorMap3->SetOutputFormatToLuminance();

  imageActor1 = vtkImageActor::New();
  imageActor2 = vtkImageActor::New();
  imageActor3 = vtkImageActor::New();

When you finally read in some volumetric image data:

    planeWidgetX->SetInput(reader->GetOutput());
    planeWidgetX->SetPlaneOrientationToXAxes();
    planeWidgetX->SetSliceIndex((reader->GetOutput()->GetExtent()[1] - \
                                 reader->GetOutput()->GetExtent()[0])/2);
    planeWidgetX->On();

    planeWidgetY->SetInput(reader->GetOutput());
    planeWidgetY->SetPlaneOrientationToYAxes();
    planeWidgetY->SetSliceIndex((reader->GetOutput()->GetExtent()[3] - \
                                 reader->GetOutput()->GetExtent()[2])/2);
    planeWidgetY->On();

    planeWidgetZ->SetInput(reader->GetOutput());
    planeWidgetZ->SetPlaneOrientationToZAxes();
    planeWidgetZ->SetSliceIndex((reader->GetOutput()->GetExtent()[5] - \
                                 reader->GetOutput()->GetExtent()[4])/2);
    planeWidgetZ->On();


    colorMap1->SetInput(planeWidgetX->GetResliceOutput());
    colorMap2->SetInput(planeWidgetY->GetResliceOutput());
    colorMap3->SetInput(planeWidgetZ->GetResliceOutput());

    imageActor1->SetInput(colorMap1->GetOutput());
    imageActor2->SetInput(colorMap2->GetOutput());
    imageActor3->SetInput(colorMap3->GetOutput());

add the imageActors to the respective renderers, and make sure you 
set their RenderWindowInteractor's interactor style to vtkInteractorStyleImage.
This could be done with one render window set up with 4 viewports/ 4 renderers.

Finally, if you want to do shared window levelling:

  if ( SharedWLCheckBox->Checked )
    {
    planeWidgetX->SetLookupTable(0); //resets the lut
    planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
    planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
    colorMap1->SetLookupTable(planeWidgetX->GetLookupTable());
    colorMap2->SetLookupTable(planeWidgetX->GetLookupTable());
    colorMap3->SetLookupTable(planeWidgetX->GetLookupTable());
    }
  else
    {
    planeWidgetX->SetLookupTable(0);
    planeWidgetY->SetLookupTable(0);
    planeWidgetZ->SetLookupTable(0);
    colorMap1->SetLookupTable(planeWidgetX->GetLookupTable());
    colorMap2->SetLookupTable(planeWidgetY->GetLookupTable());
    colorMap3->SetLookupTable(planeWidgetZ->GetLookupTable());
    }

An alternative to this whole approach is shown in 
VTK/Examles/GUI/Tcl/OrthogonalPlanesWithTkPhoto.tcl

Hope this helps,
Dean





More information about the vtkusers mailing list