18 #include "vtkImageViewer3.h" 20 #include <vtkCamera.h> 21 #include <vtkRenderer.h> 22 #include <vtkCommand.h> 23 #include <vtkImageData.h> 24 #include <vtkRenderWindow.h> 25 #include <vtkProperty.h> 26 #include <vtkRenderWindowInteractor.h> 27 #include <vtkRendererCollection.h> 28 #include <vtkPointPicker.h> 29 #include <vtkImageActor.h> 30 #include <vtkImageMapToWindowLevelColors.h> 31 #if(VTK_MAJOR_VERSION > 5) 32 #include "vtkStreamingDemandDrivenPipeline.h" 33 #include "vtkImageMapper3D.h" 42 void Execute(vtkObject *caller,
44 void *vtkNotUsed(callData))
46 if (this->IV->GetInput() == NULL)
53 if (event == vtkCommand::ResetWindowLevelEvent)
55 #if(VTK_MAJOR_VERSION > 5) 56 this->IV->GetInputAlgorithm()->UpdateInformation();
57 vtkStreamingDemandDrivenPipeline::SetUpdateExtent(
58 this->IV->GetInputInformation(),
59 vtkStreamingDemandDrivenPipeline::GetWholeExtent(
60 this->IV->GetInputInformation()));
61 this->IV->GetInputAlgorithm()->Update();
63 this->IV->GetInput()->UpdateInformation();
64 this->IV->GetInput()->SetUpdateExtent
65 (this->IV->GetInput()->GetWholeExtent());
66 this->IV->GetInput()->Update();
68 double *range = this->IV->GetInput()->GetScalarRange();
69 this->IV->SetColorWindow(range[1] - range[0]);
70 this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
77 if (event == vtkCommand::StartWindowLevelEvent)
79 this->InitialWindow = this->IV->GetColorWindow();
80 this->InitialLevel = this->IV->GetColorLevel();
86 vtkInteractorStyleImage *isi =
87 static_cast<vtkInteractorStyleImage *
>(caller);
89 int *size = this->IV->GetRenderWindow()->GetSize();
90 double window = this->InitialWindow;
91 double level = this->InitialLevel;
96 (isi->GetWindowLevelCurrentPosition()[0] -
97 isi->GetWindowLevelStartPosition()[0]) / size[0];
99 (isi->GetWindowLevelStartPosition()[1] -
100 isi->GetWindowLevelCurrentPosition()[1]) / size[1];
104 if (fabs(window) > 0.01)
110 dx = dx * (window < 0 ? -0.01 : 0.01);
112 if (fabs(level) > 0.01)
118 dy = dy * (level < 0 ? -0.01 : 0.01);
134 double newWindow = dx + window;
136 newLevel = level - dy;
140 if (fabs(newWindow) < 0.01)
142 newWindow = 0.01*(newWindow < 0 ? -1 : 1);
144 if (fabs(newLevel) < 0.01)
146 newLevel = 0.01*(newLevel < 0 ? -1 : 1);
149 this->IV->SetColorWindow(newWindow);
150 this->IV->SetColorLevel(newLevel);
151 std::cout <<
"Window: " << newWindow <<
", Level: " << newLevel << std::endl;
156 double InitialWindow;
166 dataPicker = vtkPointPicker::New();
172 dataPicker->Delete();
175 void Execute(vtkObject *caller,
177 void *vtkNotUsed(callData))
179 if (this->IV->GetInput() == NULL)
185 vtkInteractorStyleImage *isi =
186 static_cast<vtkInteractorStyleImage *
>(caller);
188 int *size = this->IV->GetRenderWindow()->GetSize();
190 if (this->IV->GetCursorEnabled())
192 if (dataPicker->Pick(isi->GetInteractor()->GetEventPosition()[0],
193 isi->GetInteractor()->GetEventPosition()[1],
195 isi->GetInteractor()->GetRenderWindow()->GetRenderers()->GetFirstRenderer()))
198 dataPicker->GetMapperPosition(picked);
200 #if(VTK_MAJOR_VERSION > 5) 201 this->IV->GetCursor()->SetCenter(picked[0], picked[1], picked[2]);
203 this->IV->GetCursor()->SetModelBounds(this->IV->GetInput()->GetBounds());
204 this->IV->GetCursor()->SetFocalPoint(picked[0], picked[1], picked[2]);
206 this->IV->GetCursor()->Update();
207 this->IV->GetRenderWindow()->Modified();
208 this->IV->UpdateDisplayExtent();
216 vtkPointPicker *dataPicker;
222 vtkImageViewer3::vtkImageViewer3()
224 NeurologicalView =
true;
225 CursorEnabled =
false;
227 #if(VTK_MAJOR_VERSION < 6) 233 vtkImageViewer3::~vtkImageViewer3()
240 #if(VTK_MAJOR_VERSION < 6) 243 cursorMapper->Delete();
249 cursorActor->Delete();
254 void vtkImageViewer3::PrintSelf(ostream& os, vtkIndent indent)
256 this->Superclass::PrintSelf(os, indent);
259 void vtkImageViewer3::UpdateOrientation()
261 vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
266 if(!NeurologicalView)
268 switch (this->SliceOrientation)
270 case vtkImageViewer3::SLICE_ORIENTATION_XY:
271 cam->SetFocalPoint(0,0,0);
272 cam->SetPosition(0,0,1);
273 cam->SetViewUp(0,1,0);
276 case vtkImageViewer3::SLICE_ORIENTATION_XZ:
277 cam->SetFocalPoint(0,0,0);
278 cam->SetPosition(0,-1,0);
279 cam->SetViewUp(0,0,1);
282 case vtkImageViewer3::SLICE_ORIENTATION_YZ:
283 cam->SetFocalPoint(0,0,0);
284 cam->SetPosition(-1,0,0);
285 cam->SetViewUp(0,0,1);
292 std::cout <<
"Using Neurological (head-first) Orientation" << std::endl;
293 switch (this->SliceOrientation)
295 case vtkImageViewer3::SLICE_ORIENTATION_XY:
296 cam->SetFocalPoint(0,0,0);
297 cam->SetPosition(0,0,-1);
298 cam->SetViewUp(0,1,0);
301 case vtkImageViewer3::SLICE_ORIENTATION_XZ:
302 cam->SetFocalPoint(0,0,0);
303 cam->SetPosition(0,1,0);
304 cam->SetViewUp(0,0,1);
307 case vtkImageViewer3::SLICE_ORIENTATION_YZ:
308 cam->SetFocalPoint(0,0,0);
309 cam->SetPosition(-1,0,0);
310 cam->SetViewUp(0,0,1);
317 void vtkImageViewer3::InstallPipeline()
319 if (this->RenderWindow && this->Renderer)
321 this->RenderWindow->AddRenderer(this->Renderer);
324 if (this->Interactor)
326 if (!this->InteractorStyle)
329 scannerInteractor->SetViewer(
this);
330 this->InteractorStyle = scannerInteractor;
333 this->InteractorStyle->AddObserver(
334 vtkCommand::WindowLevelEvent, cbk);
335 this->InteractorStyle->AddObserver(
336 vtkCommand::StartWindowLevelEvent, cbk);
337 this->InteractorStyle->AddObserver(
338 vtkCommand::ResetWindowLevelEvent, cbk);
342 this->InteractorStyle->AddObserver(
343 vtkCommand::MiddleButtonPressEvent, cbk2);
346 this->Interactor->SetInteractorStyle(this->InteractorStyle);
347 this->Interactor->SetRenderWindow(this->RenderWindow);
350 if (this->Renderer && this->ImageActor)
352 this->Renderer->AddViewProp(this->ImageActor);
355 if (this->ImageActor && this->WindowLevel)
357 #if(VTK_MAJOR_VERSION > 5) 358 this->ImageActor->GetMapper()->SetInputConnection(
359 this->WindowLevel->GetOutputPort());
361 this->ImageActor->SetInput(this->WindowLevel->GetOutput());
366 void vtkImageViewer3::SetSliceOrientation(
int orientation)
368 Superclass::SetSliceOrientation(orientation);
369 #if(VTK_MAJOR_VERSION > 5) 371 cursorActor->GetCursorAlgorithm()->SetReslicePlaneNormal(this->SliceOrientation);
381 void vtkImageViewer3::EnableCursor()
383 #if(VTK_MAJOR_VERSION > 5) 385 cursor = vtkResliceCursor::New();
386 cursor->SetImage(this->GetInput());
387 cursor->SetThickMode(0);
388 cursor->SetThickness(1, 1, 1);
395 cursor->SetCenter(this->GetInput()->GetOrigin());
399 cursorActor = vtkResliceCursorActor::New();
400 cursorActor->GetCursorAlgorithm()->SetResliceCursor(cursor);
401 cursorActor->GetCursorAlgorithm()->SetReslicePlaneNormal(this->SliceOrientation);
404 cursor = vtkCursor3D::New();
405 cursor->SetModelBounds(this->GetInput()->GetBounds());
407 cursor->OutlineOff();
410 cursorMapper = vtkPolyDataMapper::New();
411 cursorMapper->SetInputConnection(cursor->GetOutputPort());
414 cursorActor = vtkActor::New();
415 cursorActor->GetProperty()->SetColor(1, 0, 0);
416 cursorActor->SetMapper(cursorMapper);
420 this->Renderer->AddActor(cursorActor);
422 this->GetRenderWindow()->Modified();
423 this->UpdateDisplayExtent();
425 CursorEnabled =
true;
428 void vtkImageViewer3::UpdateCursor()
433 #if(VTK_MAJOR_VERSION > 5) 434 cursorActor->GetCursorAlgorithm()->SetReslicePlaneNormal(this->SliceOrientation);
439 void vtkImageViewer3::DisableCursor()
441 #if(VTK_MAJOR_VERSION > 5) 442 this->Renderer->RemoveActor(cursorActor);
447 CursorEnabled =
false;
450 double* vtkImageViewer3::GetCursorFocalPoint()
452 #if(VTK_MAJOR_VERSION > 5) 453 return cursor->GetCenter();
455 return cursor->GetFocalPoint();
459 void vtkImageViewer3::SetCursorFocalPoint(
double *point)
461 #if(VTK_MAJOR_VERSION > 5) 462 cursor->SetCenter(point);
464 cursor->SetFocalPoint(point);