1 /*=========================================================================
4 Module: $RCSfile: wxMaracasImageBrowser02.cxx,v $
6 Date: $Date: 2008/10/31 16:32:10 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
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.
16 =========================================================================*/
19 #include <wx/filedlg.h>
21 #include "wxMaracasImageBrowser02.h"
22 #include "kernel/marDicomBase.h"
24 DEFINE_EVENT_TYPE(wxEVT_MARACASIMAGEBROWSERCUTIMAGE)
26 BEGIN_EVENT_TABLE( wxMaracasImageBrowser02, wxPanel )
27 EVT_MENU( 12121, wxMaracasImageBrowser02::OnRefreshView )
28 EVT_MENU( 12122, wxMaracasImageBrowser02::OnRefreshView2 )
33 //----------------------------------------------------------------------------
36 //wxMaracasImageBrowser02::wxMaracasImageBrowser02( wxWindow* parent, marInterface* mar, wxWindowID id )
37 // : wxPanel( parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ){
39 wxMaracasImageBrowser02::wxMaracasImageBrowser02( wxWindow* parent, marFilesBase *dicom ,marParameters* parameters )
40 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ){
42 this->SetSize(100,100);
44 //parent->GetToolBar()->EnableTool(ID_TOOLBAR_3D_BROWSER, _view_image->_bboxEnabled);
45 _parameters = parameters;
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 );
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 );
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);
80 wxFlexGridSizer *sizer= new wxFlexGridSizer(1);
81 sizer->AddGrowableCol(0);
82 sizer->AddGrowableRow(1);
85 sizer->Add( panel1 ,1,wxEXPAND,0 );
86 sizer->Add( panel2 , 1, wxGROW , 0 );
88 this->SetSizer( sizer );
89 this->SetAutoLayout( true );
92 //----------------------------------------------------------------------------
93 wxMaracasImageBrowser02::~wxMaracasImageBrowser02()
95 delete _imageviewer2D_1;
98 //----------------------------------------------------------------------------
99 void wxMaracasImageBrowser02::OnBtnCutVolume( wxCommandEvent & event )
101 wxCommandEvent cevent( wxEVT_MARACASIMAGEBROWSERCUTIMAGE, GetId() );
102 cevent.SetEventObject( this );
103 GetEventHandler()->ProcessEvent( cevent );
106 //----------------------------------------------------------------------------
107 void wxMaracasImageBrowser02::OnBtnResetRoi( wxCommandEvent & event )
109 if (_loadRangeImage!=NULL) {_loadRangeImage->Reset();}
111 vtkImageData *imagedata = _vtkbasedata_1->GetImageData();
113 imagedata->GetDimensions(dim);
116 vtkImageViewer2 *IV2= this->_imageviewer2D_1->_imageViewer2XYZ->GetVtkImageViewer2();
117 vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera();
119 camera->GetPosition(pos);
124 // imagedata->GetSpacing(spc);
125 // _manRoiControl->InitRoi( dim[0]*spc[0] , dim[1]*spc[1] , 0.2 );
127 _manRoiControl->InitRoi( dim[0] , dim[1] , 0.2);
128 _manRoiControl->SetActive(true);
130 _btnRestRoi->SetLabel( _T("Reset VOI") );
132 _imageviewer2D_1->Refresh();
137 //----------------------------------------------------------------------------
138 void wxMaracasImageBrowser02::LoadData( marImageData *marimagedata )
140 vtkImageData *imagedata = marimagedata->GetImageData();
141 imagedata->UpdateInformation();
142 imagedata->SetUpdateExtent(imagedata->GetWholeExtent());
145 _vtkbasedata_1 = new vtkBaseData();
146 _vtkbasedata_1->SetMarImageData( marimagedata );
147 _imageviewer2D_1->SetVtkBaseData( _vtkbasedata_1 );
148 _imageviewer2D_1->Configure(true);
150 // vtkImageViewer2 *_imageViewer=_imageviewer2D_1->_imageViewer2XYZ->GetVtkImageViewer2();
152 _manRoiControl = new manualRoiControler();
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 );
166 imagedata->GetSpacing(spc);
167 _mViewRoi->SetSpacing(spc);
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();
176 _imageviewer2D_1->GetWxVTKRenderWindowInteractor()->Render();
178 //----------------------------------------------------------------------------
179 void wxMaracasImageBrowser02::SetROI( int voi[6] )
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);
186 //----------------------------------------------------------------------------
187 void wxMaracasImageBrowser02::GetROI( int ext[6] )
189 double minX,minY,maxX,maxY;
190 _mViewRoi->GetMinMax(minX,minY,maxX,maxY);
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];
206 _loadRangeImage->GetROI( ext ); // ext[4..5]
208 if ( (ext[0]==ext[1]) || (ext[2]==ext[3]) || (ext[4]==ext[5]) )
211 _vtkbasedata_1->GetImageData ()->GetExtent( border );
221 //----------------------------------------------------------------------------
222 void wxMaracasImageBrowser02::Start( ){
223 _loadRangeImage->Start();
226 //----------------------------------------------------------------------------
227 void wxMaracasImageBrowser02::ForceToFinisReadActiveImages(){
228 _loadRangeImage->ForceToFinisReadActiveImages();
230 //----------------------------------------------------------------------------
231 bool wxMaracasImageBrowser02::GetRoiSelected()
233 double minX,minY,maxX,maxY;
234 _mViewRoi->GetMinMax(minX,minY,maxX,maxY);
237 if ( (minX==maxX) || (minY==maxY) )
243 //----------------------------------------------------------------------------
244 void wxMaracasImageBrowser02::Refresh()
246 int z = (int)_vtkbasedata_1->GetZ( );
247 _loadRangeImage->SetActualSlice( z );
248 _loadRangeImage->RefreshSlice();
249 z = _loadRangeImage->GetActualSlice( );
250 _vtkbasedata_1->SetZ( z );
252 // _imageviewer2D_1->Refresh();
254 //----------------------------------------------------------------------------
255 void wxMaracasImageBrowser02::OnRefreshView(wxCommandEvent & event)
259 //----------------------------------------------------------------------------
260 void wxMaracasImageBrowser02::OnRefreshView2(wxCommandEvent & event)
262 _loadRangeImage -> ResetActualSlice();//SIL//
263 int z = _loadRangeImage->GetActualSlice();
264 _vtkbasedata_1->SetZ( z );
265 _imageviewer2D_1->Refresh();
271 //------------------------------------------------------------------------
272 void wxMaracasImageBrowser02::OnBtSaveVOIData(wxCommandEvent& event)
274 wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
275 if (dialog.ShowModal() == wxID_OK)
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();
285 marRAW2Files marraw2;
286 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
291 // EOF - wxImageBrowser.cxx