我正在尝试更改图像窗口的宽度和级别。
我明白我需要创建vtkWindowLevelLookupTable。 并将其附加到mapper。如描述here。
我不明白这个映射器的来源以及它的输入连接是什么。 我的代码:
_reader2 = vtkDICOMImageReader.New();
_reader2.SetDirectoryName(path);
_reader2.Update();
// Visualize
_ImageViewer2 = vtkImageViewer2.New();
_ImageViewer2.SetInputConnection(_reader2.GetOutputPort());
var image = _ImageViewer2.GetInput();
// get range of slices (min is the first index, max is the last index)
_ImageViewer2.GetSliceRange(ref _MinSlice2, ref _MaxSlice2);
this.vScrollBar2.Maximum = _MaxSlice2 + 1 + vScrollBar2.LargeChange - 1;
Debug.WriteLine("slices range from : " + _MinSlice2.ToString() + " to " + _MaxSlice2.ToString());
vtkRenderWindow renderWindow = renderWindowControl2.RenderWindow;
_interactorStyle2 = vtkInteractorStyleImage.New();
_interactorStyle2.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt2);
_interactorStyle2.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt2);
renderWindow.GetInteractor().LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(renderWindowControl2_Click);
renderWindow.GetInteractor().SetInteractorStyle(_interactorStyle2);
renderWindow.GetRenderers().InitTraversal();
vtkRenderer ren;
while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
ren.SetBackground(0.0, 0.0, 0.0);
_ImageViewer2.SetRenderWindow(renderWindow);
_ImageViewer2.GetRenderer().AddActor2D(sliceStatusActor);
_ImageViewer2.GetRenderer().AddActor2D(usageTextActor);
_ImageViewer2.SetSlice(_MinSlice2);
// Compute a simple window/level based on scalar range
vtkWindowLevelLookupTable wlLut = new vtkWindowLevelLookupTable();
double range = _reader2.GetOutput().GetScalarRange()[1] - _reader2.GetOutput().GetScalarRange()[0];
double level = (_reader2.GetOutput().GetScalarRange()[1] +
_reader2.GetOutput().GetScalarRange()[0]) / 2.0;
wlLut.SetWindow(1000);
wlLut.SetLevel(-1000);
// Create a mapper and actor.
vtkDataSetMapper mapper = new vtkDataSetMapper();
mapper.SetInputConnection(_reader2.GetOutputPort());
mapper.SetLookupTable(wlLut);
// mapper.SetScalarRange(0, 255);
vtkActor actor = new vtkActor();
var actors = _ImageViewer2.GetRenderer().GetActors();
actor.SetMapper(mapper);
// Add the actors to the scene
_ImageViewer2.GetRenderer().AddActor(actor);
_ImageViewer2.Render();
答案 0 :(得分:4)
vtkImageViewer2
已经实现了窗口/级别功能。
您可以像访问它一样访问它:
myImageViewer2.GetWindowLevel().SetWindow(1000);
myImageViewer2.GetWindowLevel().SetLevel(-1000);