1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 #include <wx/tooltip.h>
28 #include <wx/config.h>
30 #include <iostream> // for std::cout
33 #include "wxVtkClipping3DView.h"
35 #include "wxVtkClipping3DViewCntrlPanel.h"
36 #include "wxVtkClipping3DViewVolCntrlPanel.h"
38 wxVtkClipping3DView::wxVtkClipping3DView(wxVtk3DBaseView* wxvtk3Dbaseview)
41 _wxvtk3Dbaseview = wxvtk3Dbaseview;
42 _vtkclipping3Ddataviewer = NULL;
43 _wxvtkclipping3DviewCntrlPanel = NULL;
45 _boxWidgetVolume = NULL;
49 //-------------------------------------------------------------------
50 wxVtkClipping3DView::~wxVtkClipping3DView()
52 if (_boxWidgetVolume!=NULL) { _boxWidgetVolume -> Delete(); }
53 if (_boxWidgetS1!=NULL) { _boxWidgetS1 -> Delete(); }
54 if (_vtkclipping3Ddataviewer!=NULL) { delete _vtkclipping3Ddataviewer; }
55 if (_wxvtkclipping3DviewCntrlPanel!=NULL){ delete _wxvtkclipping3DviewCntrlPanel; }
58 //-------------------------------------------------------------------
59 void wxVtkClipping3DView::SetVisibleBoxSurface(bool visible)
69 //-------------------------------------------------------------------
70 void wxVtkClipping3DView::VisibleVolumeBoxActor(bool visible)
72 if (visible!=_vtkclipping3Ddataviewer->GetVisibleVolumeBox() )
74 VisibleVolumeActor(!visible);
75 _vtkclipping3Ddataviewer->BoxActorChanged(visible);
76 _vtkclipping3Ddataviewer->SetVisibleVolumeBox(visible);
77 _vtkclipping3Ddataviewer->SetVisibleVolume(!visible);
81 //-------------------------------------------------------------------
82 void wxVtkClipping3DView::Refresh()
84 _vtkclipping3Ddataviewer->Refresh();
85 if (_wxvtkclipping3DviewCntrlPanel!=NULL)
87 _wxvtkclipping3DviewCntrlPanel->Refresh();
91 //-------------------------------------------------------------------
92 wxPanel* wxVtkClipping3DView::CreateSurfControlPanel(wxWindow *parent)
94 _wxvtkclipping3DviewCntrlPanel = new wxVtkClipping3DViewCntrlPanel(parent,this);
95 return _wxvtkclipping3DviewCntrlPanel;
98 //RaC 03-2010 Divide in two panels
99 //-------------------------------------------------------------------
100 wxPanel* wxVtkClipping3DView::CreateVolControlPanel(wxWindow *parent)
102 _wxvtkclipping3DviewVolCntrlPanel = new wxVtkClipping3DViewVolCntrlPanel(parent,this);
103 return _wxvtkclipping3DviewVolCntrlPanel;
106 //-------------------------------------------------------------------
107 vtkClipping3DDataViewer* wxVtkClipping3DView::GetVtkClipping3DDataViewer()
109 return _vtkclipping3Ddataviewer;
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) );
118 _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue) );
119 // _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(idTissue) );
120 // _actor->VisibilityOn();
122 _vtkclipping3Ddataviewer->SetVisibleTissue(idTissue,visTissue);
126 //-------------------------------------------------------------------
127 void wxVtkClipping3DView::SetRepSurfaceWireFrame(int idTissue , bool representationType )
130 tmpActor = GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
132 if (representationType==false){
133 tmpActor->GetProperty()->SetRepresentationToWireframe();
135 tmpActor->GetProperty()->SetRepresentationToSurface();
138 _vtkclipping3Ddataviewer->SetRepresentationType(idTissue,representationType);
141 //-------------------------------------------------------------------
142 void wxVtkClipping3DView::VisibleVolumeActor( bool visVolume){
143 if (visVolume!=_vtkclipping3Ddataviewer->GetVisibleVolume() ){
144 if (visVolume==false){
146 // _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetVolumeActor() );
147 _wxvtk3Dbaseview->GetRenderer()->RemoveVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );
150 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetVolumeActor() );
151 _wxvtk3Dbaseview->GetRenderer()->AddVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );
153 _vtkclipping3Ddataviewer->SetVisibleVolume(visVolume);
155 else if(visVolume==false && _vtkclipping3Ddataviewer->GetVisibleVolumeBox() == true)
157 _vtkclipping3Ddataviewer->BoxActorChanged(false);
158 _vtkclipping3Ddataviewer->SetVisibleVolumeBox(false);
163 //-------------------------------------------------------------------
164 wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview()throw(char*)
166 if(_wxvtk3Dbaseview==NULL){
167 throw "wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
169 return _wxvtk3Dbaseview;
172 //-------------------------------------------------------------------
173 void wxVtkClipping3DView::Configure()
175 _wxvtk3Dbaseview->Configure();
177 // Actors are added to the renderer.
179 _boxWidgetS1 = vtkBoxWidget::New();
180 _boxWidgetS1->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
181 _boxWidgetS1->SetPlaceFactor(1.25);
183 vtkStripper *stripper=_vtkclipping3Ddataviewer->GetTissueStripper(0);
184 vtkPolyData *polydata= stripper->GetOutput();
186 //EED 2017-01-01 Migration VTK7
187 #if VTK_MAJOR_VERSION <= 5
188 _boxWidgetS1->SetInput( polydata );
191 _boxWidgetS1->SetInputData( polydata );
195 //_boxWidgetS1->PlaceWidget();
197 this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetExtent(ext);
198 _boxWidgetS1->PlaceWidget(ext[0],ext[1],ext[2],ext[3],ext[4],ext[5]);
201 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
203 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent, _vtkclipping3Ddataviewer->GetObserverS(i) );
206 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(0) );
207 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(3));
209 VisibleActor(0, false );
210 VisibleActor(1, false );
211 VisibleActor(2, false );
212 VisibleActor(3, false );
214 _boxWidgetS1->HandlesOn ();
217 // _boxWidgetS1->On();
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) );
227 _boxWidgetVolume = vtkBoxWidget::New();
228 _boxWidgetVolume->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
229 _boxWidgetVolume->SetPlaceFactor(1.25);
231 //EED 2017-01-01 Migration VTK7
232 #if VTK_MAJOR_VERSION <= 5
233 _boxWidgetVolume->SetInput( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
235 _boxWidgetVolume->SetInputData( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
238 _boxWidgetVolume->PlaceWidget();
239 _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent, _vtkclipping3Ddataviewer->GetObserverV() );
240 _boxWidgetVolume->HandlesOn ();
243 // _boxWidgetVolume->On();
244 _boxWidgetVolume->Off();
246 // vtkPlanes *vtkplanes=this->GetVtkClipping3DDataViewer()->GetVolumePlanes();
247 // _boxWidgetVolume->GetPlanes( vtkplanes );
250 // _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
251 // _wxvtk3Dbaseview->GetCamera()->Dolly(1.2);
253 // An initial camera view is created. The Dolly() method moves
254 // the camera towards the FocalPoint, thereby enlarging the image.
255 _wxvtk3Dbaseview->ResetCamera();
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);
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();
271 _vtkclipping3Ddataviewer->SetRenderer(this->GetWxvtk3Dbaseview()->GetRenderer());
272 _vtkclipping3Ddataviewer->SetInteractor(this->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor());
275 //-------------------------------------------------------------------
276 void wxVtkClipping3DView::SetVtkClipping3DDataViewer(vtkClipping3DDataViewer *vtkclipping3Ddataviewer)
278 _vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
281 void wxVtkClipping3DView::SetRayCasting(bool active)
283 _vtkclipping3Ddataviewer->SetRayCasting(active);
284 _vtkclipping3Ddataviewer->updateVolume();
287 void wxVtkClipping3DView::SetMIPActive(bool active)
289 _vtkclipping3Ddataviewer->SetMIPActive(active);
290 _vtkclipping3Ddataviewer->updateVolume();
293 void wxVtkClipping3DView::SetInterpolation(bool active)
295 _vtkclipping3Ddataviewer->SetInterpolation(active);
296 _vtkclipping3Ddataviewer->updateVolume();
299 void wxVtkClipping3DView::SetShade(bool active)
301 _vtkclipping3Ddataviewer->SetShade(active);
302 _vtkclipping3Ddataviewer->updateVolume();
305 void wxVtkClipping3DView::UpdateVolumeBox(vector<double> gf, vector<double> vf, vtkColorTransferFunction* ctfun)
307 _vtkclipping3Ddataviewer->UpdateVolumeBox(gf, vf, ctfun);