]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkBaseView.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkBaseView.cxx
1 #include <vtkRenderer.h>
2 #include <vtkRenderWindowInteractor.h>
3 #include <vtkRenderWindow.h>
4 #include <vtkObjectFactory.h>
5 #include <vtkCamera.h>
6 #include <vtkProperty.h>
7 #include <vtkActor.h>
8 #include <vtkInteractorStyleTrackballCamera.h>
9 #include <vtkInteractorStyleSwitch.h>
10 #include <vtkImageActor.h>
11 #include <vtkTextProperty.h>
12 #include <vtkImageMapToWindowLevelColors.h>
13
14 #include "wxVtkBaseView.h"
15
16
17 vtkStandardNewMacro(vtkInteractorStyleBaseView);
18 vtkStandardNewMacro(vtkInteractorStyleBaseView2D);
19 vtkStandardNewMacro(vtkInteractorStyleBaseView3D);
20
21
22
23 //-------------------------------------------------------------------
24 //-------------------------------------------------------------------
25 //-------------------------------------------------------------------
26 vtkImageViewer2_XYZ::vtkImageViewer2_XYZ()
27 {
28         _vtkimageviewer2=  vtkImageViewer2::New();
29 }
30 //-------------------------------------------------------------------
31 vtkImageViewer2_XYZ::~vtkImageViewer2_XYZ()
32 {
33         //_vtkimageviewer2->Delete();
34 }
35 //-------------------------------------------------------------------
36 void vtkImageViewer2_XYZ::SetExtentDimension(int x1,int x2,
37                                                                                          int y1,int y2,
38                                                                                          int z1,int z2)
39 {
40         _x1=x1;
41         _x2=x2;
42         _y1=y1;
43         _y2=y2;
44         _z1=z1;
45         _z2=z2;
46 }
47 //-------------------------------------------------------------------
48 void vtkImageViewer2_XYZ::SetXSlice(int slice)
49 {
50         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
51         imageActor->SetDisplayExtent(slice, slice, _y1, _y2, _z1, _z2 );  
52 }
53 //-------------------------------------------------------------------
54 void vtkImageViewer2_XYZ::SetYSlice(int slice)
55 {
56         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
57         imageActor->SetDisplayExtent(_x1, _x2, slice, slice, _z1, _z2 );  
58 }
59 //-------------------------------------------------------------------
60 void vtkImageViewer2_XYZ::SetZSlice(int slice)
61 {
62 #if (VTK_MAJOR_VERSION >= 5)
63 //              _vtkimageviewer2->SetSlice( slice );
64         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
65         imageActor->SetDisplayExtent(_x1, _x2, _y1, _y2, slice, slice );  
66 #else
67                 _vtkimageviewer2->SetZSlice( slice );
68 #endif
69
70
71 }
72 //-------------------------------------------------------------------
73 int vtkImageViewer2_XYZ::GetXSlice()
74 {
75         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
76         return imageActor->GetDisplayExtent()[0];
77 }
78 //-------------------------------------------------------------------
79 int vtkImageViewer2_XYZ::GetYSlice()
80 {
81         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
82         return imageActor->GetDisplayExtent()[2];
83 }
84 //-------------------------------------------------------------------
85 int vtkImageViewer2_XYZ::GetZSlice()
86 {
87
88          int result;
89 #if (VTK_MAJOR_VERSION >= 5)
90                 result= _vtkimageviewer2->GetSlice( );
91 #else
92                 result= _vtkimageviewer2->GetZSlice( );
93 #endif
94
95         
96         return result;
97 }
98 //-------------------------------------------------------------------
99 vtkImageViewer2 *vtkImageViewer2_XYZ::GetVtkImageViewer2()
100 {
101         return _vtkimageviewer2;
102 }
103
104
105 //-------------------------------------------------------------------
106 //-------------------------------------------------------------------
107 //-------------------------------------------------------------------
108
109
110
111 BEGIN_EVENT_TABLE( wxVTKRenderWindowInteractorPlus, wxVTKRenderWindowInteractor )
112     EVT_LEFT_DCLICK( wxVTKRenderWindowInteractorPlus::OnLeftDClick )
113     EVT_RIGHT_DCLICK( wxVTKRenderWindowInteractorPlus::OnRightDClick )
114     EVT_MIDDLE_DCLICK( wxVTKRenderWindowInteractorPlus::OnMiddleDClick )
115         EVT_MOUSEWHEEL( wxVTKRenderWindowInteractorPlus::OnMouseWheel )
116 END_EVENT_TABLE( );
117
118 //-------------------------------------------------------------------
119 wxVTKRenderWindowInteractorPlus::wxVTKRenderWindowInteractorPlus() 
120 : wxVTKRenderWindowInteractor()
121 {
122 }
123
124
125 //-------------------------------------------------------------------
126 wxVTKRenderWindowInteractorPlus::wxVTKRenderWindowInteractorPlus(wxWindow *parent, wxVtkBaseView *wxvtkbaseview)
127 : wxVTKRenderWindowInteractor(parent, -1)
128 {
129         _wxvtkbaseview = wxvtkbaseview;
130 }
131
132 //-------------------------------------------------------------------
133 wxVTKRenderWindowInteractorPlus::~wxVTKRenderWindowInteractorPlus()
134 {
135 }
136
137 //---------------------------------------------------------------------------
138 wxVTKRenderWindowInteractorPlus * wxVTKRenderWindowInteractorPlus::New()
139 {
140   // we don't make use of the objectfactory, because we're not registered
141   return new wxVTKRenderWindowInteractorPlus;
142 }
143
144 //-------------------------------------------------------------------
145 void wxVTKRenderWindowInteractorPlus::OnLeftDClick( wxMouseEvent& event )
146 {
147         _wxvtkbaseview->GetInteractorStyleBaseView()->OnLeftDClick();
148 }
149 //-------------------------------------------------------------------
150 void wxVTKRenderWindowInteractorPlus::OnRightDClick( wxMouseEvent& event )
151 {
152         _wxvtkbaseview->GetInteractorStyleBaseView()->OnRightDClick();
153 }
154 //-------------------------------------------------------------------
155 void wxVTKRenderWindowInteractorPlus::OnMiddleDClick( wxMouseEvent& event )
156 {
157         _wxvtkbaseview->GetInteractorStyleBaseView()->OnMiddleDClick();
158 }
159 //-------------------------------------------------------------------
160 void wxVTKRenderWindowInteractorPlus::OnMouseWheel( wxMouseEvent& event )
161 {
162         _wxvtkbaseview->GetInteractorStyleBaseView()->OnMouseWheel();
163 }
164
165
166
167 //-------------------------------------------------------------------
168 //-------------------------------------------------------------------
169 //-------------------------------------------------------------------
170 wxVtkBaseView::wxVtkBaseView()
171 {
172         _parent                         = NULL;
173         _iren                           = NULL;
174         _interactorStyle        = NULL;
175 }
176
177 //-------------------------------------------------------------------
178
179 wxVtkBaseView::wxVtkBaseView(wxWindow *parent)
180 {
181         _parent                         = parent;
182         _iren                           = new wxVTKRenderWindowInteractorPlus(_parent,this);
183 //      _iren->UseCaptureMouseOn();
184 //      _iren                           = new wxVTKRenderWindowInteractor(_parent,-1);
185         _interactorStyle        = NULL;
186
187
188 }
189
190 //-------------------------------------------------------------------
191 wxVtkBaseView::~wxVtkBaseView()
192 {
193  //     _iren -> Delete();
194         _iren=NULL;
195 }
196 //-------------------------------------------------------------------
197 wxVTKRenderWindowInteractor* wxVtkBaseView::GetWxVTKRenderWindowInteractor() throw (char*)
198 {
199
200         if(_iren==NULL){
201                 throw "wxVtkBaseView::GetWxVTKRenderWindowInteractor() _iren wxVTKRenderWindowInteractorPlus =NULL";
202         }
203    return _iren;
204 }
205 //-------------------------------------------------------------------
206 void wxVtkBaseView::Configure()  // virtual 
207 {
208 }
209 //-------------------------------------------------------------------
210 void wxVtkBaseView::Refresh()  // virtual 
211 {
212 // EED 10 Oct 2007
213
214         #if defined(WIN32)
215                 _iren->Refresh(false);
216         #else
217         
218 //EED 01Avril2009
219 //              _iren->Render();        
220         vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
221         vri->vtkRenderWindowInteractor::Render();
222         
223         
224                 //_iren->Refresh();
225         #endif
226
227 }
228 //-------------------------------------------------------------------
229 void wxVtkBaseView::RefreshView()  // virtual 
230 {
231 // EED 10 Oct 2007
232
233         #if defined(WIN32)
234                 GetRenWin()->Render();
235         #else
236                 //GetRenWin()->Render();
237         #endif
238
239 }
240 //---------------------------------------------------------------------------
241 vtkRenderer* wxVtkBaseView::GetRenderer()       // virtual 
242 {
243         return NULL;
244 }
245 //---------------------------------------------------------------------------
246 vtkRenderWindow* wxVtkBaseView::GetRenWin()             // virtual
247 {
248         return _iren->GetRenderWindow();
249 }
250
251 //----------------------------------------------------------------------------
252
253 void wxVtkBaseView::TransfromeCoordScreenToWorld(double &X, double &Y, double &Z, int type) // virtual
254 {  
255         GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
256         GetRenderer()->DisplayToWorld();
257         double fP[4];
258         GetRenderer()->GetWorldPoint( fP );
259         if ( fP[3] ){
260                 fP[0] /= fP[3];
261                 fP[1] /= fP[3];
262                 fP[2] /= fP[3];
263         }
264
265 // EEDx5
266         this->GetInteractorStyleBaseView()->GetWxVtk2DBaseView()->TransformCoordinate_spacing_ViewToModel( fP[0] , fP[1] , fP[2] );
267
268         if (type!=0)
269         {
270                 X=fP[0];
271         }
272         if (type!=1)
273         {
274                 Y=fP[1];
275         }
276         if (type!=2)
277         {
278                 Z=fP[2];
279         } 
280 }
281
282 //---------------------------------------------------------------------------
283
284 vtkInteractorStyleBaseView*     wxVtkBaseView::GetInteractorStyleBaseView()
285 {
286         return _interactorStyle;
287 }
288
289 //---------------------------------------------------------------------------
290
291 void wxVtkBaseView::SetInteractorStyleBaseView( vtkInteractorStyleBaseView*     interactorStyle)
292 {
293         _interactorStyle = interactorStyle;
294 }
295
296 //---------------------------------------------------------------------------
297
298 void wxVtkBaseView::GetSpacing(double spc[3])  // virtual
299 {
300         spc[0]=1;
301         spc[1]=1;
302         spc[2]=1;
303 }
304
305
306 //---------------------------------------------------------------------------
307 //---------------------------------------------------------------------------
308 //---------------------------------------------------------------------------
309
310 InteractorStyleMaracas::InteractorStyleMaracas()
311 {
312         _active                                         = true;
313         _vtkInteractorStyleBaseView     = NULL;
314 }
315 //---------------------------------------------------------------------------
316 InteractorStyleMaracas::~InteractorStyleMaracas()
317 {
318 }
319
320 // ----------------------------------------------------------------------------
321 InteractorStyleMaracas * InteractorStyleMaracas :: Clone()  // virtual 
322 {
323         InteractorStyleMaracas * clone = new InteractorStyleMaracas();
324         CopyAttributesTo(clone);
325         return clone;
326 }
327
328 // ---------------------------------------------------------------------------
329
330 void InteractorStyleMaracas::CopyAttributesTo( InteractorStyleMaracas * cloneObject)
331 {
332         // Fathers object
333         //<FATHERCLASS>::CopyAttributesTo(cloneObject);
334
335         cloneObject->SetActive(  this->GetActive() );
336 }
337
338
339 //---------------------------------------------------------------------------
340 bool InteractorStyleMaracas::OnChar()
341 {
342         return true;
343 }
344 //---------------------------------------------------------------------------
345 bool InteractorStyleMaracas::OnMouseMove()
346 {
347         return true;
348 }
349 //---------------------------------------------------------------------------
350 bool InteractorStyleMaracas::OnLeftButtonDown()
351 {
352         return true;
353 }
354 //---------------------------------------------------------------------------
355 bool InteractorStyleMaracas::OnLeftButtonUp()
356 {
357         return true;
358 }
359 //---------------------------------------------------------------------------
360 bool  InteractorStyleMaracas::OnLeftDClick()
361 {
362         return true;
363 }
364 //---------------------------------------------------------------------------
365 bool InteractorStyleMaracas::OnMiddleButtonDown() 
366 {
367         return true;
368 }
369 //---------------------------------------------------------------------------
370 bool InteractorStyleMaracas::OnMiddleButtonUp()
371 {
372         return true;
373 }
374 //---------------------------------------------------------------------------
375 bool InteractorStyleMaracas::OnMiddleDClick()
376 {
377         return true;
378 }
379 //---------------------------------------------------------------------------
380 bool InteractorStyleMaracas::OnRightButtonDown()
381 {
382         return true;
383 }
384 //---------------------------------------------------------------------------
385 bool InteractorStyleMaracas::OnRightButtonUp()
386 {
387         return true;
388 }
389 //---------------------------------------------------------------------------
390 bool InteractorStyleMaracas::OnRightDClick()
391 {
392         return true;
393 }
394 //---------------------------------------------------------------------------
395 bool InteractorStyleMaracas::OnMouseWheel()
396 {
397         return true;
398 }
399
400 //---------------------------------------------------------------------------
401 void InteractorStyleMaracas::SetVtkInteractorStyleBaseView(vtkInteractorStyleBaseView* vtkInteractorStyleBaseView)
402 {
403         _vtkInteractorStyleBaseView = vtkInteractorStyleBaseView;
404 }
405
406 //---------------------------------------------------------------------------
407 void InteractorStyleMaracas::RemoveVtkInteractorStyleBaseView()
408 {
409         _vtkInteractorStyleBaseView = NULL;
410 }
411 //---------------------------------------------------------------------------
412 void InteractorStyleMaracas::SetActive(bool active)
413 {
414         _active = active;
415 }
416 //---------------------------------------------------------------------------
417 bool InteractorStyleMaracas::GetActive()
418 {
419         return _active;
420 }
421
422
423
424 //-------------------------------------------------------------------
425 //-------------------------------------------------------------------
426 //-------------------------------------------------------------------
427
428 manualInteractorWindowLevel::manualInteractorWindowLevel()
429 {
430         _stateWindowLevel       =       false;
431         _backPx                         =       0;
432         _backPy                         =       0;
433         _backWindow                     =       -1;
434         _backLevel                      =       -1;
435 }
436
437 //-------------------------------------------------------------------
438
439 manualInteractorWindowLevel::~manualInteractorWindowLevel()
440 {
441 }
442
443 //-------------------------------------------------------------------
444
445 bool manualInteractorWindowLevel::OnMouseMove()                 // virtual 
446 {
447
448         if (_stateWindowLevel==true)
449         {
450                 int tmpPx,tmpPy;
451                 wxVTKRenderWindowInteractor *wxVTKiren;
452                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
453                 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
454                 int colorWin=_backWindow - 2*( _backPx - tmpPx );
455                 int colorLev=_backLevel  + 2*( _backPy - tmpPy );       
456
457                 if (colorWin<0)
458                 { 
459                         colorWin=0;
460                 }
461                 if (colorWin>100000)
462                 { 
463                         colorWin=100000;
464                 }       
465
466                 if (colorLev<0)
467                 { 
468                         colorLev=0;
469                 }
470                 if (colorLev>100000)
471                 { 
472                         colorLev=100000;
473                 }
474                 vtkImageViewer2 *vtkimageviewer2;
475                 vtkimageviewer2=_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->_imageViewer2XYZ->GetVtkImageViewer2();
476                 vtkimageviewer2->SetColorWindow(colorWin);
477                 vtkimageviewer2->SetColorLevel(colorLev);
478 //              vtkimageviewer2->Render();
479         }
480         return true;
481 }
482
483 //-------------------------------------------------------------------
484
485 bool manualInteractorWindowLevel::OnMiddleButtonDown()  // virtual 
486 {
487         if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
488                 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ){
489
490                 _stateWindowLevel       = true;
491                 wxVTKRenderWindowInteractor *wxVTKiren;
492                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
493                 wxVTKiren->GetEventPosition( _backPx , _backPy );
494
495                 _backWindow = (int)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorWindow());
496                 _backLevel  = (int)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorLevel());
497         }
498         return true;
499 }
500
501 //-------------------------------------------------------------------
502
503 bool manualInteractorWindowLevel::OnMiddleButtonUp()            // virtual
504 {
505         if (_stateWindowLevel==true)
506         {
507                 _stateWindowLevel=false;
508         }
509         return true;
510 }
511
512
513
514 //---------------------------------------------------------------------------
515 //---------------------------------------------------------------------------
516 //---------------------------------------------------------------------------
517
518 vtkInteractorScrollZ::vtkInteractorScrollZ()
519 {
520         _stateFordware=false;
521 }
522 //---------------------------------------------------------------------------
523 vtkInteractorScrollZ::~vtkInteractorScrollZ()
524 {
525 }
526 //---------------------------------------------------------------------------
527 bool vtkInteractorScrollZ::OnRightButtonDown()
528 {    
529         vtkRenderWindowInteractor *interactor = _vtkInteractorStyleBaseView->GetInteractor();
530         if ((interactor->GetControlKey()==0) && (interactor->GetShiftKey()==0) ){
531                 _stateFordware  = true;
532                 _fordwareX      = interactor->GetEventPosition()[0];
533                 _fordwareY      = interactor->GetEventPosition()[1];
534                 _sliceZ         = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetActualSlice();
535         }
536         return true;
537 }
538 //---------------------------------------------------------------------------
539 bool vtkInteractorScrollZ::OnRightButtonUp() 
540 {
541         _stateFordware=false;
542         return true;
543 }
544 //---------------------------------------------------------------------------
545 bool vtkInteractorScrollZ::OnMouseMove () 
546 {
547         if (_stateFordware==true){
548             //int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];  // JPRx
549         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
550                 int delta = (_fordwareY - fy)/3;
551                 _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->SetActualSlice( _sliceZ + delta);
552
553                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
554
555         //      wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12121);
556         //      _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent);
557
558                 //_wxvtk2Dbaseview->Refresh();
559         } 
560         return true;
561 }
562
563
564
565
566
567 //---------------------------------------------------------------------------
568 //---------------------------------------------------------------------------
569 //---------------------------------------------------------------------------
570
571 vtkInteractorStyleBaseView::vtkInteractorStyleBaseView()
572 {
573         _refresh_waiting                = false;
574         _parent_refresh_waiting = false;
575         _blockRefresh                   = false;
576 }
577 //---------------------------------------------------------------------------
578 vtkInteractorStyleBaseView::~vtkInteractorStyleBaseView()
579 {
580 }
581 //---------------------------------------------------------------------------
582 void vtkInteractorStyleBaseView::OnMouseMove() // virtual 
583 {
584         CallLstInteractorStyleMaracas(3);
585 }
586 //---------------------------------------------------------------------------
587 void vtkInteractorStyleBaseView::OnLeftButtonDown()  // virtual 
588 {
589         CallLstInteractorStyleMaracas(4);
590 }
591 //---------------------------------------------------------------------------
592 void vtkInteractorStyleBaseView::OnLeftButtonUp() // virtual 
593 {
594         CallLstInteractorStyleMaracas(5);
595 }
596
597 //---------------------------------------------------------------------------
598 void vtkInteractorStyleBaseView::OnLeftDClick()  // virtual
599 {
600         CallLstInteractorStyleMaracas( 11 );
601 }
602
603 //---------------------------------------------------------------------------
604 void vtkInteractorStyleBaseView::OnMiddleButtonDown()  // virtual 
605 {
606         CallLstInteractorStyleMaracas(6);
607 }
608 //---------------------------------------------------------------------------
609 void vtkInteractorStyleBaseView::OnMiddleButtonUp() // virtual 
610 {
611         CallLstInteractorStyleMaracas(7);
612 }
613 //---------------------------------------------------------------------------
614 void vtkInteractorStyleBaseView::OnMiddleDClick()  // virtual
615 {
616         CallLstInteractorStyleMaracas( 13 );
617 }
618
619 //---------------------------------------------------------------------------
620 void vtkInteractorStyleBaseView::OnRightButtonDown() // virtual 
621 {
622         CallLstInteractorStyleMaracas(1);
623 }
624 //---------------------------------------------------------------------------
625 void vtkInteractorStyleBaseView::OnRightButtonUp() // virtual 
626 {
627         CallLstInteractorStyleMaracas(2);
628 }
629 //---------------------------------------------------------------------------
630 void vtkInteractorStyleBaseView::OnRightDClick()  // virtual
631 {
632         CallLstInteractorStyleMaracas( 12 );
633 }
634 //---------------------------------------------------------------------------
635 void vtkInteractorStyleBaseView::OnMouseWheel()  // virtual
636 {
637         CallLstInteractorStyleMaracas( 14 );
638 }
639 //---------------------------------------------------------------------------
640 void vtkInteractorStyleBaseView::AddInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
641 {
642         interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
643         _lstInteractorStyleMaracas.push_back(interactorStyleMaracas);
644 }
645 //---------------------------------------------------------------------------
646 void  vtkInteractorStyleBaseView::RemoveInteractorStyleMaracas(InteractorStyleMaracas* interactorStyleMaracas)
647 {
648         interactorStyleMaracas->RemoveVtkInteractorStyleBaseView();
649         int i, size = _lstInteractorStyleMaracas.size();
650         std::vector< InteractorStyleMaracas* >::iterator iter = _lstInteractorStyleMaracas.begin();
651         bool removed = false;
652         for (i=0; !removed && i<size; i++)
653         {
654                 if ( _lstInteractorStyleMaracas[i] == interactorStyleMaracas )
655                 {
656                         _lstInteractorStyleMaracas.erase(iter);
657                         removed = true;
658                 }
659                 iter++;
660         }               
661 }
662 //---------------------------------------------------------------------------
663 void vtkInteractorStyleBaseView::InsertInteractorStyleMaracas(int pos, InteractorStyleMaracas* interactorStyleMaracas)
664 {
665         interactorStyleMaracas->SetVtkInteractorStyleBaseView(this);
666         _lstInteractorStyleMaracas.insert(_lstInteractorStyleMaracas.begin()+pos,interactorStyleMaracas);
667 }
668 //---------------------------------------------------------------------------
669 void vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas(int type)
670 {
671
672         InteractorStyleMaracas *intStyMar;
673
674         int i,size=_lstInteractorStyleMaracas.size();
675
676 //EED Borrame
677 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
678 //fprintf(ff,"EED vtkInteractorStyleBaseView::CallLstInteractorStyleMaracas \n" );
679 //for (i=0;i<size;i++)
680 //{
681 //fprintf(ff,"    %p\n" , _lstInteractorStyleMaracas[i] );
682 //}
683 //fclose(ff);
684
685
686
687         for (i=0;i<size;i++)
688         {
689                 intStyMar = _lstInteractorStyleMaracas[i];
690                 if (intStyMar->GetActive()==true){
691                         if (type ==1)
692                         {  // OnRightButtonDown
693                                 if (intStyMar->OnRightButtonDown()==false)
694                                 {
695                                         i=size;
696                                 }
697                         }
698                         if (type ==2)
699                         {  // OnRightButtonUp
700                                 if (intStyMar->OnRightButtonUp()==false)
701                                 {
702                                         i=size;
703                                 }
704                         }
705                         if (type==3)
706                         {  // OnMouseMouve
707                                 if (intStyMar->OnMouseMove()==false)
708                                 {
709                                         i=size;
710                                 }
711                         }
712                         if (type==4)
713                         {  // OnLeftButtonDown
714                                 if (intStyMar->OnLeftButtonDown()==false)
715                                 {
716                                         i=size;
717                                 }
718                         }
719                         if (type==5)
720                         {  // OnLeftButtonUp
721                                 if (intStyMar->OnLeftButtonUp()==false)
722                                 {
723                                         i=size;
724                                 }
725                         }
726                         if (type==6)
727                         {  // OnMiddleButtonDown
728                                 if (intStyMar->OnMiddleButtonDown()==false)
729                                 {
730                                         i=size;
731                                 }
732                         }
733                         if (type==7)
734                         {  // OnMiddleButtonUp
735                                 if (intStyMar->OnMiddleButtonUp()==false)
736                                 {
737                                         i=size;
738                                 }
739                         }
740                         if (type==10)
741                         {  // OnMiddleButtonUp
742                                 if (intStyMar->OnChar()==false)
743                                 {
744                                         i=size;
745                                 }
746                         }
747                         if (type==11)
748                         {  // OnLeftDClick
749                                 if (intStyMar->OnLeftDClick()==false)
750                                 {
751                                         i=size;
752                                 }
753                         }
754                         if (type==12)
755                         {  // OnRightDClick
756                                 if (intStyMar->OnRightDClick()==false)
757                                 {
758                                         i=size;
759                                 }
760                         }
761                         if (type==13)
762                         {  // OnMiddleDClick
763                                 if (intStyMar-> OnMiddleDClick()==false)
764                                 {
765                                         i=size;
766                                 }
767                         }
768                         if (type==14)
769                         {  // OnMouseWheel
770                                 if (intStyMar->OnMouseWheel()==false)
771                                 {
772                                         i=size;
773                                 }
774                         }
775                 } // if active
776         } // for
777
778         EvaluateToRefresh();
779 }
780 //---------------------------------------------------------------------------
781 void  vtkInteractorStyleBaseView::OnChar()  // virtual 
782 {    
783 //      char a=GetInteractor()->GetKeyCode();
784         CallLstInteractorStyleMaracas(10);
785 }
786 //---------------------------------------------------------------------------
787 void vtkInteractorStyleBaseView::TransformCoordinate(double &X, double &Y, double &Z)
788 {
789     vtkImageViewer2 *imageViewer = GetWxVtk2DBaseView()->_imageViewer2XYZ->GetVtkImageViewer2();
790
791         imageViewer->GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
792         imageViewer->GetRenderer()->DisplayToWorld();
793         double fP[4];
794         imageViewer->GetRenderer()->GetWorldPoint( fP );
795
796         if ( fP[3] ){
797                 fP[0] /= fP[3];
798                 fP[1] /= fP[3];
799                 fP[2] /= fP[3];
800         }
801
802 // EEDx5
803         GetWxVtk2DBaseView()->TransformCoordinate_spacing_ViewToModel(fP[0],fP[1],fP[2]);
804
805         X=fP[0];
806         Y=fP[1];
807         Z=fP[2];
808 }
809 //---------------------------------------------------------------------------
810 void vtkInteractorStyleBaseView::SetwxVtkBaseView(wxVtkBaseView *wxvtkbaseview)
811 {
812         _wxvtkbaseview = wxvtkbaseview;
813 }
814 //---------------------------------------------------------------------------
815 wxVtk2DBaseView* vtkInteractorStyleBaseView::GetWxVtk2DBaseView()
816 {
817         return (wxVtk2DBaseView*)_wxvtkbaseview;
818 }
819 //---------------------------------------------------------------------------
820 wxVtk3DBaseView* vtkInteractorStyleBaseView::GetWxVtk3DBaseView()
821 {
822         return (wxVtk3DBaseView*)_wxvtkbaseview;
823 }
824 //---------------------------------------------------------------------------
825 void vtkInteractorStyleBaseView::SetActiveAllInteractors(bool ok)
826 {
827         InteractorStyleMaracas *intStyMar;
828         int i,size=_lstInteractorStyleMaracas.size();
829         for (i=0;i<size;i++)
830         {
831                 intStyMar = _lstInteractorStyleMaracas[i];
832                 intStyMar->SetActive(ok);
833         }
834
835 }
836 //---------------------------------------------------------------------------
837 void vtkInteractorStyleBaseView::SetRefresh_waiting()
838 {
839         _refresh_waiting=true;
840 }
841 //---------------------------------------------------------------------------
842 bool vtkInteractorStyleBaseView::GetRefresh_waiting()
843 {
844         return _refresh_waiting;
845 }
846 //---------------------------------------------------------------------------
847 void vtkInteractorStyleBaseView::SetParent_refresh_waiting()
848 {
849         _parent_refresh_waiting=true;
850 }
851 //---------------------------------------------------------------------------
852 bool vtkInteractorStyleBaseView::GetParent_refresh_waiting()
853 {
854         return _parent_refresh_waiting;
855 }
856 //---------------------------------------------------------------------------
857 void vtkInteractorStyleBaseView::EvaluateToRefresh()
858 {
859
860         if  ( _blockRefresh==false )
861         {
862                 if ( (_refresh_waiting==true) && (_parent_refresh_waiting==false))
863                 {
864                         _refresh_waiting                = false;
865                         this->_wxvtkbaseview->Refresh();
866                 }
867                 if (_parent_refresh_waiting==true)
868                 {
869                         _parent_refresh_waiting = false;
870                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
871                         this->_wxvtkbaseview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
872                 }
873         }
874 }
875 //---------------------------------------------------------------------------
876 void vtkInteractorStyleBaseView::BlockRefresh()
877 {
878         _blockRefresh=true;
879 }
880 //---------------------------------------------------------------------------
881 void vtkInteractorStyleBaseView::UnBlockRefresh()
882 {
883         _blockRefresh=false;
884 }
885
886 //---------------------------------------------------------------------------
887 //---------------------------------------------------------------------------
888 //---------------------------------------------------------------------------
889
890
891
892 //---------------------------------------------------------------------------
893 vtkInteractorStyleBaseView2D::vtkInteractorStyleBaseView2D()
894 {
895         _manualinteractorwindowlevel= new manualInteractorWindowLevel();
896         AddInteractorStyleMaracas( _manualinteractorwindowlevel );
897
898         _vtkInteractorScrollZ = new vtkInteractorScrollZ();
899         AddInteractorStyleMaracas(_vtkInteractorScrollZ);
900         
901 }
902 //---------------------------------------------------------------------------
903 vtkInteractorStyleBaseView2D::~vtkInteractorStyleBaseView2D()
904 {
905 }
906
907 //---------------------------------------------------------------------------
908 void  vtkInteractorStyleBaseView2D::OnRightButtonDown()  // virtual
909 {    
910         vtkInteractorStyleBaseView::OnRightButtonDown();
911
912         if ((GetInteractor()->GetControlKey()==1) && (GetInteractor()->GetShiftKey()==0) ){
913                 this->vtkInteractorStyleImage::OnRightButtonDown();
914         }
915
916 }
917
918 //---------------------------------------------------------------------------
919 void  vtkInteractorStyleBaseView2D::OnRightButtonUp()  // virtual
920 {
921         vtkInteractorStyleBaseView::OnRightButtonUp();
922         this->vtkInteractorStyleImage::OnRightButtonUp();
923 }
924 //---------------------------------------------------------------------------
925 void  vtkInteractorStyleBaseView2D::OnMouseMove () // virtual
926 {
927         vtkInteractorStyleBaseView::OnMouseMove();
928         this->vtkInteractorStyleImage::OnMouseMove();
929 }
930 //---------------------------------------------------------------------------
931 void  vtkInteractorStyleBaseView2D::OnLeftButtonDown() // virtual
932 {
933         vtkInteractorStyleBaseView::OnLeftButtonDown();
934
935         if ((GetInteractor()->GetControlKey()==0) && (GetInteractor()->GetShiftKey()==1) )
936         {
937                 this->vtkInteractorStyleImage::OnLeftButtonDown();
938         }
939 }
940 //---------------------------------------------------------------------------
941 void  vtkInteractorStyleBaseView2D::OnLeftButtonUp () // virtual
942 {
943         vtkInteractorStyleBaseView::OnLeftButtonUp();
944
945         this->vtkInteractorStyleImage::OnLeftButtonUp();
946 }
947 //---------------------------------------------------------------------------
948 void  vtkInteractorStyleBaseView2D::OnMiddleButtonDown () // virtual
949 {
950         vtkInteractorStyleBaseView::OnMiddleButtonDown();
951
952         if ((GetInteractor()->GetControlKey()==1) || (GetInteractor()->GetShiftKey()==1) )
953         {
954                 this->vtkInteractorStyleImage::OnLeftButtonDown();
955         }
956 }
957 //---------------------------------------------------------------------------
958 void vtkInteractorStyleBaseView2D::OnMiddleButtonUp () // virtual
959 {
960         vtkInteractorStyleBaseView::OnMiddleButtonUp();
961
962         if ((GetInteractor()->GetControlKey()==1) || (GetInteractor()->GetShiftKey()==1) )
963         {
964                 this->vtkInteractorStyleImage::OnLeftButtonUp();
965         }
966 }
967
968
969
970 //-------------------------------------------------------------------
971 //-------------------------------------------------------------------
972 //-------------------------------------------------------------------
973
974
975 //---------------------------------------------------------------------------
976 vtkInteractorStyleBaseView3D::vtkInteractorStyleBaseView3D(){
977 }
978 //---------------------------------------------------------------------------
979 vtkInteractorStyleBaseView3D::~vtkInteractorStyleBaseView3D(){
980 }
981 //---------------------------------------------------------------------------
982 void  vtkInteractorStyleBaseView3D::OnRightButtonDown ()
983 {    
984         vtkInteractorStyleBaseView::OnRightButtonDown();
985
986 /*
987                 if (GetInteractor()->GetControlKey()==1 ){
988                         this->vtkInteractorStyleTrackballCamera::OnRightButtonDown();
989                 }
990 */
991   this->FindPokedRenderer(this->Interactor->GetEventPosition()[0], 
992                           this->Interactor->GetEventPosition()[1]);
993
994   if (this->CurrentRenderer == NULL)
995     {
996     return;
997     }
998
999   if (this->Interactor->GetControlKey()) {
1000       this->StartDolly();
1001   }
1002
1003 }
1004 //---------------------------------------------------------------------------
1005 void  vtkInteractorStyleBaseView3D::OnRightButtonUp () 
1006 {
1007         vtkInteractorStyleBaseView::OnRightButtonUp();
1008
1009 /*
1010                 if (GetInteractor()->GetControlKey()==1 ){
1011                         this->vtkInteractorStyleTrackballCamera::OnRightButtonUp();
1012                 }
1013 */
1014
1015                 
1016   switch (this->State) 
1017     {
1018     case VTKIS_DOLLY:
1019       this->EndDolly();
1020       break;
1021     }
1022 }
1023 //---------------------------------------------------------------------------
1024 void  vtkInteractorStyleBaseView3D::OnMouseMove () 
1025 {
1026         vtkInteractorStyleBaseView::OnMouseMove();
1027
1028 //              this->vtkInteractorStyleTrackballCamera::OnMouseMove();
1029
1030  // int x = this->Interactor->GetEventPosition()[0]; // JPRx
1031  // int y = this->Interactor->GetEventPosition()[1]; // JPRx
1032
1033
1034  // vtkRenderWindowInteractor *rwi = this->Interactor;
1035
1036  // int lx =  rwi->GetLastEventPosition()[0]; // JPRx
1037  // int ly =  rwi->GetLastEventPosition()[1]; // JPRx
1038  // int dx = rwi->GetEventPosition()[0] ; // JPRx
1039  // int dy = rwi->GetEventPosition()[1] ; // JPRx
1040
1041
1042   switch (this->State) 
1043     {
1044     case VTKIS_ROTATE:
1045  //     this->FindPokedRenderer(x, y);
1046       this->Rotate();
1047  //     this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
1048       break;
1049
1050     case VTKIS_PAN:
1051  //     this->FindPokedRenderer(x, y);
1052       this->Pan();
1053  //     this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
1054       break;
1055
1056     case VTKIS_DOLLY:
1057  //     this->FindPokedRenderer(x, y);
1058       this->Dolly();
1059  //     this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
1060       break;
1061
1062     case VTKIS_SPIN:
1063  //     this->FindPokedRenderer(x, y);
1064       this->Spin();
1065  //     this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
1066       break;
1067     }
1068
1069
1070
1071 }
1072 //---------------------------------------------------------------------------
1073 void  vtkInteractorStyleBaseView3D::OnLeftButtonDown ()
1074 {
1075         vtkInteractorStyleBaseView::OnLeftButtonDown();
1076 /*
1077                 if (GetInteractor()->GetControlKey()==1 ){
1078                         this->vtkInteractorStyleTrackballCamera::OnMiddleButtonDown();
1079                 } else {
1080                         this->vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
1081                 }
1082 */
1083
1084
1085   this->FindPokedRenderer(this->Interactor->GetEventPosition()[0], 
1086                           this->Interactor->GetEventPosition()[1]);
1087   if (this->CurrentRenderer == NULL)
1088     {
1089     return;
1090     }
1091
1092   if (this->Interactor->GetControlKey()) {
1093       this->StartPan();
1094   } else {
1095       this->StartRotate();
1096   }
1097
1098  /* 
1099   if (this->Interactor->GetShiftKey()) 
1100     {
1101     if (this->Interactor->GetControlKey()) 
1102       {
1103       this->StartDolly();
1104       }
1105     else 
1106       {
1107       this->StartPan();
1108       }
1109     } 
1110   else 
1111     {
1112     if (this->Interactor->GetControlKey()) 
1113       {
1114       this->StartSpin();
1115       }
1116     else 
1117       {
1118       this->StartRotate();
1119       }
1120     }
1121 */
1122
1123
1124 }
1125 //---------------------------------------------------------------------------
1126 void  vtkInteractorStyleBaseView3D::OnLeftButtonUp () 
1127 {
1128         vtkInteractorStyleBaseView::OnLeftButtonUp();
1129
1130 /*
1131                 if (GetInteractor()->GetControlKey()==1 ){
1132                         this->vtkInteractorStyleTrackballCamera::OnMiddleButtonUp();
1133                 } else {
1134                         this->vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
1135                 }
1136 */
1137   switch (this->State) 
1138     {
1139
1140     case VTKIS_PAN:
1141       this->EndPan();
1142       break;
1143
1144     case VTKIS_ROTATE:
1145       this->EndRotate();
1146       break;
1147     }
1148 }
1149 //---------------------------------------------------------------------------
1150 void  vtkInteractorStyleBaseView3D::OnMiddleButtonDown () 
1151 {
1152         vtkInteractorStyleBaseView::OnMiddleButtonDown();
1153         //              this->vtkInteractorStyleTrackballCamera::OnMiddleButtonDown();
1154 }
1155 //---------------------------------------------------------------------------
1156 void  vtkInteractorStyleBaseView3D::OnMiddleButtonUp () 
1157 {
1158         vtkInteractorStyleBaseView::OnMiddleButtonUp();
1159
1160         //              this->vtkInteractorStyleTrackballCamera::OnMiddleButtonUp();
1161 }
1162
1163
1164 //-------------------------------------------------------------------
1165 //-------------------------------------------------------------------
1166 //-------------------------------------------------------------------
1167
1168 vtkInfoTextImage::vtkInfoTextImage()
1169 {
1170         _vtkText_WindowLevel    = NULL;
1171         _vtkText_ColorLevel             = NULL;
1172         _vtkText_position               = NULL;
1173         _vtkText_pixelIntensity = NULL;
1174         _marimagedata                   = NULL;
1175 }
1176
1177 //-------------------------------------------------------------------
1178
1179 vtkInfoTextImage::~vtkInfoTextImage()
1180 {
1181 }
1182
1183 //-------------------------------------------------------------------
1184
1185 void vtkInfoTextImage::Configure()
1186 {
1187         _vtkText_WindowLevel    = Create_Text_Label( 10 , 55 );
1188         _vtkText_ColorLevel             = Create_Text_Label( 10 , 40 );
1189         _vtkText_position               = Create_Text_Label( 10 , 25 );
1190         _vtkText_pixelIntensity = Create_Text_Label( 10 , 10 );
1191 }
1192
1193
1194 //-------------------------------------------------------------------
1195
1196 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
1197 {
1198         _marimagedata=marimagedata;
1199 }
1200
1201 //-------------------------------------------------------------------
1202
1203 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
1204 {
1205         _wxvtk2Dbaseview=wxvtk2Dbaseview;
1206 }
1207
1208 //-------------------------------------------------------------------
1209
1210 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
1211 {
1212         // Text Window Level
1213         vtkTextActor *textActor = vtkTextActor::New();
1214         textActor->SetDisplayPosition(px, py);
1215         textActor->SetInput("0");
1216
1217         // Set coordinates to match the old vtkScaledTextActor default value
1218         textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
1219         textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
1220
1221         vtkTextProperty *tprop = textActor->GetTextProperty();
1222         tprop->SetFontSize(14);
1223         tprop->SetFontFamilyToArial();
1224         tprop->SetColor(1, 1, 0);
1225         _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
1226
1227         return textActor;
1228 }
1229
1230 //-------------------------------------------------------------------
1231
1232 void vtkInfoTextImage::PutWindowLevel()
1233 {
1234         int value = (int)( _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() );
1235         char zTzxt[20];
1236         char resultText[50];
1237
1238         strcpy(resultText,"w:");
1239
1240
1241         //ltoa ( (long)value , zTzxt , 10 );
1242         sprintf(zTzxt,"%d",value);
1243
1244         strcat(resultText,zTzxt);
1245         _vtkText_WindowLevel            -> SetInput(resultText);
1246 }
1247
1248 //-------------------------------------------------------------------
1249
1250 void vtkInfoTextImage::PutColorLevel()
1251 {
1252         int value = (int)(_wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel());
1253         char zTzxt[20];
1254         char resultText[50];
1255
1256         strcpy(resultText,"c:");
1257
1258 //      itoa (value,zTzxt,10);
1259         sprintf(zTzxt,"%d",value);
1260
1261         strcat(resultText,zTzxt);
1262         _vtkText_ColorLevel             -> SetInput(resultText);
1263 }
1264
1265 //-------------------------------------------------------------------
1266
1267 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
1268 {
1269
1270 //EEDx7
1271 //      double spa[3];
1272 //      _imagedata->GetSpacing(spa);
1273 //      xx=xx*(1/spa[0]);
1274 //      yy=yy*(1/spa[1]);
1275
1276
1277         char zTzxt[50];
1278         char resultText[50];
1279         strcpy(resultText,"p: ");
1280 //      itoa ((int)xx,zTzxt,10);
1281         sprintf(zTzxt,"%d",xx);
1282
1283         strcat(resultText,zTzxt);
1284         strcat(resultText," , ");
1285
1286 //      itoa ((int)yy,zTzxt,10);
1287         sprintf(zTzxt,"%d",yy);
1288
1289         strcat(resultText,zTzxt);
1290         strcat(resultText," , ");
1291
1292 //      itoa ((int)zz,zTzxt,10);
1293         sprintf(zTzxt,"%d",zz);
1294
1295         strcat(resultText,zTzxt);
1296
1297
1298         
1299         int nX = _marimagedata->GetXOriginal(xx);
1300         int nY = _marimagedata->GetYOriginal(yy);
1301         int nZ = _marimagedata->GetZOriginal(zz);
1302
1303         strcat(resultText,"   (");
1304 //      ltoa ((int)nX,zTzxt,10);
1305         sprintf(zTzxt,"%d",nX);
1306
1307         strcat(resultText,zTzxt);
1308         strcat(resultText,",");
1309
1310 //      ltoa ((int)nY,zTzxt,10);
1311         sprintf(zTzxt,"%d",nY);
1312
1313         strcat(resultText,zTzxt);
1314         strcat(resultText,",");
1315
1316 //      ltoa ((int)nZ,zTzxt,10);
1317         sprintf(zTzxt,"%d",nZ);
1318
1319         strcat(resultText,zTzxt);
1320         strcat(resultText,")");
1321
1322
1323
1324
1325         _vtkText_position               -> SetInput(resultText);
1326 }
1327
1328 //-------------------------------------------------------------------
1329
1330 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
1331 {
1332
1333 //EEDx2
1334         bool ok=true;
1335
1336         int dim[3];
1337         double spa[3];
1338         vtkImageData *imagedata = _marimagedata->GetImageData();
1339         imagedata->GetDimensions(dim);
1340         imagedata->GetSpacing(spa);
1341
1342 // EEDx7
1343 //      xx=xx*(1/spa[0]);
1344 //      yy=yy*(1/spa[1]);
1345 //      zz=xx*spa[2];
1346
1347         if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
1348         {
1349                 ok=false;
1350         }
1351
1352         
1353         char zTzxt[20];
1354         char resultText[50];
1355         strcpy(resultText,"GL: ");
1356         if (ok==true) 
1357         {
1358                 if (imagedata->GetScalarType()==VTK_BIT)
1359                 {
1360                         char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1361         //              itoa (*pOrg,zTzxt,10);
1362                         if(*pOrg==0)
1363                         {
1364                                 sprintf(zTzxt,"%d",0);
1365                         }
1366                         else
1367                         {
1368                                 sprintf(zTzxt,"%d",1);
1369                         }
1370                 }
1371         
1372                 if (imagedata->GetScalarType()==VTK_CHAR)
1373                 {
1374                         char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1375         //              itoa (*pOrg,zTzxt,10);
1376                         int tmp=*pOrg;
1377                         sprintf(zTzxt,"%d",tmp);
1378                 }
1379
1380                 if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
1381                 {
1382                         signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1383         //              itoa (*pOrg,zTzxt,10);
1384                         int tmp=*pOrg;
1385                         sprintf(zTzxt,"%d",tmp);
1386                 }
1387
1388                 if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
1389                 {
1390                         unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1391         //              itoa (*pOrg,zTzxt,10);
1392                         int tmp=*pOrg;
1393                         sprintf(zTzxt,"%d",tmp);
1394                 }
1395
1396                 if (imagedata->GetScalarType()==VTK_SHORT)
1397                 {
1398                         short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1399         //              itoa (*pOrg,zTzxt,10);
1400                         int tmp=*pOrg;
1401                         sprintf(zTzxt,"%d",tmp);
1402                 }
1403
1404                 if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
1405                 {
1406                         unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1407         //              itoa (*pOrg,zTzxt,10);
1408                         int tmp=*pOrg;
1409                         sprintf(zTzxt,"%d",tmp);
1410                 }
1411         
1412                 if (imagedata->GetScalarType()==VTK_INT)
1413                 {
1414                         int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1415         //              itoa (*pOrg,zTzxt,10);
1416                         sprintf(zTzxt,"%d",*pOrg);
1417                 }
1418
1419                 if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
1420                 {
1421                         unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1422         //              itoa (*pOrg,zTzxt,10);
1423                         int tmp=*pOrg;
1424                         sprintf(zTzxt,"%d",tmp);
1425                 }
1426
1427                 if (imagedata->GetScalarType()==VTK_LONG)
1428                 {
1429                         long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1430         //              itoa (*pOrg,zTzxt,10);
1431                         double tmp=*pOrg;
1432                         sprintf(zTzxt,"%3.2f",tmp);
1433                 }
1434
1435                 if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
1436                 {
1437                         unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1438         //              itoa (*pOrg,zTzxt,10);
1439                         double tmp=*pOrg;
1440                         sprintf(zTzxt,"%3.2f",tmp);
1441                 }
1442
1443                 if (imagedata->GetScalarType()==VTK_FLOAT)
1444                 {
1445                         long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1446         //              itoa (*pOrg,zTzxt,10);
1447                         double tmp=*pOrg;
1448                         sprintf(zTzxt,"%3.2f",tmp);
1449                 }
1450
1451                 if (imagedata->GetScalarType()==VTK_DOUBLE)
1452                 {
1453                         double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
1454         //              itoa (*pOrg,zTzxt,10);
1455                         double tmp=*pOrg;
1456                         sprintf(zTzxt,"%3.2f",tmp);
1457                 }
1458         } 
1459         else 
1460         {
1461                 strcpy(zTzxt,"---");
1462         }
1463         strcat(resultText,zTzxt);
1464         _vtkText_pixelIntensity -> SetInput(resultText);
1465 }
1466
1467
1468
1469 //-------------------------------------------------------------------
1470 //-------------------------------------------------------------------
1471 //-------------------------------------------------------------------
1472
1473 vtkInfoTextImageInteractor::vtkInfoTextImageInteractor()
1474 {
1475 }
1476
1477 //-------------------------------------------------------------------
1478 vtkInfoTextImageInteractor::~vtkInfoTextImageInteractor()
1479 {
1480 }
1481
1482 //-------------------------------------------------------------------
1483
1484 void vtkInfoTextImageInteractor::SetModelVtkInfoTextImage(vtkInfoTextImage *vtkinfotextimage)
1485 {
1486         _vtkinfotextimage       = vtkinfotextimage;
1487 }
1488
1489 //-------------------------------------------------------------------
1490 bool vtkInfoTextImageInteractor::OnMouseMove()
1491 {
1492         int X,Y;
1493         wxVTKRenderWindowInteractor *wxVTKiren;
1494         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1495         wxVTKiren->GetEventPosition(X,Y);
1496
1497         int z = (int)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetVtkBaseData()->GetZ());
1498         double xx=X,yy=Y,zz=z;
1499         _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->TransfromeCoordScreenToWorld(xx,yy,zz);
1500
1501         GetVtkInfoTextImage()->PutWindowLevel();
1502         GetVtkInfoTextImage()->PutColorLevel();
1503         GetVtkInfoTextImage()->PutPosition( (int)xx , (int)yy , (int)zz );
1504         GetVtkInfoTextImage()->PutPixelIntensity( (int)xx , (int)yy , (int)zz );
1505
1506         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1507         return true;
1508 }
1509
1510 //-------------------------------------------------------------------
1511 vtkInfoTextImage *vtkInfoTextImageInteractor::GetVtkInfoTextImage()
1512 {
1513         return _vtkinfotextimage;
1514 }
1515
1516
1517 //-------------------------------------------------------------------
1518 //-------------------------------------------------------------------
1519 //-------------------------------------------------------------------
1520
1521
1522 wxVtk2DBaseView::wxVtk2DBaseView(wxWindow *parent)
1523 :wxVtkBaseView(parent)
1524 {
1525         _imageViewer2XYZ        = NULL;
1526         _vtkIinfoTextImage      = NULL;
1527 }
1528
1529 //EED 5mai2009
1530 //-------------------------------------------------------------------
1531 wxVtk2DBaseView::~wxVtk2DBaseView()
1532 {       
1533         if (_vtkIinfoTextImage!=NULL) 
1534         {
1535                 delete _vtkIinfoTextImage; 
1536         }
1537
1538         if (_imageViewer2XYZ!=NULL) 
1539         {
1540                 delete _imageViewer2XYZ; 
1541         }
1542 }
1543
1544 //-------------------------------------------------------------------
1545 void wxVtk2DBaseView::TransformCoordinate_spacing_ViewToModel(double &X,double &Y, double &Z) //        virtual 
1546 {
1547 //EEDx5
1548         double spc[3];
1549 //      GetVtkBaseData()->GetImageData()->GetSpacing(spc);
1550         this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
1551
1552         X = X / spc[0];
1553         Y = Y / spc[1];
1554         Z = Z / spc[2];
1555
1556 }
1557
1558 //-------------------------------------------------------------------
1559 void wxVtk2DBaseView::TransformCoordinate_spacing_ModelToView(double &X,double &Y, double &Z) //        virtual 
1560 {
1561 //EEDx5
1562         double spc[3];
1563 //      GetVtkBaseData()->GetImageData()->GetSpacing(spc);
1564         this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
1565
1566         X=X*spc[0];
1567         Y=Y*spc[1];
1568         Z=Z*spc[2];
1569
1570 }
1571
1572 //-------------------------------------------------------------------
1573 void wxVtk2DBaseView::ResetView()
1574 {
1575         double spx,spy,spz;
1576         int x1,x2,y1,y2,z1,z2;
1577         wxVtkBaseView::Configure();
1578         
1579         wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
1580         vtkImageData *imageData = GetVtkBaseData()->GetImageData();
1581         imageData->UpdateInformation();
1582         imageData->SetUpdateExtent( imageData->GetWholeExtent());
1583         imageData->Update();
1584
1585         _imageViewer2XYZ->GetVtkImageViewer2()->SetInput(imageData );
1586         imageData->GetSpacing (spx,spy,spz);
1587         imageData->GetExtent (x1,x2,y1,y2,z1,z2);
1588         _imageViewer2XYZ -> SetExtentDimension(x1,x2,y1,y2,z1,z2);
1589         _imageViewer2XYZ -> GetVtkImageViewer2()->SetupInteractor ( iren );
1590
1591         _imageViewer2XYZ->GetVtkImageViewer2()->Render();
1592         SetInteractorStyleImage( vtkInteractorStyleBaseView2D::New() );
1593         
1594 }
1595
1596
1597 //-------------------------------------------------------------------
1598 void wxVtk2DBaseView::Configure(bool okimage)
1599 {
1600         double spx,spy,spz;
1601         int x1,x2,y1,y2,z1,z2;
1602         wxVtkBaseView::Configure();
1603
1604 // EED 17 Oct 2007
1605                         if (_imageViewer2XYZ==NULL)
1606                         {
1607                                 _imageViewer2XYZ = new vtkImageViewer2_XYZ();
1608                                 wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
1609                                 _imageViewer2XYZ -> GetVtkImageViewer2()->SetupInteractor ( iren );
1610                                 SetInteractorStyleImage( vtkInteractorStyleBaseView2D::New() );
1611                         }
1612
1613
1614         vtkImageData *imageData = GetVtkBaseData()->GetMarImageData()->GetImageData();
1615         if (imageData!=NULL){
1616                 imageData->UpdateInformation();
1617                 imageData->SetUpdateExtent( imageData->GetWholeExtent());
1618                 imageData->Update();
1619                 if (okimage==true){
1620                         imageData->GetSpacing (spx,spy,spz);
1621                         imageData->GetExtent (x1,x2,y1,y2,z1,z2);
1622
1623
1624                         _imageViewer2XYZ->GetVtkImageViewer2()->SetInput(imageData );
1625                         _imageViewer2XYZ->SetExtentDimension(x1,x2,y1,y2,z1,z2);
1626                         double range[2];
1627                           imageData->GetScalarRange(range);
1628                           if (range[1]<20000){
1629                                  _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow( (range[1]-range[0])/2 );
1630                                  _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel( (range[1]+range[0])/4 );
1631                           } else {
1632                                  _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow( 1000 );
1633                                  _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel( 500 );
1634                           }
1635 // EED 31 Janvier 2007
1636 //vtkImageActor *vtkimageactor = _imageViewer2XYZ->GetVtkImageViewer2()->GetImageActor ();
1637 //vtkimageactor->InterpolateOff ();
1638 //vtkLookupTable * _collookup = vtkLookupTable::New( );
1639 //_collookup->SetNumberOfColors( 256 );
1640 //_collookup->SetTableRange( 0 , 255 );
1641 //_collookup->Build( );
1642 //_collookup->SetTableValue( 0  , 1 , 0 , 0 , 1 );
1643 //_collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
1644 //_collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
1645 //_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel ()->SetLookupTable(_collookup );
1646
1647
1648 // EED 17 Oct 2007
1649 //                      SetInteractorStyleImage( vtkInteractorStyleBaseView2D::New() );
1650
1651
1652                         vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2();
1653                         vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera();
1654
1655 //EED 17Avril2009       
1656 /*                      
1657                         camera->SetViewUp               ( spx*0                 , -spy*1                        , spz*0         );
1658                         camera->SetPosition             ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , -spz*10000    ); 
1659                         camera->SetFocalPoint   ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0         ); 
1660 */ 
1661                         camera->SetViewUp               ( spx*0                 , spy*1                 , spz*0         );
1662                         camera->SetPosition             ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*10000     ); 
1663                         camera->SetFocalPoint   ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0         ); 
1664                         
1665                         
1666                         camera->SetClippingRange( 0.01                  , 1000000 );
1667                         camera->ComputeViewPlaneNormal();
1668                         camera->SetParallelScale( spx*(x2-x1)/3.0 );
1669                         
1670                         // text information over the graphic window
1671                         _vtkIinfoTextImage                              = new vtkInfoTextImage();
1672                         _vtkIinfoTextImageInteractor    = new vtkInfoTextImageInteractor();
1673                         _vtkIinfoTextImage->SetWxVtk2DBaseView(this);
1674                         _vtkIinfoTextImage->SetMarImageData( GetVtkBaseData()->GetMarImageData() );
1675                         _vtkIinfoTextImageInteractor->SetModelVtkInfoTextImage(_vtkIinfoTextImage);     
1676                         _vtkIinfoTextImage->Configure();
1677                         this->GetInteractorStyleBaseView()->AddInteractorStyleMaracas(_vtkIinfoTextImageInteractor);
1678                 } // okimage
1679         } // imageData
1680
1681 }
1682
1683 //-------------------------------------------------------------------
1684
1685 int     wxVtk2DBaseView::GetActualSlice()  // virtual 
1686 {
1687         return (int)(_vtkbasedata->GetZ());
1688 }
1689
1690 //-------------------------------------------------------------------
1691 void wxVtk2DBaseView::SetActualSlice(int slice)  // Virtual
1692 {
1693         _vtkbasedata->SetZ(slice);
1694 }
1695
1696 //-------------------------------------------------------------------
1697
1698 vtkBaseData *wxVtk2DBaseView::GetVtkBaseData()
1699 {
1700         return _vtkbasedata;
1701 }
1702
1703 //-------------------------------------------------------------------
1704
1705 void wxVtk2DBaseView::SetVtkBaseData(vtkBaseData *vtkbasedata)
1706 {
1707         _vtkbasedata=vtkbasedata;
1708 }
1709
1710 //-------------------------------------------------------------------
1711
1712 void wxVtk2DBaseView::Refresh()
1713 {
1714         int z = (int)(GetVtkBaseData()->GetZ());
1715         _imageViewer2XYZ->SetZSlice( z ); 
1716
1717         wxVtkBaseView::Refresh();
1718 }
1719
1720 //-------------------------------------------------------------------
1721
1722 void wxVtk2DBaseView::SetInteractorStyleImage(vtkInteractorStyleBaseView *interactorstylebaseview)
1723 {
1724         SetInteractorStyleBaseView(interactorstylebaseview);
1725
1726         wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
1727         interactorstylebaseview->SetInteractor ( iren );
1728         iren->SetInteractorStyle(interactorstylebaseview);
1729         interactorstylebaseview->SetwxVtkBaseView(this);        
1730
1731         vtkMaracasImageViewer2Callback * cbk = vtkMaracasImageViewer2Callback::New();
1732         cbk->IV = _imageViewer2XYZ->GetVtkImageViewer2();
1733         interactorstylebaseview->AddObserver( vtkCommand::WindowLevelEvent, cbk );
1734         interactorstylebaseview->AddObserver( vtkCommand::StartWindowLevelEvent, cbk );
1735         interactorstylebaseview->AddObserver( vtkCommand::ResetWindowLevelEvent, cbk );
1736         cbk->Delete();
1737 }
1738
1739 //---------------------------------------------------------------------------
1740 vtkRenderer* wxVtk2DBaseView::GetRenderer()     // virtual 
1741 {
1742         return  _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer();
1743 }
1744 //---------------------------------------------------------------------------
1745 vtkRenderWindow* wxVtk2DBaseView::GetRenWin()           // virtual
1746 {
1747         return  _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderWindow();
1748 }
1749
1750 //-------------------------------------------------------------------
1751
1752 void wxVtk2DBaseView::GetSpacing(double spc[3])  // virtual
1753 {
1754         vtkImageData *imageData = GetVtkBaseData()->GetImageData();
1755         imageData->GetSpacing(spc);
1756 }
1757
1758 //-------------------------------------------------------------------
1759 //-------------------------------------------------------------------
1760 //-------------------------------------------------------------------
1761
1762
1763
1764
1765 wxVtk3DBaseView::wxVtk3DBaseView(wxWindow *parent)
1766 :wxVtkBaseView( parent )
1767 {
1768         _configure      = false;
1769         _aRenderer      = NULL;
1770         _renWin         = NULL;
1771         _aCamera        = NULL;
1772 }
1773 //-------------------------------------------------------------------
1774 wxVtk3DBaseView::~wxVtk3DBaseView()
1775 {
1776         if (_aCamera!=NULL)             { _aCamera              -> Delete(); }
1777         if (_aRenderer!=NULL)   { _aRenderer    -> Delete(); }
1778         if (_renWin!=NULL)              { _renWin               -> Delete(); }
1779 }
1780 //-------------------------------------------------------------------
1781 vtkCamera* wxVtk3DBaseView::GetCamera()
1782 {
1783         return _aCamera;
1784 }
1785 //-------------------------------------------------------------------
1786 vtkRenderer* wxVtk3DBaseView::GetRenderer()  // virtual
1787 {
1788         return _aRenderer;
1789 }
1790 //-------------------------------------------------------------------
1791 vtkRenderWindow* wxVtk3DBaseView::GetRenWin()  // virtual
1792 {
1793         return _renWin;
1794 }
1795 //-------------------------------------------------------------------
1796 void wxVtk3DBaseView::Refresh()
1797 {
1798 //      _renWin->Render();
1799         vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
1800         vri->vtkRenderWindowInteractor::Render();
1801 }
1802 //-------------------------------------------------------------------
1803 void wxVtk3DBaseView::Configure()
1804 {
1805         if (_configure==false)
1806         {
1807                 _configure=true;
1808                 //wxVtkBaseView::Configure();
1809                 _aRenderer      = vtkRenderer::New();
1810                 _renWin         = vtkRenderWindow::New();
1811                 _renWin->AddRenderer(_aRenderer);
1812
1813
1814 //       _renWin->SetStereoCapableWindow(1);
1815 // //      //renderwindow->SetStereoTypeToCrystalEyes();  
1816 //       _renWin->SetStereoTypeToRedBlue();
1817 //       _renWin->SetStereoRender(1);
1818
1819                 GetWxVTKRenderWindowInteractor()->SetRenderWindow(_renWin);
1820
1821
1822 // EED Borrame
1823 //              vtkInteractorStyle3DMaracas *interactorStyle3DMaracas = vtkInteractorStyle3DMaracas::New(); 
1824                 vtkInteractorStyleBaseView3D *interactorStyleBaseView3D = vtkInteractorStyleBaseView3D::New(); 
1825
1826                 SetInteractorStyleBaseView( interactorStyleBaseView3D );
1827                 interactorStyleBaseView3D->SetInteractor (  GetWxVTKRenderWindowInteractor() );
1828                 GetWxVTKRenderWindowInteractor()->SetInteractorStyle( interactorStyleBaseView3D );
1829                 interactorStyleBaseView3D->SetwxVtkBaseView(this);      
1830
1831
1832 /* EED Borrame
1833   vtkInteractorStyleSwitch *iss = dynamic_cast<vtkInteractorStyleSwitch*>(_iren->GetInteractorStyle());
1834   iss->SetCurrentStyleToTrackballCamera();
1835 */
1836
1837                 // It is convenient to create an initial view of the data. The
1838                 // FocalPoint and Position form a vector direction. Later on
1839                 // (ResetCamera() method) this vector is used to position the camera
1840                 // to look at the data in this direction.
1841                 _aCamera = vtkCamera::New();
1842
1843 //EED 17Avril2009       
1844 /*
1845                 _aCamera->SetViewUp (0, 0, -1);
1846                 _aCamera->SetPosition (0, 1, 0);
1847  */
1848                 _aCamera->SetViewUp (0, 1, 0);
1849                 _aCamera->SetPosition (0, 0, 1);
1850                 
1851                 _aCamera->SetFocalPoint (0, 0, 0);
1852                 _aCamera->ComputeViewPlaneNormal();
1853
1854         }
1855 }
1856 //-------------------------------------------------------------------
1857 //EED 27 sep 2006
1858 void wxVtk3DBaseView::GetSpacing(double spc[3])
1859 {
1860         spc[0]=1;
1861         spc[1]=1;
1862         spc[2]=1;
1863 }