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