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