]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DView.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkClipping3DView.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 "wxVtkClipping3DView.h"
27
28 #include "wxVtkClipping3DViewCntrlPanel.h"
29 #include "wxVtkClipping3DViewVolCntrlPanel.h"
30
31 wxVtkClipping3DView::wxVtkClipping3DView(wxVtk3DBaseView* wxvtk3Dbaseview)
32 {
33
34         _wxvtk3Dbaseview                                =       wxvtk3Dbaseview;
35         _vtkclipping3Ddataviewer                =       NULL;
36         _wxvtkclipping3DviewCntrlPanel  =       NULL;
37
38         _boxWidgetVolume                                =       NULL;
39         _boxWidgetS1                                    =       NULL;
40 }
41
42 //-------------------------------------------------------------------
43 wxVtkClipping3DView::~wxVtkClipping3DView(){
44         if (_boxWidgetVolume!=NULL)                              { _boxWidgetVolume     -> Delete();                                    }
45         if (_boxWidgetS1!=NULL)                                  { _boxWidgetS1         -> Delete();                                    }
46         if (_vtkclipping3Ddataviewer!=NULL)              { delete _vtkclipping3Ddataviewer;                     }
47         if (_wxvtkclipping3DviewCntrlPanel!=NULL){ delete _wxvtkclipping3DviewCntrlPanel;       }
48 }
49 //-------------------------------------------------------------------
50 void wxVtkClipping3DView::SetVisibleBoxSurface(bool visible)
51 {
52         if (visible==true){
53                 _boxWidgetS1->On();
54         } else {
55                 _boxWidgetS1->Off();
56         }
57 }
58 //-------------------------------------------------------------------
59 void wxVtkClipping3DView::VisibleVolumeBoxActor(bool visible)
60 {
61         if (visible!=_vtkclipping3Ddataviewer->GetVisibleVolumeBox() ){
62         VisibleVolumeActor(!visible);
63         _vtkclipping3Ddataviewer->BoxActorChanged(visible);
64         _vtkclipping3Ddataviewer->SetVisibleVolumeBox(visible);
65         _vtkclipping3Ddataviewer->SetVisibleVolume(!visible);
66         }
67 }
68 //-------------------------------------------------------------------
69 void wxVtkClipping3DView::Refresh()
70 {
71         _vtkclipping3Ddataviewer->Refresh();
72         if (_wxvtkclipping3DviewCntrlPanel!=NULL)
73         {
74                 _wxvtkclipping3DviewCntrlPanel->Refresh();
75         }
76 }
77 //-------------------------------------------------------------------
78 wxPanel* wxVtkClipping3DView::CreateSurfControlPanel(wxWindow *parent)
79 {
80         _wxvtkclipping3DviewCntrlPanel = new wxVtkClipping3DViewCntrlPanel(parent,this);
81         return _wxvtkclipping3DviewCntrlPanel;
82 }
83
84 //RaC 03-2010 Divide in two panels
85 //-------------------------------------------------------------------
86 wxPanel* wxVtkClipping3DView::CreateVolControlPanel(wxWindow *parent)
87 {
88         _wxvtkclipping3DviewVolCntrlPanel = new wxVtkClipping3DViewVolCntrlPanel(parent,this);
89         return _wxvtkclipping3DviewVolCntrlPanel;
90 }
91
92
93 //-------------------------------------------------------------------
94 vtkClipping3DDataViewer* wxVtkClipping3DView::GetVtkClipping3DDataViewer()
95 {
96         return _vtkclipping3Ddataviewer;
97 }
98 //-------------------------------------------------------------------
99 void wxVtkClipping3DView::VisibleActor(int idTissue, bool visTissue){
100         if (visTissue!=_vtkclipping3Ddataviewer->GetVisibleTissue(idTissue)){
101                 if (visTissue==false){
102                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );
103                 } else {
104                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );
105 //                      _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(idTissue) );
106 //                      _actor->VisibilityOn();
107                 }
108                 _vtkclipping3Ddataviewer->SetVisibleTissue(idTissue,visTissue);
109         }
110 }
111 //-------------------------------------------------------------------
112 void wxVtkClipping3DView::SetRepSurfaceWireFrame(int idTissue , bool representationType )
113 {
114         vtkActor *tmpActor;
115         tmpActor = GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
116
117         if (representationType==false){
118                 tmpActor->GetProperty()->SetRepresentationToWireframe();
119         } else {
120                 tmpActor->GetProperty()->SetRepresentationToSurface();
121         }
122
123         _vtkclipping3Ddataviewer->SetRepresentationType(idTissue,representationType);
124 }
125
126 //-------------------------------------------------------------------
127 void wxVtkClipping3DView::VisibleVolumeActor( bool visVolume){
128         if (visVolume!=_vtkclipping3Ddataviewer->GetVisibleVolume() ){
129                 if (visVolume==false){
130 //EED 31/03/2008
131 //                      _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetVolumeActor()  );
132                         _wxvtk3Dbaseview->GetRenderer()->RemoveVolume( _vtkclipping3Ddataviewer->GetVolumeActor()  );
133                 } else {
134 //EED 31/03/2008
135 //                      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetVolumeActor() );
136                         _wxvtk3Dbaseview->GetRenderer()->AddVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );
137                 }
138                 _vtkclipping3Ddataviewer->SetVisibleVolume(visVolume);
139         }
140         else if(visVolume==false  && _vtkclipping3Ddataviewer->GetVisibleVolumeBox() == true)
141         {
142             _vtkclipping3Ddataviewer->BoxActorChanged(false);
143         _vtkclipping3Ddataviewer->SetVisibleVolumeBox(false);
144         }
145
146 }
147 //-------------------------------------------------------------------
148 wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview()throw(char*)
149 {
150         if(_wxvtk3Dbaseview==NULL){
151                 throw "wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
152         }
153         return _wxvtk3Dbaseview;
154 }
155 //-------------------------------------------------------------------
156 void wxVtkClipping3DView::Configure(){
157         _wxvtk3Dbaseview->Configure();
158
159         // Actors are added to the renderer.
160         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetOutlineActor() );
161
162         _boxWidgetS1 = vtkBoxWidget::New();
163         _boxWidgetS1->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
164         _boxWidgetS1->SetPlaceFactor(1.25);
165
166
167
168         vtkStripper *stripper=_vtkclipping3Ddataviewer->GetTissueStripper(0);
169         vtkPolyData *polydata= stripper->GetOutput();
170
171
172         _boxWidgetS1->SetInput( polydata );
173         _boxWidgetS1->PlaceWidget();
174
175         int i;
176         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
177         {
178                 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent, _vtkclipping3Ddataviewer->GetObserverS(i) );
179         }
180
181
182
183
184 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(0) );
185 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(3));
186
187         VisibleActor(0, false );
188         VisibleActor(1, false );
189         VisibleActor(2, false );
190         VisibleActor(3, false );
191
192         _boxWidgetS1->HandlesOn ();
193
194 //EED 29Mars2009
195 //      _boxWidgetS1->On();
196
197         _boxWidgetS1->Off();
198
199         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(0) );
200         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(1) );
201         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(2) );
202         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(3) );
203
204 // EED 9 fev 2007
205 // box Volume
206         _boxWidgetVolume = vtkBoxWidget::New();
207         _boxWidgetVolume->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
208         _boxWidgetVolume->SetPlaceFactor(1.25);
209
210         _boxWidgetVolume->SetInput( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
211         _boxWidgetVolume->PlaceWidget();
212
213         _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent              , _vtkclipping3Ddataviewer->GetObserverV() );
214
215         _boxWidgetVolume->HandlesOn ();
216
217 //EED 29Mars2009
218 //      _boxWidgetVolume->On();
219
220         _boxWidgetVolume->Off();
221
222
223 //      vtkPlanes *vtkplanes=this->GetVtkClipping3DDataViewer()->GetVolumePlanes();
224 //      _boxWidgetVolume->GetPlanes( vtkplanes );
225
226
227   // An initial camera view is created.  The Dolly() method moves
228   // the camera towards the FocalPoint, thereby enlarging the image.
229   _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
230   _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
231   _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
232
233   // Set a background color for the renderer and set the size of the
234   // render window (expressed in pixels).
235   _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
236   _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
237
238   // Note that when camera movement occurs (as it does in the Dolly()
239   // method), the clipping planes often need adjusting. Clipping planes
240   // consist of two planes: near and far along the view direction. The
241   // near plane clips out objects in front of the plane; the far plane
242   // clips out objects behind the plane. This way only what is drawn
243   // between the planes is actually rendered.
244   _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
245
246         _vtkclipping3Ddataviewer->SetRenderer(this->GetWxvtk3Dbaseview()->GetRenderer());
247         _vtkclipping3Ddataviewer->SetInteractor(this->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor());
248
249 }
250 //-------------------------------------------------------------------
251 void wxVtkClipping3DView::SetVtkClipping3DDataViewer(vtkClipping3DDataViewer *vtkclipping3Ddataviewer)
252 {
253         _vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
254 }
255
256 void wxVtkClipping3DView::SetRayCasting(bool active)
257 {
258     _vtkclipping3Ddataviewer->SetRayCasting(active);
259     _vtkclipping3Ddataviewer->updateVolume();
260 }
261
262 void wxVtkClipping3DView::SetMIPActive(bool active)
263 {
264     _vtkclipping3Ddataviewer->SetMIPActive(active);
265     _vtkclipping3Ddataviewer->updateVolume();
266 }
267
268 void wxVtkClipping3DView::SetInterpolation(bool active)
269 {
270     _vtkclipping3Ddataviewer->SetInterpolation(active);
271     _vtkclipping3Ddataviewer->updateVolume();
272 }
273
274 void wxVtkClipping3DView::SetShade(bool active)
275 {
276     _vtkclipping3Ddataviewer->SetShade(active);
277     _vtkclipping3Ddataviewer->updateVolume();
278 }
279
280 void wxVtkClipping3DView::UpdateVolumeBox(vector<double> gf, vector<double> vf, vtkColorTransferFunction* ctfun)
281 {
282     _vtkclipping3Ddataviewer->UpdateVolumeBox(gf, vf, ctfun);
283 }
284
285
286