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