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