]> Creatis software - bbtk.git/blob - packages/wxvtk/src/wxvtkImageViewer2.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / wxvtk / src / wxvtkImageViewer2.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29
30   Program:   Visualization Toolkit
31   Module:    $RCSfile: wxvtkImageViewer2.cxx,v $
32
33   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
34   All rights reserved.
35   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42 #include "wxvtkImageViewer2.h"
43
44 #include "vtkCamera.h"
45 #include "vtkCommand.h"
46 #include "vtkImageActor.h"
47 #include "vtkImageData.h"
48 #include "vtkImageData.h"
49 #include "vtkImageMapToWindowLevelColors.h"
50 #include "vtkInteractorStyleImage.h"
51 #include "vtkObjectFactory.h"
52 #include "vtkRenderWindow.h"
53 #include "vtkRenderWindowInteractor.h"
54 #include "vtkRenderer.h"
55
56 //EED 2017-01-01 Migration VTK7
57 #if VTK_MAJOR_VERSION <= 5
58 vtkCxxRevisionMacro(wxvtkImageViewer2, "$Revision: 1.8 $");
59 #else
60   //...
61 #endif
62
63 vtkStandardNewMacro(wxvtkImageViewer2);
64
65 //----------------------------------------------------------------------------
66 wxvtkImageViewer2::wxvtkImageViewer2()
67 {
68   this->RenderWindow    = NULL;
69   this->Renderer        = NULL;
70   this->ImageActor      = vtkImageActor::New();
71   this->WindowLevel     = vtkImageMapToWindowLevelColors::New();
72   this->Interactor      = NULL;
73   this->InteractorStyle = NULL;
74
75   this->Slice = 0;
76   this->FirstRender = 1;
77   this->SliceOrientation = wxvtkImageViewer2::SLICE_ORIENTATION_XY;
78
79   // Setup the pipeline
80
81   vtkRenderWindow *renwin = vtkRenderWindow::New();
82   this->SetRenderWindow(renwin);
83   renwin->Delete();
84
85   vtkRenderer *ren = vtkRenderer::New();
86   this->SetRenderer(ren);
87   ren->Delete();
88
89   this->InstallPipeline();
90 }
91
92 //----------------------------------------------------------------------------
93 wxvtkImageViewer2::~wxvtkImageViewer2()
94 {
95   if (this->WindowLevel)
96     {
97     this->WindowLevel->Delete();
98     this->WindowLevel = NULL;
99     }
100
101   if (this->ImageActor)
102     {
103     this->ImageActor->Delete();
104     this->ImageActor = NULL;
105     }
106
107   if (this->Renderer)
108     {
109     this->Renderer->Delete();
110     this->Renderer = NULL;
111     }
112
113   if (this->RenderWindow)
114     {
115     this->RenderWindow->Delete();
116     this->RenderWindow = NULL;
117     }
118
119   if (this->Interactor)
120     {
121     this->Interactor->Delete();
122     this->Interactor = NULL;
123     }
124
125   if (this->InteractorStyle)
126     {
127     this->InteractorStyle->Delete();
128     this->InteractorStyle = NULL;
129     }
130 }
131
132 //----------------------------------------------------------------------------
133 void wxvtkImageViewer2::SetupInteractor(vtkRenderWindowInteractor *arg)
134 {
135   if (this->Interactor == arg)
136     {
137     return;
138     }
139
140   this->UnInstallPipeline();
141
142   if (this->Interactor)
143     {
144     this->Interactor->UnRegister(this);
145     }
146
147   this->Interactor = arg;
148
149   if (this->Interactor)
150     {
151     this->Interactor->Register(this);
152     }
153
154   this->InstallPipeline();
155
156   if (this->Renderer)
157     {
158     this->Renderer->GetActiveCamera()->ParallelProjectionOn();
159     }
160 }
161
162 //----------------------------------------------------------------------------
163 void wxvtkImageViewer2::SetRenderWindow(vtkRenderWindow *arg)
164 {
165   if (this->RenderWindow == arg)
166     {
167     return;
168     }
169
170   this->UnInstallPipeline();
171
172   if (this->RenderWindow)
173     {
174     this->RenderWindow->UnRegister(this);
175     }
176
177   this->RenderWindow = arg;
178
179   if (this->RenderWindow)
180     {
181     this->RenderWindow->Register(this);
182     }
183
184   this->InstallPipeline();
185 }
186
187 //----------------------------------------------------------------------------
188 void wxvtkImageViewer2::SetRenderer(vtkRenderer *arg)
189 {
190   if (this->Renderer == arg)
191     {
192     return;
193     }
194
195   this->UnInstallPipeline();
196
197   if (this->Renderer)
198     {
199     this->Renderer->UnRegister(this);
200     }
201
202   this->Renderer = arg;
203
204   if (this->Renderer)
205     {
206     this->Renderer->Register(this);
207     }
208
209   this->InstallPipeline();
210   this->UpdateOrientation();
211 }
212
213 //----------------------------------------------------------------------------
214 void wxvtkImageViewer2::SetSize(int a,int b)
215 {
216   this->RenderWindow->SetSize(a, b);
217 }
218
219 //----------------------------------------------------------------------------
220 int* wxvtkImageViewer2::GetSize()
221 {
222   return this->RenderWindow->GetSize();
223 }
224
225 //----------------------------------------------------------------------------
226 void wxvtkImageViewer2::GetSliceRange(int &min, int &max)
227 {
228   vtkImageData *input = this->GetInput();
229   if (input)
230     {
231
232 //EED 2017-01-01 Migration VTK7
233 #if VTK_MAJOR_VERSION <= 5
234     input->UpdateInformation();
235     int *w_ext = input->GetWholeExtent();
236 #else
237     int *w_ext = input->GetExtent();
238 #endif
239
240     min = w_ext[this->SliceOrientation * 2];
241     max = w_ext[this->SliceOrientation * 2 + 1];
242     }
243 }
244
245 //----------------------------------------------------------------------------
246 int* wxvtkImageViewer2::GetSliceRange()
247 {
248   vtkImageData *input = this->GetInput();
249   if (input)
250     {
251 //EED 2017-01-01 Migration VTK7
252 #if VTK_MAJOR_VERSION <= 5
253     input->UpdateInformation();
254 printf("EED Warning wxvtkImageViewer2::GetSliceRange  GetWholeExtent()[2] ??? /n");
255     return input->GetWholeExtent() + this->SliceOrientation * 2;
256 #else
257 printf("EED Warning wxvtkImageViewer2::GetSliceRange  GetExtent()[2] ??? /n");
258     return input->GetExtent() + this->SliceOrientation * 2;
259 #endif
260     }
261   return NULL;
262 }
263
264 //----------------------------------------------------------------------------
265 int wxvtkImageViewer2::GetSliceMin()
266 {
267   int *range = this->GetSliceRange();
268   if (range)
269     {
270     return range[0];
271     }
272   return 0;
273 }
274
275 //----------------------------------------------------------------------------
276 int wxvtkImageViewer2::GetSliceMax()
277 {
278   int *range = this->GetSliceRange();
279   if (range)
280     {
281     return range[1];
282     }
283   return 0;
284 }
285
286 //----------------------------------------------------------------------------
287 void wxvtkImageViewer2::SetSlice(int slice)
288 {
289   int *range = this->GetSliceRange();
290   if (range)
291     {
292     if (slice < range[0])
293       {
294       slice = range[0];
295       }
296     else if (slice > range[1])
297       {
298       slice = range[1];
299       }
300     }
301
302   if (this->Slice == slice)
303     {
304     return;
305     }
306
307   this->Slice = slice;
308   this->Modified();
309
310   this->UpdateDisplayExtent();
311   this->Render();
312 }
313
314 //----------------------------------------------------------------------------
315 void wxvtkImageViewer2::SetSliceOrientation(int orientation)
316 {
317   if (orientation < wxvtkImageViewer2::SLICE_ORIENTATION_YZ ||
318       orientation > wxvtkImageViewer2::SLICE_ORIENTATION_XY)
319     {
320     vtkErrorMacro("Error - invalid slice orientation " << orientation);
321     return;
322     }
323
324   if (this->SliceOrientation == orientation)
325     {
326     return;
327     }
328
329   this->SliceOrientation = orientation;
330
331   // Update the viewer
332
333   int *range = this->GetSliceRange();
334   if (range)
335     {
336     this->Slice = static_cast<int>((range[0] + range[1]) * 0.5);
337     }
338
339   this->UpdateOrientation();
340   this->UpdateDisplayExtent();
341
342   if (this->Renderer && this->GetInput())
343     {
344     double scale = this->Renderer->GetActiveCamera()->GetParallelScale();
345     this->Renderer->ResetCamera();
346     this->Renderer->GetActiveCamera()->SetParallelScale(scale);
347     }
348
349   this->Render();
350 }
351
352 //----------------------------------------------------------------------------
353 void wxvtkImageViewer2::UpdateOrientation()
354 {
355   // Set the camera position
356
357   vtkCamera *cam = this->Renderer ? this->Renderer->GetActiveCamera() : NULL;
358   if (cam)
359     {
360
361 // EED 21 mars FLIP problem  ..PLOP..           
362     switch (this->SliceOrientation)
363         {
364                 case wxvtkImageViewer2::SLICE_ORIENTATION_YZ:
365                           cam->SetViewUp(0,0,1);
366                           cam->SetPosition(1,0,0); // -1 if medical ?
367                           cam->SetFocalPoint(0,0,0);
368                         break;
369                         
370                 case wxvtkImageViewer2::SLICE_ORIENTATION_XZ:
371                         cam->SetViewUp(0,0,1);
372                         cam->SetPosition(0,-1,0); // 1 if medical ?
373                         cam->SetFocalPoint(0,0,0);
374                         break;
375                         
376                 case wxvtkImageViewer2::SLICE_ORIENTATION_XY:
377                           cam->SetViewUp(0,-1,0);
378                           cam->SetPosition(0,0,-1); 
379                           cam->SetFocalPoint(0,0,0);
380                         break;
381       }
382
383 /*              
384                 switch (this->SliceOrientation)
385                 {
386                         case wxvtkImageViewer2::SLICE_ORIENTATION_YZ:
387                                 cam->SetViewUp(0,0,1);
388                                 cam->SetPosition(1,0,0); // -1 if medical ?
389                                 cam->SetFocalPoint(0,0,0);
390                                 break;
391  
392                         case wxvtkImageViewer2::SLICE_ORIENTATION_XZ:
393                                 cam->SetViewUp(0,0,1);
394                                 cam->SetPosition(0,-1,0); // 1 if medical ?
395                                 cam->SetFocalPoint(0,0,0);
396                                 break;
397  
398                         case wxvtkImageViewer2::SLICE_ORIENTATION_XY:
399                                 cam->SetViewUp(0,1,0);
400                                 cam->SetPosition(0,0,1); // -1 if medical ?
401                                 cam->SetFocalPoint(0,0,0);
402                                 break;
403  
404                                 
405                 }               
406 */              
407                 
408     }
409 }
410
411 //----------------------------------------------------------------------------
412 void wxvtkImageViewer2::UpdateDisplayExtent()
413 {
414   vtkImageData *input = this->GetInput();
415   if (!input || !this->ImageActor)
416     {
417     return;
418     }
419
420   //  std::cout << "--- wxvtkImageViewer2::UpdateDisplayExtent()"<<std::endl;
421 //EED 2017-01-01 Migration VTK7
422 #if VTK_MAJOR_VERSION <= 5
423   input->UpdateInformation();
424   int *w_ext = input->GetWholeExtent();
425 #else
426   int *w_ext = input->GetExtent();
427 #endif
428
429   //    std::cout << "ext = "
430   //    <<w_ext[0]<<" - "<<w_ext[1]<<" ; "
431   //            <<w_ext[2]<<" - "<<w_ext[3]<<" ; "
432   //            <<w_ext[4]<<" - "<<w_ext[5]
433   //            <<std::endl;
434       // Is the slice in range ? If not, fix it
435
436   int slice_min = w_ext[this->SliceOrientation * 2];
437   int slice_max = w_ext[this->SliceOrientation * 2 + 1];
438   if (this->Slice < slice_min || this->Slice > slice_max)
439     {
440     this->Slice = static_cast<int>((slice_min + slice_max) * 0.5);
441     }
442
443   // Set the image actor
444
445   switch (this->SliceOrientation)
446     {
447     case wxvtkImageViewer2::SLICE_ORIENTATION_XY:
448       this->ImageActor->SetDisplayExtent(
449         w_ext[0], w_ext[1], w_ext[2], w_ext[3], this->Slice, this->Slice);
450       break;
451
452     case wxvtkImageViewer2::SLICE_ORIENTATION_XZ:
453       this->ImageActor->SetDisplayExtent(
454         w_ext[0], w_ext[1], this->Slice, this->Slice, w_ext[4], w_ext[5]);
455       break;
456
457     case wxvtkImageViewer2::SLICE_ORIENTATION_YZ:
458       this->ImageActor->SetDisplayExtent(
459         this->Slice, this->Slice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
460       break;
461     }
462
463   // Figure out the correct clipping range
464
465   if (this->Renderer)
466     {
467     if (this->InteractorStyle &&
468         this->InteractorStyle->GetAutoAdjustCameraClippingRange())
469       {
470       this->Renderer->ResetCameraClippingRange();
471       } else {
472       vtkCamera *cam = this->Renderer->GetActiveCamera();
473       if (cam)
474         {
475         double bounds[6];
476         this->ImageActor->GetBounds(bounds);
477         double spos = bounds[this->SliceOrientation * 2];
478         double cpos = cam->GetPosition()[this->SliceOrientation];
479         double range = fabs(spos - cpos);
480         double *spacing = input->GetSpacing();
481         double avg_spacing =
482           //(spacing[0] + spacing[1] + spacing[2]) / 3.0;
483           spacing[2]; // JPR??
484         cam->SetClippingRange(
485           range - avg_spacing * 3.0, range + avg_spacing * 3.0);
486         } // if cam
487       } // if InteractorStyle
488     } // if Renderer
489 }
490
491 //----------------------------------------------------------------------------
492 void wxvtkImageViewer2::SetPosition(int a,int b)
493 {
494   this->RenderWindow->SetPosition(a, b);
495 }
496
497 //----------------------------------------------------------------------------
498 int* wxvtkImageViewer2::GetPosition()
499 {
500   return this->RenderWindow->GetPosition();
501 }
502
503 //----------------------------------------------------------------------------
504 void wxvtkImageViewer2::SetDisplayId(void *a)
505 {
506   this->RenderWindow->SetDisplayId(a);
507 }
508
509 //----------------------------------------------------------------------------
510 void wxvtkImageViewer2::SetWindowId(void *a)
511 {
512   this->RenderWindow->SetWindowId(a);
513 }
514
515 //----------------------------------------------------------------------------
516 void wxvtkImageViewer2::SetParentId(void *a)
517 {
518   this->RenderWindow->SetParentId(a);
519 }
520
521 //----------------------------------------------------------------------------
522 double wxvtkImageViewer2::GetColorWindow()
523 {
524   return this->WindowLevel->GetWindow();
525 }
526
527 //----------------------------------------------------------------------------
528 double wxvtkImageViewer2::GetColorLevel()
529 {
530   return this->WindowLevel->GetLevel();
531 }
532
533 //----------------------------------------------------------------------------
534 void wxvtkImageViewer2::SetColorWindow(double s)
535 {
536   this->WindowLevel->SetWindow(s);
537 }
538
539 //----------------------------------------------------------------------------
540 void wxvtkImageViewer2::SetColorLevel(double s)
541 {
542   this->WindowLevel->SetLevel(s);
543 }
544
545 //----------------------------------------------------------------------------
546 class wxvtkImageViewer2Callback : public vtkCommand
547 {
548 public:
549   static wxvtkImageViewer2Callback *New() { return new wxvtkImageViewer2Callback; }
550
551   void Execute(vtkObject *caller,
552                unsigned long event,
553                void *vtkNotUsed(callData))
554     {
555       if (this->IV->GetInput() == NULL)
556         {
557         return;
558         }
559
560       // Reset
561
562       if (event == vtkCommand::ResetWindowLevelEvent)
563         {
564
565 //EED 2017-01-01 Migration VTK7
566 #if VTK_MAJOR_VERSION <= 5
567         this->IV->GetInput()->UpdateInformation();
568         this->IV->GetInput()->SetUpdateExtent
569           (this->IV->GetInput()->GetWholeExtent());
570         this->IV->GetInput()->Update();
571 #else
572   //...
573 #endif
574
575         double *range = this->IV->GetInput()->GetScalarRange();
576         this->IV->SetColorWindow(range[1] - range[0]);
577         this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
578         this->IV->Render();
579         return;
580         }
581
582       // Start
583
584       if (event == vtkCommand::StartWindowLevelEvent)
585         {
586         this->InitialWindow = this->IV->GetColorWindow();
587         this->InitialLevel = this->IV->GetColorLevel();
588         return;
589         }
590
591       // Adjust the window level here
592
593       vtkInteractorStyleImage *isi =
594         static_cast<vtkInteractorStyleImage *>(caller);
595
596       int *size = this->IV->GetRenderWindow()->GetSize();
597       double window = this->InitialWindow;
598       double level = this->InitialLevel;
599
600       // Compute normalized delta
601
602       double dx = 4.0 *
603         (isi->GetWindowLevelCurrentPosition()[0] -
604          isi->GetWindowLevelStartPosition()[0]) / size[0];
605       double dy = 4.0 *
606         (isi->GetWindowLevelStartPosition()[1] -
607          isi->GetWindowLevelCurrentPosition()[1]) / size[1];
608
609       // Scale by current values
610
611       if (fabs(window) > 0.01)
612         {
613         dx = dx * window;
614         }
615       else
616         {
617         dx = dx * (window < 0 ? -0.01 : 0.01);
618         }
619       if (fabs(level) > 0.01)
620         {
621         dy = dy * level;
622         }
623       else
624         {
625         dy = dy * (level < 0 ? -0.01 : 0.01);
626         }
627
628       // Abs so that direction does not flip
629
630       if (window < 0.0)
631         {
632         dx = -1*dx;
633         }
634       if (level < 0.0)
635         {
636         dy = -1*dy;
637         }
638
639       // Compute new window level
640
641       double newWindow = dx + window;
642       double newLevel;
643       newLevel = level - dy;
644
645       // Stay away from zero and really
646
647       if (fabs(newWindow) < 0.01)
648         {
649         newWindow = 0.01*(newWindow < 0 ? -1 : 1);
650         }
651       if (fabs(newLevel) < 0.01)
652         {
653         newLevel = 0.01*(newLevel < 0 ? -1 : 1);
654         }
655
656       this->IV->SetColorWindow(newWindow);
657       this->IV->SetColorLevel(newLevel);
658       this->IV->Render();
659     }
660
661   wxvtkImageViewer2 *IV;
662   double InitialWindow;
663   double InitialLevel;
664 };
665
666 //----------------------------------------------------------------------------
667 void wxvtkImageViewer2::InstallPipeline()
668 {
669   if (this->RenderWindow && this->Renderer)
670     {
671     this->RenderWindow->AddRenderer(this->Renderer);
672     }
673
674   if (this->Interactor)
675     {
676     if (!this->InteractorStyle)
677       {
678       this->InteractorStyle = vtkInteractorStyleImage::New();
679       wxvtkImageViewer2Callback *cbk = wxvtkImageViewer2Callback::New();
680       cbk->IV = this;
681       this->InteractorStyle->AddObserver(
682         vtkCommand::WindowLevelEvent, cbk);
683       this->InteractorStyle->AddObserver(
684         vtkCommand::StartWindowLevelEvent, cbk);
685       this->InteractorStyle->AddObserver(
686         vtkCommand::ResetWindowLevelEvent, cbk);
687       cbk->Delete();
688       }
689
690     this->Interactor->SetInteractorStyle(this->InteractorStyle);
691     this->Interactor->SetRenderWindow(this->RenderWindow);
692     }
693
694   if (this->Renderer && this->ImageActor)
695     {
696     this->Renderer->AddViewProp(this->ImageActor);
697     }
698
699   if (this->ImageActor && this->WindowLevel)
700     {
701 //EED 2017-01-01 Migration VTK7
702 #if VTK_MAJOR_VERSION <= 5
703     this->ImageActor->SetInput(this->WindowLevel->GetOutput());
704 #else
705         this->WindowLevel->Update();
706     this->ImageActor->SetInputData(this->WindowLevel->GetOutput());
707 #endif
708     }
709 }
710
711 //----------------------------------------------------------------------------
712 void wxvtkImageViewer2::UnInstallPipeline()
713 {
714   if (this->ImageActor)
715     {
716 //EED 2017-01-01 Migration VTK7
717 #if VTK_MAJOR_VERSION <= 5
718     this->ImageActor->SetInput(NULL);
719 #else
720     this->ImageActor->SetInputData(NULL);
721 #endif
722     }
723
724   if (this->Renderer && this->ImageActor)
725     {
726     this->Renderer->RemoveViewProp(this->ImageActor);
727     }
728
729   if (this->RenderWindow && this->Renderer)
730     {
731     this->RenderWindow->RemoveRenderer(this->Renderer);
732     }
733
734   if (this->Interactor)
735     {
736     this->Interactor->SetInteractorStyle(NULL);
737     this->Interactor->SetRenderWindow(NULL);
738     }
739 }
740
741 //----------------------------------------------------------------------------
742 void wxvtkImageViewer2::Render()
743 {
744   if (this->FirstRender)
745     {
746     // Initialize the size if not set yet
747
748     vtkImageData *input = this->GetInput();
749     if (this->RenderWindow->GetSize()[0] == 0 &&
750         input)
751       {
752
753
754 //EED 2017-01-01 Migration VTK7
755 #if VTK_MAJOR_VERSION <= 5
756       input->UpdateInformation();
757       int *w_ext = input->GetWholeExtent();
758 #else
759       int *w_ext = input->GetExtent();
760 #endif
761
762       int xs = 0, ys = 0;
763
764       //        std::cout << "wxvtkImageViewer2::Render ext = "
765       //        <<w_ext[0]<<" - "<<w_ext[1]<<" ; "
766       //                <<w_ext[2]<<" - "<<w_ext[3]<<" ; "
767       //                <<w_ext[4]<<" - "<<w_ext[5]
768       //                <<std::endl;
769
770       switch (this->SliceOrientation)
771         {
772         case wxvtkImageViewer2::SLICE_ORIENTATION_XY:
773         default:
774           xs = w_ext[1] - w_ext[0] + 1;
775           ys = w_ext[3] - w_ext[2] + 1;
776           //      std::cout << "SLICE_ORIENTATION_XY" << std::endl;
777           break;
778
779         case wxvtkImageViewer2::SLICE_ORIENTATION_XZ:
780           xs = w_ext[1] - w_ext[0] + 1;
781           ys = w_ext[5] - w_ext[4] + 1;
782           //      std::cout << "SLICE_ORIENTATION_XZ" << std::endl;
783           break;
784
785         case wxvtkImageViewer2::SLICE_ORIENTATION_YZ:
786           xs = w_ext[3] - w_ext[2] + 1;
787           ys = w_ext[5] - w_ext[4] + 1;
788           //      std::cout << "SLICE_ORIENTATION_YZ" << std::endl;
789           break;
790         }
791
792       // if it would be smaller than 150 by 100 then limit to 150 by 100
793       this->RenderWindow->SetSize(
794         xs < 150 ? 150 : xs, ys < 100 ? 100 : ys);
795
796       //      std::cout << "wxvtkImageViewer2::Render() : "<<xs<<"-"<<ys<<std::endl;
797       if (this->Renderer)
798         {
799         this->Renderer->ResetCamera();
800         this->Renderer->GetActiveCamera()->SetParallelScale(
801           xs < 150 ? 75 : (xs - 1 ) / 2.0);
802         }
803       this->FirstRender = 0;
804
805       }
806     }
807   if (this->GetInput())
808     {
809     this->RenderWindow->Render();
810     }
811 }
812
813 //----------------------------------------------------------------------------
814 const char* wxvtkImageViewer2::GetWindowName()
815 {
816   return this->RenderWindow->GetWindowName();
817 }
818
819 //----------------------------------------------------------------------------
820 void wxvtkImageViewer2::SetOffScreenRendering(int i)
821 {
822   this->RenderWindow->SetOffScreenRendering(i);
823 }
824
825 //----------------------------------------------------------------------------
826 int wxvtkImageViewer2::GetOffScreenRendering()
827 {
828   return this->RenderWindow->GetOffScreenRendering();
829 }
830
831 //----------------------------------------------------------------------------
832 void wxvtkImageViewer2::SetInput(vtkImageData *in)
833 {
834   //  std::cout << "### wxvtkImageViewer2::SetInput"<<std::endl;
835 //EED 2017-01-01 Migration VTK7
836 #if VTK_MAJOR_VERSION <= 5
837   this->WindowLevel->SetInput(in);
838 #else
839   this->WindowLevel->SetInputData(in);
840 #endif
841
842   this->UpdateDisplayExtent();
843   // LG 03/12/08
844   //  FirstRender = 1;
845 }
846 //----------------------------------------------------------------------------
847 vtkImageData* wxvtkImageViewer2::GetInput()
848 {
849   return vtkImageData::SafeDownCast(this->WindowLevel->GetInput());
850 }
851
852 //----------------------------------------------------------------------------
853 void wxvtkImageViewer2::SetInputConnection(vtkAlgorithmOutput* input)
854 {
855   this->WindowLevel->SetInputConnection(input);
856   this->UpdateDisplayExtent();
857 }
858
859 //----------------------------------------------------------------------------
860 #ifndef VTK_LEGACY_REMOVE
861 int wxvtkImageViewer2::GetWholeZMin()
862 {
863   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::GetWholeZMin, "VTK 5.0",
864                            wxvtkImageViewer2::GetSliceMin);
865   return this->GetSliceMin();
866 }
867 int wxvtkImageViewer2::GetWholeZMax()
868 {
869   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::GetWholeZMax, "VTK 5.0",
870                            wxvtkImageViewer2::GetSliceMax);
871   return this->GetSliceMax();
872 }
873 int wxvtkImageViewer2::GetZSlice()
874 {
875   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::GetZSlice, "VTK 5.0",
876                            wxvtkImageViewer2::GetSlice);
877   return this->GetSlice();
878 }
879 void wxvtkImageViewer2::SetZSlice(int s)
880 {
881   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::SetZSlice, "VTK 5.0",
882                            wxvtkImageViewer2::SetSlice);
883   this->SetSlice(s);
884 }
885 #endif
886
887 //----------------------------------------------------------------------------
888 void wxvtkImageViewer2::PrintSelf(ostream& os, vtkIndent indent)
889 {
890   this->Superclass::PrintSelf(os, indent);
891
892   os << indent << "RenderWindow:\n";
893   this->RenderWindow->PrintSelf(os,indent.GetNextIndent());
894   os << indent << "Renderer:\n";
895   this->Renderer->PrintSelf(os,indent.GetNextIndent());
896   os << indent << "ImageActor:\n";
897   this->ImageActor->PrintSelf(os,indent.GetNextIndent());
898   os << indent << "WindowLevel:\n" << endl;
899   this->WindowLevel->PrintSelf(os,indent.GetNextIndent());
900   os << indent << "Slice: " << this->Slice << endl;
901   os << indent << "SliceOrientation: " << this->SliceOrientation << endl;
902   os << indent << "InteractorStyle: " << endl;
903   if (this->InteractorStyle)
904     {
905     os << "\n";
906     this->InteractorStyle->PrintSelf(os,indent.GetNextIndent());
907     }
908   else
909     {
910     os << "None";
911     }
912 }