1 /*=========================================================================
4 Module: $RCSfile: wxILPDwithImage.cxx,v $
6 Date: $Date: 2008/10/31 16:32:09 $
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 "wxILPDwithImage.h"
22 #include "ILPD/src/controlerInterface/ILPDViewListPatient.h"
23 #include "ILPD/src/wxInterface/ILPDViewWxWindow.h"
27 #include "vtkGdcmReader.h"
29 #include "marImageData.h"
30 #include "marGdcmDicom.h"
32 #include <vtkImageData.h>
36 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
38 //----------------------------------------------------------------------------
41 BEGIN_EVENT_TABLE(wxILPDwithImage , wxPanel)
42 EVT_MENU(20001, wxILPDwithImage::OnSelectPatientStudySerieImage)
46 //----------------------------------------------------------------------------
48 wxILPDwithImage::wxILPDwithImage(wxWindow *parent)
52 _wxvtk2Dbaseview = NULL;
57 panel->SetAutoLayout(true);
60 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL );
61 _pnlSplitter_ViewImage_wxILPD = new wxSplitterWindow( panel , -1);
62 _wxILPD = new wxILPD( _pnlSplitter_ViewImage_wxILPD );
63 ILPDViewListPatient* _ilpdViewListPatient = new ILPDViewListPatient( new ILPDViewWxWindow(_wxILPD) );
64 wxPanel *viewPanel = CreatePanel_ViewImagePanel_WxILPD( _pnlSplitter_ViewImage_wxILPD );
66 topsizer -> Add( _pnlSplitter_ViewImage_wxILPD ,1,wxGROW ,0);
70 while (pp->GetParent()!=NULL) pp=pp->GetParent();
75 // pnlSplitter -> SplitHorizontally( viewPanel , _wxILPD, (int)(hh*0.45) );
76 _pnlSplitter_ViewImage_wxILPD -> SplitVertically( _wxILPD , viewPanel,300);
77 _pnlSplitter_ViewImage_wxILPD -> SetMinimumPaneSize( 10 );
80 // panel->FitInside();
83 panel->SetSizer( topsizer ); // use the sizer for layout
88 //----------------------------------------------------------------------------
89 wxILPDwithImage::~wxILPDwithImage()
91 if (_vtkbasedata!=NULL) { delete _vtkbasedata; }
92 if (_wxvtk2Dbaseview!=NULL) { delete _wxvtk2Dbaseview; }
95 //----------------------------------------------------------------------------
96 wxPanel *wxILPDwithImage::CreatePanel_ViewImagePanel_WxILPD( wxWindow *parent )
98 wxPanel *panel =new wxPanel( parent, -1 );
100 wxBoxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL );
101 _pnlSplitter_Image_DicomList = new wxSplitterWindow( panel , -1);
103 _panelImage = new wxPanel(_pnlSplitter_Image_DicomList,-1);
104 _panelImage->SetBackgroundColour( wxColour(0,0,0) );
105 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL );
106 // _panelImage->SetAutoLayout(true);
107 _panelImage->SetSizer( sizer ); // use the sizer for layout
108 // _panelImage->Layout();
109 // _panelImage->FitInside();
113 while (pp->GetParent()!=NULL) pp=pp->GetParent();
114 pp->GetSize(&ww,&hh);
117 _dicomPanelListView = new wxListView( _pnlSplitter_Image_DicomList, -1 );
118 _pnlSplitter_Image_DicomList->SetMinimumPaneSize( 200 );
121 // pnlSplitter -> SplitVertically( _panelImage, _dicomPanelListView, (int)(ww*0.45) );
122 _pnlSplitter_Image_DicomList -> SplitHorizontally( _panelImage, _dicomPanelListView, 300);
124 topsizer -> Add( _pnlSplitter_Image_DicomList ,1,wxGROW ,0);
126 panel->SetAutoLayout(true);
127 panel->SetSizer( topsizer ); // use the sizer for layout
131 // panel->FitInside();
138 //----------------------------------------------------------------------------
140 void wxILPDwithImage::SelectedSerie()
142 if (_wxILPD->GetTypeOfSelection() == 3)
144 vector <string*> lstStringFileName;
145 _wxILPD->GetLstImageFiles(&lstStringFileName);
148 // marGdcmDicomILPD *margdcmdicomILPD = (marGdcmDicomILPD*)_mar->_dicom;
149 // margdcmdicomILPD->SetListImages( &lstStringFileName );
151 if (_backStringFirstFile==*(lstStringFileName[0]))
153 //EED 14Avril2008 OJO
154 // _noteBook->SetPageImage(1, 4);
156 //EED 14Avril2008 OJO
157 // _noteBook->SetPageImage(1, 3);
161 int i,sizeLstNameFiles=lstStringFileName.size();
162 i=sizeLstNameFiles/2;
164 ShowDicomImage( lstStringFileName[i] );
166 // Show Number of Images
167 _dicomPanelListView->InsertColumn(0, _T("Number of Images") , wxLIST_FORMAT_LEFT, 100);
169 text.Printf(_T("%d"),sizeLstNameFiles);
170 SetItem(_dicomPanelListView,0,0, text );
174 //EED 14Avril2008 OJO
175 // _noteBook->SetPageImage(1, 5);
180 //----------------------------------------------------------------------------
182 void wxILPDwithImage::ShowDicomInformation(string *fileImageName)
186 GDCM_NAME_SPACE::File *gdcmFile = GDCM_NAME_SPACE::File::New();
187 gdcmFile->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
188 gdcmFile->SetFileName( fileImageName->c_str() );
189 bool ok = gdcmFile->Load();
192 if (gdcmFile->IsEmpty()==true)
194 _dicomPanelListView->InsertColumn(0, _T("Error") , wxLIST_FORMAT_LEFT, 80);
195 SetItem(_dicomPanelListView,0,0, _T("File not found...") );
199 _dicomPanelListView->InsertColumn(0, _T("Tag") , wxLIST_FORMAT_LEFT, 80);
200 _dicomPanelListView->InsertColumn(1, _T("VR") , wxLIST_FORMAT_LEFT, 40);
201 _dicomPanelListView->InsertColumn(2, _T("Name") , wxLIST_FORMAT_LEFT, 150);
202 _dicomPanelListView->InsertColumn(3, _T("Value") , wxLIST_FORMAT_LEFT, 400);
207 GDCM_NAME_SPACE::DataEntry *entry;
208 entry = (GDCM_NAME_SPACE::DataEntry*)gdcmFile->GetFirstEntry();
211 string groupelem = GDCM_NAME_SPACE::Util::Format("%04x | %04x" , entry->GetGroup() , entry->GetElement());
212 SetItem(_dicomPanelListView,line,0, wxString(groupelem.c_str(), wxConvUTF8) );
214 string vr =entry->GetVR().str();
215 SetItem(_dicomPanelListView,line,1, wxString(vr.c_str(), wxConvUTF8) );
216 SetItem(_dicomPanelListView,line,2, wxString(entry->GetName().c_str(), wxConvUTF8) );
218 if (entry->GetBinArea())
222 if( vr == "US" || vr == "SS" || vr == "UL" || vr == "SL" || vr == "FL" || vr == "FD")
224 value = entry->GetString();
226 value = GDCM_NAME_SPACE::Util::CreateCleanString( entry->GetBinArea(),entry->GetLength() );
228 value = "[" + value + "]" ;
229 SetItem(_dicomPanelListView,line,3, wxString(value.c_str(), wxConvUTF8) );
231 SetItem(_dicomPanelListView,line,3, _T("- NOT LOADED -") );
233 entry = (GDCM_NAME_SPACE::DataEntry*)gdcmFile->GetNextEntry();
240 //----------------------------------------------------------------------------
242 void wxILPDwithImage::ShowDicomImage(string *fileImageName)
245 bool reconfigure=false;
250 FILE *ff = fopen( fileImageName->c_str(),"r");
253 // string msgText= "File not found: \n\n";
254 // msgText.append(fileImageName->c_str());
255 // wxMessageDialog msgBox(this, msgText.c_str(),"Read file ERROR", wxOK );
256 // msgBox.ShowModal();
259 if (_wxvtk2Dbaseview!=NULL)
262 colorwindow = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorWindow();
263 colorlevel = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorLevel();
268 GDCM_NAME_SPACE::File *gdcmFile = GDCM_NAME_SPACE::File::New();
269 gdcmFile->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOW);
270 gdcmFile->SetFileName( fileImageName->c_str() );
271 bool ok = gdcmFile->Load();
272 long int offset = gdcmFile->GetPixelOffset();
274 dim[0]=gdcmFile->GetXSize();
275 dim[1]=gdcmFile->GetYSize();
280 vtkImageData *imageData = vtkImageData::New();
281 imageData->SetDimensions ( dim );
282 imageData->SetScalarTypeToUnsignedShort();
283 imageData->AllocateScalars();
286 marImageData *marimagedata = new marImageData(imageData);
289 marGdcmDicom margdcmdicom;
290 void *p_vol = imageData->GetScalarPointer(0,0,0);
291 margdcmdicom.loadFileDicom( p_vol , dim , (char *)fileImageName->c_str() );
293 // EED 17 Oct 2007 Before
294 // if ( _wxvtk2Dbaseview ) { delete _wxvtk2Dbaseview; }
295 // _wxvtk2Dbaseview = new wxVtk2DBaseView( _panelImage );
298 // EED 17 Oct 2007 After
299 if ( _wxvtk2Dbaseview==NULL )
301 _wxvtk2Dbaseview = new wxVtk2DBaseView( _panelImage );
302 wxVTKRenderWindowInteractor *imagePanel = _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
303 wxSizer *sizer=_panelImage->GetSizer();
304 sizer-> Add( imagePanel ,1,wxGROW ,0);
305 _panelImage->SetAutoLayout(true);
306 _panelImage->Layout();
310 if ( _vtkbasedata ) { delete _vtkbasedata; }
311 // if ( _widgetMesure ) { delete _widgetMesure; }
314 //_widgetMesure = new wxWidgetMesure2D(_panelImage);
316 //_wxvtk2Dbaseview = new wxVtk2DBaseView( _widgetMesure );
320 _vtkbasedata = new vtkBaseData();
321 _vtkbasedata->SetMarImageData( marimagedata );
322 _wxvtk2Dbaseview->SetVtkBaseData( _vtkbasedata );
323 _wxvtk2Dbaseview->Configure(true);
325 //_widgetMesure->ConfigureA(_wxvtk2Dbaseview);
326 //_widgetMesure -> SetMesureScale( gdcmFile->GetXSpacing() );
330 //sizer-> Add( _widgetMesure ,1,wxGROW ,0);
333 _wxvtk2Dbaseview->Refresh();
335 if (reconfigure==true)
337 _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow( colorwindow );
338 _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel( colorlevel );
346 //----------------------------------------------------------------------------
347 void wxILPDwithImage::ResetwxListView()
350 _dicomPanelListView->DeleteAllItems();
351 int i,size=_dicomPanelListView->GetColumnCount();
354 _dicomPanelListView->DeleteColumn(0);
358 //----------------------------------------------------------------------------
360 void wxILPDwithImage::SelectedImage()
362 if (_wxILPD->GetTypeOfSelection() == 4)
364 string fileImageName;
365 _wxILPD->GetFileImageName( &fileImageName );
366 ShowDicomInformation( &fileImageName );
367 ShowDicomImage(&fileImageName);
371 //----------------------------------------------------------------------------
373 void wxILPDwithImage::SelectedPatient()
375 if (_wxILPD->GetTypeOfSelection() == 1)
377 _dicomPanelListView->InsertColumn(0, _T("Number of Series") , wxLIST_FORMAT_LEFT, 80);
378 int numberOfSeries = _wxILPD->GetNumberOfSeries();
380 text.Printf(_T("%d"),numberOfSeries);
381 SetItem(_dicomPanelListView,0,0, text );
385 //----------------------------------------------------------------------------
387 void wxILPDwithImage::OnSelectPatientStudySerieImage(wxCommandEvent& event)
395 // Reset Image if there is no selection
396 if ((_wxILPD->GetTypeOfSelection() == 4) || (_wxILPD->GetTypeOfSelection() == 3))
404 if (_wxvtk2Dbaseview)
406 // delete _wxvtk2Dbaseview;
407 // _wxvtk2Dbaseview=NULL;
413 //----------------------------------------------------------------------------
414 void wxILPDwithImage::SetItem( wxListView *wxlistview, int line, int col, wxString text )
416 if (wxlistview->GetItemCount() <= line)
418 wxlistview->InsertItem(line,_T(" "),1);
421 item.m_itemId = line;
422 item.SetTextColour(*wxBLACK);
423 item.SetFont(*wxNORMAL_FONT); // or wxNORMAL_FONT, wxSMALL_FONT, wxSWISS_FONT
424 item.SetBackgroundColour(wxColour(255,255,255));
425 wxlistview->SetItem( item );
426 wxlistview->SetItem(line,col,text);
433 //----------------------------------------------------------------------------
435 wxILPD *wxILPDwithImage::GetWxILPD()
446 //----------------------------------------------------------------------------
447 void wxILPDwithImage::Configure()
449 _pnlSplitter_ViewImage_wxILPD -> SetSashPosition(850);
450 _pnlSplitter_Image_DicomList -> SetSashPosition(400);