]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/wxMaracasImageBrowser02.cxx
Compila en Unix Fedora
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / wxMaracasImageBrowser02.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracasImageBrowser02.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/11/21 14:15:17 $
7   Version:   $Revision: 1.2 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18 #include <wx/image.h>
19 #include <wx/filedlg.h>
20
21 #include "wxMaracasImageBrowser02.h"
22 //#include "kernel/marDicomBase.h" // JPRx
23
24 DEFINE_EVENT_TYPE(wxEVT_MARACASIMAGEBROWSERCUTIMAGE)
25
26 BEGIN_EVENT_TABLE( wxMaracasImageBrowser02, wxPanel )
27         EVT_MENU( 12121, wxMaracasImageBrowser02::OnRefreshView  )
28         EVT_MENU( 12122, wxMaracasImageBrowser02::OnRefreshView2 )
29 END_EVENT_TABLE( );
30
31
32
33 //----------------------------------------------------------------------------
34
35 //EED 15Avril2008
36 //wxMaracasImageBrowser02::wxMaracasImageBrowser02( wxWindow* parent, marInterface* mar, wxWindowID id )
37 //    : wxPanel( parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ){
38
39 wxMaracasImageBrowser02::wxMaracasImageBrowser02( wxWindow* parent, marFilesBase *dicom ,marParameters* parameters )
40     : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ){
41
42         this->SetSize(100,100);
43
44     //parent->GetToolBar()->EnableTool(ID_TOOLBAR_3D_BROWSER, _view_image->_bboxEnabled);
45         _parameters = parameters;
46
47     wxPanel *panel1=new wxPanel(this,-1);
48         _btnRestRoi     = new wxButton (panel1,-1,_T("Set VOI"),wxDefaultPosition ,wxSize(100,80)  );
49         _loadRangeImage = new LoadRangeImage(panel1,dicom);
50         _loadRangeImage->SetSize(100,100);
51         wxButton *bt_SavePerpSlice      = new wxButton(panel1,-1,_T("Save VOI image"));
52         wxButton *bt_CutVolume  = new wxButton(panel1,-1,_T("Cut Volume"));
53         Connect(bt_SavePerpSlice->GetId()       , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxMaracasImageBrowser02::OnBtSaveVOIData );
54         Connect(bt_CutVolume->GetId()           , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxMaracasImageBrowser02::OnBtnCutVolume );
55         Connect(_btnRestRoi->GetId()            , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) (wxCommandEventFunction) &wxMaracasImageBrowser02::OnBtnResetRoi      );
56
57
58     wxPanel *panel2=new wxPanel(this,-1);
59         _imageviewer2D_1 = new wxVtk2DBaseView(panel2);
60         wxVTKRenderWindowInteractor *iren = _imageviewer2D_1->GetWxVTKRenderWindowInteractor();
61     wxBoxSizer *sizerDown= new wxBoxSizer(wxVERTICAL);
62         sizerDown->Add( iren            , 1,  wxEXPAND , 0 );
63     panel2->SetSizer( sizerDown );
64     panel2->SetAutoLayout( true );
65     panel2->SetSize( 100,100 );
66     panel2->Layout();
67
68
69
70 //    wxBoxSizer *sizer1= new wxBoxSizer(wxHORIZONTAL);
71     wxFlexGridSizer *sizer1= new wxFlexGridSizer(10);
72     panel1->SetSizer( sizer1 );
73         sizer1->AddGrowableCol(1);
74         sizer1->Add( _btnRestRoi        );
75         sizer1->Add( _loadRangeImage,1,wxEXPAND,0               );
76         sizer1->Add( bt_SavePerpSlice);
77         sizer1->Add( bt_CutVolume);
78
79
80     wxFlexGridSizer *sizer= new wxFlexGridSizer(1);
81         sizer->AddGrowableCol(0);
82         sizer->AddGrowableRow(1);
83
84
85         sizer->Add(     panel1  ,1,wxEXPAND,0 );
86         sizer->Add(     panel2          , 1,  wxGROW , 0 );
87
88     this->SetSizer( sizer );
89     this->SetAutoLayout( true );
90     this->Layout();
91 }
92 //----------------------------------------------------------------------------
93 wxMaracasImageBrowser02::~wxMaracasImageBrowser02()
94 {
95   delete _imageviewer2D_1;
96 }
97
98 //----------------------------------------------------------------------------
99 void wxMaracasImageBrowser02::OnBtnCutVolume( wxCommandEvent &  event )
100 {
101                 wxCommandEvent cevent( wxEVT_MARACASIMAGEBROWSERCUTIMAGE, GetId() );
102                 cevent.SetEventObject( this );
103                 GetEventHandler()->ProcessEvent( cevent );
104 }
105
106 //----------------------------------------------------------------------------
107 void wxMaracasImageBrowser02::OnBtnResetRoi( wxCommandEvent &  event )
108 {
109         if (_loadRangeImage!=NULL) {_loadRangeImage->Reset();}
110
111         vtkImageData *imagedata = _vtkbasedata_1->GetImageData();
112         int dim[3];
113         imagedata->GetDimensions(dim);
114
115
116         vtkImageViewer2         *IV2= this->_imageviewer2D_1->_imageViewer2XYZ->GetVtkImageViewer2();
117         vtkCamera               *camera = IV2->GetRenderer()->GetActiveCamera();
118         double pos[3];
119         camera->GetPosition(pos);
120
121
122 // EED 27 sep 2006
123 //      double spc[3];
124 //      imagedata->GetSpacing(spc);
125 //      _manRoiControl->InitRoi( dim[0]*spc[0] , dim[1]*spc[1] , 0.2 );
126
127         _manRoiControl->InitRoi( dim[0]  , dim[1] , 0.2);
128         _manRoiControl->SetActive(true);
129
130         _btnRestRoi->SetLabel( _T("Reset VOI") );
131
132         _imageviewer2D_1->Refresh();
133
134 }
135
136
137 //----------------------------------------------------------------------------
138 void wxMaracasImageBrowser02::LoadData( marImageData *marimagedata )
139 {
140         vtkImageData *imagedata = marimagedata->GetImageData();
141         imagedata->UpdateInformation();
142         imagedata->SetUpdateExtent(imagedata->GetWholeExtent());
143         imagedata->Update();
144
145         _vtkbasedata_1 = new vtkBaseData();
146         _vtkbasedata_1->SetMarImageData( marimagedata );
147         _imageviewer2D_1->SetVtkBaseData( _vtkbasedata_1 );
148         _imageviewer2D_1->Configure(true);
149
150 //      vtkImageViewer2 *_imageViewer=_imageviewer2D_1->_imageViewer2XYZ->GetVtkImageViewer2();
151
152         _manRoiControl  = new manualRoiControler();
153
154 //JSTG 25-02-08 -------------------------------------
155         //_mContourModel  = new manualContourModel();
156         _mContourModel  = new manualContourModelRoi();
157 //---------------------------------------------------
158         _mViewRoi               = new manualViewRoi();
159         _mViewRoi->SetModel( _mContourModel );
160         _mViewRoi->SetWxVtkBaseView( _imageviewer2D_1 );
161         _mViewRoi->SetRange( (int)1.5 );
162
163
164 // EED 3 oct 2006
165         double spc[3];
166         imagedata->GetSpacing(spc);
167         _mViewRoi->SetSpacing(spc);
168
169         _manRoiControl->SetModelView( _mContourModel , _mViewRoi );
170         _imageviewer2D_1->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manRoiControl );
171         _manRoiControl->CreateNewManualContour();
172         _manRoiControl->SetState(0);
173         _manRoiControl->SetActive(false);
174         _mViewRoi->RefreshContour();
175
176         _imageviewer2D_1->GetWxVTKRenderWindowInteractor()->Render();
177 }
178 //----------------------------------------------------------------------------
179 void wxMaracasImageBrowser02::SetROI( int voi[6] )
180 {       
181         _loadRangeImage->Reset();
182         _loadRangeImage->SetStartEnd( voi[4],voi[5]);
183         _manRoiControl->SetRoi( voi[0],voi[2], voi[1],voi[3] );
184         _manRoiControl->SetActive(true);
185 }
186 //----------------------------------------------------------------------------
187 void wxMaracasImageBrowser02::GetROI( int ext[6] )
188 {       
189         double minX,minY,maxX,maxY;
190         _mViewRoi->GetMinMax(minX,minY,maxX,maxY);
191         ext[0]=(int)minX;
192         ext[1]=(int)maxX;
193         ext[2]=(int)minY;
194         ext[3]=(int)maxY;
195
196
197
198 // EED 27 sep 206
199 //      double spacing[3];
200 //      _vtkbasedata_1->GetImageData ()->GetSpacing( spacing );
201 //      ext[0] /= spacing[0];
202 //      ext[1] /= spacing[0];
203 //      ext[2] /= spacing[1];
204 //      ext[3] /= spacing[1];
205
206         _loadRangeImage->GetROI( ext ); // ext[4..5]
207
208         if ( (ext[0]==ext[1]) || (ext[2]==ext[3]) || (ext[4]==ext[5]) )
209         {
210                 int border[6];
211                 _vtkbasedata_1->GetImageData ()->GetExtent( border );
212                 ext[0] = border[0];
213                 ext[1] = border[1];
214                 ext[2] = border[2];
215                 ext[3] = border[3];
216                 ext[4] = border[4];
217                 ext[5] = border[5];
218         }
219
220 }
221 //----------------------------------------------------------------------------
222 void wxMaracasImageBrowser02::Start( ){
223         _loadRangeImage->Start();
224 }
225
226 //----------------------------------------------------------------------------
227 void wxMaracasImageBrowser02::ForceToFinisReadActiveImages(){
228         _loadRangeImage->ForceToFinisReadActiveImages();
229 }
230 //----------------------------------------------------------------------------
231 bool wxMaracasImageBrowser02::GetRoiSelected()
232 {
233         double minX,minY,maxX,maxY;
234         _mViewRoi->GetMinMax(minX,minY,maxX,maxY);
235
236         bool result=true;
237         if ( (minX==maxX) || (minY==maxY) )
238         {
239                 result=false;
240         }
241         return result;
242 }
243 //----------------------------------------------------------------------------
244 void wxMaracasImageBrowser02::Refresh()
245 {
246         int z = (int)_vtkbasedata_1->GetZ( ); 
247         _loadRangeImage->SetActualSlice( z );
248         _loadRangeImage->RefreshSlice();
249         z = _loadRangeImage->GetActualSlice(  );
250         _vtkbasedata_1->SetZ( z );
251
252 //      _imageviewer2D_1->Refresh();
253 }
254 //----------------------------------------------------------------------------
255 void wxMaracasImageBrowser02::OnRefreshView(wxCommandEvent & event)
256 {
257         Refresh();
258 }
259 //----------------------------------------------------------------------------
260 void wxMaracasImageBrowser02::OnRefreshView2(wxCommandEvent & event)
261 {
262         _loadRangeImage -> ResetActualSlice();//SIL//
263         int z = _loadRangeImage->GetActualSlice();      
264         _vtkbasedata_1->SetZ( z );
265         _imageviewer2D_1->Refresh();
266 }
267
268
269
270 // EED 04Janvier2007
271 //------------------------------------------------------------------------
272 void wxMaracasImageBrowser02::OnBtSaveVOIData(wxCommandEvent& event)
273 {
274         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
275         if (dialog.ShowModal() == wxID_OK)
276         {
277                 ForceToFinisReadActiveImages();
278                 std::string directory           = (const char *)(dialog.GetDirectory().mb_str());
279                 std::string filename            = (const char *)(dialog.GetFilename().mb_str());
280                 float rescalaSlope          =  _parameters->getRescaleSlope();
281                 float rescalaIntercept      =  _parameters->getRescaleIntercept();
282                 vtkImageData *vtkimagedata      = this->_vtkbasedata_1->GetMarImageData()->GetImageData();
283                 int voi[6];
284                 this->GetROI(voi);
285                 marRAW2Files marraw2;
286                 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
287         }
288 }
289
290
291 // EOF - wxImageBrowser.cxx