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 # ------------------------------------------------------------------------ */
26 #include "wxVtkClipping3DView.h"
28 #include "wxVtkClipping3DViewCntrlPanel.h"
29 #include "wxVtkClipping3DViewVolCntrlPanel.h"
31 wxVtkClipping3DView::wxVtkClipping3DView(wxVtk3DBaseView* wxvtk3Dbaseview)
34 _wxvtk3Dbaseview = wxvtk3Dbaseview;
35 _vtkclipping3Ddataviewer = NULL;
36 _wxvtkclipping3DviewCntrlPanel = NULL;
38 _boxWidgetVolume = NULL;
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; }
49 //-------------------------------------------------------------------
50 void wxVtkClipping3DView::SetVisibleBoxSurface(bool visible)
58 //-------------------------------------------------------------------
59 void wxVtkClipping3DView::VisibleVolumeBoxActor(bool visible)
61 if (visible!=_vtkclipping3Ddataviewer->GetVisibleVolumeBox() ){
62 VisibleVolumeActor(!visible);
63 _vtkclipping3Ddataviewer->BoxActorChanged(visible);
64 _vtkclipping3Ddataviewer->SetVisibleVolumeBox(visible);
65 _vtkclipping3Ddataviewer->SetVisibleVolume(!visible);
68 //-------------------------------------------------------------------
69 void wxVtkClipping3DView::Refresh()
71 _vtkclipping3Ddataviewer->Refresh();
72 if (_wxvtkclipping3DviewCntrlPanel!=NULL)
74 _wxvtkclipping3DviewCntrlPanel->Refresh();
77 //-------------------------------------------------------------------
78 wxPanel* wxVtkClipping3DView::CreateSurfControlPanel(wxWindow *parent)
80 _wxvtkclipping3DviewCntrlPanel = new wxVtkClipping3DViewCntrlPanel(parent,this);
81 return _wxvtkclipping3DviewCntrlPanel;
84 //RaC 03-2010 Divide in two panels
85 //-------------------------------------------------------------------
86 wxPanel* wxVtkClipping3DView::CreateVolControlPanel(wxWindow *parent)
88 _wxvtkclipping3DviewVolCntrlPanel = new wxVtkClipping3DViewVolCntrlPanel(parent,this);
89 return _wxvtkclipping3DviewVolCntrlPanel;
93 //-------------------------------------------------------------------
94 vtkClipping3DDataViewer* wxVtkClipping3DView::GetVtkClipping3DDataViewer()
96 return _vtkclipping3Ddataviewer;
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) );
104 _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue) );
105 // _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(idTissue) );
106 // _actor->VisibilityOn();
108 _vtkclipping3Ddataviewer->SetVisibleTissue(idTissue,visTissue);
111 //-------------------------------------------------------------------
112 void wxVtkClipping3DView::SetRepSurfaceWireFrame(int idTissue , bool representationType )
115 tmpActor = GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
117 if (representationType==false){
118 tmpActor->GetProperty()->SetRepresentationToWireframe();
120 tmpActor->GetProperty()->SetRepresentationToSurface();
123 _vtkclipping3Ddataviewer->SetRepresentationType(idTissue,representationType);
126 //-------------------------------------------------------------------
127 void wxVtkClipping3DView::VisibleVolumeActor( bool visVolume){
128 if (visVolume!=_vtkclipping3Ddataviewer->GetVisibleVolume() ){
129 if (visVolume==false){
131 // _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetVolumeActor() );
132 _wxvtk3Dbaseview->GetRenderer()->RemoveVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );
135 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetVolumeActor() );
136 _wxvtk3Dbaseview->GetRenderer()->AddVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );
138 _vtkclipping3Ddataviewer->SetVisibleVolume(visVolume);
140 else if(visVolume==false && _vtkclipping3Ddataviewer->GetVisibleVolumeBox() == true)
142 _vtkclipping3Ddataviewer->BoxActorChanged(false);
143 _vtkclipping3Ddataviewer->SetVisibleVolumeBox(false);
147 //-------------------------------------------------------------------
148 wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview()throw(char*)
150 if(_wxvtk3Dbaseview==NULL){
151 throw "wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
153 return _wxvtk3Dbaseview;
155 //-------------------------------------------------------------------
156 void wxVtkClipping3DView::Configure(){
157 _wxvtk3Dbaseview->Configure();
159 // Actors are added to the renderer.
160 _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetOutlineActor() );
162 _boxWidgetS1 = vtkBoxWidget::New();
163 _boxWidgetS1->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
164 _boxWidgetS1->SetPlaceFactor(1.25);
168 vtkStripper *stripper=_vtkclipping3Ddataviewer->GetTissueStripper(0);
169 vtkPolyData *polydata= stripper->GetOutput();
172 _boxWidgetS1->SetInput( polydata );
173 _boxWidgetS1->PlaceWidget();
176 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
178 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent, _vtkclipping3Ddataviewer->GetObserverS(i) );
184 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(0) );
185 // _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(3));
187 VisibleActor(0, false );
188 VisibleActor(1, false );
189 VisibleActor(2, false );
190 VisibleActor(3, false );
192 _boxWidgetS1->HandlesOn ();
195 // _boxWidgetS1->On();
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) );
206 _boxWidgetVolume = vtkBoxWidget::New();
207 _boxWidgetVolume->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
208 _boxWidgetVolume->SetPlaceFactor(1.25);
210 _boxWidgetVolume->SetInput( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
211 _boxWidgetVolume->PlaceWidget();
213 _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent , _vtkclipping3Ddataviewer->GetObserverV() );
215 _boxWidgetVolume->HandlesOn ();
218 // _boxWidgetVolume->On();
220 _boxWidgetVolume->Off();
223 // vtkPlanes *vtkplanes=this->GetVtkClipping3DDataViewer()->GetVolumePlanes();
224 // _boxWidgetVolume->GetPlanes( vtkplanes );
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);
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);
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();
246 _vtkclipping3Ddataviewer->SetRenderer(this->GetWxvtk3Dbaseview()->GetRenderer());
247 _vtkclipping3Ddataviewer->SetInteractor(this->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor());
250 //-------------------------------------------------------------------
251 void wxVtkClipping3DView::SetVtkClipping3DDataViewer(vtkClipping3DDataViewer *vtkclipping3Ddataviewer)
253 _vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
256 void wxVtkClipping3DView::SetRayCasting(bool active)
258 _vtkclipping3Ddataviewer->SetRayCasting(active);
259 _vtkclipping3Ddataviewer->updateVolume();
262 void wxVtkClipping3DView::SetMIPActive(bool active)
264 _vtkclipping3Ddataviewer->SetMIPActive(active);
265 _vtkclipping3Ddataviewer->updateVolume();
268 void wxVtkClipping3DView::SetInterpolation(bool active)
270 _vtkclipping3Ddataviewer->SetInterpolation(active);
271 _vtkclipping3Ddataviewer->updateVolume();
274 void wxVtkClipping3DView::SetShade(bool active)
276 _vtkclipping3Ddataviewer->SetShade(active);
277 _vtkclipping3Ddataviewer->updateVolume();
280 void wxVtkClipping3DView::UpdateVolumeBox(vector<double> gf, vector<double> vf, vtkColorTransferFunction* ctfun)
282 _vtkclipping3Ddataviewer->UpdateVolumeBox(gf, vf, ctfun);