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