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