From 7fe8cc3b940607846369ea5d10e2c2aaa6359862 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Sun, 21 Feb 2016 01:18:52 +0100 Subject: [PATCH] #2842 creaImageIO Bug New Normal - Read images from directory --- .../bbcreaImageIOImagesChooserDialogBox.xml | 19 +++- src/creaImageIOExternalGimmick.cpp | 20 ++-- src/creaImageIOWxSimpleDlg.cpp | 94 ++++++++++++++++++- src/creaImageIOWxSimpleDlg.h | 2 + 4 files changed, 122 insertions(+), 13 deletions(-) diff --git a/bbtk/src/bbcreaImageIOImagesChooserDialogBox.xml b/bbtk/src/bbcreaImageIOImagesChooserDialogBox.xml index 67e768e..816784b 100644 --- a/bbtk/src/bbcreaImageIOImagesChooserDialogBox.xml +++ b/bbtk/src/bbcreaImageIOImagesChooserDialogBox.xml @@ -79,13 +79,19 @@
-     
+	
+	     
+
         creaImageIO::WxSimpleDlg dlg(0,crea::std2wx(bbGetInputTitle()),"localdatabase_Descriptor.dscp","Local Database"); 
                 dlg.SetAttrDicomTags( bbGetInputDicomTags() );
 		dlg.ShowModal(); 
                 bbSetOutputDicomInfo( dlg.getDicomInfoImagesSelected() );
