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