diff --git a/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.cxx b/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.cxx index eeab2b657d6410bab2ddc759ab81e9047f9bd69d..7a08f7189424c025c9e33d1375e39cf246d15367 100644 --- a/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.cxx +++ b/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.cxx @@ -58,7 +58,7 @@ ImageViewerManagerController } catch (itk::ExceptionObject & err) { - MsgReporter::GetInstance()->SendError(err.GetDescription()); + MsgReporter::GetInstance()->SendError(err.GetDescription()); } } @@ -168,29 +168,5 @@ ImageViewerManagerController } } -bool -ImageViewerManagerController -::IsJPEG2000File(const std::string & filepath) -{ - return m_Model->IsJPEG2000File(filepath); -} - -std::vector<unsigned int> -ImageViewerManagerController -::GetJPEG2000Resolution(const std::string & filepath) -{ - std::vector<unsigned int> res; - if( !this->IsJPEG2000File(filepath) ) - { - MsgReporter::GetInstance()->SendError("Can't get file resolution, not JPEG2000 format..."); - } - else - { - res = m_Model->GetJPEG2000Resolution(filepath); - } - - return res; -} - } // end namespace otb diff --git a/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.h b/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.h index a953dcea35fcd96234314f71de395286432b347d..53cb818f9d4395df65b5d1c74e5d95647e3334ac 100644 --- a/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.h +++ b/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerController.h @@ -107,11 +107,6 @@ public: virtual void UpdatePhaseChannelOrder(int realChoice , int imChoice, unsigned int selectedItem); virtual void Link(unsigned int leftChoice, unsigned int rightChoice , OffsetType offset); virtual void UpdateImageViewController(unsigned int selectedItem); - // Test a filename and returns true if the file is JPEG2000 - virtual bool IsJPEG2000File(const std::string & filepath); - // If the file is JPEG2000, the function will find the available - // resolutions. - virtual std::vector<unsigned int> GetJPEG2000Resolution(const std::string & filepath); protected: /** Constructor */ diff --git a/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerControllerInterface.h b/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerControllerInterface.h index a262383c0cc7fadfacae03f51358cd1f5f9713a0..6417f7ce68edf46fddf43b4876bcd617a7c1607c 100644 --- a/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerControllerInterface.h +++ b/Code/Visualization/ViewerManager/Controller/otbImageViewerManagerControllerInterface.h @@ -75,8 +75,6 @@ public: /** NewVisu */ virtual VisuControllerPointerType GetVisuController()=0; virtual VisuControllerPointerType GetPreviewVisuController() = 0; - virtual bool IsJPEG2000File(const std::string & filepath) = 0; - virtual std::vector<unsigned int> GetJPEG2000Resolution(const std::string & filepath) = 0; protected: /** Constructor */ diff --git a/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.cxx b/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.cxx index b8408a4567244d303a79c8f08d1bd938867c8bb7..ce2b4bfae2ede02fcf48abde9158f67741d12622 100644 --- a/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.cxx +++ b/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.cxx @@ -89,6 +89,7 @@ ImageViewerManagerModel #endif } + std::vector<unsigned int> ImageViewerManagerModel ::GetJPEG2000Resolution(const std::string & filepath) @@ -102,6 +103,7 @@ ImageViewerManagerModel { JPEG2000ImageIO::Pointer readerJPEG2000 = otb::JPEG2000ImageIO::New(); readerJPEG2000->SetFileName(filepath); + readerJPEG2000->ReadImageInformation(); readerJPEG2000->GetAvailableResolutions(res); } @@ -109,6 +111,22 @@ ImageViewerManagerModel } +void +ImageViewerManagerModel +::GetJPEG2000ResolutionAndInformations(const std::string & filepath, std::vector<unsigned int>& res, std::vector<std::string> & desc) +{ + if( !this->IsJPEG2000File(filepath) ) + { + itkExceptionMacro( "Image "<<filepath<< " is not a JPEG2000." ); + } + else + { + JPEG2000ImageIO::Pointer readerJPEG2000 = otb::JPEG2000ImageIO::New(); + readerJPEG2000->SetFileName(filepath); + readerJPEG2000->ReadImageInformation(); + readerJPEG2000->GetResolutionInfo(res, desc); + } +} unsigned int ImageViewerManagerModel @@ -120,7 +138,9 @@ ImageViewerManagerModel // If jpeg2000, add the selected resolution at the end of the file name if( isJPEG2000 ) - { + { + std::cout<<"ImageViewerManagerModel::OpenImage is JPEG2000"<<std::endl; + unsigned int resolution = 0; otbFilepath += ":"; std::ostringstream ossRes; @@ -133,16 +153,17 @@ ImageViewerManagerModel reader->SetFileName(otbFilepath); reader->GenerateOutputInformation(); - + std::cout<<"ImageViewerManagerModel::OpenImage go for QL"<<std::endl; // Quick look generation - ImagePointerType quicklook = ImageType::New(); + ImagePointerType quicklook = NULL; unsigned int shrinkFactor = 1; //// if jpeg2000, try to load the less resolution image as quicklook if( isJPEG2000 ) { ReaderPointerType jpeg2000QLReader = ReaderType::New(); - jpeg2000QLReader->SetFileName(otbFilepath); - unsigned int resSize = this->GetJPEG2000Resolution( otbFilepath ).size(); + jpeg2000QLReader->SetFileName(filename); + unsigned int resSize = this->GetJPEG2000Resolution( filename ).size(); + if( resSize > 0 ) jpeg2000QLReader->SetAdditionalNumber( resSize-1 ); @@ -151,10 +172,10 @@ ImageViewerManagerModel quicklook->DisconnectPipeline(); shrinkFactor = (1 << (resSize - 1)); } - - //// If not jpeg2000or trouble in jpeg2000 quicloock, use a streaming shrink image filter + //// If not jpeg2000 or trouble in jpeg2000 quicloock, use a streaming shrink image filter if (quicklook.IsNull()) { + std::cout<<"ImageViewerManagerModel::OpenImage quicklook.IsNull()"<<std::endl; typedef otb::StreamingShrinkImageFilter<ImageType> StreamingShrinkImageFilterType; StreamingShrinkImageFilterType::Pointer shrinker = StreamingShrinkImageFilterType::New(); shrinker->SetInput(reader->GetOutput()); @@ -167,7 +188,7 @@ ImageViewerManagerModel quicklook->DisconnectPipeline(); } - + std::cout<<"ImageViewerManagerModel::OpenImage go for layer"<<std::endl; /** Generate the layer*/ LayerGeneratorPointerType visuGenerator = LayerGeneratorType::New(); visuGenerator->SetImage(reader->GetOutput()); @@ -180,7 +201,6 @@ ImageViewerManagerModel /** Rendering image*/ VisuModelPointerType rendering = VisuModelType::New(); rendering->AddLayer(visuGenerator->GetLayer()); - rendering->Update(); /** View*/ @@ -204,9 +224,10 @@ ImageViewerManagerModel /** Store all the information in the structure*/ ObjectsTracked currentComponent; - currentComponent.fileName = otbFilepath; + currentComponent.pFileName = otbFilepath; currentComponent.pLayer = visuGenerator->GetLayer(); currentComponent.pReader = reader; + currentComponent.pQuicklook = quicklook; currentComponent.pRendering = rendering; currentComponent.pVisuView = visuView; currentComponent.pWidgetController = controller; @@ -217,6 +238,7 @@ ImageViewerManagerModel assert(currentComponent.pLayer); assert(currentComponent.pReader); + assert(currentComponent.pQuicklook); assert(currentComponent.pRendering); assert(currentComponent.pVisuView); assert(currentComponent.pWidgetController); @@ -285,7 +307,7 @@ ImageViewerManagerModel /** Store all the information in the structure*/ ObjectsTracked currentComponent; - currentComponent.fileName = reader->GetFileName(i); + currentComponent.pFileName = reader->GetFileName(i); currentComponent.pLayer = visuGenerator->GetLayer(); currentComponent.pReader = reader->GetImageFileReader(i); currentComponent.pRendering = rendering; diff --git a/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.h b/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.h index 3e240301423edc32ba258e1ab0d3393984c0b4e3..a085916668988f4aa85007b60a4cbc7bbbe884ae 100644 --- a/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.h +++ b/Code/Visualization/ViewerManager/Model/otbImageViewerManagerModel.h @@ -129,16 +129,17 @@ public: */ struct _ObjectsTracked { - ReaderPointerType pReader; - LayerPointerType pLayer; - VisuModelPointerType pRendering; - WidgetControllerPointerType pWidgetController; - VisuViewPointerType pVisuView; - RenderingFunctionType::Pointer pRenderFunction; - PixelDescriptionViewType::Pointer pPixelView; - PixelDescriptionModelPointerType pPixelModel; - CurvesWidgetType::Pointer pCurveWidget; - std::string fileName; + ReaderPointerType pReader; + ImagePointerType pQuicklook; + LayerPointerType pLayer; + VisuModelPointerType pRendering; + WidgetControllerPointerType pWidgetController; + VisuViewPointerType pVisuView; + RenderingFunctionType::Pointer pRenderFunction; + PixelDescriptionViewType::Pointer pPixelView; + PixelDescriptionModelPointerType pPixelModel; + CurvesWidgetType::Pointer pCurveWidget; + std::string pFileName; }; typedef struct _ObjectsTracked ObjectsTracked; @@ -173,11 +174,13 @@ public: itkGetMacro(HasChangedChannelOrder, bool); // Test a filename and returns true if the file is JPEG2000 - virtual bool IsJPEG2000File(const std::string & filepath); + bool IsJPEG2000File(const std::string & filepath); // If the file is JPEG2000, the function will find the available // resolutions. - virtual std::vector<unsigned int> GetJPEG2000Resolution(const std::string & filepath); - + std::vector<unsigned int> GetJPEG2000Resolution(const std::string & filepath); + // If the file is JPEG2000, the function will find the available + // resolutions and informations + void GetJPEG2000ResolutionAndInformations(const std::string & filepath, std::vector<unsigned int>& res, std::vector<std::string> & desc); protected: /** This is protected for the singleton. Use GetInstance() instead. */ diff --git a/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.cxx b/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.cxx index 87807582a2675ff43284dd70cdddf8c38e609134..2db062e65fc44435a97c464148b7800e74dbc907 100644 --- a/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.cxx +++ b/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.cxx @@ -97,18 +97,19 @@ ImageViewerManagerViewGUI Fl::check(); guiMainWindow->redraw(); - if( m_ImageViewerManagerController->IsJPEG2000File( cfname ) ) + if( m_ImageViewerManagerModel->IsJPEG2000File( cfname ) ) { guiJpeg2000Res->clear(); itk::OStringStream oss; - std::vector<unsigned int> res = m_ImageViewerManagerController->GetJPEG2000Resolution( cfname ); + std::vector<unsigned int> res; + std::vector<std::string> desc; + m_ImageViewerManagerModel->GetJPEG2000ResolutionAndInformations( cfname, res, desc ); + for( unsigned int j=0; j<res.size(); j++ ) { - oss.str(""); - oss << res[j]; - guiJpeg2000Res->add( oss.str().c_str() ); + guiJpeg2000Res->add( desc[j].c_str() ); } - + guiJpeg2000Res->value(0); guiJpeg2000Filename->value( cfname ); guiJpeg2000ResSelection->redraw(); @@ -170,10 +171,35 @@ ImageViewerManagerViewGUI void ImageViewerManagerViewGUI -::LoadSelectedJpeg2000Resolution() +::OpenJpeg2000Image() { - unsigned int res = atoi(guiJpeg2000Res->value()); - unsigned int numberOfOpenedImages = m_ImageViewerManagerController->OpenInputImage(guiJpeg2000Filename->value(), res); + const std::string descRes = guiJpeg2000Res->value(); + const char * cfname = guiJpeg2000Filename->value(); + + // Find the resolution id from the selected description + std::vector<unsigned int> res; + std::vector<std::string> desc; + m_ImageViewerManagerModel->GetJPEG2000ResolutionAndInformations( cfname, res, desc ); + unsigned int resVal; + bool found = false; + unsigned int id = 0; + while ( id<desc.size() && !found) + { + if( desc[id] == descRes ) + { + resVal = res[id]; + found = true; + } + id++; + } + + if (!found) + { + itkExceptionMacro( "Unable to find the resolution associated to the description "<<descRes); + } + + unsigned int numberOfOpenedImages = m_ImageViewerManagerController->OpenInputImage(cfname, resVal); + for ( unsigned int i = 0; i < numberOfOpenedImages; i++ ) { //Initialise the boolean pair @@ -369,7 +395,7 @@ ImageViewerManagerViewGUI { //Update the Image List widget unsigned int len = m_ImageViewerManagerModel->GetObjectList().size(); - std::string fileName = m_ImageViewerManagerModel->GetObjectList().at(len-1).fileName; + std::string fileName = m_ImageViewerManagerModel->GetObjectList().at(len-1).pFileName; int slashIndex = fileName.find_last_of("/", fileName.size()); itk::OStringStream oss; @@ -662,7 +688,7 @@ ImageViewerManagerViewGUI ::UpdateImageListShowed(unsigned int selectedItem, std::string status) { /* Update the ImageList using the status label "+" or "-" */ - std::string fileName = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).fileName; + std::string fileName = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pFileName; int slashIndex = fileName.find_last_of("/", fileName.size()); itk::OStringStream oss; @@ -778,7 +804,7 @@ ImageViewerManagerViewGUI { itk::OStringStream oss; oss.str(""); - std::string selectedImageName = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).fileName; + std::string selectedImageName = m_ImageViewerManagerModel->GetObjectList().at(selectedItem-1).pFileName; // Clear the info buffer guiViewerInformation->buffer()->remove(0, guiViewerInformation->buffer()->length()); oss<<"Filename: "<<selectedImageName<<std::endl; @@ -1082,7 +1108,7 @@ ImageViewerManagerViewGUI ImageViewerManagerViewGUI ::CutFileName(unsigned int selectedItem) { - std::string fileName = m_ImageViewerManagerModel->GetObjectList().at(selectedItem).fileName; + std::string fileName = m_ImageViewerManagerModel->GetObjectList().at(selectedItem).pFileName; int slashIndex = fileName.find_last_of("/", fileName.size()); std::string fileNameCut = fileName.substr(slashIndex+1, fileName.size()); diff --git a/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.h b/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.h index ac0e1179bb5d3b9ac3c4cc4e8767ba37369938ed..e30faf4f9b3eec1b172f368b0bb8697663c0f5bc 100644 --- a/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.h +++ b/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGUI.h @@ -47,7 +47,6 @@ See OTBCopyright.txt for details. #include "otbSplittedWidgetManager.h" #include "otbObjectList.h" -#include "otbFixedSizeFullImageWidget.h" #include <FL/Fl_File_Chooser.H> namespace otb @@ -186,7 +185,7 @@ protected: virtual void LinkSetupRemove(); virtual void InitializeImageController(unsigned int selectedItem ); - virtual void LoadSelectedJpeg2000Resolution(); + virtual void OpenJpeg2000Image(); /** Constructor */ ImageViewerManagerViewGUI(); diff --git a/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGroup.fl b/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGroup.fl index c791a538f435b62d027db48ea59aecf1a77b2daa..3f2f6963a49c9a6db0f328c66704228006bd39a7 100644 --- a/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGroup.fl +++ b/Code/Visualization/ViewerManager/View/otbImageViewerManagerViewGroup.fl @@ -11,7 +11,7 @@ class ImageViewerManagerViewGroup {open } { Fl_Window guiMainWindow { label otbImageViewerManagerView - callback {this->Quit()} + callback {this->Quit()} open xywh {366 65 610 460} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 resizable visible } { Fl_Text_Display guiViewerInformation { @@ -171,7 +171,7 @@ class ImageViewerManagerViewGroup {open } Fl_Window guiLinkSetupWindow { label {Link Images} - xywh {397 582 560 220} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 resizable visible + xywh {855 634 560 220} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 resizable visible } { Fl_Input guiLinkXOffset { label {X offset} @@ -236,25 +236,26 @@ class ImageViewerManagerViewGroup {open } Fl_Window guiJpeg2000ResSelection { label {Jpeg2000 resolution selection} open - xywh {636 580 290 110} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 visible + xywh {316 565 460 145} type Double box UP_BOX color 52 selection_color 7 labelcolor 187 visible } { Fl_Button {} { label Cancel callback {guiJpeg2000ResSelection->hide();} - tooltip {Next image in diaporama} xywh {49 75 105 25} box ROUND_UP_BOX down_box ROUND_DOWN_BOX shortcut 0xff56 color 23 selection_color 23 labelcolor 186 + tooltip {Next image in diaporama} xywh {220 110 105 25} box ROUND_UP_BOX down_box ROUND_DOWN_BOX shortcut 0xff56 color 23 selection_color 23 labelcolor 186 } Fl_Return_Button {} { label Ok - callback {LoadSelectedJpeg2000Resoltion();} - tooltip {Leave diaporama mode} xywh {171 75 105 25} box ROUND_UP_BOX down_box ROUND_DOWN_BOX shortcut 0xff0d color 23 selection_color 23 labelcolor 186 + callback {guiJpeg2000ResSelection->hide(); +OpenJpeg2000Image();} + tooltip {Leave diaporama mode} xywh {342 110 105 25} box ROUND_UP_BOX down_box ROUND_DOWN_BOX shortcut 0xff0d color 23 selection_color 23 labelcolor 186 } Fl_Input_Choice guiJpeg2000Res { label {Select resolution} open - xywh {131 36 77 24} box EMBOSSED_BOX labelcolor 187 + xywh {80 59 300 24} box EMBOSSED_BOX labelcolor 187 align 1 } {} Fl_Output guiJpeg2000Filename { - label Filename selected - xywh {70 6 210 24} box EMBOSSED_BOX labelcolor 187 + label Filename + xywh {70 8 370 23} box EMBOSSED_BOX labelcolor 187 } } } @@ -311,5 +312,5 @@ class ImageViewerManagerViewGroup {open Function {PackedViewMode()} {open return_type {virtual void} } {comment {for fluid 1.3} {in_source not_in_header}} } {} - Function {LoadSelectedJpeg2000Resoltion()} {open return_type {virtual void} + Function {OpenJpeg2000Image()} {open selected return_type {virtual void} }