]> Creatis software - bbtk.git/blob - packages/wxvtk/src/wxvtkImageViewer2.cxx
dc3dcfc69586b494efc07ca0b875ca8f7ad4c952
[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       }
472     else
473       {
474       vtkCamera *cam = this->Renderer->GetActiveCamera();
475       if (cam)
476         {
477         double bounds[6];
478         this->ImageActor->GetBounds(bounds);
479         double spos = bounds[this->SliceOrientation * 2];
480         double cpos = cam->GetPosition()[this->SliceOrientation];
481         double range = fabs(spos - cpos);
482         double *spacing = input->GetSpacing();
483         double avg_spacing =
484           //(spacing[0] + spacing[1] + spacing[2]) / 3.0;
485           spacing[2]; // JPR??
486         cam->SetClippingRange(
487           range - avg_spacing * 3.0, range + avg_spacing * 3.0);
488         }
489       }
490     }
491 }
492
493 //----------------------------------------------------------------------------
494 void wxvtkImageViewer2::SetPosition(int a,int b)
495 {
496   this->RenderWindow->SetPosition(a, b);
497 }
498
499 //----------------------------------------------------------------------------
500 int* wxvtkImageViewer2::GetPosition()
501 {
502   return this->RenderWindow->GetPosition();
503 }
504
505 //----------------------------------------------------------------------------
506 void wxvtkImageViewer2::SetDisplayId(void *a)
507 {
508   this->RenderWindow->SetDisplayId(a);
509 }
510
511 //----------------------------------------------------------------------------
512 void wxvtkImageViewer2::SetWindowId(void *a)
513 {
514   this->RenderWindow->SetWindowId(a);
515 }
516
517 //----------------------------------------------------------------------------
518 void wxvtkImageViewer2::SetParentId(void *a)
519 {
520   this->RenderWindow->SetParentId(a);
521 }
522
523 //----------------------------------------------------------------------------
524 double wxvtkImageViewer2::GetColorWindow()
525 {
526   return this->WindowLevel->GetWindow();
527 }
528
529 //----------------------------------------------------------------------------
530 double wxvtkImageViewer2::GetColorLevel()
531 {
532   return this->WindowLevel->GetLevel();
533 }
534
535 //----------------------------------------------------------------------------
536 void wxvtkImageViewer2::SetColorWindow(double s)
537 {
538   this->WindowLevel->SetWindow(s);
539 }
540
541 //----------------------------------------------------------------------------
542 void wxvtkImageViewer2::SetColorLevel(double s)
543 {
544   this->WindowLevel->SetLevel(s);
545 }
546
547 //----------------------------------------------------------------------------
548 class wxvtkImageViewer2Callback : public vtkCommand
549 {
550 public:
551   static wxvtkImageViewer2Callback *New() { return new wxvtkImageViewer2Callback; }
552
553   void Execute(vtkObject *caller,
554                unsigned long event,
555                void *vtkNotUsed(callData))
556     {
557       if (this->IV->GetInput() == NULL)
558         {
559         return;
560         }
561
562       // Reset
563
564       if (event == vtkCommand::ResetWindowLevelEvent)
565         {
566
567 //EED 2017-01-01 Migration VTK7
568 #if VTK_MAJOR_VERSION <= 5
569         this->IV->GetInput()->UpdateInformation();
570         this->IV->GetInput()->SetUpdateExtent
571           (this->IV->GetInput()->GetWholeExtent());
572         this->IV->GetInput()->Update();
573 #else
574   //...
575 #endif
576
577         double *range = this->IV->GetInput()->GetScalarRange();
578         this->IV->SetColorWindow(range[1] - range[0]);
579         this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
580         this->IV->Render();
581         return;
582         }
583
584       // Start
585
586       if (event == vtkCommand::StartWindowLevelEvent)
587         {
588         this->InitialWindow = this->IV->GetColorWindow();
589         this->InitialLevel = this->IV->GetColorLevel();
590         return;
591         }
592
593       // Adjust the window level here
594
595       vtkInteractorStyleImage *isi =
596         static_cast<vtkInteractorStyleImage *>(caller);
597
598       int *size = this->IV->GetRenderWindow()->GetSize();
599       double window = this->InitialWindow;
600       double level = this->InitialLevel;
601
602       // Compute normalized delta
603
604       double dx = 4.0 *
605         (isi->GetWindowLevelCurrentPosition()[0] -
606          isi->GetWindowLevelStartPosition()[0]) / size[0];
607       double dy = 4.0 *
608         (isi->GetWindowLevelStartPosition()[1] -
609          isi->GetWindowLevelCurrentPosition()[1]) / size[1];
610
611       // Scale by current values
612
613       if (fabs(window) > 0.01)
614         {
615         dx = dx * window;
616         }
617       else
618         {
619         dx = dx * (window < 0 ? -0.01 : 0.01);
620         }
621       if (fabs(level) > 0.01)
622         {
623         dy = dy * level;
624         }
625       else
626         {
627         dy = dy * (level < 0 ? -0.01 : 0.01);
628         }
629
630       // Abs so that direction does not flip
631
632       if (window < 0.0)
633         {
634         dx = -1*dx;
635         }
636       if (level < 0.0)
637         {
638         dy = -1*dy;
639         }
640
641       // Compute new window level
642
643       double newWindow = dx + window;
644       double newLevel;
645       newLevel = level - dy;
646
647       // Stay away from zero and really
648
649       if (fabs(newWindow) < 0.01)
650         {
651         newWindow = 0.01*(newWindow < 0 ? -1 : 1);
652         }
653       if (fabs(newLevel) < 0.01)
654         {
655         newLevel = 0.01*(newLevel < 0 ? -1 : 1);
656         }
657
658       this->IV->SetColorWindow(newWindow);
659       this->IV->SetColorLevel(newLevel);
660       this->IV->Render();
661     }
662
663   wxvtkImageViewer2 *IV;
664   double InitialWindow;
665   double InitialLevel;
666 };
667
668 //----------------------------------------------------------------------------
669 void wxvtkImageViewer2::InstallPipeline()
670 {
671   if (this->RenderWindow && this->Renderer)
672     {
673     this->RenderWindow->AddRenderer(this->Renderer);
674     }
675
676   if (this->Interactor)
677     {
678     if (!this->InteractorStyle)
679       {
680       this->InteractorStyle = vtkInteractorStyleImage::New();
681       wxvtkImageViewer2Callback *cbk = wxvtkImageViewer2Callback::New();
682       cbk->IV = this;
683       this->InteractorStyle->AddObserver(
684         vtkCommand::WindowLevelEvent, cbk);
685       this->InteractorStyle->AddObserver(
686         vtkCommand::StartWindowLevelEvent, cbk);
687       this->InteractorStyle->AddObserver(
688         vtkCommand::ResetWindowLevelEvent, cbk);
689       cbk->Delete();
690       }
691
692     this->Interactor->SetInteractorStyle(this->InteractorStyle);
693     this->Interactor->SetRenderWindow(this->RenderWindow);
694     }
695
696   if (this->Renderer && this->ImageActor)
697     {
698     this->Renderer->AddViewProp(this->ImageActor);
699     }
700
701   if (this->ImageActor && this->WindowLevel)
702     {
703 //EED 2017-01-01 Migration VTK7
704 #if VTK_MAJOR_VERSION <= 5
705     this->ImageActor->SetInput(this->WindowLevel->GetOutput());
706 #else
707     this->ImageActor->SetInputData(this->WindowLevel->GetOutput());
708 #endif
709     }
710 }
711
712 //----------------------------------------------------------------------------
713 void wxvtkImageViewer2::UnInstallPipeline()
714 {
715   if (this->ImageActor)
716     {
717 //EED 2017-01-01 Migration VTK7
718 #if VTK_MAJOR_VERSION <= 5
719     this->ImageActor->SetInput(NULL);
720 #else
721     this->ImageActor->SetInputData(NULL);
722 #endif
723     }
724
725   if (this->Renderer && this->ImageActor)
726     {
727     this->Renderer->RemoveViewProp(this->ImageActor);
728     }
729
730   if (this->RenderWindow && this->Renderer)
731     {
732     this->RenderWindow->RemoveRenderer(this->Renderer);
733     }
734
735   if (this->Interactor)
736     {
737     this->Interactor->SetInteractorStyle(NULL);
738     this->Interactor->SetRenderWindow(NULL);
739     }
740 }
741
742 //----------------------------------------------------------------------------
743 void wxvtkImageViewer2::Render()
744 {
745   if (this->FirstRender)
746     {
747     // Initialize the size if not set yet
748
749     vtkImageData *input = this->GetInput();
750     if (this->RenderWindow->GetSize()[0] == 0 &&
751         input)
752       {
753
754
755 //EED 2017-01-01 Migration VTK7
756 #if VTK_MAJOR_VERSION <= 5
757       input->UpdateInformation();
758       int *w_ext = input->GetWholeExtent();
759 #else
760       int *w_ext = input->GetExtent();
761 #endif
762
763       int xs = 0, ys = 0;
764
765       //        std::cout << "wxvtkImageViewer2::Render ext = "
766       //        <<w_ext[0]<<" - "<<w_ext[1]<<" ; "
767       //                <<w_ext[2]<<" - "<<w_ext[3]<<" ; "
768       //                <<w_ext[4]<<" - "<<w_ext[5]
769       //                <<std::endl;
770
771       switch (this->SliceOrientation)
772         {
773         case wxvtkImageViewer2::SLICE_ORIENTATION_XY:
774         default:
775           xs = w_ext[1] - w_ext[0] + 1;
776           ys = w_ext[3] - w_ext[2] + 1;
777           //      std::cout << "SLICE_ORIENTATION_XY" << std::endl;
778           break;
779
780         case wxvtkImageViewer2::SLICE_ORIENTATION_XZ:
781           xs = w_ext[1] - w_ext[0] + 1;
782           ys = w_ext[5] - w_ext[4] + 1;
783           //      std::cout << "SLICE_ORIENTATION_XZ" << std::endl;
784           break;
785
786         case wxvtkImageViewer2::SLICE_ORIENTATION_YZ:
787           xs = w_ext[3] - w_ext[2] + 1;
788           ys = w_ext[5] - w_ext[4] + 1;
789           //      std::cout << "SLICE_ORIENTATION_YZ" << std::endl;
790           break;
791         }
792
793       // if it would be smaller than 150 by 100 then limit to 150 by 100
794       this->RenderWindow->SetSize(
795         xs < 150 ? 150 : xs, ys < 100 ? 100 : ys);
796
797       //      std::cout << "wxvtkImageViewer2::Render() : "<<xs<<"-"<<ys<<std::endl;
798       if (this->Renderer)
799         {
800         this->Renderer->ResetCamera();
801         this->Renderer->GetActiveCamera()->SetParallelScale(
802           xs < 150 ? 75 : (xs - 1 ) / 2.0);
803         }
804       this->FirstRender = 0;
805
806       }
807     }
808   if (this->GetInput())
809     {
810     this->RenderWindow->Render();
811     }
812 }
813
814 //----------------------------------------------------------------------------
815 const char* wxvtkImageViewer2::GetWindowName()
816 {
817   return this->RenderWindow->GetWindowName();
818 }
819
820 //----------------------------------------------------------------------------
821 void wxvtkImageViewer2::SetOffScreenRendering(int i)
822 {
823   this->RenderWindow->SetOffScreenRendering(i);
824 }
825
826 //----------------------------------------------------------------------------
827 int wxvtkImageViewer2::GetOffScreenRendering()
828 {
829   return this->RenderWindow->GetOffScreenRendering();
830 }
831
832 //----------------------------------------------------------------------------
833 void wxvtkImageViewer2::SetInput(vtkImageData *in)
834 {
835   //  std::cout << "### wxvtkImageViewer2::SetInput"<<std::endl;
836 //EED 2017-01-01 Migration VTK7
837 #if VTK_MAJOR_VERSION <= 5
838   this->WindowLevel->SetInput(in);
839 #else
840   this->WindowLevel->SetInputData(in);
841 #endif
842
843   this->UpdateDisplayExtent();
844   // LG 03/12/08
845   //  FirstRender = 1;
846 }
847 //----------------------------------------------------------------------------
848 vtkImageData* wxvtkImageViewer2::GetInput()
849 {
850   return vtkImageData::SafeDownCast(this->WindowLevel->GetInput());
851 }
852
853 //----------------------------------------------------------------------------
854 void wxvtkImageViewer2::SetInputConnection(vtkAlgorithmOutput* input)
855 {
856   this->WindowLevel->SetInputConnection(input);
857   this->UpdateDisplayExtent();
858 }
859
860 //----------------------------------------------------------------------------
861 #ifndef VTK_LEGACY_REMOVE
862 int wxvtkImageViewer2::GetWholeZMin()
863 {
864   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::GetWholeZMin, "VTK 5.0",
865                            wxvtkImageViewer2::GetSliceMin);
866   return this->GetSliceMin();
867 }
868 int wxvtkImageViewer2::GetWholeZMax()
869 {
870   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::GetWholeZMax, "VTK 5.0",
871                            wxvtkImageViewer2::GetSliceMax);
872   return this->GetSliceMax();
873 }
874 int wxvtkImageViewer2::GetZSlice()
875 {
876   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::GetZSlice, "VTK 5.0",
877                            wxvtkImageViewer2::GetSlice);
878   return this->GetSlice();
879 }
880 void wxvtkImageViewer2::SetZSlice(int s)
881 {
882   VTK_LEGACY_REPLACED_BODY(wxvtkImageViewer2::SetZSlice, "VTK 5.0",
883                            wxvtkImageViewer2::SetSlice);
884   this->SetSlice(s);
885 }
886 #endif
887
888 //----------------------------------------------------------------------------
889 void wxvtkImageViewer2::PrintSelf(ostream& os, vtkIndent indent)
890 {
891   this->Superclass::PrintSelf(os, indent);
892
893   os << indent << "RenderWindow:\n";
894   this->RenderWindow->PrintSelf(os,indent.GetNextIndent());
895   os << indent << "Renderer:\n";
896   this->Renderer->PrintSelf(os,indent.GetNextIndent());
897   os << indent << "ImageActor:\n";
898   this->ImageActor->PrintSelf(os,indent.GetNextIndent());
899   os << indent << "WindowLevel:\n" << endl;
900   this->WindowLevel->PrintSelf(os,indent.GetNextIndent());
901   os << indent << "Slice: " << this->Slice << endl;
902   os << indent << "SliceOrientation: " << this->SliceOrientation << endl;
903   os << indent << "InteractorStyle: " << endl;
904   if (this->InteractorStyle)
905     {
906     os << "\n";
907     this->InteractorStyle->PrintSelf(os,indent.GetNextIndent());
908     }
909   else
910     {
911     os << "None";
912     }
913 }