]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/wxMaracasDataBrowser.cxx
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / wxMaracasDataBrowser.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracasDataBrowser.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/10/31 16:32:09 $
7   Version:   $Revision: 1.1 $
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 "wxMaracasFrame02.h"
19 #include "wxMaracasDataBrowser.h"
20
21 #include "marGdcmDicom.h"
22
23
24 #include "gdcmDocument.h"
25 #include "gdcmDicomDir.h"
26 #include "gdcmDicomDirPatient.h"
27 #include "gdcmDicomDirStudy.h"
28 #include "gdcmDicomDirSerie.h"
29 #include "gdcmDicomDirImage.h"
30 #include "gdcmTS.h"
31
32
33
34 //-------------------------------------------------------------------------
35
36 class wxDlgDefineRegionZ : public wxDialog {
37 public :
38         wxDlgDefineRegionZ(wxWindow *parent,int maxSize, wxString title);
39         int  GetIniSlice();
40         int  GetEndSlice();
41         void OnIni(wxScrollEvent& event);
42         void OnEnd(wxScrollEvent& event);
43
44         wxSlider *sldIni;
45         wxSlider *sldEnd;
46 private :
47 };
48
49 //-------------------------------------------------------------------------
50 //-------------------------------------------------------------------------
51 //-------------------------------------------------------------------------
52
53 wxDlgDefineRegionZ::wxDlgDefineRegionZ(wxWindow *parent,int maxSize, wxString title)
54 : wxDialog(parent, -1, title){
55
56                                 sldIni          = new wxSlider(this, -1, 0              , 0, maxSize, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );        
57                                 sldEnd          = new wxSlider(this, -1, maxSize, 0, maxSize, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );        
58         wxStaticText *text1             = new wxStaticText(this, -1, _T("Start : "));
59         wxStaticText *text2             = new wxStaticText(this, -1, _T("End : "));
60         wxButton        *btnOk          = new wxButton(this, wxID_OK , _T("OK"));
61         wxButton        *btnCancel      = new wxButton(this, wxID_CANCEL , _T("CANCEL"));
62
63         sldIni->SetSize(300,20);
64         sldEnd->SetSize(300,20);
65
66         wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
67         sizer->Add(text1);
68         sizer->Add(sldIni);
69         sizer->Add(text2);
70         sizer->Add(sldEnd);
71         sizer->Add(btnOk);
72         sizer->Add(btnCancel);
73         this->SetSizer(sizer);
74         this->SetSize(450,200);
75
76         this->Connect(sldIni->GetId()  , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxDlgDefineRegionZ::OnIni );
77         this->Connect(sldEnd->GetId()  , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxDlgDefineRegionZ::OnEnd );
78 }
79
80 //-------------------------------------------------------------------------
81
82 int wxDlgDefineRegionZ::GetIniSlice(){
83         return sldIni->GetValue();
84 }
85
86 //-------------------------------------------------------------------------
87
88 int wxDlgDefineRegionZ::GetEndSlice(){
89         return sldEnd->GetValue();
90 }
91
92 //-------------------------------------------------------------------------
93
94 void wxDlgDefineRegionZ::OnIni(wxScrollEvent& event){
95         if (sldIni->GetValue() > sldEnd->GetValue() ){
96          sldEnd->SetValue(sldIni->GetValue() );
97         }
98 }
99
100 //-------------------------------------------------------------------------
101
102 void wxDlgDefineRegionZ::OnEnd(wxScrollEvent& event){
103         if (sldIni->GetValue() > sldEnd->GetValue() ){
104          sldIni->SetValue(sldEnd->GetValue() );
105         }
106 }
107
108
109
110 //-------------------------------------------------------------------------
111 //-------------------------------------------------------------------------
112 //-------------------------------------------------------------------------
113
114
115 BEGIN_EVENT_TABLE( wxMaracasDataBrowser, wxPanel )
116     EVT_BUTTON( ID_BUTTON_CHANGEDIR                     , wxMaracasDataBrowser::OnChangeDir                     )
117     EVT_BUTTON( ID_BUTTON_CHANGEDICOMFILE       , wxMaracasDataBrowser::OnChangeDicomFile       )
118     EVT_BUTTON( ID_BUTTON_CREATEDICOMFILE       , wxMaracasDataBrowser::OnCreateDicomFile       )
119
120     EVT_LIST_ITEM_SELECTED(  ID_STUDIES_LIST, wxMaracasDataBrowser::OnStudySelected )
121     EVT_LIST_ITEM_SELECTED(  ID_SERIES_LIST     , wxMaracasDataBrowser::OnSerieSelected )
122     EVT_LIST_ITEM_ACTIVATED( ID_SERIES_LIST     , wxMaracasDataBrowser::OnActivated     )
123 END_EVENT_TABLE( );
124
125 //-------------------------------------------------------------------------
126 wxMaracasDataBrowser::wxMaracasDataBrowser( wxFrame* parent, marInterface* mar, wxWindowID id )
127     : wxPanel( parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
128 {
129     _mar = mar;
130     frame_parent = parent;
131
132     _splitter = new wxSplitterWindow( this, -1, wxDefaultPosition, wxSize( 1200, 800 ), wxSP_3D );
133
134     _studies = new wxListCtrl( _splitter, ID_STUDIES_LIST, wxDefaultPosition, wxSize(100,100), wxLC_REPORT );
135     _studies->InsertColumn( 0, _T("Patient's name"      ));
136     _studies->InsertColumn( 1, _T("Patient's ID"        ));
137     _studies->InsertColumn( 2, _T("Study's name"        ));
138     _studies->InsertColumn( 3, _T("Study's ID"          ));
139     _studies->InsertColumn( 4, _T("Study's date"        ));
140     _studies->InsertColumn( 5, _T("Study's time"        ));
141     _studies->InsertColumn( 6, _T("Study's description" ));
142
143     _series = new wxListCtrl( _splitter, ID_SERIES_LIST, wxDefaultPosition,  wxSize(100,100), wxLC_REPORT );
144     _series->InsertColumn( 0, _T("Serie's name"         ));
145     _series->InsertColumn( 1, _T("Serie's ID"           ));
146     _series->InsertColumn( 2, _T("Serie's date"         ));
147     _series->InsertColumn( 3, _T("Serie's time"         ));
148     _series->InsertColumn( 4, _T("Modality"             ));
149     _series->InsertColumn( 5, _T("Body part examined"   ));
150     _series->InsertColumn( 6, _T("Serie's description"  ));
151     _series->InsertColumn( 7, _T("Serie's diagnostic"   ));
152     _series->InsertColumn( 8, _T("Institution name"     ));
153     _series->InsertColumn( 9, _T("Number of images"     ));
154
155     _splitter->SplitHorizontally( _studies, _series);
156
157         wxFlexGridSizer *szTop  = new wxFlexGridSizer( 1 );
158
159         wxButton *btnChangeDir = new wxButton(this,ID_BUTTON_CHANGEDIR,_T("Change Directory")) ;
160         wxButton *btnChangeDicomFile = new wxButton(this,ID_BUTTON_CHANGEDICOMFILE,_T("Change DICOMDIR file")) ;
161         wxButton *btnCreateDicomFile = new wxButton(this,ID_BUTTON_CREATEDICOMFILE,_T("Create DICOMDIR file")) ;
162
163         btnChangeDir->SetSize(150,25);
164         btnChangeDicomFile->SetSize(150,25);
165         btnCreateDicomFile->SetSize(150,25);
166
167     szTop->Add( btnChangeDicomFile      , 0 , wxALL, 10);
168     szTop->Add( btnCreateDicomFile      , 0 , wxALL, 10);
169     szTop->Add( btnChangeDir            , 0 , wxALL, 10);
170
171
172
173         wxFlexGridSizer *szVertical  = new wxFlexGridSizer( 2 );
174     szVertical->Add( szTop, 1, wxALL|wxEXPAND , 0 );
175     szVertical->Add( _splitter, 1, wxALL|wxEXPAND , 0 );
176
177     this->SetSizer( szVertical );
178     this->SetAutoLayout( true );
179         this->Layout();
180
181     szTop->Fit( this );
182     szTop->SetSizeHints( this );
183 //    _splitter->SetMinimumPaneSize( 50 );
184         _splitter->SetSashPosition(500,true);
185
186         _parseDir=false;
187
188 }
189 //----------------------------------------------------------------------------
190 void wxMaracasDataBrowser::CreateDicomFile(){
191         marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
192         wxBusyCursor wait;
193         gdcmDicom->CreateDicomFile();
194 }
195 //-------------------------------------------------------------------------
196 void wxMaracasDataBrowser::LoadData( ){
197         wxBusyCursor    wait;
198     long                        tmp;
199     int                         it = 0;
200
201     _studies->Hide( );                          
202         _series->Hide( );
203     _studies->DeleteAllItems( );        
204         _series->DeleteAllItems( );
205
206         marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
207         gdcmDicom->FillDicomInfo(_parseDir);
208         GDCM_NAME_SPACE::DicomDir                       *dicomDir = gdcmDicom->getGdcmDicomDir();
209         GDCM_NAME_SPACE::DicomDirPatient        *pa;
210         GDCM_NAME_SPACE::DicomDirStudy          *st;
211
212     pa = dicomDir->GetFirstPatient();
213         while (pa){ // on degouline les PATIENT de ce DICOMDIR
214          st = pa->GetFirstStudy();
215          while ( st ) { // on degouline les STUDY de ce patient
216                         tmp = _studies->InsertItem( it, wxString(pa->GetEntryString (0x0010, 0x0010).c_str(), wxConvUTF8) , 0 ); // Patient's Name
217                         _studies->SetItemData( tmp, it );
218                         _studies->SetItem( it, 1, wxString(pa->GetEntryString (0x0010, 0x0020).c_str(), wxConvUTF8) );  // ID_Patient_ID
219                         _studies->SetItem( it, 2, wxString(st->GetEntryString (0x0020, 0x000d).c_str(), wxConvUTF8) );  // ID_Study_Instance_UID 
220                         _studies->SetItem( it, 3, wxString(st->GetEntryString (0x0020, 0x0010).c_str(), wxConvUTF8) );  // ID_Study_ID
221                         _studies->SetItem( it, 4, wxString(st->GetEntryString (0x0008, 0x0020).c_str(), wxConvUTF8) );  // ID_Study_Date        
222                         _studies->SetItem( it, 5, wxString(st->GetEntryString (0x0008, 0x0030).c_str(), wxConvUTF8) );  // ID_Study_Time
223                         _studies->SetItem( it, 6, wxString(st->GetEntryString (0x0008, 0x1030).c_str(), wxConvUTF8) );  // ID_Study_Description
224                         it++;
225                 st = pa->GetNextStudy();
226                  }
227                  pa = dicomDir->GetNextPatient(); 
228         }
229         
230     _studies->Show( ); _series->Show( );
231 }
232
233
234 //----------------------------------------------------------------------------
235 void wxMaracasDataBrowser::LoadDicomData(int type, wxString msg){
236         wxString dirHome = _mar->_parameters->getStringParam(
237                 marParameters::e_dicom_images_directory );
238         wxDirDialog dialog( this, msg,
239                         ( !dirHome.IsEmpty( ) )? dirHome: wxGetHomeDir( ) );
240
241         if( dialog.ShowModal( ) == wxID_OK ){
242                 _mar->_parameters->setStringParam(
243                 marParameters::e_dicom_images_directory, dialog.GetPath( ) );
244                 _mar->saveParameters( );
245                 if (type==1){
246                         _parseDir=true;
247                         this->LoadData();
248                 }
249                 if (type==2){
250                         _parseDir=false;
251                         this->LoadData();
252                 }
253                 if (type==3){
254                         this->CreateDicomFile();
255                         _parseDir=false;
256                         this->LoadData();
257                 }
258         }
259 }
260 //----------------------------------------------------------------------------
261 void wxMaracasDataBrowser::OnChangeDir( wxCommandEvent& event ){
262         this->LoadDicomData(1,_T("Choose a directory..."));
263 }
264 //----------------------------------------------------------------------------
265 void wxMaracasDataBrowser::OnChangeDicomFile( wxCommandEvent& event ){
266         this->LoadDicomData(2,_T("Choose a DICOM directory..."));
267 }
268 //----------------------------------------------------------------------------
269 void wxMaracasDataBrowser::OnCreateDicomFile( wxCommandEvent& event ){
270         this->LoadDicomData(3,_T("Create a DICOM file. Choose a directory..."));
271 }
272 //-------------------------------------------------------------------------
273 void wxMaracasDataBrowser::OnStudySelected( wxListEvent& event ){
274     int it=0;
275     int maxCount=event.GetIndex();
276         marGdcmDicom                    *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
277         GDCM_NAME_SPACE::DicomDir                       *dicomDir = gdcmDicom->getGdcmDicomDir();
278         GDCM_NAME_SPACE::DicomDirPatient        *pa;
279         GDCM_NAME_SPACE::DicomDirStudy          *st;
280         GDCM_NAME_SPACE::DicomDirSerie          *se;
281         GDCM_NAME_SPACE::DicomDirImage          *im;
282
283         bool ok=true;
284     pa = dicomDir->GetFirstPatient();
285         while ((pa) && (ok==true)){ // on degouline les PATIENT de ce DICOMDIR
286          st = pa->GetFirstStudy();
287          while ((st) && (ok==true)) { // on degouline les STUDY de ce patient
288                         if (it==maxCount) {
289                                 gdcmDicom->setActualPatient( pa );
290                                 gdcmDicom->setActualStudy( st );
291                                 ok=false;
292                         }
293                         it++;
294                         if (ok==true) { 
295                                 st = pa->GetNextStudy(); 
296                         }
297                  }
298                  pa = dicomDir->GetNextPatient(); 
299         }
300
301     _series->DeleteAllItems( );
302     long tmp;
303     it=0;
304
305         se = st->GetFirstSerie();
306         while ( se ) { // on degouline les SERIES de cette study
307         tmp = _series->InsertItem( it, wxString(se->GetEntryString(0x0020, 0x000e).c_str(), wxConvUTF8) , 0 ); // ID_Series_Instance_UID
308         _series->SetItemData( tmp, it );
309         _series->SetItem( it, 1, wxString(se->GetEntryString(0x0020, 0x0011).c_str(), wxConvUTF8 )); // ID_Series_Number
310         _series->SetItem( it, 2, wxString(se->GetEntryString(0x0008, 0x0021).c_str(), wxConvUTF8 )); // ID_Series_Date
311         _series->SetItem( it, 3, wxString(se->GetEntryString(0x0008, 0x0031).c_str(), wxConvUTF8 )); // ID_Series_Time
312         _series->SetItem( it, 4, wxString(se->GetEntryString(0x0008, 0x0060).c_str(), wxConvUTF8 )); // ID_Modality 
313         _series->SetItem( it, 5, wxString(se->GetEntryString(0x0018, 0x0015).c_str(), wxConvUTF8 )); // ID_Body_Part_Examined 
314         _series->SetItem( it, 6, wxString(se->GetEntryString(0x0008, 0x103e).c_str(), wxConvUTF8 )); // ID_Series_Description 
315 //      _series->SetItem( it, 7, wxString(se->GetEntryString(0x0008, 0x1080).c_str(), wxConvUTF8 )); // ID_Admitting_Diagnoses_Description
316 //      _series->SetItem( it, 8, wxString(se->GetEntryString(0x0008, 0x0080).c_str(), wxConvUTF8 )); // ID_Institution_Name
317                 int numOfImg = 0;
318         im = se->GetFirstImage();
319         while ( im ) { // on degouline les Images de cette serie
320                         numOfImg++;
321                         im = se->GetNextImage();   
322                 }
323                 wxString strNumOfImg;
324                 strNumOfImg.sprintf(_T("%d"),numOfImg);
325                 _series->SetItem( it, 9, strNumOfImg ); // number of images in the serie
326
327                 it++;
328         se = st->GetNextSerie();   
329         }
330
331   //re-disable
332   frame_parent->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, false);
333
334
335
336 }
337 //-------------------------------------------------------------------------
338 void wxMaracasDataBrowser::OnSerieSelected( wxListEvent& event ){
339         marGdcmDicom *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
340         GDCM_NAME_SPACE::DicomDirStudy *st = gdcmDicom->getActualStudy();
341         GDCM_NAME_SPACE::DicomDirSerie *se;
342
343     int it       = 0;
344         int maxCount = event.GetIndex();
345     se = st->GetFirstSerie();
346         bool ok=true;
347     while ( (se)  && (ok==true) ) { // on degouline les SERIES de cette study
348                 if (it==maxCount){
349                         gdcmDicom->setActualSerie(  se  );
350                         ok=false;
351                 }
352                 it++;
353         se = st->GetNextSerie();   
354         }
355     frame_parent->GetToolBar()->EnableTool(ID_TOOLBAR_IMAGE_BROWSER, true);
356 }
357 //-------------------------------------------------------------------------
358 void wxMaracasDataBrowser::OnActivated( wxListEvent& event )
359 {
360
361         bool ok=false;
362         marGdcmDicom                    *gdcmDicom = (marGdcmDicom*)_mar->_dicom;
363         GDCM_NAME_SPACE::DicomDirSerie          *se;
364         GDCM_NAME_SPACE::DicomDirImage          *im;
365         int                                             numOfImg = 0;
366
367         se = gdcmDicom->getActualSerie();
368     im = se->GetFirstImage();
369     while ( im ) { // on degouline les Images de cette serie
370                 numOfImg++;
371                 im = se->GetNextImage();   
372         }
373
374         wxDlgDefineRegionZ *wxdlgdefineregionZ = new wxDlgDefineRegionZ(this,numOfImg, _T("Define Z region"));
375         if (wxdlgdefineregionZ->ShowModal() == wxID_OK ){
376                 gdcmDicom->setIniSlice( wxdlgdefineregionZ->GetIniSlice() );
377                 gdcmDicom->setEndSlice( wxdlgdefineregionZ->GetEndSlice() );
378                 ok=true;
379         }
380         wxdlgdefineregionZ->Destroy();
381
382         if (ok==true){
383                 wxCommandEvent _evt(  wxEVT_COMMAND_MENU_SELECTED ,ID_TOOLBAR_IMAGE_BROWSER   );
384                 ProcessEvent(_evt);
385         }
386
387 }
388 // EOF - wxDataBrowser.cxx
389