]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/include/wxEmptyPanel_3_Widget.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / include / wxEmptyPanel_3_Widget.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 //EED 29Dic2006 Borrame prueba mara Michael
27
28 #include <vtkMetaImageReader.h>
29 #include <vtkMetaImageWriter.h>
30 #include <vtkPlaneSource.h>
31 #include <vtkProbeFilter.h>
32 #include <vtkDataSet.h>
33 #include <vtkStructuredPoints.h>
34 #include <vtkPointData.h>
35 #include <vtkImageResample.h>
36 #include <vtkJPEGWriter.h>
37 #include <vtkBMPWriter.h>
38  
39
40
41 #include "vtkActor.h"
42 #include "vtkSphereSource.h"
43 #include "vtkPolyDataMapper.h"
44 #include "vtkImageData.h"
45 #include "vtkImageCast.h"
46
47 #include "wxEmptyPanel_3_Widget.h"
48
49
50
51 #include <wx/splitter.h>
52
53 //-------------------------------------------------------------------
54 //-------------------------------------------------------------------
55 //-------------------------------------------------------------------
56 BEGIN_EVENT_TABLE( wxEmptyPanel_3_Widget, wxPanel )
57         EVT_MENU( 12121, wxEmptyPanel_3_Widget::OnRefreshView )
58 END_EVENT_TABLE( );
59 //-------------------------------------------------------------------
60 wxEmptyPanel_3_Widget::wxEmptyPanel_3_Widget(wxWindow *parent)
61 : wxPanel( parent, -1) 
62 {
63         wxBoxSizer                      *sizer                  = new wxBoxSizer(wxVERTICAL  );
64     wxSplitterWindow    *pnlSplitter    = new wxSplitterWindow( this , -1);
65         wxPanel                         *viewPanel              = CreateViewPanel(pnlSplitter);
66         wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);
67
68         sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
69         pnlSplitter     -> SetMinimumPaneSize( 50 );
70     pnlSplitter -> SplitVertically( viewPanel, controlPanel );
71         this            -> SetSizer(sizer);
72 //EEDxx2.4
73 //      FitInside();
74 }
75 //-------------------------------------------------------------------
76 wxEmptyPanel_3_Widget::~wxEmptyPanel_3_Widget(){
77         delete _imageviewer2D_1;
78 }
79 //-------------------------------------------------------------------
80 wxPanel* wxEmptyPanel_3_Widget::CreateViewPanel(wxWindow *parent)
81 {
82         wxPanel *panel          =       new wxPanel(parent,-1);
83     wxBoxSizer *sizer   =       new wxBoxSizer(wxVERTICAL);
84
85         _imageviewer2D_1        = new wxVtk2DBaseView(panel);
86         wxVTKRenderWindowInteractor *iren   = _imageviewer2D_1->GetWxVTKRenderWindowInteractor();
87         sizer->Add(iren , 1, wxEXPAND, 0);
88
89
90         panel->SetSizer(sizer);
91         panel->SetAutoLayout(true);
92         panel->SetSize(400,400);
93         panel->Layout();
94         return panel;
95 }
96 //-------------------------------------------------------------------
97 wxPanel* wxEmptyPanel_3_Widget::CreateControlPanel(wxWindow *parent)
98 {
99         _parent=parent;
100         wxPanel *panel  = new wxPanel(parent,-1);
101
102         wxButton *btnContourA   = new wxButton( panel, -1, _T("Active Contour A"));
103         wxButton *btnContourB   = new wxButton( panel, -1, _T("Active Contour B"));
104         wxButton *btnContourAB  = new wxButton( panel, -1, _T("Active Contour AB"));
105
106
107     wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
108         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
109         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
110         sizer->Add(btnContourA);
111         sizer->Add(btnContourB);
112         sizer->Add(btnContourAB);
113
114         panel->SetSizer(sizer);
115         panel->SetAutoLayout(true);
116         panel->SetSize(400,400);
117         panel->Layout();
118         Connect(btnContourA->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxEmptyPanel_3_Widget::OnContourA  );
119         Connect(btnContourB->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxEmptyPanel_3_Widget::OnContourB  );
120         Connect(btnContourAB->GetId()           , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxEmptyPanel_3_Widget::OnContourAB );
121         return panel;
122 }
123 //------------------------------------------------------------------------
124 void wxEmptyPanel_3_Widget::Refresh()
125 {
126         _imageviewer2D_1->Refresh();
127 }
128 //----------------------------------------------------------------------------
129 void wxEmptyPanel_3_Widget::OnRefreshView(wxCommandEvent & event)
130 {
131         Refresh();
132 }
133
134
135 //------------------------------------------------------------------------
136
137 void wxEmptyPanel_3_Widget::ConfigureVTK(marImageData *marimagedata)
138 {
139     wxBusyCursor wait;
140         double spc[3];
141         
142         vtkImageData *vtkimagedata = marimagedata->GetImageData(); // image t=0
143         vtkimagedata->UpdateInformation();
144         vtkimagedata->SetUpdateExtent(vtkimagedata->GetWholeExtent());
145         vtkimagedata->Update();
146         _data = vtkimagedata;
147         _data->GetSpacing(spc);
148         _vtkbasedata_1 = new vtkBaseData();
149         _vtkbasedata_1->SetMarImageData(marimagedata);  
150         _imageviewer2D_1->SetVtkBaseData( _vtkbasedata_1 );
151         _imageviewer2D_1->Configure();
152
153 //      vtkImageViewer2 *_imageViewer=_imageviewer2D_1->_imageViewer2XYZ->GetVtkImageViewer2();
154
155         // Contorno 1
156         _manContourControl_1    = new manualContourControler();
157         _mContourModel_1                = new manualContourModel();
158         _mViewContour_1                 = new manualViewContour();
159         _mViewContour_1->SetModel( _mContourModel_1 );
160         _mViewContour_1->SetWxVtkBaseView( _imageviewer2D_1 );
161         _mViewContour_1->SetRange( 2 );
162         _mViewContour_1->SetZ( 1000 );
163
164
165 //EED 3 oct 2006
166         _mViewContour_1->SetSpacing(spc);
167
168
169 //EED 3 oct 2006
170         _mViewContour_1->SetColorNormalContour(0, 0, 1);
171         _mViewContour_1->SetColorEditContour(0, 0.5, 0.5);
172
173
174         _manContourControl_1->SetModelView( _mContourModel_1 , _mViewContour_1 );
175         _imageviewer2D_1->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manContourControl_1 );
176         _manContourControl_1->CreateNewManualContour();
177         _manContourControl_1->SetActive(false);
178         _mViewContour_1->RefreshContour();
179
180         // Rectangulo
181         _manRoiControl  = new manualRoiControler();
182         _mContourModel  = new manualContourModel();
183         _mViewRoi               = new manualViewRoi();
184         _mViewRoi->SetModel( _mContourModel );
185         _mViewRoi->SetWxVtkBaseView( _imageviewer2D_1 );
186         _mViewRoi->SetRange( 2 );
187         _mViewRoi->SetZ( 1000 );
188
189 //EED 3 oct 2006
190         _mViewRoi->SetSpacing(spc);
191
192         _manRoiControl->SetModelView( _mContourModel , _mViewRoi );
193         _imageviewer2D_1->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manRoiControl );
194         _manRoiControl->CreateNewManualContour();
195         _manRoiControl->SetActive(true);
196         _mViewRoi->RefreshContour();
197
198         // Contorno 2
199         _manContourControl_2    = new manualContourControler();
200         _mContourModel_2                = new manualContourModel();
201         _mViewContour_2                 = new manualViewContour();
202         _mViewContour_2->SetModel( _mContourModel_2 );
203         _mViewContour_2->SetWxVtkBaseView( _imageviewer2D_1 );
204         _mViewContour_2->SetRange( 2 );
205         _mViewContour_2->SetZ( 1000 );
206
207 //EED 3 oct 2006
208         _mViewContour_2->SetSpacing(spc);
209
210 //EED 3 oct 2006
211         _mViewContour_2->SetColorNormalContour(1, 1, 1);
212         _mViewContour_2->SetColorEditContour(0.5, 0.5, 0.5);
213
214
215         _manContourControl_2->SetModelView( _mContourModel_2 , _mViewContour_2 );
216         _imageviewer2D_1->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manContourControl_2 );
217         _manContourControl_2->CreateNewManualContour();
218         _manContourControl_2->SetActive(false);
219         _mViewContour_2->RefreshContour();
220
221 CreateNewPoint( 0,0);
222
223         Refresh();      
224 }
225
226
227 //----------------------------------------------------------------------------
228 //eedx21
229 void wxEmptyPanel_3_Widget::CreateNewPoint(double x, double y)
230 {
231 /*
232
233                 vtkSphereSource* aSphere =vtkSphereSource::New();
234         aSphere->SetRadius(0.2);
235         aSphere->SetCenter(x,y,0.5);
236
237         point_mapped.push_back(vtkPolyDataMapper::New());
238         point_mapped.back()->ImmediateModeRenderingOn();
239         //point_mapped.back()->ScalarVisibilityOff( );
240         point_mapped.back()->SetInput(aSphere->GetOutput());
241
242         point_actor.push_back(vtkActor::New());
243         point_actor.back()->SetMapper(point_mapped.back());
244         point_actor.back()->GetProperty()->BackfaceCullingOff();
245         point_actor.back()->GetProperty()->SetColor(0, 1, 0);
246
247         point_actor.back()->ApplyProperties();
248
249         _wxvtkbaseview->GetRenderer()->AddActor(point_actor.back());
250         _wxvtkbaseview->GetRenWin()->Render();
251 */
252
253 /*
254                 vtkActor                        *spheresActor   = vtkActor::New( );
255         vtkSphereSource         *spheres                = vtkSphereSource::New( );
256         vtkPolyDataMapper       *spheresMapper  = vtkPolyDataMapper::New( );
257         spheresMapper   -> SetInput( spheres->GetOutput( ) );
258         spheresActor    -> SetMapper( spheresMapper );
259                 _imageviewer2D_1 -> GetRenderer() -> AddActor( spheresActor );
260                 spheres->SetCenter( x,y,0 );
261                 spheres->SetRadius( 10 );
262 */
263
264         vtkSphereSource         *spheres                = vtkSphereSource::New( );
265                 spheres->SetCenter( x,y,0 );
266                 spheres->SetRadius( 5 );
267         vtkPolyDataMapper       *spheresMapper  = vtkPolyDataMapper::New( );
268                 spheresMapper   ->ImmediateModeRenderingOn();
269         spheresMapper   -> SetInput( spheres->GetOutput( ) );
270         vtkActor                        *spheresActor   = vtkActor::New( );
271         spheresActor    -> SetMapper( spheresMapper );
272         spheresActor    ->GetProperty()->BackfaceCullingOff();
273         spheresActor    ->GetProperty()->SetColor(0, 1, 0);
274         spheresActor    ->ApplyProperties();
275                 _imageviewer2D_1 -> GetRenderer() -> AddActor( spheresActor );
276
277
278 }
279
280
281
282
283 //------------------------------------------------------------------------
284 void wxEmptyPanel_3_Widget::OnContourA(wxCommandEvent& event)
285 {
286         _manRoiControl           -> SetActive(false);
287         _manContourControl_1 -> SetActive(true);
288         _manContourControl_2 -> SetActive(false);
289 }
290 //------------------------------------------------------------------------
291 void wxEmptyPanel_3_Widget::OnContourB(wxCommandEvent& event)
292 {
293         _manRoiControl           -> SetActive(false);
294         _manContourControl_1 -> SetActive(false);
295         _manContourControl_2 -> SetActive(true);
296 }
297 //------------------------------------------------------------------------
298 void wxEmptyPanel_3_Widget::OnContourAB(wxCommandEvent& event)
299 {
300         _manRoiControl           -> SetActive(false);
301         _manContourControl_1 -> SetActive(true);
302         _manContourControl_2 -> SetActive(true);
303 }
304 //------------------------------------------------------------------------
305