[vtkusers] Does anybody has a sample of new class vtkImageSlice Or correct my code.
shiina
shiina at yndrd.com
Thu May 26 22:17:58 EDT 2011
Hello VTK users,
I want to get oblique plane images of voxel data.
And, I read web page titled "VTK/Image Rendering Classes".
= http://www.vtk.org/Wiki/VTK/Image_Rendering_Classes
So I tried to use new class vtkImageSlice, but I failed to get oblique plane
images, only got orthogonal plane images.
Does anybody has a sample of new class vtkImageSlice Or correct my code.
The following is my code that modified official example Medical3.
------------------------------------------------------------------
int main (int argc, char *argv[])
{
if (argc < 2) {
cout << "Usage: " << argv[0] << " DATADIR/prefix" << endl;
return EXIT_FAILURE;
}
vtkSmartPointer<vtkRenderer> aRenderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(aRenderer);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
aRenderer->SetBackground(.2, .3, .4);
renWin->SetSize(640, 480);
// vtkVolume16Reader Setting
vtkSmartPointer<vtkVolume16Reader> v16 =
vtkSmartPointer<vtkVolume16Reader>::New();
v16->SetDataDimensions (426,426);
v16->SetImageRange (1,318);
v16->SetDataByteOrderToLittleEndian();
v16->SetFilePrefix (argv[1]);
v16->SetDataSpacing (1.0, 1.0, 1.0);
v16->Update();
// outline provides context around the data.
vtkSmartPointer<vtkOutlineFilter> outlineData =
vtkSmartPointer<vtkOutlineFilter>::New();
outlineData->SetInputConnection(v16->GetOutputPort());
outlineData->Update();
vtkSmartPointer<vtkPolyDataMapper> mapOutline =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapOutline->SetInputConnection(outlineData->GetOutputPort());
vtkSmartPointer<vtkActor> outline = vtkSmartPointer<vtkActor>::New();
outline->SetMapper(mapOutline);
outline->GetProperty()->SetColor(0,0,0);
// LookupTable
vtkSmartPointer<vtkLookupTable> bwLut =
vtkSmartPointer<vtkLookupTable>::New();
bwLut->SetTableRange (0, 65535);
bwLut->SetSaturationRange (0, 0);
bwLut->SetHueRange (0, 0);
bwLut->SetValueRange (0, 1);
bwLut->Build(); //effective built
vtkSmartPointer<vtkImageMapToColors> colors =
vtkSmartPointer<vtkImageMapToColors>::New();
colors->SetInputConnection(v16->GetOutputPort());
colors->SetLookupTable(bwLut);
colors->Update();
// Try of using vtkImageSlice
vtkSmartPointer<vtkImageSliceMapper > sliceMapper =
vtkSmartPointer<vtkImageSliceMapper>::New();
vtkSmartPointer<vtkImageSlice> imageSlice =
vtkSmartPointer<vtkImageSlice>::New();
vtkSmartPointer<vtkInteractorStyleImage > styleImage =
vtkSmartPointer<vtkInteractorStyleImage>::New();
sliceMapper->SetInput(colors->GetOutput());
imageSlice->SetMapper(sliceMapper);
sliceMapper->SliceAtFocalPointOn();
//imageSlice->RotateX(45); // This Rotation only show orthogonal plane
image on oblique position.
styleImage->SetInteractionModeToImage3D();
iren->SetInteractorStyle(styleImage);
// camera Setting
vtkSmartPointer<vtkCamera> aCamera = vtkSmartPointer<vtkCamera>::New();
aCamera->SetViewUp (0, 0, -1);
aCamera->SetPosition (0, 1, 0);
aCamera->SetFocalPoint (0, 0, 0);
aCamera->ComputeViewPlaneNormal();
aCamera->Azimuth(30.0);
aCamera->Elevation(30.0);
// Actors are added to the renderer.
aRenderer->AddActor(outline);
aRenderer->AddActor(imageSlice);
aRenderer->SetActiveCamera(aCamera);
renWin->Render();
aRenderer->ResetCamera();
aCamera->Dolly(1.5);
aRenderer->ResetCameraClippingRange ();
// interact with data
iren->Initialize();
iren->Start();
return EXIT_SUCCESS;
}
------------------------------------------------------------------
sorry for my english.
Thanks.
SHIINA Hideaki
--
View this message in context: http://vtk.1045678.n5.nabble.com/Does-anybody-has-a-sample-of-new-class-vtkImageSlice-Or-correct-my-code-tp4430673p4430673.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list