]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DView.cxx
7333e9334ec9bc140b99774d851bcc7cf5e81945
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkClipping3DView.cxx
1 #include "wxVtkClipping3DView.h"
2
3 #include "wxVtkClipping3DViewCntrlPanel.h"
4
5 wxVtkClipping3DView::wxVtkClipping3DView(wxVtk3DBaseView* wxvtk3Dbaseview)
6 {
7         _wxvtk3Dbaseview                                =       wxvtk3Dbaseview;
8         _vtkclipping3Ddataviewer                =       NULL;
9         _wxvtkclipping3DviewCntrlPanel  =       NULL;
10
11         _boxWidgetVolume                                =       NULL;
12         _boxWidgetS1                                    =       NULL;
13 }
14
15 //-------------------------------------------------------------------
16 wxVtkClipping3DView::~wxVtkClipping3DView(){
17         if (_boxWidgetVolume!=NULL)                              { _boxWidgetVolume     -> Delete();                                    }
18         if (_boxWidgetS1!=NULL)                                  { _boxWidgetS1         -> Delete();                                    }
19         if (_vtkclipping3Ddataviewer!=NULL)              { delete _vtkclipping3Ddataviewer;                     }
20         if (_wxvtkclipping3DviewCntrlPanel!=NULL){ delete _wxvtkclipping3DviewCntrlPanel;       }
21 }
22 //-------------------------------------------------------------------
23 void wxVtkClipping3DView::SetVisibleBoxSurface(bool visible)
24 {
25         if (visible==true){
26                 _boxWidgetS1->On();
27         } else {
28                 _boxWidgetS1->Off();
29         }
30 }
31 //-------------------------------------------------------------------
32 void wxVtkClipping3DView::SetVisibleBoxVolume(bool visible)
33 {
34         if (_boxWidgetVolume!=NULL){
35                 if (visible==true){
36                         _boxWidgetVolume->On();
37                 } else {
38                         _boxWidgetVolume->Off();
39                 }
40         }
41 }
42 //-------------------------------------------------------------------
43 void wxVtkClipping3DView::Refresh()
44 {
45         _vtkclipping3Ddataviewer->Refresh();
46         if (_wxvtkclipping3DviewCntrlPanel!=NULL)
47         {
48                 _wxvtkclipping3DviewCntrlPanel->Refresh();
49         }
50 }
51 //-------------------------------------------------------------------
52 wxPanel* wxVtkClipping3DView::CreateControlPanel(wxWindow *parent)
53 {
54         _wxvtkclipping3DviewCntrlPanel = new wxVtkClipping3DViewCntrlPanel(parent,this);
55         return _wxvtkclipping3DviewCntrlPanel;
56 }
57 //-------------------------------------------------------------------
58 vtkClipping3DDataViewer* wxVtkClipping3DView::GetVtkClipping3DDataViewer()
59 {
60         return _vtkclipping3Ddataviewer; 
61 }
62 //-------------------------------------------------------------------
63 void wxVtkClipping3DView::VisibleActor(int idTissue, bool visTissue){
64         if (visTissue!=_vtkclipping3Ddataviewer->GetVisibleTissue(idTissue)){
65                 if (visTissue==false){
66                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );    
67                 } else {
68                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );       
69 //                      _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(idTissue) );
70 //                      _actor->VisibilityOn();
71                 }
72                 _vtkclipping3Ddataviewer->SetVisibleTissue(idTissue,visTissue);
73         }
74 }
75 //-------------------------------------------------------------------
76 void wxVtkClipping3DView::SetRepSurfaceWireFrame(int idTissue , bool representationType )
77 {
78         vtkActor *tmpActor;
79         tmpActor = GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
80
81         if (representationType==false){
82                 tmpActor->GetProperty()->SetRepresentationToWireframe();
83         } else {
84                 tmpActor->GetProperty()->SetRepresentationToSurface();
85         }
86
87         _vtkclipping3Ddataviewer->SetRepresentationType(idTissue,representationType);
88 }
89
90 //-------------------------------------------------------------------
91 void wxVtkClipping3DView::VisibleVolumeActor( bool visVolume){
92         if (visVolume!=_vtkclipping3Ddataviewer->GetVisibleVolume() ){
93                 if (visVolume==false){
94 //EED 31/03/2008                        
95 //                      _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetVolumeActor()  );    
96                         _wxvtk3Dbaseview->GetRenderer()->RemoveVolume( _vtkclipping3Ddataviewer->GetVolumeActor()  );   
97                 } else {
98 //EED 31/03/2008                        
99 //                      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetVolumeActor() );        
100                         _wxvtk3Dbaseview->GetRenderer()->AddVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );       
101                 }
102                 _vtkclipping3Ddataviewer->SetVisibleVolume(visVolume);
103         }
104 }
105 //-------------------------------------------------------------------
106 wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview()throw(char*)
107 {
108         if(_wxvtk3Dbaseview==NULL){
109                 throw "wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
110         }
111         return _wxvtk3Dbaseview;
112 }
113 //-------------------------------------------------------------------
114 void wxVtkClipping3DView::Configure(){
115         _wxvtk3Dbaseview->Configure();
116
117         // Actors are added to the renderer. 
118         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetOutlineActor() );                       
119
120         _boxWidgetS1 = vtkBoxWidget::New();
121         _boxWidgetS1->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
122         _boxWidgetS1->SetPlaceFactor(1.25);
123
124
125
126         vtkStripper *stripper=_vtkclipping3Ddataviewer->GetTissueStripper(0);
127         vtkPolyData *polydata= stripper->GetOutput();
128  
129
130         _boxWidgetS1->SetInput( polydata );
131         _boxWidgetS1->PlaceWidget();
132
133         int i;
134         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
135         {
136                 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent          , _vtkclipping3Ddataviewer->GetObserverS(i) );
137         }
138
139
140
141
142 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(0) );                       
143 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(3));                        
144
145         VisibleActor(0, false );
146         VisibleActor(1, false );
147         VisibleActor(2, false );
148         VisibleActor(3, false );
149
150         _boxWidgetS1->HandlesOn ();
151         
152 //EED 29Mars2009        
153 //      _boxWidgetS1->On();
154         
155         _boxWidgetS1->Off();
156
157         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(0) );
158         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(1) );
159         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(2) );
160         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(3) );
161         
162 // EED 9 fev 2007
163 // box Volume
164         _boxWidgetVolume = vtkBoxWidget::New();
165         _boxWidgetVolume->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
166         _boxWidgetVolume->SetPlaceFactor(1.25);
167
168         _boxWidgetVolume->SetInput( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
169         _boxWidgetVolume->PlaceWidget();
170
171         _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent              , _vtkclipping3Ddataviewer->GetObserverV() );
172
173         _boxWidgetVolume->HandlesOn ();
174         
175 //EED 29Mars2009        
176 //      _boxWidgetVolume->On();
177         
178         _boxWidgetVolume->Off();
179
180
181 //      vtkPlanes *vtkplanes=this->GetVtkClipping3DDataViewer()->GetVolumePlanes();
182 //      _boxWidgetVolume->GetPlanes( vtkplanes );
183
184
185   // An initial camera view is created.  The Dolly() method moves 
186   // the camera towards the FocalPoint, thereby enlarging the image.
187   _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
188   _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
189   _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
190
191   // Set a background color for the renderer and set the size of the
192   // render window (expressed in pixels).
193   _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
194   _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
195
196   // Note that when camera movement occurs (as it does in the Dolly()
197   // method), the clipping planes often need adjusting. Clipping planes
198   // consist of two planes: near and far along the view direction. The 
199   // near plane clips out objects in front of the plane; the far plane
200   // clips out objects behind the plane. This way only what is drawn
201   // between the planes is actually rendered.
202   _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
203 }
204 //-------------------------------------------------------------------
205 void wxVtkClipping3DView::SetVtkClipping3DDataViewer(vtkClipping3DDataViewer *vtkclipping3Ddataviewer)
206 {
207         _vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
208 }