From: Frederic Cervenansky Date: Thu, 23 Jun 2011 10:17:02 +0000 (+0000) Subject: modifications for bbtkItkImageChooserDialogBox X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=cc87ce2c00fc2ec3cc2fefc4375b53f7e16ff6fa;p=creaImageIO.git modifications for bbtkItkImageChooserDialogBox --- diff --git a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx index 1f4d1e6..2d90749 100644 --- a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx +++ b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx @@ -21,7 +21,8 @@ void ItkImagesChooserDialogBox::Process() bbtk::TypeInfo typ = bbitk::GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(*dlg->getTypes().front(), dlg->getDims().front()); BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, Export); - bbSetOutputOutVImages(dlg->getVtkImagesSelected()); + BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, ExportVTK); + delete dlg; } template @@ -34,8 +35,8 @@ void ItkImagesChooserDialogBox::Export() else if (dlg->getImagesSelected().size() > 1) { OutputImagesITKType outVect; - typename std::vector< typename TImage::Pointer> tempImgs= dlg->getTemplatedImagesSelected(); // JPR typename typename - typename std::vector< typename TImage::Pointer>::iterator it = tempImgs.begin(); // JPR typename typename + std::vector tempImgs= dlg->getTemplatedImagesSelected(); + std::vector::iterator it = tempImgs.begin(); for(;it != tempImgs.end(); ++it) { outVect.push_back( (*it).GetPointer() ); @@ -56,6 +57,33 @@ void ItkImagesChooserDialogBox::Export() //reader->GetOutput()->Register(); // this->bbSetOutputOut(reader->GetOutput()); } +template +void ItkImagesChooserDialogBox::ExportVTK() +{ + // BBTK can support only a vector with same dimensions image. + if (dlg->getDims().front() < 4) + { + std::vector tempImgs= dlg->getTemplatedImagesSelected(); + std::vector::iterator it = tempImgs.begin(); + for(;it != tempImgs.end(); ++it) + { + dlg->split3Din3Dvtk( (*it) ); + } + bbSetOutputOutVImages( dlg->getVtkImagesSelected() ); + } + else if (dlg->getDims().front() == 4) + { + // To Test + // dlg->split4Din3Dvtk("d:/temp2"); + // bbSetOutputOutVImages( dlg->getVtkImagesSelected()); + } + else + { + // NOT IMPLEMENTED YET FOR DIMENSIONS > 4 + + } + +} //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== diff --git a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h index f99b859..95088c6 100644 --- a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h +++ b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h @@ -50,6 +50,10 @@ class bbcreaImageIO_EXPORT ItkImagesChooserDialogBox private: // Template read method template void Export(); + + // Template export vtk Images + template void ExportVTK(); + itk::Object* mOutput; //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/src/creaImageIOWxAnySimpleDlg.cpp b/src/creaImageIOWxAnySimpleDlg.cpp index e66d2ba..ffaccd3 100644 --- a/src/creaImageIOWxAnySimpleDlg.cpp +++ b/src/creaImageIOWxAnySimpleDlg.cpp @@ -18,7 +18,7 @@ #include #include #include -#include "itkImageToVTKImageFilter.h" + namespace creaImageIO { @@ -50,7 +50,7 @@ namespace creaImageIO Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadGimmick ); /// \TODO Button to select Bruker directory - m_dicom = true; + m_dicom = false; Layout(); } @@ -515,7 +515,7 @@ namespace creaImageIO } - template + /* template void WxAnySimpleDlg::split3Din3Dvtk(TImage* i_Img) { typedef itk::ImageToVTKImageFilter< TImage > ConnectorType; @@ -527,7 +527,7 @@ namespace creaImageIO im->ShallowCopy(connector->GetOutput()); im->Update(); m_Vresults.push_back(im); - } + }*/ template diff --git a/src/creaImageIOWxAnySimpleDlg.h b/src/creaImageIOWxAnySimpleDlg.h index 17656da..49218a1 100644 --- a/src/creaImageIOWxAnySimpleDlg.h +++ b/src/creaImageIOWxAnySimpleDlg.h @@ -1,7 +1,5 @@ - - -#ifndef __creaImageIOWxAnySimpleDlg_h_INCLUDED__ -#define __creaImageIOWxAnySimpleDlg_h_INCLUDED__ +#ifndef __creaImageWxAnySimpleDlg_h_INCLUDED__ +#define __creaImageWxAnySimpleDlg_h_INCLUDED__ @@ -10,6 +8,8 @@ #include #include #include +#include "itkImageToVTKImageFilter.h" + namespace creaImageIO { /** @@ -80,6 +80,25 @@ namespace creaImageIO return imgs; } bool AllSameType(); + template + void split3Din3Dvtk(TImage* i_Img) + { + typedef itk::ImageToVTKImageFilter< TImage > ConnectorType; + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(i_Img); + connector->GetImporter()->SetDataScalarTypeToUnsignedChar(); + connector->Update(); + vtkImageData *im = vtkImageData::New(); + im->ShallowCopy(connector->GetOutput()); + im->Update(); + m_Vresults.push_back(im); + } + + + template + void split4Din3Dvtk(TImage* i_Img); + + private: // strange compile error with gcc 4.5.1-4 //JPR @@ -91,13 +110,9 @@ namespace creaImageIO std::string namedb; wxString infoimage; std::string m_dir; - template - void split3Din3Dvtk(TImage* i_Img); - template - void split4Din3Dvtk(TImage* i_Img); - bool m_dicom; + bool m_dicom; /// interface to read data SimpleView m_view; void readImg(const std::string &i_name); @@ -108,7 +123,6 @@ namespace creaImageIO const std::type_info & getType(const std::string &i_name); }; -} - -#endif //__creaImageIOWxAnySimpleDlg_h_INCLUDED__ +}// namespace creaImageIO +#endif //__creaImageWxAnySimpleDlg_h_INCLUDED__ diff --git a/src/creaImageIOWxISimpleDlg.hpp b/src/creaImageIOWxISimpleDlg.hpp index dbbbf8d..40553c3 100644 --- a/src/creaImageIOWxISimpleDlg.hpp +++ b/src/creaImageIOWxISimpleDlg.hpp @@ -220,156 +220,162 @@ namespace creaImageIO ////////////////////////////////////////////////////////////////////// // Return the results vector // ////////////////////////////////////////////////////////////////////// - template - std::vector WxISimpleDlg::getImagesSelected() - { - return m_Iresults; - } - - template - void WxISimpleDlg::readImg(const std::string &i_name) - { - // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images - // uncomment to test - /*typedef itk::ImageIOBase::IOComponentType ScalarPixelType; - itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(i_name.c_str(), itk::ImageIOFactory::ReadMode); - imageIO->SetFileName(i_name.c_str()); - imageIO->ReadImageInformation(); - ScalarPixelType pixelType = imageIO->GetComponentType(); - const size_t dims = imageIO->GetNumberOfDimensions();*/ - - typedef itk::ImageFileReader ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - try - { - reader->Update(); - } - catch( itk::ExceptionObject & err ) - { - std::cout << "Caught an exception reading" << i_name << ": " << std::endl; - std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; - throw err; - } - catch(...) - { - std::cout << "Error while reading image " << i_name << std::endl; - throw; - } - m_Iresults.push_back(reader->GetOutput()); - } - - - - template - void WxISimpleDlg::readDicomImg(const std::vector &i_names) - { - typedef itk::GDCMImageIO GDCMType; - typedef itk::DICOMSeriesFileNames dicnames; - GDCMType::Pointer gdcmIO = GDCMType::New(); - dicnames::Pointer generator = dicnames::New(); -// generator->SetInput(i_names); - typedef itk::ImageSeriesReader ReaderType; - typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetImageIO(gdcmIO); - reader->SetFileNames(i_names); - // reader->SetFileName( i_name ); - try - { - reader->Update(); - } - catch( itk::ExceptionObject & err ) - { - // std::cout << "Caught an exception reading" << i_name << ": " << std::endl; - std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; - throw err; - } - catch(...) - { - //std::cout << "Error while reading image " << i_name << std::endl; - throw; - } - m_Iresults.push_back(reader->GetOutput()); - } - - - - - template - void WxISimpleDlg::split3Din3Dvtk() - { - if ((m_Iresults).size() != 0) - { - typedef itk::ImageToVTKImageFilter< TImage > ConnectorType; - ConnectorType::Pointer connector = ConnectorType::New(); - for(unsigned int i = 0 ;i < m_Iresults.size(); i++) - { - connector->SetInput(m_Iresults[i]); - connector->GetImporter()->SetDataScalarTypeToUnsignedChar(); - connector->Update(); - vtkImageData *im = vtkImageData::New(); - im->ShallowCopy(connector->GetOutput()); - im->Update(); - m_Vresults.push_back(im); - } - } - } - - - - template - void WxISimpleDlg::split4Din3Dvtk(const std::string &i_dir) - { - if ((m_Iresults).size() != 0) - { - typename TImage::Pointer image = m_Iresults[0]; - - if(image->GetImageDimension() == 4) - { - // size of fourth dimension - int dsize = image->GetLargestPossibleRegion().GetSize(3); - // Output Type - typedef itk::Image ImageOutputType; - typedef itk::ImageSeriesWriter SeriesWriterType; - typedef itk::MetaImageIO MetaImageType; - MetaImageType::Pointer metaIO; - SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New(); - - // from JPR file to generate output files - typedef itk::NumericSeriesFileNames NamesGeneratorType; - NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New(); - namesGenerator->SetStartIndex(0); - namesGenerator->SetEndIndex(dsize-1); - namesGenerator->SetIncrementIndex(1); - std::string format = i_dir; - format += "/image%03d.mhd"; - namesGenerator->SetSeriesFormat( format.c_str() ); - - const std::vector names = namesGenerator->GetFileNames(); - seriesWriter->SetFileNames( names ); - seriesWriter->SetInput(image); - seriesWriter->SetImageIO(metaIO); - try - { - seriesWriter->Update(); - vtkMetaImageReader *vReader = vtkMetaImageReader::New(); - std::vector::const_iterator it = names.begin(); - for( ;it != names.end(); ++it) - { - vReader->SetFileName((*it).c_str()); - vReader->Update(); - m_Vresults.push_back(vReader->GetOutput()); - } - } - catch( itk::ExceptionObject & excp ) - { - std::cerr << "Exception thrown while writing the series " << std::endl; - std::cerr << excp << std::endl; - //return EXIT_FAILURE; - } - } - } - } + template + std::vector WxISimpleDlg::getImagesSelected() + { + return m_Iresults; + } + + template + void WxISimpleDlg::readImg(const std::string &i_name) + { + // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images + // uncomment to test + /*typedef itk::ImageIOBase::IOComponentType ScalarPixelType; + itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(i_name.c_str(), itk::ImageIOFactory::ReadMode); + imageIO->SetFileName(i_name.c_str()); + imageIO->ReadImageInformation(); + ScalarPixelType pixelType = imageIO->GetComponentType(); + const size_t dims = imageIO->GetNumberOfDimensions();*/ + + typedef itk::ImageFileReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + try + { + reader->Update(); + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Caught an exception reading" << i_name << ": " << std::endl; + std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; + throw err; + } + catch(...) + { + std::cout << "Error while reading image " << i_name << std::endl; + throw; + } + m_Iresults.push_back(reader->GetOutput()); + + } + + + + template + void WxISimpleDlg::readDicomImg(const std::vector &i_names) + { + typedef itk::GDCMImageIO GDCMType; + typedef itk::DICOMSeriesFileNames dicnames; + GDCMType::Pointer gdcmIO = GDCMType::New(); + dicnames::Pointer generator = dicnames::New(); +// generator->SetInput(i_names); + typedef itk::ImageSeriesReader ReaderType; + typename ReaderType::Pointer reader = ReaderType::New(); + reader->SetImageIO(gdcmIO); + reader->SetFileNames(i_names); + // reader->SetFileName( i_name ); + try + { + reader->Update(); + } + catch( itk::ExceptionObject & err ) + { + // std::cout << "Caught an exception reading" << i_name << ": " << std::endl; + std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; + throw err; + } + catch(...) + { + //std::cout << "Error while reading image " << i_name << std::endl; + throw; + } + m_Iresults.push_back(reader->GetOutput()); + + } + + + + + template + void WxISimpleDlg::split3Din3Dvtk() + { + if ((m_Iresults).size() != 0) + { + typedef itk::ImageToVTKImageFilter< TImage > ConnectorType; + ConnectorType::Pointer connector = ConnectorType::New(); + for(unsigned int i = 0 ;i < m_Iresults.size(); i++) + { + connector->SetInput(m_Iresults[i]); + connector->GetImporter()->SetDataScalarTypeToUnsignedChar(); + connector->Update(); + vtkImageData *im = vtkImageData::New(); + im->ShallowCopy(connector->GetOutput()); + im->Update(); + m_Vresults.push_back(im); + } + } + } + + + + template + void WxISimpleDlg::split4Din3Dvtk(const std::string &i_dir) + { + if ((m_Iresults).size() != 0) + { + typename TImage::Pointer image = m_Iresults[0]; + + if(image->GetImageDimension() == 4) + { + boost::any a1(image); + m_AnyImages.push_back(a1); + // size of fourth dimension + int dsize = image->GetLargestPossibleRegion().GetSize(3); + // Output Type + typedef itk::Image ImageOutputType; + typedef itk::ImageSeriesWriter SeriesWriterType; + typedef itk::MetaImageIO MetaImageType; + MetaImageType::Pointer metaIO; + SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New(); + + // from JPR file to generate output files + typedef itk::NumericSeriesFileNames NamesGeneratorType; + NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New(); + namesGenerator->SetStartIndex(0); + namesGenerator->SetEndIndex(dsize-1); + namesGenerator->SetIncrementIndex(1); + std::string format = i_dir; + format += "/image%03d.mhd"; + namesGenerator->SetSeriesFormat( format.c_str() ); + + const std::vector names = namesGenerator->GetFileNames(); + seriesWriter->SetFileNames( names ); + seriesWriter->SetInput(image); + seriesWriter->SetImageIO(metaIO); + try + { + seriesWriter->Update(); + vtkMetaImageReader *vReader = vtkMetaImageReader::New(); + std::vector::const_iterator it = names.begin(); + for( ;it != names.end(); ++it) + { + vReader->SetFileName((*it).c_str()); + vReader->Update(); + m_Vresults.push_back(vReader->GetOutput()); + + } + } + catch( itk::ExceptionObject & excp ) + { + std::cerr << "Exception thrown while writing the series " << std::endl; + std::cerr << excp << std::endl; + //return EXIT_FAILURE; + } + } + } + + } }// namespace end diff --git a/src/creaImageIOWxIsimpleDlg.h b/src/creaImageIOWxIsimpleDlg.h index 201c3dc..21555d8 100644 --- a/src/creaImageIOWxIsimpleDlg.h +++ b/src/creaImageIOWxIsimpleDlg.h @@ -7,7 +7,7 @@ #include "itkImageToVTKImageFilter.h" #include #include - +#include namespace creaImageIO { /** @@ -50,8 +50,10 @@ namespace creaImageIO void split4Din3Dvtk(const std::string &i_dir); void split3Din3Dvtk( ); void set(bool i_dicom){m_dicom= i_dicom;} + std::vector & getAnyImages(){ return m_AnyImages;} private: + std::vector m_AnyImages; std::vector m_exts; std::string namedescp; std::string namedb; diff --git a/tests/TestDcmDescriptor.cpp b/tests/TestDcmDescriptor.cpp index 4637c6e..54c14e3 100644 --- a/tests/TestDcmDescriptor.cpp +++ b/tests/TestDcmDescriptor.cpp @@ -6,7 +6,8 @@ #include #include - +using namespace creaImageIO; +using namespace creaImageIO::tree; /** * TestDcmDescriptor * \brief Read a descriptor file and check its content.