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