From bab44651d156b382895b3ce1cc29e25d6ec2dbdf Mon Sep 17 00:00:00 2001 From: jean-pierre roux Date: Thu, 26 May 2011 12:34:21 +0000 Subject: [PATCH] Now it compiles in Linux... --- src/creaImageIOWxAnySimpleDlg.cpp | 213 +++++++++++++++--------------- src/creaImageIOWxAnySimpleDlg.h | 22 +-- 2 files changed, 115 insertions(+), 120 deletions(-) diff --git a/src/creaImageIOWxAnySimpleDlg.cpp b/src/creaImageIOWxAnySimpleDlg.cpp index 593d389..e66d2ba 100644 --- a/src/creaImageIOWxAnySimpleDlg.cpp +++ b/src/creaImageIOWxAnySimpleDlg.cpp @@ -39,7 +39,7 @@ namespace creaImageIO } // 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 ); + 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) ); @@ -53,6 +53,7 @@ namespace creaImageIO m_dicom = true; Layout(); } + ////////////////////////////////////////////////////////////////////// // // ////////////////////////////////////////////////////////////////////// @@ -84,13 +85,11 @@ namespace creaImageIO // Close(); EndModal( resultShowModal ); } - - -void WxAnySimpleDlg::setExts(std::vector i_exts) -{ - m_exts = i_exts; -} + void WxAnySimpleDlg::setExts(std::vector i_exts) + { + m_exts = i_exts; + } ///////////////////////////////////////////////////////////////////// // // ////////////////////////////////////////////////////////////////////// @@ -124,10 +123,10 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) break; } } - if (!boost::filesystem::is_directory(itr->status()) && bvalid) - { - readImg(itr->string().c_str()); - } + if (!boost::filesystem::is_directory(itr->status()) && bvalid) + { + readImg(itr->string().c_str()); + } } } SetReturnCode( resultShowModal ); @@ -142,7 +141,7 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) void WxAnySimpleDlg::OnReadGimmick(wxCommandEvent &event) { // Run Gimmick - WxGimmickReaderDialog dlg(0,-1, + WxGimmickReaderDialog dlg(0,-1, namedescp, namedb, _T("Select image(s) - Gimmick! (c) CREATIS-LRMN 2008"), @@ -179,7 +178,7 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) - wxString WxAnySimpleDlg::getInfoImage() + wxString WxAnySimpleDlg::getInfoImage() { return infoimage; } @@ -187,7 +186,7 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) // 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()); @@ -195,7 +194,7 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) return imageIO->GetComponentTypeInfo();//AsString( imageIO->GetComponentType()); } - const size_t WxAnySimpleDlg::getNumberOfDimensions(const std::string &i_name) + 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); @@ -204,8 +203,8 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) return imageIO->GetNumberOfDimensions(); } - void WxAnySimpleDlg::readImg(const std::string &i_name) - { + void WxAnySimpleDlg::readImg(const std::string &i_name) + { size_t dims = getNumberOfDimensions(i_name); const std::type_info *type= &getType(i_name); switch(dims) @@ -221,8 +220,8 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); } - else if (getType(i_name) == typeid(signed char)) - { + else if (getType(i_name) == typeid(signed char)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -230,7 +229,7 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->Update(); reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); - } + } else if (getType(i_name) == typeid(short)) { typedef itk::Image TImage; @@ -241,8 +240,8 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); } - else if (getType(i_name) == typeid(unsigned short)) - { + else if (getType(i_name) == typeid(unsigned short)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -329,8 +328,8 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); } - else if (getType(i_name) == typeid(signed char)) - { + else if (getType(i_name) == typeid(signed char)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -339,8 +338,8 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned short)) + } + else if (getType(i_name) == typeid(unsigned short)) { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; @@ -351,8 +350,8 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); } - else if(getType(i_name) == typeid(short)) - { + else if(getType(i_name) == typeid(short)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -375,9 +374,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned short)) - { + } + else if (getType(i_name) == typeid(unsigned short)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -386,9 +385,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned int)) - { + } + else if (getType(i_name) == typeid(unsigned int)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -397,9 +396,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed int)) - { + } + else if (getType(i_name) == typeid(signed int)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -408,9 +407,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(unsigned long)) - { + } + else if (getType(i_name) == typeid(unsigned long)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -419,9 +418,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(signed long)) - { + } + else if (getType(i_name) == typeid(signed long)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -430,9 +429,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(float)) - { + } + else if (getType(i_name) == typeid(float)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -441,9 +440,9 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else if (getType(i_name) == typeid(double)) - { + } + else if (getType(i_name) == typeid(double)) + { typedef itk::Image TImage; typedef itk::ImageFileReader ReaderType; ReaderType::Pointer reader = ReaderType::New(); @@ -452,16 +451,16 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) reader->GetOutput()->Register(); m_AnyImages.push_back(reader->GetOutput()); split4Din3Dvtk(reader->GetOutput()); - } - else - { + } + else + { //????FCY, so what the type???? - } - break; + } + break; } // Test to know if we have to add new type - bool btest = false; + bool btest = false; if( m_AnyDims.size() != 0) { btest = true; @@ -469,23 +468,20 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) else { m_AnyDims.push_back(dims); - m_AnyType.push_back(&getType(i_name)); + m_AnyType.push_back((std::type_info*)&getType(i_name)); //JPR cast } 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)); + m_AnyType.push_back((std::type_info*)&getType(i_name)); //JPR cast } else{} } else {} } - - - void WxAnySimpleDlg::readDicomImg(const std::vector &i_names) { typedef itk::Image TImage; @@ -519,9 +515,6 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) } - - - template void WxAnySimpleDlg::split3Din3Dvtk(TImage* i_Img) { @@ -540,55 +533,55 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) 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(); + 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; - } + // 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() - { + bool WxAnySimpleDlg::AllSameType() + { if(m_AnyType.size() == 1) { return true; @@ -598,7 +591,7 @@ void WxAnySimpleDlg::setExts(std::vector i_exts) return false; } - } + } - }// namespace end + } // namespace end diff --git a/src/creaImageIOWxAnySimpleDlg.h b/src/creaImageIOWxAnySimpleDlg.h index 9bbde5a..3412024 100644 --- a/src/creaImageIOWxAnySimpleDlg.h +++ b/src/creaImageIOWxAnySimpleDlg.h @@ -7,8 +7,8 @@ namespace creaImageIO { /** - * \ingroup View - */ + * \ingroup View + */ /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display //EED class __declspec(dllexport) WxAnySimpleDlg : public wxDialog @@ -19,8 +19,8 @@ namespace creaImageIO WxAnySimpleDlg( wxWindow *parent, wxString i_title =_T(""), const std::string i_namedescp = "localdatabase_Descriptor.dscp", - const std::string i_namedb = "Local Database" - ); + const std::string i_namedb = "Local Database" + ); ~WxAnySimpleDlg(){}; @@ -43,13 +43,14 @@ namespace creaImageIO std::vector & getImagesSelected(){ return m_AnyImages;} // return the size of readed images - //strange compile error // JPR - std::vector getDims(){ return m_AnyDims;} + std::vector getDims(){ return m_AnyDims;} // comment out const // JPR // return the type of readed images - std::vector getTypes(){ return m_AnyType;} + std::vector getTypes(){ return m_AnyType;} // comment out const // JPR // get an Image on wanted type + /* + // strange compile error, commented out on Fred's advice // JPR template typename TImage::Pointer getImage(boost::any i_AnyImage) { @@ -58,6 +59,7 @@ namespace creaImageIO img = boost::any_cast< ImageOut::Pointer>(i_AnyImage); return img; } + */ // get the images on itk type defined by user template @@ -75,9 +77,9 @@ namespace creaImageIO 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_AnyDims; //comment out const JPR + std::vector m_AnyType; //comment out const JPR + std::vector m_AnyImages; //comment out const JPR std::vector m_exts; std::string namedescp; std::string namedb; -- 2.47.1