]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk3DBaseView.cxx
75d6c1e7a346018d19f30492560f01ee9c6ff113
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtk3DBaseView.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 #include "wxVtk3DBaseView.h"
27
28 #include "vtkInteractorStyleBaseView3D.h"
29
30 #ifdef _DEBUG
31 #define new DEBUG_NEW
32 #endif
33 wxVtk3DBaseView::wxVtk3DBaseView(wxWindow *parent, vtkBaseData* vtkbasedata)
34 :wxVtkBaseView( parent )
35 {
36         SetVtkBaseData( vtkbasedata );
37         _configure      = false;
38         _aRenderer      = NULL;
39         _renWin         = NULL;
40         _aCamera                = NULL;
41 }
42 //-------------------------------------------------------------------
43 wxVtk3DBaseView::~wxVtk3DBaseView()
44 {
45
46         if (_aCamera!=NULL)             { _aCamera              -> Delete(); _aCamera=NULL;}
47         if (_aRenderer!=NULL)   { _aRenderer    -> Delete(); _aRenderer=NULL;}
48         if (_renWin!=NULL)              { 
49                 if(_renWin->GetReferenceCount()==0)
50                 {
51                         _renWin         -> Delete(); _renWin=NULL;
52                 }
53         }
54 }
55 //-------------------------------------------------------------------
56 vtkCamera* wxVtk3DBaseView::GetCamera()
57 {
58         return _aCamera;
59 }
60 //-------------------------------------------------------------------
61 vtkRenderer* wxVtk3DBaseView::GetRenderer()  // virtual
62 {
63         return _aRenderer;
64 }
65 //-------------------------------------------------------------------
66 vtkRenderWindow* wxVtk3DBaseView::GetRenWin()  // virtual
67 {
68         return _renWin;
69 }
70 //-------------------------------------------------------------------
71 void wxVtk3DBaseView::Refresh()
72 {
73 //      _renWin->Render();
74         vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
75         vri->vtkRenderWindowInteractor::Render();
76 }
77
78 //-------------------------------------------------------------------
79 // EED 27/05/2013
80 void wxVtk3DBaseView::ResetCamera(int* ext, double* spc)
81 {
82
83       GetRenderer()->ResetCameraClippingRange();
84
85         if(ext == NULL)
86         {
87
88                 GetRenderer()->ResetCamera ();
89                 GetCamera()->Dolly(1.2);
90         }else{
91                 
92                 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
93                 double y = (spc[1])*(origin[1]+(double)ext[3]);
94                 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
95                 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
96                 double x1=(spc[0])*((double)ext[1]+origin[0]);
97                 double y0=(spc[1])*((double)ext[2]+origin[1]);
98                 double y1=(spc[1])*((double)ext[3]+origin[1]);
99                 double z0=(spc[2])*((double)ext[4]+origin[2]);
100                 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
101                 
102                 double x0=(spc[0])*((double)ext[0]);
103                 double x1=(spc[0])*((double)ext[1]);
104                 double y0=(spc[1])*((double)ext[2]);
105                 double y1=(spc[1])*((double)ext[3]);
106                 double z0=(spc[2])*((double)ext[4]);
107                 double z1=(spc[2])*((double)ext[5]);
108
109                 GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
110                 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
111                 GetCamera()->Dolly(1.5);        
112         }       
113 }
114
115 //-------------------------------------------------------------------
116 void wxVtk3DBaseView::SetStereo(int type)
117 {
118         //EED 02/06/2012  
119         
120         if (_renWin!=NULL)
121         {
122                 if (type==0)
123                 {
124                         _renWin->SetStereoRender(0); // OFF
125                 } else {
126                         _renWin->SetStereoRender(1); // ON
127                         _renWin->SetStereoCapableWindow(1);
128                         _renWin->SetAnaglyphColorMask(4,3);
129                         _renWin->SetAnaglyphColorSaturation(0.65);
130                 
131                         // VTK_STEREO_CRYSTAL_EYES 1
132                         // VTK_STEREO_RED_BLUE     2
133                         // VTK_STEREO_INTERLACED   3
134                         // VTK_STEREO_LEFT         4
135                         // VTK_STEREO_RIGHT        5
136                         // VTK_STEREO_DRESDEN      6
137                         // VTK_STEREO_ANAGLYPH     7
138                         // VTK_STEREO_CHECKERBOARD 8            
139                         _renWin->SetStereoType(type);      
140                 
141                 } // if type
142         } // _renWin
143 }
144
145
146 //-------------------------------------------------------------------
147 void wxVtk3DBaseView::Configure()
148 {
149         if (_configure==false)
150         {
151                 _configure=true;
152                 //wxVtkBaseView::Configure();
153                 _aRenderer      = vtkRenderer::New();
154                 _renWin         = vtkRenderWindow::New();
155                 _renWin->AddRenderer(_aRenderer);
156
157                 _aRenderer->GradientBackgroundOn();
158                 _aRenderer->SetBackground( 0.33 , 0.33 , 0.33 );
159                 _aRenderer->SetBackground2( 0.66 , 0.66 , 0.66 );
160
161
162
163 //              _aRenderer->GradientBackgroundOff();
164 //              _aRenderer->SetBackground(0,0,0 );
165
166                 
167                 SetStereo(0);
168                 
169                 GetWxVTKRenderWindowInteractor()->SetRenderWindow(_renWin);
170
171                 vtkInteractorStyleBaseView3D *interactorStyleBaseView3D = vtkInteractorStyleBaseView3D::New(); 
172
173                 SetInteractorStyleBaseView( interactorStyleBaseView3D );
174                 interactorStyleBaseView3D->SetInteractor (  GetWxVTKRenderWindowInteractor() );
175                 GetWxVTKRenderWindowInteractor()->SetInteractorStyle( interactorStyleBaseView3D );
176                 interactorStyleBaseView3D->SetwxVtkBaseView(this);      
177
178                 // It is convenient to create an initial view of the data. The
179                 // FocalPoint and Position form a vector direction. Later on
180                 // (ResetCamera() method) this vector is used to position the camera
181                 // to look at the data in this direction.
182                 _aCamera = vtkCamera::New();
183
184 //EED 17Avril2009       
185 /*
186                 _aCamera->SetViewUp (0, 0, -1);
187                 _aCamera->SetPosition (0, 1, 0);
188  */
189                 _aCamera->SetViewUp (0, 1, 0);
190                 _aCamera->SetPosition (0, 0, 1);
191                 
192                 _aCamera->SetFocalPoint (0, 0, 0);
193                 _aCamera->ComputeViewPlaneNormal();
194
195 //EED 27/05/2013
196                 GetRenderer()->SetActiveCamera(GetCamera());
197                 
198 //EED 21 mars 2012  FLIP probleme  ..PLOP..
199 //EED 13 may 2013  FLIP probleme  ..PLOP..
200                 GetCamera()->Roll(180);
201                 GetCamera()->Yaw(180+30);
202                 GetCamera()->Pitch(-22);
203
204
205         }
206 }
207 //-------------------------------------------------------------------
208 //EED 27 sep 2006
209 void wxVtk3DBaseView::GetSpacing(double spc[3])
210 {
211         spc[0]=1;
212         spc[1]=1;
213         spc[2]=1;
214 }
215