-		if (dlg.getImagesSelected().size()!=0){ 
-		  bbSetOutputFileName( std::string( dlg.getInfoImage().mb_str() ) );
+		if (dlg.getImagesSelected().size()!=0)
+		{ 
+			bbSetOutputFileName( std::string( dlg.getInfoImage().mb_str() ) );
+			bbSetOutputOut( dlg.getVolumeSelected() );
+		
+/*
 		  if(dlg.getImagesSelected().size() ==1)
 		  {
 			bbSetOutputOut( dlg.getImagesSelected()[0] );  
@@ -152,9 +158,14 @@
 			 bbSetOutputOut(first);
 			} // dim
 		  }
+*/
+
 		} else { 
-	        bbSetOutputOut( NULL );  
+			bbSetOutputOut( NULL );
 	} // dlg.getImagesSelected().size()!=0
+
+
+
         bbSetOutputOutImages( dlg.getImagesSelected());  
 printf("EED  creaImageIOWxSimpleDlg 5 \n");
     
diff --git a/src/creaImageIOExternalGimmick.cpp b/src/creaImageIOExternalGimmick.cpp index 42e07e2..f29cf98 100644 --- a/src/creaImageIOExternalGimmick.cpp +++ b/src/creaImageIOExternalGimmick.cpp @@ -39,18 +39,22 @@ vtkImageData* getImageDataDialog() std::vector images; creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB"); w.ShowModal(); + + vtkImageData *result=NULL; + if(w.GetReturnCode() == wxID_OK) { - std::vector s; - images = w.getImagesSelected(); - infoImage = w.getInfoImage(); +// images = w.getImagesSelected(); +// infoImage = w.getInfoImage(); + result=w.getVolumeSelected(); + } // if - vtkImageData *result=NULL; - if (images.size()>0) - { - result=images[0]; - } +// EED 2016/02/16 +// if (images.size()>0) +// { +// result=images[0]; +// } return result; } diff --git a/src/creaImageIOWxSimpleDlg.cpp b/src/creaImageIOWxSimpleDlg.cpp index 5d05322..e750b91 100644 --- a/src/creaImageIOWxSimpleDlg.cpp +++ b/src/creaImageIOWxSimpleDlg.cpp @@ -171,6 +171,7 @@ namespace creaImageIO EndModal( dlg.GetReturnCode() ); } +//----------------------------------------------------------------------------- wxString WxSimpleDlg::getInfoImage() { return infoimage; @@ -184,17 +185,108 @@ namespace creaImageIO return m_results; } +//----------------------------------------------------------------------------- std::vector< std::map > WxSimpleDlg::getDicomInfoImagesSelected() { return m_resultsDicomAtr; } +//----------------------------------------------------------------------------- void WxSimpleDlg::SetAttrDicomTags( std::vector attr ) { m_attrDicomTags=attr; } +//----------------------------------------------------------------------------- + vtkImageData* WxSimpleDlg::getVolumeSelected() + { + vtkImageData *result; + +// creaImageIO::WxSimpleDlg dlg(0,crea::std2wx(bbGetInputTitle()),"localdatabase_Descriptor.dscp","Local Database"); +// dlg.SetAttrDicomTags( bbGetInputDicomTags() ); +// dlg.ShowModal(); +// bbSetOutputDicomInfo( dlg.getDicomInfoImagesSelected() ); + + if (getImagesSelected().size()!=0){ +// bbSetOutputFileName( std::string( dlg.getInfoImage().mb_str() ) ); + if(getImagesSelected().size() ==1) + { + result = getImagesSelected()[0] ; + } else { + // FCY: it will be a big problem if we have several kind of data in the same folder. + // creation of a huge vtkImageData!!!! + vtkImageData* first = getImagesSelected()[0]; + int dim[3]; + first->GetDimensions(dim); + if (dim[2]==1) + { + vtkImageData *out; + out = vtkImageData::New(); + out->SetScalarType(first->GetScalarType()); + out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents()); + int ext[6]; + first->GetWholeExtent(ext); + if(ext[5] == 0) + { + ext[5] = getImagesSelected().size()-1; + } else { + ext[5] = ext[5] * getImagesSelected().size()-1; // to deal with multiframes + } // ext + out->SetExtent(ext); + double spac[3]; + first->GetDimensions(dim); + first->GetSpacing(spac); + if (spac[0]==spac[1]) + { + spac[2]=spac[0]; + } + out->SetSpacing(spac); + out->SetDimensions(dim[0], dim[1], getImagesSelected().size() ); + out->AllocateScalars(); + out->Update(); + unsigned long imsize = dim[0] * dim[1]; + imsize = imsize * dim[2]; // deal with multiframes here + // differents formats char , short, etc... + // differents components 1..3 ex. jpg ->RGB 3 + imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents(); + int slice,sizeImageVector=getImagesSelected().size(); + for (slice=0 ; sliceGetScalarPointer(0,0,slice), img->GetScalarPointer(0,0,0), imsize); + //img->Delete(); + } // for slice + +//EED This is NOT working. The iteration over the pointer vtkImageData +// int slice=0; +// std::vector::iterator it; +// for (it=dlg.getImagesSelected().begin(); it!=dlg.getImagesSelected().end(); ++it) +// { +// memcpy(out->GetScalarPointer(0,0,slice), (*it)->GetScalarPointer(0,0,0), imsize); +// slice++; +// } +// //for (it=dlg.getImagesSelected().begin(); it!=dlg.getImagesSelected().end(); ++it) +// //{ +// // (*it)->Delete(); +// //} + + result =out; + + } else { + result = first; + } // dim + } // if getImagesSelected size + } else { + result = NULL; + } // getImagesSelected().size()!=0 + + + return result; + + } + + -} +} // namespace creaImageIO diff --git a/src/creaImageIOWxSimpleDlg.h b/src/creaImageIOWxSimpleDlg.h index 5e3f5f0..f572373 100644 --- a/src/creaImageIOWxSimpleDlg.h +++ b/src/creaImageIOWxSimpleDlg.h @@ -58,6 +58,8 @@ namespace creaImageIO /// return a vtkImageData vector of selected images, if available std::vector getImagesSelected(); + vtkImageData* getVolumeSelected(); + wxString getInfoImage(); std::vector< std::map > getDicomInfoImagesSelected(); -- 2.47.1