From e0a559861dcfa6732d80b3158eb2906ca650d5d4 Mon Sep 17 00:00:00 2001 From: jean-pierre roux Date: Thu, 26 May 2011 09:07:26 +0000 Subject: [PATCH] reindent --- src/creaImageIOWxAnySimpleDlg.cpp | 1103 ++++++++++++++--------------- src/creaImageIOWxAnySimpleDlg.h | 179 +++-- 2 files changed, 640 insertions(+), 642 deletions(-) diff --git a/src/creaImageIOWxAnySimpleDlg.cpp b/src/creaImageIOWxAnySimpleDlg.cpp index 4e0bf4d..593d389 100644 --- a/src/creaImageIOWxAnySimpleDlg.cpp +++ b/src/creaImageIOWxAnySimpleDlg.cpp @@ -22,584 +22,583 @@ namespace creaImageIO { - - ///Ctor + + ///Ctor WxAnySimpleDlg::WxAnySimpleDlg(wxWindow *parent, wxString i_title, const std::string i_namedescp , const std::string i_namedb) : wxDialog(parent, -1,_T("DISPLAY IMAGES"), wxDefaultPosition, wxSize(230,150)) { - namedescp = i_namedescp; - namedb = i_namedb; - - if(!i_title.empty()) - { - this->SetTitle(i_title); - } - // Button to select file(s) - wxButton *fileBut = new wxButton(this, -1,_T("Select a file to display"), wxPoint(10,7) ); - Connect( fileBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadFile ); - - // Button to select directory - wxButton *directoryBut = new wxButton(this, -1,_T("Select a directory to display"), wxPoint(10,40) ); - Connect( directoryBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadDirectory ); - - // button to select creaImageIO - wxButton *gimmickBut = new wxButton(this, -1,_T("Select Gimmick"), wxPoint(10,70) ); - Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadGimmick ); - - /// \TODO Button to select Bruker directory - m_dicom = true; - Layout(); - - } + namedescp = i_namedescp; + namedb = i_namedb; + + if(!i_title.empty()) + { + this->SetTitle(i_title); + } + // Button to select file(s) + wxButton *fileBut = new wxButton(this, -1,_T("Select a file to display"), wxPoint(10,7) ); + Connect( fileBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadFile ); + + // Button to select directory + wxButton *directoryBut = new wxButton(this, -1,_T("Select a directory to display"), wxPoint(10,40) ); + Connect( directoryBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadDirectory ); + + // button to select creaImageIO + wxButton *gimmickBut = new wxButton(this, -1,_T("Select Gimmick"), wxPoint(10,70) ); + Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadGimmick ); + + /// \TODO Button to select Bruker directory + m_dicom = true; + Layout(); + } ////////////////////////////////////////////////////////////////////// // // ////////////////////////////////////////////////////////////////////// - void WxAnySimpleDlg::OnReadFile(wxCommandEvent& event) - { - int resultShowModal; - wxFileDialog* fileDlg = new wxFileDialog( 0, _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition); + void WxAnySimpleDlg::OnReadFile(wxCommandEvent& event) + { + int resultShowModal; + wxFileDialog* fileDlg = new wxFileDialog( 0, _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition); - resultShowModal = fileDlg->ShowModal(); - if ( resultShowModal==wxID_OK ) - { - wxArrayString wxArray; - fileDlg->GetPaths(wxArray); - if(wxArray.size() >0) - { - for( int i = 0; i < wxArray.GetCount(); i++) - { - std::string name = crea::wx2std(wxArray[i]); - // FOR THE MOMENT ONLY short 3D et short 4D - readImg(name); - } - } - else { - // TO DO WARNING MESSAGES - } - } - SetReturnCode( resultShowModal ); -// Close(); - EndModal( resultShowModal ); - } - - - + resultShowModal = fileDlg->ShowModal(); + if ( resultShowModal==wxID_OK ) + { + wxArrayString wxArray; + fileDlg->GetPaths(wxArray); + if(wxArray.size() >0) + { + for( int i = 0; i < wxArray.GetCount(); i++) + { + std::string name = crea::wx2std(wxArray[i]); + // FOR THE MOMENT ONLY short 3D et short 4D + readImg(name); + } + } + else { + // TO DO WARNING MESSAGES + } + } + SetReturnCode( resultShowModal ); +// Close(); + EndModal( resultShowModal ); + } + + + void WxAnySimpleDlg::setExts(std::vector i_exts) { - m_exts = i_exts; + m_exts = i_exts; } - ////////////////////////////////////////////////////////////////////// -// // + ///////////////////////////////////////////////////////////////////// +// // ////////////////////////////////////////////////////////////////////// - void WxAnySimpleDlg::OnReadDirectory(wxCommandEvent &event) - { - int resultShowModal; - bool bvalid = false; - long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST; - wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style); - - resultShowModal = dirDlg->ShowModal(); - if ( resultShowModal==wxID_OK ) - { - std::string path = crea::wx2std(dirDlg->GetPath()); - typedef boost::filesystem::directory_iterator dir_it; - dir_it itr(path); - dir_it end_itr; - /*if (boost::filesystem::exists(path)) - {*/ - for(;itr != end_itr; ++itr) - { - bvalid = m_exts.size() == 0? true : false; - std::vector::iterator it = m_exts.begin(); - std::string ext = itr->filename().substr(itr->filename().find_last_of(".")); - for(; it != m_exts.end(); it++) - { - if(ext == (*it) ) - { - bvalid = true; - break; - } - } - if (!boost::filesystem::is_directory(itr->status()) && bvalid) - { - readImg(itr->string().c_str()); - } - } - } - SetReturnCode( resultShowModal ); -// Close(); - EndModal( resultShowModal ); - } - - ////////////////////////////////////////////////////////////////////// -// // + void WxAnySimpleDlg::OnReadDirectory(wxCommandEvent &event) + { + int resultShowModal; + bool bvalid = false; + long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST; + wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style); + + resultShowModal = dirDlg->ShowModal(); + if ( resultShowModal==wxID_OK ) + { + std::string path = crea::wx2std(dirDlg->GetPath()); + typedef boost::filesystem::directory_iterator dir_it; + dir_it itr(path); + dir_it end_itr; + /*if (boost::filesystem::exists(path)) + {*/ + for(;itr != end_itr; ++itr) + { + bvalid = m_exts.size() == 0? true : false; + std::vector::iterator it = m_exts.begin(); + std::string ext = itr->filename().substr(itr->filename().find_last_of(".")); + for(; it != m_exts.end(); it++) + { + if(ext == (*it) ) + { + bvalid = true; + break; + } + } + if (!boost::filesystem::is_directory(itr->status()) && bvalid) + { + readImg(itr->string().c_str()); + } + } + } + SetReturnCode( resultShowModal ); +// Close(); + EndModal( resultShowModal ); + } + + ////////////////////////////////////////////////////////////////////// +// // ////////////////////////////////////////////////////////////////////// - - void WxAnySimpleDlg::OnReadGimmick(wxCommandEvent &event) - { - // Run Gimmick - WxGimmickReaderDialog dlg(0,-1, - namedescp, - namedb, - _T("Select image(s) - Gimmick! (c) CREATIS-LRMN 2008"), + + void WxAnySimpleDlg::OnReadGimmick(wxCommandEvent &event) + { + // Run Gimmick + WxGimmickReaderDialog dlg(0,-1, + namedescp, + namedb, + _T("Select image(s) - Gimmick! (c) CREATIS-LRMN 2008"), wxDefaultPosition, wxSize(810,750), GIMMICK_2D_IMAGE_SELECTION, GIMMICK_3D_IMAGE_SELECTION, _3D, - 1); - dlg.ShowModal(); - if (dlg.GetReturnCode() == wxID_OK) - { - std::vector out; - dlg.stopReading(); - dlg.GetSelectedFiles(out); - if(m_dicom) - { - readDicomImg( out); - } - else - { - std::vector::iterator ii = out.begin(); - for (;ii != out.end();ii++) - { - readImg( (*ii).c_str() ); - } - } - dlg.OnExit(); - } - SetReturnCode( dlg.GetReturnCode() ); -// Close(); - EndModal( dlg.GetReturnCode() ); - } + 1); + dlg.ShowModal(); + if (dlg.GetReturnCode() == wxID_OK) + { + std::vector out; + dlg.stopReading(); + dlg.GetSelectedFiles(out); + if(m_dicom) + { + readDicomImg( out); + } + else + { + std::vector::iterator ii = out.begin(); + for (;ii != out.end();ii++) + { + readImg( (*ii).c_str() ); + } + } + dlg.OnExit(); + } + SetReturnCode( dlg.GetReturnCode() ); +// Close(); + EndModal( dlg.GetReturnCode() ); + } - wxString WxAnySimpleDlg::getInfoImage() - { - return infoimage; - } - - - // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images - const std::type_info & WxAnySimpleDlg::getType(const std::string &i_name) - { - 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(); - return imageIO->GetComponentTypeInfo();//AsString( imageIO->GetComponentType()); - } - - const size_t WxAnySimpleDlg::getNumberOfDimensions(const std::string &i_name) - { - 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(); - return imageIO->GetNumberOfDimensions(); - } - - void WxAnySimpleDlg::readImg(const std::string &i_name) - { - size_t dims = getNumberOfDimensions(i_name); - const std::type_info *type= &getType(i_name); - switch(dims) - { - case 3: - if (getType(i_name) == typeid(unsigned char)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed char)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(short)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned short)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned int)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed int)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned long)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed long)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(float)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else if (getType(i_name) == typeid(double)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - } - else - { - //????FCY, so what the type???? - } - break; - //assume that we have only one 4D file - case 4: - if (getType(i_name) == typeid(unsigned char)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed char)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned short)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if(getType(i_name) == typeid(short)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - 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; - } - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned short)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned int)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed int)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned long)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed long)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(float)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(double)) - { - typedef itk::Image TImage; - typedef itk::ImageFileReader ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( i_name ); - reader->Update(); - reader->GetOutput()->Register(); - m_AnyImages.push_back(reader->GetOutput()); - split4Din3Dvtk(reader->GetOutput()); - } - else - { - //????FCY, so what the type???? - } - break; - } - - // Test to know if we have to add new type - bool btest = false; - if( m_AnyDims.size() != 0) - { - btest = true; - } - else - { - m_AnyDims.push_back(dims); - m_AnyType.push_back(&getType(i_name)); - } - if (btest) - { - if(m_AnyDims.front() != dims || m_AnyType.front()->before(getType(i_name))) - { - m_AnyDims.push_back(dims); - m_AnyType.push_back(&getType(i_name)); - } - else{} - } - else {} - } - - - - - void WxAnySimpleDlg::readDicomImg(const std::vector &i_names) - { - typedef itk::Image TImage; - typedef itk::GDCMImageIO GDCMType; - typedef itk::DICOMSeriesFileNames dicnames; - GDCMType::Pointer gdcmIO = GDCMType::New(); - dicnames::Pointer generator = dicnames::New(); - - - typedef itk::ImageSeriesReader ReaderType; - 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()); + wxString WxAnySimpleDlg::getInfoImage() + { + return infoimage; + } + + + // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images + const std::type_info & WxAnySimpleDlg::getType(const std::string &i_name) + { + 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(); + return imageIO->GetComponentTypeInfo();//AsString( imageIO->GetComponentType()); + } + + const size_t WxAnySimpleDlg::getNumberOfDimensions(const std::string &i_name) + { + 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(); + return imageIO->GetNumberOfDimensions(); + } + + void WxAnySimpleDlg::readImg(const std::string &i_name) + { + size_t dims = getNumberOfDimensions(i_name); + const std::type_info *type= &getType(i_name); + switch(dims) + { + case 3: + if (getType(i_name) == typeid(unsigned char)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(signed char)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(short)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned short)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned int)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(signed int)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned long)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(signed long)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(float)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else if (getType(i_name) == typeid(double)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + } + else + { + //????FCY, so what the type???? + } + break; + //assume that we have only one 4D file + case 4: + if (getType(i_name) == typeid(unsigned char)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(signed char)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned short)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if(getType(i_name) == typeid(short)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + 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; + } + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned short)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned int)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(signed int)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(unsigned long)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(signed long)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(float)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else if (getType(i_name) == typeid(double)) + { + typedef itk::Image TImage; + typedef itk::ImageFileReader ReaderType; + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName( i_name ); + reader->Update(); + reader->GetOutput()->Register(); + m_AnyImages.push_back(reader->GetOutput()); + split4Din3Dvtk(reader->GetOutput()); + } + else + { + //????FCY, so what the type???? + } + break; + } + + // Test to know if we have to add new type + bool btest = false; + if( m_AnyDims.size() != 0) + { + btest = true; + } + else + { + m_AnyDims.push_back(dims); + m_AnyType.push_back(&getType(i_name)); + } + if (btest) + { + if(m_AnyDims.front() != dims || m_AnyType.front()->before(getType(i_name))) + { + m_AnyDims.push_back(dims); + m_AnyType.push_back(&getType(i_name)); + } + else{} + } + else {} + } + + + + + void WxAnySimpleDlg::readDicomImg(const std::vector &i_names) + { + typedef itk::Image TImage; + typedef itk::GDCMImageIO GDCMType; + typedef itk::DICOMSeriesFileNames dicnames; + GDCMType::Pointer gdcmIO = GDCMType::New(); + dicnames::Pointer generator = dicnames::New(); + + + typedef itk::ImageSeriesReader ReaderType; + 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 WxAnySimpleDlg::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 WxAnySimpleDlg::split4Din3Dvtk(TImage* i_Img) - { - if(i_Img->GetImageDimension() == 4) - { - // size of fourth dimension - int dsize = i_Img->GetLargestPossibleRegion().GetSize(3); - // Output Type - typedef itk::Image ImageOutputType; - typedef itk::ImageSeriesWriter SeriesWriterType; - typedef itk::MetaImageIO MetaImageType; - MetaImageType::Pointer metaIO; - typename 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 = m_dir; - format += "/image%03d.mhd"; - namesGenerator->SetSeriesFormat( format.c_str() ); - - const std::vector names = namesGenerator->GetFileNames(); - seriesWriter->SetFileNames( names ); - seriesWriter->SetInput(i_Img); - 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; - } - } - } - - bool WxAnySimpleDlg::AllSameType() - { - if(m_AnyType.size() == 1) - { - return true; - } - else - { - return false; - } - - } + } + + + + + template + void WxAnySimpleDlg::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 WxAnySimpleDlg::split4Din3Dvtk(TImage* i_Img) + { + if(i_Img->GetImageDimension() == 4) + { + // size of fourth dimension + int dsize = i_Img->GetLargestPossibleRegion().GetSize(3); + // Output Type + typedef itk::Image ImageOutputType; + typedef itk::ImageSeriesWriter SeriesWriterType; + typedef itk::MetaImageIO MetaImageType; + MetaImageType::Pointer metaIO; + typename 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 = m_dir; + format += "/image%03d.mhd"; + namesGenerator->SetSeriesFormat( format.c_str() ); + + const std::vector names = namesGenerator->GetFileNames(); + seriesWriter->SetFileNames( names ); + seriesWriter->SetInput(i_Img); + 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; + } + } + } + + bool WxAnySimpleDlg::AllSameType() + { + if(m_AnyType.size() == 1) + { + return true; + } + else + { + return false; + } + + } }// namespace end diff --git a/src/creaImageIOWxAnySimpleDlg.h b/src/creaImageIOWxAnySimpleDlg.h index aa82927..eb10d1e 100644 --- a/src/creaImageIOWxAnySimpleDlg.h +++ b/src/creaImageIOWxAnySimpleDlg.h @@ -9,95 +9,94 @@ namespace creaImageIO * \ingroup View */ - /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display -//EED class __declspec(dllexport) WxAnySimpleDlg : public wxDialog - class CREAIMAGEIO_EXPORT WxAnySimpleDlg : public wxDialog - { - public: - /// Ctor - WxAnySimpleDlg( wxWindow *parent, - wxString i_title =_T(""), - const std::string i_namedescp = "localdatabase_Descriptor.dscp", - const std::string i_namedb = "Local Database" - ); - - ~WxAnySimpleDlg(){}; - - void setExts(std::vector); - /// Callback to read file(s) - void OnReadFile(wxCommandEvent& event); - - /// Callback to read directory, no recursive - void OnReadDirectory(wxCommandEvent &event); - - /// Callback to select from creaImageIO database - void OnReadGimmick(wxCommandEvent &event); - - /// return a vtkImageData vector of selected images, if available - std::vector getVtkImagesSelected() {return m_Vresults;} - - wxString getInfoImage(); - - - void set(bool i_dicom){m_dicom= i_dicom;} - std::vector & getImagesSelected(){ return m_AnyImages;} - - // return the size of readed images - std::vector getDims(){ return m_AnyDims;} - - // return the type of readed images - std::vector getTypes(){ return m_AnyType;} - - // get an Image on wanted type - template - typename TImage::Pointer getImage(boost::any i_AnyImage) - { - typedef itk::Image ImageOut; - typename ImageOut::Pointer img = ImageOut::New(); - img = boost::any_cast< ImageOut::Pointer>(i_AnyImage); - return img; - } - - // get the images on itk type defined by user - template - std::vector getTemplatedImagesSelected() - { - std::vector imgs; - std::vector::iterator it = m_AnyImages.begin(); - for(; it != m_AnyImages.end(); it++) - { - imgs.push_back(boost::any_cast (*it)); - } - return imgs; - } - bool AllSameType(); - private: - - - std::vector m_AnyDims; - std::vector m_AnyType; - std::vector m_AnyImages; - std::vector m_exts; - std::string namedescp; - std::string namedb; - wxString infoimage; - std::string m_dir; - template - void split3Din3Dvtk(TImage* i_Img); - - template - void split4Din3Dvtk(TImage* i_Img); - - bool m_dicom; - /// interface to read data - SimpleView m_view; - void readImg(const std::string &i_name); - void readDicomImg(const std::vector &i_names); - std::vector m_Vresults; - - const size_t getNumberOfDimensions(const std::string &i_name); - const std::type_info & getType(const std::string &i_name); - }; - + /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display +//EED class __declspec(dllexport) WxAnySimpleDlg : public wxDialog + class CREAIMAGEIO_EXPORT WxAnySimpleDlg : public wxDialog + { + public: + /// Ctor + WxAnySimpleDlg( wxWindow *parent, + wxString i_title =_T(""), + const std::string i_namedescp = "localdatabase_Descriptor.dscp", + const std::string i_namedb = "Local Database" + ); + + ~WxAnySimpleDlg(){}; + + void setExts(std::vector); + /// Callback to read file(s) + void OnReadFile(wxCommandEvent& event); + + /// Callback to read directory, no recursive + void OnReadDirectory(wxCommandEvent &event); + + /// Callback to select from creaImageIO database + void OnReadGimmick(wxCommandEvent &event); + + /// return a vtkImageData vector of selected images, if available + std::vector getVtkImagesSelected() {return m_Vresults;} + + wxString getInfoImage(); + + void set(bool i_dicom){m_dicom= i_dicom;} + std::vector & getImagesSelected(){ return m_AnyImages;} + + // return the size of readed images + //strange compile error // JPR + std::vector getDims(){ return m_AnyDims;} + + // return the type of readed images + std::vector getTypes(){ return m_AnyType;} + + // get an Image on wanted type + template + typename TImage::Pointer getImage(boost::any i_AnyImage) + { + typedef itk::Image ImageOut; + typename ImageOut::Pointer img = ImageOut::New(); + img = boost::any_cast< ImageOut::Pointer>(i_AnyImage); + return img; + } + + // get the images on itk type defined by user + template + std::vector getTemplatedImagesSelected() + { + std::vector imgs; + std::vector::iterator it = m_AnyImages.begin(); + for(; it != m_AnyImages.end(); it++) + { + imgs.push_back(boost::any_cast (*it)); + } + return imgs; + } + bool AllSameType(); + private: + + // strange compile error with gcc 4.5.1-4 //JPR + std::vector m_AnyDims; + std::vector m_AnyType; + std::vector m_AnyImages; + std::vector m_exts; + std::string namedescp; + std::string namedb; + wxString infoimage; + std::string m_dir; + template + void split3Din3Dvtk(TImage* i_Img); + + template + void split4Din3Dvtk(TImage* i_Img); + + bool m_dicom; + /// interface to read data + SimpleView m_view; + void readImg(const std::string &i_name); + void readDicomImg(const std::vector &i_names); + std::vector m_Vresults; + + const size_t getNumberOfDimensions(const std::string &i_name); + const std::type_info & getType(const std::string &i_name); + }; } -- 2.47.1