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