]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkBaseView.cxx
#3012 creaMaracasVisu Bug New Normal - Update Image in ViewerNV
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkBaseView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27
28 //#include "vtkInteractorStyleBaseView.h"
29
30 #include "wxVtkBaseView.h"
31 #include "wxVtk2DBaseView.h"
32 #include "wxVTKRenderWindowInteractorPlus.h"
33
34
35
36 wxVtkBaseView::wxVtkBaseView()
37 {
38         _parent                         = NULL;
39         _iren                           = NULL;
40         _interactorStyle        = NULL;
41 }
42
43 //-------------------------------------------------------------------
44
45 wxVtkBaseView::wxVtkBaseView(wxWindow *parent)
46 {
47         _parent                         = parent;
48         _iren                           = (wxVTKRenderWindowInteractor*)new wxVTKRenderWindowInteractorPlus(_parent,this);
49 //      _iren->UseCaptureMouseOn();
50 //      _iren                           = new wxVTKRenderWindowInteractor(_parent,-1);
51         _interactorStyle        = NULL;
52 }
53
54 //-------------------------------------------------------------------
55 wxVtkBaseView::~wxVtkBaseView()
56 {
57         _iren -> Delete();
58         //_iren=NULL;
59 }
60 //-------------------------------------------------------------------
61 wxVTKRenderWindowInteractor* wxVtkBaseView::GetWxVTKRenderWindowInteractor() throw (char*)
62 {
63
64         if(_iren==NULL){
65                 throw "wxVtkBaseView::GetWxVTKRenderWindowInteractor() _iren wxVTKRenderWindowInteractorPlus =NULL";
66         }
67    return _iren;
68 }
69 //-------------------------------------------------------------------
70 void wxVtkBaseView::Configure()  // virtual 
71 {
72 }
73 //-------------------------------------------------------------------
74 void wxVtkBaseView::Refresh()  // virtual 
75 {
76         
77 // EED 10 Oct 2007
78         #if defined(WIN32)
79                 _iren->Refresh(false);
80         #else
81         
82 //EED 01Avril2009
83 //              _iren->Render();        
84         vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
85         vri->vtkRenderWindowInteractor::Render();
86         
87                 //_iren->Refresh();
88         #endif
89
90 }
91 //-------------------------------------------------------------------
92 void wxVtkBaseView::RefreshView()  // virtual 
93 {
94         printf("EED wxVtkBaseView::RefreshView() \n");
95 // EED 10 Oct 2007
96
97         #if defined(WIN32)
98                 GetRenWin()->Render();
99         #else
100                 //GetRenWin()->Render();
101         #endif
102 }
103 //---------------------------------------------------------------------------
104 vtkRenderer* wxVtkBaseView::GetRenderer()       // virtual 
105 {
106         return NULL;
107 }
108 //---------------------------------------------------------------------------
109 vtkRenderWindow* wxVtkBaseView::GetRenWin()             // virtual
110 {
111         return _iren->GetRenderWindow();
112 }
113
114 //----------------------------------------------------------------------------
115
116 void wxVtkBaseView::TransCoordScreenToWorld(double &X, double &Y, double &Z, int type)
117 {
118         GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
119         GetRenderer()->DisplayToWorld();
120         double fP[4];
121         GetRenderer()->GetWorldPoint( fP );
122         if ( fP[3] ){
123                 fP[0] /= fP[3];
124                 fP[1] /= fP[3];
125                 fP[2] /= fP[3];
126         }
127
128         if (type!=0)
129         {
130                 X=fP[0];
131         }
132         if (type!=1)
133         {
134                 Y=fP[1];
135         }
136         if (type!=2)
137         {
138                 Z=fP[2];
139         } 
140 }
141 //----------------------------------------------------------------------------
142                                         
143 void wxVtkBaseView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
144 {
145         double xx = X;
146         double yy = Y;
147         double zz = Z;
148
149         //RaC 03-2010
150         TransCoordScreenToWorld(xx,yy,zz,type);
151
152         X = xx;
153         Y = yy;
154         Z=zz;
155
156 // EEDx5
157         //JCP 13/05/2009
158         vtkInteractorStyleBaseView* interactorstyle = (vtkInteractorStyleBaseView*)this->GetInteractorStyleBaseView();
159     wxVtk2DBaseView* baseview = (wxVtk2DBaseView*)interactorstyle->GetWxVtk2DBaseView();
160
161         double fP[3];
162         fP[0] = X;
163         fP[1] = Y;
164         fP[2] = Z;
165
166         baseview->TransformCoordinate_spacing_ViewToModel( fP[0] , fP[1] , fP[2] );
167         //JCP 13/05/2009
168
169         if (type!=0)
170         {
171                 X=fP[0];
172         }
173         if (type!=1)
174         {
175                 Y=fP[1];
176         }
177         if (type!=2)
178         {
179                 Z=fP[2];
180         } 
181 }
182
183 //---------------------------------------------------------------------------
184 /* JCP 14/05/09
185 vtkInteractorStyleBaseView*     wxVtkBaseView::GetInteractorStyleBaseView()
186 {
187         return _interactorStyle;
188 }
189 */
190 vtkInteractorStyleImage*        wxVtkBaseView::GetInteractorStyleBaseView()
191 {
192         return _interactorStyle;
193 }
194
195 //---------------------------------------------------------------------------
196
197 void wxVtkBaseView::SetInteractorStyleBaseView( vtkInteractorStyleImage*        interactorStyle)
198 {
199         _interactorStyle = interactorStyle;
200 }
201
202 //---------------------------------------------------------------------------
203
204 void wxVtkBaseView::GetSpacing(double spc[3])  // virtual
205 {
206         spc[0]=1;
207         spc[1]=1;
208         spc[2]=1;
209 }
210
211
212 //---------------------------------------------------------------------------
213 int  wxVtkBaseView::GetDirection()   // virtual 
214 {
215         return -1;
216 }
217
218 //-------------------------------------------------------------------
219 vtkBaseData *wxVtkBaseView::GetVtkBaseData()
220 {
221    return _vtkbasedata;
222 }
223
224 //-------------------------------------------------------------------
225 void wxVtkBaseView::SetVtkBaseData(vtkBaseData *vtkbasedata)
226 {
227    _vtkbasedata=vtkbasedata;
228 }
229
230
231
232 //-------------------------------------------------------------------
233 //-------------------------------------------------------------------
234 //-------------------------------------------------------------------
235
236
237