]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk3DBaseView.cxx
699750d2b6fcf01a33da8f9fa6c73e45662b0e14
[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)
34 :wxVtkBaseView( parent )
35 {
36         _configure      = false;
37         _aRenderer      = NULL;
38         _renWin         = NULL;
39         _aCamera        = NULL;
40 }
41 //-------------------------------------------------------------------
42 wxVtk3DBaseView::~wxVtk3DBaseView()
43 {
44
45         if (_aCamera!=NULL)     { _aCamera              -> Delete(); _aCamera=NULL;}
46         if (_aRenderer!=NULL)   { _aRenderer    -> Delete(); _aRenderer=NULL;}
47         if (_renWin!=NULL)      { 
48                 if(_renWin->GetReferenceCount()==0){
49                         _renWin         -> Delete(); _renWin=NULL;
50                 }
51         }
52 }
53 //-------------------------------------------------------------------
54 vtkCamera* wxVtk3DBaseView::GetCamera()
55 {
56         return _aCamera;
57 }
58 //-------------------------------------------------------------------
59 vtkRenderer* wxVtk3DBaseView::GetRenderer()  // virtual
60 {
61         return _aRenderer;
62 }
63 //-------------------------------------------------------------------
64 vtkRenderWindow* wxVtk3DBaseView::GetRenWin()  // virtual
65 {
66         return _renWin;
67 }
68 //-------------------------------------------------------------------
69 void wxVtk3DBaseView::Refresh()
70 {
71 //      _renWin->Render();
72         vtkRenderWindowInteractor *vri = GetWxVTKRenderWindowInteractor();
73         vri->vtkRenderWindowInteractor::Render();
74 }
75
76
77 //-------------------------------------------------------------------
78 void wxVtk3DBaseView::SetStereo(int type)
79 {
80         //EED 02/06/2012  
81         
82         if (_renWin!=NULL)
83         {
84                 if (type==0)
85                 {
86                         _renWin->SetStereoRender(0); // OFF
87                 } else {
88                         _renWin->SetStereoRender(1); // ON
89                         _renWin->SetStereoCapableWindow(1);
90                         _renWin->SetAnaglyphColorMask(4,3);
91                         _renWin->SetAnaglyphColorSaturation(0.65);
92                 
93                         // VTK_STEREO_CRYSTAL_EYES 1
94                         // VTK_STEREO_RED_BLUE     2
95                         // VTK_STEREO_INTERLACED   3
96                         // VTK_STEREO_LEFT         4
97                         // VTK_STEREO_RIGHT        5
98                         // VTK_STEREO_DRESDEN      6
99                         // VTK_STEREO_ANAGLYPH     7
100                         // VTK_STEREO_CHECKERBOARD 8            
101                         _renWin->SetStereoType(type);      
102                 
103                 } // if type
104         } // _renWin
105 }
106
107
108 //-------------------------------------------------------------------
109 void wxVtk3DBaseView::Configure()
110 {
111         if (_configure==false)
112         {
113                 _configure=true;
114                 //wxVtkBaseView::Configure();
115                 _aRenderer      = vtkRenderer::New();
116                 _renWin         = vtkRenderWindow::New();
117                 _renWin->AddRenderer(_aRenderer);
118
119                 _aRenderer->GradientBackgroundOn();
120                 _aRenderer->SetBackground( 0.33 , 0.33 , 0.33 );
121                 _aRenderer->SetBackground2( 0.66 , 0.66 , 0.66 );
122                 
123                 SetStereo(0);
124                 
125                 GetWxVTKRenderWindowInteractor()->SetRenderWindow(_renWin);
126
127                 vtkInteractorStyleBaseView3D *interactorStyleBaseView3D = vtkInteractorStyleBaseView3D::New(); 
128
129                 SetInteractorStyleBaseView( interactorStyleBaseView3D );
130                 interactorStyleBaseView3D->SetInteractor (  GetWxVTKRenderWindowInteractor() );
131                 GetWxVTKRenderWindowInteractor()->SetInteractorStyle( interactorStyleBaseView3D );
132                 interactorStyleBaseView3D->SetwxVtkBaseView(this);      
133
134                 // It is convenient to create an initial view of the data. The
135                 // FocalPoint and Position form a vector direction. Later on
136                 // (ResetCamera() method) this vector is used to position the camera
137                 // to look at the data in this direction.
138                 _aCamera = vtkCamera::New();
139
140 //EED 17Avril2009       
141 /*
142                 _aCamera->SetViewUp (0, 0, -1);
143                 _aCamera->SetPosition (0, 1, 0);
144  */
145                 _aCamera->SetViewUp (0, 1, 0);
146                 _aCamera->SetPosition (0, 0, 1);
147                 
148                 _aCamera->SetFocalPoint (0, 0, 0);
149                 _aCamera->ComputeViewPlaneNormal();
150
151         }
152 }
153 //-------------------------------------------------------------------
154 //EED 27 sep 2006
155 void wxVtk3DBaseView::GetSpacing(double spc[3])
156 {
157         spc[0]=1;
158         spc[1]=1;
159         spc[2]=1;
160 }
161