1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "wxVtk3DBaseView.h"
28 #include "vtkInteractorStyleBaseView3D.h"
33 wxVtk3DBaseView::wxVtk3DBaseView(wxWindow *parent, vtkBaseData* vtkbasedata)
34 :wxVtkBaseView( parent )
36 SetVtkBaseData( vtkbasedata );
42 //-------------------------------------------------------------------
43 wxVtk3DBaseView::~wxVtk3DBaseView()
45 if (_aCamera!=NULL) { _aCamera -> Delete(); _aCamera=NULL;}
46 if (_aRenderer!=NULL) { _aRenderer -> Delete(); _aRenderer=NULL;}
49 if(_renWin->GetReferenceCount()==0)
56 //-------------------------------------------------------------------
57 vtkCamera* wxVtk3DBaseView::GetCamera()
61 //-------------------------------------------------------------------
62 vtkRenderer* wxVtk3DBaseView::GetRenderer() // virtual
66 //-------------------------------------------------------------------
67 vtkRenderWindow* wxVtk3DBaseView::GetRenWin() // virtual
71 //-------------------------------------------------------------------
72 void wxVtk3DBaseView::Refresh()
74 printf("EED wxVtk3DBaseView::Refresh Start\n");
76 vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
77 vri->vtkRenderWindowInteractor::Render();
78 printf("EED wxVtk3DBaseView::Refresh End\n");
81 //-------------------------------------------------------------------
83 void wxVtk3DBaseView::ResetCamera(int* ext, double* spc)
85 GetRenderer()->ResetCameraClippingRange();
88 GetRenderer()->ResetCamera ();
89 GetCamera()->Dolly(1.2);
91 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
92 double y = (spc[1])*(origin[1]+(double)ext[3]);
93 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
94 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
95 double x1=(spc[0])*((double)ext[1]+origin[0]);
96 double y0=(spc[1])*((double)ext[2]+origin[1]);
97 double y1=(spc[1])*((double)ext[3]+origin[1]);
98 double z0=(spc[2])*((double)ext[4]+origin[2]);
99 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
100 double x0=(spc[0])*((double)ext[0]);
101 double x1=(spc[0])*((double)ext[1]);
102 double y0=(spc[1])*((double)ext[2]);
103 double y1=(spc[1])*((double)ext[3]);
104 double z0=(spc[2])*((double)ext[4]);
105 double z1=(spc[2])*((double)ext[5]);
106 GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
107 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
108 GetCamera()->Dolly(1.5);
112 //-------------------------------------------------------------------
113 void wxVtk3DBaseView::SetStereo(int type)
120 _renWin->SetStereoRender(0); // OFF
122 _renWin->SetStereoRender(1); // ON
123 _renWin->SetStereoCapableWindow(1);
124 _renWin->SetAnaglyphColorMask(4,3);
125 _renWin->SetAnaglyphColorSaturation(0.65);
127 // VTK_STEREO_CRYSTAL_EYES 1
128 // VTK_STEREO_RED_BLUE 2
129 // VTK_STEREO_INTERLACED 3
131 // VTK_STEREO_RIGHT 5
132 // VTK_STEREO_DRESDEN 6
133 // VTK_STEREO_ANAGLYPH 7
134 // VTK_STEREO_CHECKERBOARD 8
135 _renWin->SetStereoType(type);
141 //-------------------------------------------------------------------
142 void wxVtk3DBaseView::Configure()
144 if (_configure==false)
147 //wxVtkBaseView::Configure();
148 _aRenderer = vtkRenderer::New();
149 _renWin = vtkRenderWindow::New();
151 int supportopengl=_renWin->SupportsOpenGL();
152 printf("EED wxVtk3DBaseView::Configure >>>>> vtkRenderWindow SupportsOpenGL %d\n", supportopengl );
153 printf("EED wxVtk3DBaseView::Configure >>>>> vtkRenderWindow IsDirect %d\n", _renWin->IsDirect() );
154 if (supportopengl==0)
157 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");
159 printf(" OpenGL 3 not detected.\n Try to install opengl drivers or use de opengl-mesa version.\n");
164 _renWin->AddRenderer(_aRenderer);
166 _aRenderer->GradientBackgroundOn();
167 _aRenderer->SetBackground( 0.33 , 0.33 , 0.33 );
168 _aRenderer->SetBackground2( 0.66 , 0.66 , 0.66 );
172 // _aRenderer->GradientBackgroundOff();
173 // _aRenderer->SetBackground(0,0,0 );
178 GetWxVTKRenderWindowInteractor()->SetRenderWindow(_renWin);
180 vtkInteractorStyleBaseView3D *interactorStyleBaseView3D = vtkInteractorStyleBaseView3D::New();
182 SetInteractorStyleBaseView( interactorStyleBaseView3D );
183 interactorStyleBaseView3D->SetInteractor ( GetWxVTKRenderWindowInteractor() );
184 GetWxVTKRenderWindowInteractor()->SetInteractorStyle( interactorStyleBaseView3D );
185 interactorStyleBaseView3D->SetwxVtkBaseView(this);
187 // It is convenient to create an initial view of the data. The
188 // FocalPoint and Position form a vector direction. Later on
189 // (ResetCamera() method) this vector is used to position the camera
190 // to look at the data in this direction.
191 _aCamera = vtkCamera::New();
195 _aCamera->SetViewUp (0, 0, -1);
196 _aCamera->SetPosition (0, 1, 0);
198 _aCamera->SetViewUp (0, 1, 0);
199 _aCamera->SetPosition (0, 0, 1);
201 _aCamera->SetFocalPoint (0, 0, 0);
202 _aCamera->ComputeViewPlaneNormal();
205 GetRenderer()->SetActiveCamera(GetCamera());
207 //EED 21 mars 2012 FLIP probleme ..PLOP..
208 //EED 13 may 2013 FLIP probleme ..PLOP..
209 GetCamera()->Roll(180);
210 GetCamera()->Yaw(180+30);
211 GetCamera()->Pitch(-22);
213 //https://stackoverflow.com/questions/47528086/problems-with-rendering-transparent-objects-in-vtk
214 //https://itk.org/Wiki/VTK/Depth_Peeling
215 _aRenderer->SetUseDepthPeeling(1);
216 _aRenderer->SetOcclusionRatio(0.1);
217 _aRenderer->SetMaximumNumberOfPeels(100);
218 _renWin->SetMultiSamples(0);
219 _renWin->SetAlphaBitPlanes(1);
223 //-------------------------------------------------------------------
225 void wxVtk3DBaseView::GetSpacing(double spc[3])