diff --git a/Code/Common/mvdAbstractImageModel.h b/Code/Common/mvdAbstractImageModel.h index 1d6fdab484650aa90cd653b09633ee953267237c..52035e5e07f17022f2aeb9ea46df500ec626d2f3 100644 --- a/Code/Common/mvdAbstractImageModel.h +++ b/Code/Common/mvdAbstractImageModel.h @@ -251,9 +251,16 @@ AbstractImageModel if( GetCurrentLod()==lod ) return; - virtual_SetCurrentLod( lod ); - - m_CurrentLod = lod; + try + { + virtual_SetCurrentLod( lod ); + + m_CurrentLod = lod; + } + catch( std::exception& exc ) + { + throw; + } } /*****************************************************************************/ diff --git a/Code/Common/mvdDatasetModel.cxx b/Code/Common/mvdDatasetModel.cxx index 748085a6ddccdc39ba36988dfdef17d956caff20..78640631e7ada616aac79a961acbce231debb121 100644 --- a/Code/Common/mvdDatasetModel.cxx +++ b/Code/Common/mvdDatasetModel.cxx @@ -75,7 +75,7 @@ DatasetModel try { // 2.1. Information. - vectorImageModel->LoadFile( filename, w, h); + vectorImageModel->SetFilename( filename, w, h); // 2.2. Generate cached data. // TODO: generate image-model cached data (quicklook, diff --git a/Code/Common/mvdQuicklookModel.cxx b/Code/Common/mvdQuicklookModel.cxx index e7eb07d5b84f7ff5e81d2c0d3371348a3eeebd6d..38ad5360e0642c2fc65c6c2d8221df42c2f37618 100644 --- a/Code/Common/mvdQuicklookModel.cxx +++ b/Code/Common/mvdQuicklookModel.cxx @@ -75,14 +75,10 @@ QuicklookModel // // Step #3: Post-process of the BuildModel() pattern. - /* - // - // Step #2: get the image used as quicklook - VectorImageModel* imageModel = qobject_cast< VectorImageModel* >( parent() ); - - // TODO : remove size - this->LoadFile(imageModel->GetInputFilename(), 500, 500); - */ + SetFilename( + qobject_cast< VectorImageModel* >( parent() )->GetFilename(), + 512, 512 + ); // Initialize RgbaImageModel. InitializeRgbaPipeline(); diff --git a/Code/Common/mvdVectorImageModel.cxx b/Code/Common/mvdVectorImageModel.cxx index 5bed5e961987ae3c7396ab894bab913e28a09c14..f4fc8c6bedea33f729e46c4235691f1841231518 100644 --- a/Code/Common/mvdVectorImageModel.cxx +++ b/Code/Common/mvdVectorImageModel.cxx @@ -66,7 +66,7 @@ VectorImageModel m_AlreadyLoadedRegion(), m_Region(), m_RegionsToLoadVector(), - m_InputFilename(), + m_Filename(), m_NbLod( 0 ) { } @@ -81,10 +81,10 @@ VectorImageModel /*******************************************************************************/ void VectorImageModel -::LoadFile( const QString& filename , int w, int h) +::SetFilename( const QString& filename , int w, int h) { // 1. store the input filename - m_InputFilename = filename; + m_Filename = filename; // // 2. Setup file-reader. @@ -496,7 +496,7 @@ VectorImageModel::GetBestLevelOfDetail(const double zoomFactor, #if defined(OTB_USE_JPEG2000) otb::JPEG2000ImageIO::Pointer readerJPEG2000 = otb::JPEG2000ImageIO::New(); - std::string filename( m_InputFilename.toStdString() ); + std::string filename( m_Filename.toStdString() ); readerJPEG2000->SetFileName( filename.c_str() ); if(readerJPEG2000->CanReadFile( filename.c_str() ) ) @@ -547,34 +547,52 @@ VectorImageModel::Closest(double invZoomfactor, const std::vector<unsigned int> /*******************************************************************************/ void -VectorImageModel::SetupCurrentLodImage(int w, int h) +VectorImageModel +::SetupCurrentLodImage( int width, int height ) { // Get the largest possible region of the image DefaultImageFileReaderType::Pointer tmpReader( DefaultImageFileReaderType::New() ); - tmpReader->SetFileName( m_InputFilename.toStdString() ); + tmpReader->SetFileName( m_Filename.toStdString() ); tmpReader->UpdateOutputInformation(); // Get native image largest region, which is LOD level zero. ImageRegionType nativeLargestRegion = tmpReader->GetOutput()->GetLargestPossibleRegion(); - double factorX = (double)w/(double)(nativeLargestRegion.GetSize()[0]); - double factorY = (double)h/(double)(nativeLargestRegion.GetSize()[1]); + // Initialize lod count. + CountType nbLod = 1; + bool hasBestLod = false; + int bestLod = 0; - double initialZoomFactor = std::min(factorX, factorY); + // Try to compute best LOD. + if( width>0 && height>0 ) + { + double factorX = + double( width ) / double( nativeLargestRegion.GetSize()[ 0 ] ); - int best_lod = 0; - CountType nbLod = 1; + double factorY = + double( height ) / double( nativeLargestRegion.GetSize()[ 1 ] ); + + double initialZoomFactor = std::min(factorX, factorY); // if mutli-resolution file - if ( this->GetBestLevelOfDetail(initialZoomFactor, best_lod, nbLod) ) + hasBestLod = GetBestLevelOfDetail(initialZoomFactor, bestLod, nbLod); + } + + // If best-lod is available for multi-resolution image. + if( hasBestLod ) { - this->SetCurrentLod(best_lod); + // Change current-lod: update m_ImageFileReader, m_Image and + // current LOD index. + this->SetCurrentLod( bestLod ); } - else // if not jpeg2k image + + else // Otherwise { + // Leave current LOD index to 0. + // Update m_ImageFileReader m_ImageFileReader = tmpReader; @@ -584,6 +602,7 @@ VectorImageModel::SetupCurrentLodImage(int w, int h) // Remember native largest region. m_NativeLargestRegion = nativeLargestRegion; + // Remember number of LOD levels. m_NbLod = nbLod; } @@ -602,16 +621,35 @@ void VectorImageModel ::virtual_SetCurrentLod( CountType lod ) { + assert( lod<GetNbLod() ); + // new filename if lod is not 0 - QString lodFilename( m_InputFilename ); - lodFilename.append( QString( "?&resol=%1" ).arg( lod ) ); + QString lodFilename( m_Filename ); - // Update m_ImageFileReader - m_ImageFileReader = DefaultImageFileReaderType::New(); - m_ImageFileReader->SetFileName( lodFilename.toStdString() ); - m_ImageFileReader->UpdateOutputInformation(); - - // Update m_Image + // If model is a multi-resolution image. + if( lod>1 ) + { + lodFilename.append( QString( "?&resol=%1" ).arg( lod ) ); + + // Update m_ImageFileReader + DefaultImageFileReaderType::Pointer fileReader( + DefaultImageFileReaderType::New() + ); + + try + { + fileReader->SetFileName( lodFilename.toStdString() ); + fileReader->UpdateOutputInformation(); + + m_ImageFileReader = fileReader; + } + catch( std::exception& exc ) + { + throw; + } + } + + // (Always) Update m_Image reference. m_Image = m_ImageFileReader->GetOutput(); } diff --git a/Code/Common/mvdVectorImageModel.h b/Code/Common/mvdVectorImageModel.h index 90a7d844337d9db0a4f1408f4d7054c45273f22b..3abc8f1c21c1287ca36490a910d4e7597ce56998 100644 --- a/Code/Common/mvdVectorImageModel.h +++ b/Code/Common/mvdVectorImageModel.h @@ -275,10 +275,13 @@ public: inline void SetSettings( Settings settings); /** - * w and h are added to compute the best level of detail to load - * from the image if multi-resolution image + * Width and height are added to compute the best level of detail to + * load from the image if multi-resolution image. */ - void LoadFile( const QString& filename, int w, int h ); + void SetFilename( const QString& filename, int width, int height ); + + /** Get input filename */ + inline QString GetFilename() const; /** Rasterize the buffered region in a buffer */ unsigned char * RasterizeRegion(const ImageRegionType& region, @@ -311,12 +314,6 @@ public: */ virtual ImageBaseType::Pointer ToImageBase(); - /** Get input filename */ - QString GetInputFilename() - { - return m_InputFilename; - } - /*-[ PUBLIC SLOTS SECTION ]------------------------------------------------*/ // @@ -492,7 +489,7 @@ private: std::vector< ImageRegionType > m_RegionsToLoadVector; // store the input image filename - QString m_InputFilename; + QString m_Filename; /** */ CountType m_NbLod; @@ -542,6 +539,15 @@ VectorImageModel m_Settings = settings; } +/*****************************************************************************/ +inline +QString +VectorImageModel +::GetFilename() const +{ + return m_Filename; +} + /*****************************************************************************/ inline unsigned int