]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkBaseView.cxx
#3155 creaMaracasVisu Feature New Normal - ViewerPlane ComplexBox
[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 // EED 10 Oct 2007
77         #if defined(WIN32)
78                 _iren->Refresh(true);
79 // EED 27 sept 2016
80            vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
81            vri->vtkRenderWindowInteractor::Render();
82         #else
83 //EED 01Avril2009
84 //              _iren->Render();        
85         vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
86         vri->vtkRenderWindowInteractor::Render();
87                 //_iren->Refresh();
88         #endif
89 }
90 //-------------------------------------------------------------------
91 void wxVtkBaseView::RefreshView()  // virtual 
92 {
93 // EED 10 Oct 2007
94         #if defined(WIN32)
95                 GetRenWin()->Render();
96         #else
97                 //GetRenWin()->Render();
98         #endif
99 }
100 //---------------------------------------------------------------------------
101 vtkRenderer* wxVtkBaseView::GetRenderer()       // virtual 
102 {
103         return NULL;
104 }
105 //---------------------------------------------------------------------------
106 vtkRenderWindow* wxVtkBaseView::GetRenWin()             // virtual
107 {
108         return _iren->GetRenderWindow();
109 }
110
111 //----------------------------------------------------------------------------
112
113 void wxVtkBaseView::TransCoordScreenToWorld(double &X, double &Y, double &Z, int type)
114 {
115         GetRenderer()->SetDisplayPoint((int)X, (int)Y, (int)Z);
116         GetRenderer()->DisplayToWorld();
117         double fP[4];
118         GetRenderer()->GetWorldPoint( fP );
119         if ( fP[3] ){
120                 fP[0] /= fP[3];
121                 fP[1] /= fP[3];
122                 fP[2] /= fP[3];
123         }
124
125         if (type!=0)
126         {
127                 X=fP[0];
128         }
129         if (type!=1)
130         {
131                 Y=fP[1];
132         }
133         if (type!=2)
134         {
135                 Z=fP[2];
136         } 
137 }
138 //----------------------------------------------------------------------------
139                                         
140 void wxVtkBaseView::TransFromCoordScreenToWorld(double &X, double &Y, double &Z, bool keepNormalDirection, int type) //virtual //keepNormalDirection=false, type=2
141 {
142         double xx = X;
143         double yy = Y;
144         double zz = Z;
145
146         //RaC 03-2010
147         TransCoordScreenToWorld(xx,yy,zz,type);
148
149         X = xx;
150         Y = yy;
151         Z=zz;
152
153 // EEDx5
154         //JCP 13/05/2009
155         vtkInteractorStyleBaseView* interactorstyle = (vtkInteractorStyleBaseView*)this->GetInteractorStyleBaseView();
156     wxVtk2DBaseView* baseview = (wxVtk2DBaseView*)interactorstyle->GetWxVtk2DBaseView();
157
158         double fP[3];
159         fP[0] = X;
160         fP[1] = Y;
161         fP[2] = Z;
162
163         baseview->TransformCoordinate_spacing_ViewToModel( fP[0] , fP[1] , fP[2] );
164         //JCP 13/05/2009
165
166         if (type!=0)
167         {
168                 X=fP[0];
169         }
170         if (type!=1)
171         {
172                 Y=fP[1];
173         }
174         if (type!=2)
175         {
176                 Z=fP[2];
177         } 
178 }
179
180 //---------------------------------------------------------------------------
181 /* JCP 14/05/09
182 vtkInteractorStyleBaseView*     wxVtkBaseView::GetInteractorStyleBaseView()
183 {
184         return _interactorStyle;
185 }
186 */
187 vtkInteractorStyleImage*        wxVtkBaseView::GetInteractorStyleBaseView()
188 {
189         return _interactorStyle;
190 }
191
192 //---------------------------------------------------------------------------
193
194 void wxVtkBaseView::SetInteractorStyleBaseView( vtkInteractorStyleImage*        interactorStyle)
195 {
196         _interactorStyle = interactorStyle;
197 }
198
199 //---------------------------------------------------------------------------
200
201 void wxVtkBaseView::GetSpacing(double spc[3])  // virtual
202 {
203         spc[0]=1;
204         spc[1]=1;
205         spc[2]=1;
206 }
207
208
209 //---------------------------------------------------------------------------
210 int  wxVtkBaseView::GetDirection()   // virtual 
211 {
212         return -1;
213 }
214
215 //-------------------------------------------------------------------
216 vtkBaseData *wxVtkBaseView::GetVtkBaseData()
217 {
218    return _vtkbasedata;
219 }
220
221 //-------------------------------------------------------------------
222 void wxVtkBaseView::SetVtkBaseData(vtkBaseData *vtkbasedata)
223 {
224    _vtkbasedata=vtkbasedata;
225 }
226
227
228
229 //-------------------------------------------------------------------
230 //-------------------------------------------------------------------
231 //-------------------------------------------------------------------
232
233
234