Commit 9ac8f746 authored by David Gobbi's avatar David Gobbi
Browse files

ENH: Add new image mappers to VTK.

New class vtkImageSliceMapper will draw slices of a 3D image, while
new class vtkImageResliceMapper will draw oblique reformatted slices.
New class vtkImageSlice is the corresponding Prop3D for the mappers,
and is a replacement for vtkImageActor, which is now a subclass of it.
New class vtkImageProperty controls window/level, lookup table, etc.

Change-Id: Id6816402404c8d18d1523dec2c36bd809a060170
parent bad00876
......@@ -102,6 +102,7 @@
// Constants for InterpolationType
#define VTK_NEAREST_INTERPOLATION 0
#define VTK_LINEAR_INTERPOLATION 1
#define VTK_CUBIC_INTERPOLATION 2
// For volume rendering
#define VTK_MAX_VRCOMP 4
......
#!/usr/bin/env python
# A simple vtkInteractorStyleImage example for
# 3D image viewing with the vtkImageResliceMapper.
# Drag Left mouse button to window/level
# Shift-Left drag to rotate (oblique slice)
# Shift-Middle drag to slice through image
# OR Ctrl-Right drag to slice through image
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
reader = vtk.vtkImageReader()
reader.ReleaseDataFlagOff()
reader.SetDataByteOrderToLittleEndian()
reader.SetDataMask(0x7fff)
reader.SetDataExtent(0,63,0,63,1,93)
reader.SetDataSpacing(3.2,3.2,1.5)
reader.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter")
# Create the RenderWindow, Renderer
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
im = vtk.vtkImageResliceMapper()
im.SetInputConnection(reader.GetOutputPort())
im.SliceFacesCameraOn()
im.SliceAtFocalPointOn()
im.BorderOff()
ip = vtk.vtkImageProperty()
ip.SetColorWindow(2000)
ip.SetColorLevel(1000)
ip.SetAmbient(0.0)
ip.SetDiffuse(1.0)
ip.SetOpacity(1.0)
ip.SetInterpolationTypeToLinear()
ia = vtk.vtkImageSlice()
ia.SetMapper(im)
ia.SetProperty(ip)
ren1.AddViewProp(ia)
ren1.SetBackground(0.1,0.2,0.4)
renWin.SetSize(300,300)
iren = vtk.vtkRenderWindowInteractor()
style = vtk.vtkInteractorStyleImage()
style.SetInteractionModeToImage3D()
iren.SetInteractorStyle(style)
renWin.SetInteractor(iren)
# render the image
renWin.Render()
cam1 = ren1.GetActiveCamera()
cam1.ParallelProjectionOn()
ren1.ResetCameraClippingRange()
renWin.Render()
iren.Start()
......@@ -74,6 +74,11 @@ SET( Kit_SRCS
vtkHierarchicalPolyDataMapper.cxx
vtkImageActor.cxx
vtkImageMapper.cxx
vtkImageMapper3D.cxx
vtkImageProperty.cxx
vtkImageResliceMapper.cxx
vtkImageSlice.cxx
vtkImageSliceMapper.cxx
vtkImageViewer2.cxx
vtkImageViewer.cxx
vtkImagingFactory.cxx
......@@ -245,8 +250,9 @@ SET( KitOpenGL_SRCS
vtkOpenGLExtensionManager.cxx
vtkOpenGLGlyph3DMapper.cxx
vtkOpenGLHardwareSupport.cxx
vtkOpenGLImageActor.cxx
vtkOpenGLImageMapper.cxx
vtkOpenGLImageResliceMapper.cxx
vtkOpenGLImageSliceMapper.cxx
vtkOpenGLLight.cxx
vtkOpenGLLightingPainter.cxx
vtkOpenGLPainterDeviceAdapter.cxx
......@@ -290,6 +296,7 @@ SET_SOURCE_FILES_PROPERTIES(
vtkCuller
vtkExporter
vtkGPUInfoList
vtkImageMapper3D
vtkImageProcessingPass
vtkImporter
vtkInteractorObserver
......@@ -469,6 +476,7 @@ SET(shader_files
vtkSurfaceLICPainter_fs1.glsl
vtkSurfaceLICPainter_fs2.glsl
vtkSurfaceLICPainter_vs1.glsl
vtkTextureBicubicARB_fp.asm
)
# Create custom commands to encode each assembly file into a C string
......@@ -703,8 +711,9 @@ IF (VTK_USE_MANGLED_MESA)
vtkMesaClipPlanesPainter.cxx
vtkMesaCoincidentTopologyResolutionPainter.cxx
vtkMesaDisplayListPainter.cxx
vtkMesaImageActor.cxx
vtkMesaImageMapper.cxx
vtkMesaImageResliceMapper.cxx
vtkMesaImageSliceMapper.cxx
vtkMesaLight.cxx
vtkMesaLightingPainter.cxx
vtkMesaPainterDeviceAdapter.cxx
......
......@@ -31,6 +31,16 @@ IF(VTK_USE_DISPLAY)
TestGPUInfo.cxx
TestGradientBackground.cxx
TestHomogeneousTransformOfActor.cxx
TestImageResliceMapperAlpha.cxx
TestImageResliceMapperBorder.cxx
TestImageResliceMapperInterpolation.cxx
TestImageResliceMapperOffAxis.cxx
TestImageResliceMapperOrient3D.cxx
TestImageSliceMapperAlpha.cxx
TestImageSliceMapperBorder.cxx
TestImageSliceMapperOrient2D.cxx
TestImageSliceMapperOrient3D.cxx
TestImageSliceMapperInterpolation.cxx
TestInteractorTimers.cxx
TestLabelPlacer.cxx
TestLabelPlacer2D.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageResliceMapperAlpha.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Test alpha blending RGBA, LA, Opacity<1.0, lookup table
//
// The command line arguments are:
// -I => run in interactive mode
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkImageData.h"
#include "vtkLookupTable.h"
#include "vtkImageMapToColors.h"
#include "vtkImageResliceMapper.h"
#include "vtkImageProperty.h"
#include "vtkImageSlice.h"
#include "vtkImageReader2.h"
#include "vtkImageGridSource.h"
int TestImageResliceMapperAlpha(int argc, char* argv[])
{
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkInteractorStyle *style = vtkInteractorStyleImage::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
renWin->Delete();
style->Delete();
vtkImageReader2 *reader = vtkImageReader2::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetDataExtent(0, 63, 0, 63, 1, 93);
reader->SetDataSpacing(3.2, 3.2, 1.5);
// a nice random-ish origin for testing
reader->SetDataOrigin(2.5, -13.6, 2.8);
char* fname = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/headsq/quarter");
reader->SetFilePrefix(fname);
delete[] fname;
vtkImageGridSource *grid = vtkImageGridSource::New();
grid->SetDataExtent(0, 60, 0, 60, 1, 93);
grid->SetDataSpacing(3.2, 3.2, 1.5);
grid->SetDataOrigin(0, 0, 0);
grid->SetDataScalarTypeToUnsignedChar();
grid->SetLineValue(255);
vtkLookupTable *table = vtkLookupTable::New();
table->SetRampToLinear();
table->SetRange(0.0, 255.0);
table->SetValueRange(1.0, 1.0);
table->SetSaturationRange(0.0, 0.0);
table->SetAlphaRange(0.0, 1.0);
table->Build();
vtkLookupTable *table2 = vtkLookupTable::New();
table2->SetRampToLinear();
table2->SetRange(0.0, 255.0);
table2->SetValueRange(1.0, 1.0);
table2->SetHueRange(0.2, 0.4);
table2->SetSaturationRange(1.0, 1.0);
table2->SetAlphaRange(0.5, 1.0);
table2->Build();
vtkImageMapToColors *colors = vtkImageMapToColors::New();
colors->SetInputConnection(grid->GetOutputPort());
colors->SetLookupTable(table);
colors->PassAlphaToOutputOn();
colors->SetOutputFormatToLuminanceAlpha();
vtkImageMapToColors *colors2 = vtkImageMapToColors::New();
colors2->SetInputConnection(grid->GetOutputPort());
colors2->SetLookupTable(table2);
colors2->SetOutputFormatToRGB();
for (int i = 0; i < 4; i++)
{
vtkRenderer *renderer = vtkRenderer::New();
vtkCamera *camera = renderer->GetActiveCamera();
renderer->SetBackground(0.1,0.2,0.4);
renderer->SetViewport(0.5*(i&1), 0.25*(i&2),
0.5 + 0.5*(i&1), 0.5 + 0.25*(i&2));
renWin->AddRenderer(renderer);
renderer->Delete();
vtkImageResliceMapper *imageMapper = vtkImageResliceMapper::New();
imageMapper->SetInputConnection(reader->GetOutputPort());
imageMapper->SliceFacesCameraOn();
imageMapper->SliceAtFocalPointOn();
vtkImageSlice *image = vtkImageSlice::New();
image->SetMapper(imageMapper);
image->GetProperty()->SetColorWindow(2000.0);
image->GetProperty()->SetColorLevel(1000.0);
imageMapper->Delete();
vtkImageResliceMapper *imageMapper2 = vtkImageResliceMapper::New();
imageMapper2->SliceFacesCameraOn();
imageMapper2->SliceAtFocalPointOn();
vtkImageSlice *image2 = vtkImageSlice::New();
image2->SetMapper(imageMapper2);
imageMapper2->Delete();
if (i == 0)
{
imageMapper2->SetInputConnection(grid->GetOutputPort());
image2->GetProperty()->SetOpacity(0.5);
}
else if (i == 1)
{
imageMapper2->SetInputConnection(colors->GetOutputPort());
camera->Elevation(30);
}
else if (i == 2)
{
imageMapper2->SetInputConnection(colors2->GetOutputPort());
image2->GetProperty()->SetOpacity(0.5);
}
else
{
imageMapper2->SetInputConnection(grid->GetOutputPort());
image2->GetProperty()->SetLookupTable(table2);
image2->GetProperty()->SetOpacity(0.9);
image->RotateWXYZ(30, 1, 0.5, 0);
}
renderer->AddViewProp(image);
renderer->AddViewProp(image2);
camera->ParallelProjectionOn();
renderer->ResetCamera();
camera->SetParallelScale(110.0);
image->Delete();
image2->Delete();
}
colors->Delete();
colors2->Delete();
table->Delete();
table2->Delete();
renWin->SetSize(400,400);
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR )
{
iren->Start();
}
iren->Delete();
reader->Delete();
grid->Delete();
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageResliceMapperBorder.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Test the Border variable on ImageResliceMapper
//
// The command line arguments are:
// -I => run in interactive mode
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkImageData.h"
#include "vtkImageResliceMapper.h"
#include "vtkImageProperty.h"
#include "vtkImageSlice.h"
#include "vtkTIFFReader.h"
#include "vtkImageClip.h"
int TestImageResliceMapperBorder(int argc, char* argv[])
{
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkInteractorStyle *style = vtkInteractorStyleImage::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
renWin->Delete();
style->Delete();
vtkTIFFReader *reader = vtkTIFFReader::New();
char* fname = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/beach.tif");
reader->SetFileName(fname);
delete[] fname;
vtkImageClip *clip = vtkImageClip::New();
clip->SetInputConnection(reader->GetOutputPort());
clip->SetOutputWholeExtent(100, 107, 100, 107, 0, 0);
for (int i = 0; i < 4; i++)
{
vtkRenderer *renderer = vtkRenderer::New();
vtkCamera *camera = renderer->GetActiveCamera();
renderer->SetBackground(0.1,0.2,0.4);
renderer->SetViewport(0.5*(i&1), 0.25*(i&2),
0.5 + 0.5*(i&1), 0.5 + 0.25*(i&2));
renWin->AddRenderer(renderer);
renderer->Delete();
vtkImageResliceMapper *imageMapper = vtkImageResliceMapper::New();
imageMapper->SetInputConnection(clip->GetOutputPort());
double *bounds = imageMapper->GetBounds();
double point[3];
point[0] = 0.5*(bounds[0] + bounds[1]);
point[1] = 0.5*(bounds[2] + bounds[3]);
point[2] = 0.5*(bounds[4] + bounds[5]);
camera->SetFocalPoint(point);
point[2] += 500.0;
camera->SetPosition(point);
camera->ParallelProjectionOn();
camera->SetParallelScale(5.0);
vtkImageSlice *image = vtkImageSlice::New();
image->SetMapper(imageMapper);
imageMapper->Delete();
renderer->AddViewProp(image);
if ((i&1))
{
image->GetMapper()->BorderOn();
}
if ((i&2))
{
image->GetProperty()->SetInterpolationTypeToNearest();
}
image->GetProperty()->SetColorWindow(255.0);
image->GetProperty()->SetColorLevel(127.5);
image->Delete();
}
renWin->SetSize(400,400);
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR )
{
iren->Start();
}
iren->Delete();
clip->Delete();
reader->Delete();
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageResliceMapperInterpolation.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This tests the Nearest, Linear, and Cubic interpolation.
//
// The command line arguments are:
// -I => run in interactive mode
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkImageData.h"
#include "vtkImageResliceMapper.h"
#include "vtkImageProperty.h"
#include "vtkImageSlice.h"
#include "vtkImageReader2.h"
#include "vtkLookupTable.h"
#include "vtkPlane.h"
int TestImageResliceMapperInterpolation(int argc, char* argv[])
{
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkInteractorStyle *style = vtkInteractorStyleImage::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->SetSize(400,400);
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
renWin->Delete();
style->Delete();
vtkImageReader2 *reader = vtkImageReader2::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetDataExtent(0, 63, 0, 63, 1, 93);
reader->SetDataSpacing(3.2, 3.2, 1.5);
reader->SetDataOrigin(-100.8, -100.9, -69.0);
char* fname = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/headsq/quarter");
reader->SetFilePrefix(fname);
delete[] fname;
for (int i = 0; i < 4; i++)
{
vtkRenderer *renderer = vtkRenderer::New();
vtkCamera *camera = renderer->GetActiveCamera();
renderer->SetBackground(0.1, 0.2, 0.4);
renderer->SetViewport(0.5*(i&1), 0.25*(i&2),
0.5 + 0.5*(i&1), 0.5 + 0.25*(i&2));
renWin->AddRenderer(renderer);
renderer->Delete();
vtkImageResliceMapper *imageMapper = vtkImageResliceMapper::New();
imageMapper->SetInputConnection(reader->GetOutputPort());
imageMapper->SliceFacesCameraOn();
vtkImageSlice *image = vtkImageSlice::New();
image->SetMapper(imageMapper);
imageMapper->Delete();
renderer->AddViewProp(image);
if (i < 3)
{
image->GetProperty()->SetColorWindow(1000);
image->GetProperty()->SetColorLevel(1500);
image->GetProperty()->SetInterpolationType(i);
}
else
{
vtkLookupTable *table = vtkLookupTable::New();
table->Build();
table->SetRange(1000, 2000);
image->GetProperty()->SetLookupTable(table);
image->GetProperty()->UseLookupTableScalarRangeOn();
image->GetProperty()->SetInterpolationType(VTK_CUBIC_INTERPOLATION);
table->Delete();
camera->Elevation(20);
}
image->Delete();
camera->ParallelProjectionOn();
renderer->ResetCamera();
camera->SetParallelScale(30.0);
}
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR )
{
iren->Start();
}
iren->Delete();
reader->Delete();
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestImageResliceMapperOffAxis.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This tests off-axis views of 3D images.
//
// The command line arguments are:
// -I => run in interactive mode
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkImageData.h"
#include "vtkImageResliceMapper.h"
#include "vtkImageProperty.h"
#include "vtkImageSlice.h"
#include "vtkPlane.h"
#include "vtkImageReader2.h"
#include "vtkOutlineFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkActor.h"
int TestImageResliceMapperOffAxis(int argc, char* argv[])
{
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
iren->SetRenderWindow(renWin);
renWin->SetMultiSamples(0);
renWin->Delete();
vtkImageReader2 *reader = vtkImageReader2::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetDataExtent(0, 63, 0, 63, 1, 93);
reader->SetDataSpacing(3.2, 3.2, 1.5);
// a nice random-ish origin for testing
reader->SetDataOrigin(2.5, -13.6, 2.8);
char* fname =