From 45eac7f781dd0d2bebcd50fab2a002b20e4366e9 Mon Sep 17 00:00:00 2001 From: Christophe Meynard Date: Thu, 5 Dec 2024 17:30:05 +0100 Subject: [PATCH] MMVII: GDAL: light refactoring --- MMVII/include/MMVII_Image2D.h | 4 +++- MMVII/include/V1VII.h | 4 +--- MMVII/src/DenseMatch/EpipGenDenseMatch.cpp | 6 ++++++ MMVII/src/ImagesBase/FileImages.cpp | 16 +++++--------- MMVII/src/ImagesBase/cGdalApi.h | 25 ++++++++++++++++++---- MMVII/src/MMV1/ImageFilterMMV1.cpp | 2 +- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/MMVII/include/MMVII_Image2D.h b/MMVII/include/MMVII_Image2D.h index 3967d17366..48867f60fc 100755 --- a/MMVII/include/MMVII_Image2D.h +++ b/MMVII/include/MMVII_Image2D.h @@ -50,9 +50,11 @@ class cDataFileIm2D : public cRect2 static cDataFileIm2D Create(const std::string & aName,eForceGray); /// Create the file before returning the descriptor static cDataFileIm2D Create(const std::string & aName,eTyNums,const cPt2di & aSz, int aNbChan=1); + /// Options depends on each format driver and may be not applied if the file already exits ... static cDataFileIm2D Create(const std::string & aName,eTyNums,const cPt2di & aSz, const tOptions& aOptions, int aNbChan=1); - // Special creation for full write (non updatable) format : jpeg, png, ... + // Special creation for fully write format : jpeg, png, ... File will be (re)created on each write and the full file must be written at once + // This function guarantees that the options will be applied (if driver allows them ...) static cDataFileIm2D CreateOnWrite(const std::string & aName,eTyNums,const cPt2di & aSz, const tOptions& aOptions={}, int aNbChan=1); static cDataFileIm2D CreateOnWrite(const std::string & aName,eTyNums,const cPt2di & aSz, int aNbChan=1); diff --git a/MMVII/include/V1VII.h b/MMVII/include/V1VII.h index e6e9307c38..42a48fe22a 100755 --- a/MMVII/include/V1VII.h +++ b/MMVII/include/V1VII.h @@ -37,7 +37,7 @@ void MakeStdIm8BIts(cIm2D aImIn,const std::string& aName); -//FIXME CM->MPD: Must replace cMMV1_Conv::ImToMMV1 +//FIXME CM->MPD: Mail MPD fichier xmmlV1.cpp Must replace cMMV1_Conv::ImToMMV1 template class cMMV1_Conv { public : @@ -64,8 +64,6 @@ template class cMMV1_Conv #endif }; -std::string V1NameMasqOfIm(const std::string & aName); - // Call V1 Fast kth value extraction double KthVal(std::vector &, double aProportion); // Idem but indicate a number and not a proportion diff --git a/MMVII/src/DenseMatch/EpipGenDenseMatch.cpp b/MMVII/src/DenseMatch/EpipGenDenseMatch.cpp index 8e668f707c..b2d0fc4187 100755 --- a/MMVII/src/DenseMatch/EpipGenDenseMatch.cpp +++ b/MMVII/src/DenseMatch/EpipGenDenseMatch.cpp @@ -293,6 +293,12 @@ struct cParam1Match /* */ /* ============================================== */ +static std::string V1NameMasqOfIm(const std::string & aName) +{ + return LastPrefix(aName) + "_Masq.tif"; +} + + std::string cOneLevel::StdFullName(const std::string & aName) const { return (mLevel==0) ? diff --git a/MMVII/src/ImagesBase/FileImages.cpp b/MMVII/src/ImagesBase/FileImages.cpp index eb30911449..c16ffb232f 100644 --- a/MMVII/src/ImagesBase/FileImages.cpp +++ b/MMVII/src/ImagesBase/FileImages.cpp @@ -20,11 +20,6 @@ extern std::string MM3DFixeByMMVII; // Declared in MMV1 for its own stuff namespace MMVII { -// FIXME CM->MPD: A virer ? A mettre dans EpipGenDenseMatch ou ImageFilterMMV1 ? -std::string V1NameMasqOfIm(const std::string & aName) -{ - return LastPrefix(aName) + "_Masq.tif"; -} #ifdef MMVII_KEEP_MMV1_IMAGE static GenIm::type_el ToMMV1(eTyNums aV2) @@ -186,7 +181,6 @@ cDataFileIm2D cDataFileIm2D::Create(const std::string & aName,eTyNums aType,con return Create(aName,aType,aSz,{},aNbChan); } - cDataFileIm2D cDataFileIm2D::CreateOnWrite(const std::string & aName,eTyNums aType,const cPt2di & aSz, const tOptions& aOptions, int aNbChan) { if (aNbChan!=1 && aNbChan!=3) @@ -229,9 +223,7 @@ void cDataFileIm2D::SetCreatedNoUpdate() const bool cDataFileIm2D::IsPostFixNameImage(const std::string & aPost) { - static std::vector aVNames({"jpg","jpeg","tif","tiff"}); - - return UCaseMember(aVNames,aPost); + return cGdalApi::IsPostFixNameImage(aPost); } bool cDataFileIm2D::IsNameWith_PostFixImage(const std::string & aName) @@ -468,13 +460,15 @@ template void cIm2D::Write(const cDataFileIm2D & aFile,cons -// FIXME CM->MPD: check correctness double DifAbsInVal(const std::string & aN1,const std::string & aN2,double aDef) { auto aIm1 = cIm2D::FromFile(aN1); auto aIm2 = cIm2D::FromFile(aN2); double aSom = 0; - + + +// ELISE_COPY(aF1.all_pts(),Abs(aF1.in()-aF2.in()),sigma(aSom)); + if (aIm1.DIm().Sz()!=aIm2.DIm().Sz()) { MMVII_INTERNAL_ASSERT_always(aDef!=0.0,"Diff sz and bad def in DifAbsInVal"); diff --git a/MMVII/src/ImagesBase/cGdalApi.h b/MMVII/src/ImagesBase/cGdalApi.h index 9ce544bb2c..21ff6805b2 100644 --- a/MMVII/src/ImagesBase/cGdalApi.h +++ b/MMVII/src/ImagesBase/cGdalApi.h @@ -31,6 +31,8 @@ class cGdalApi { static void InitGDAL(); + static bool IsPostFixNameImage(const std::string& aPost); + static void GetFileInfo(const std::string& aName, eTyNums& aType, cPt2di& aSz, int& aNbChannel); static void CreateFileIfNeeded(const cDataFileIm2D& aDataFileIm2D); @@ -75,6 +77,7 @@ class cGdalApi { // Avoid printing of error message => each API call must test and handle error case. static void GdalErrorHandler(CPLErr aErrorCat, CPLErrorNum aErrorNum, const char *aMesg); static GDALDriver* GetDriver(const std::string& aName); + static const std::map &SupportedDrivers(); static bool GDalDriverCanCreate(GDALDriver *aGdalDriver); static CPLStringList GetCreateOptions(GDALDriver* aGdalDriver, const cDataFileIm2D::tOptions& aOptions); @@ -608,9 +611,10 @@ void cGdalApi::CloseDataset(GDALDataset *aGdalDataset) GDALClose(GDALDataset::ToHandle(aGdalDataset)); } -GDALDriver* cGdalApi::GetDriver(const std::string& aName) + +const std::map &cGdalApi::SupportedDrivers() { - static std::map DriverNames = { + static std::map cSupportedDrivers= { {"tif", "GTiff"}, {"tiff", "GTiff"}, {"dng", "GTiff"}, @@ -622,9 +626,22 @@ GDALDriver* cGdalApi::GetDriver(const std::string& aName) {"pnm","PNM"}, {"gif","GIF"}, }; + return cSupportedDrivers; +} + +bool cGdalApi::IsPostFixNameImage(const std::string &aPost) +{ + const auto aDriverList = SupportedDrivers(); + auto aDriverIt = aDriverList.find(ToLower(aPost)); + return aDriverIt != aDriverList.end(); +} + - auto aDriverIt = DriverNames.find(ToLower(LastPostfix(aName,'.'))); - if (aDriverIt == DriverNames.end()) +GDALDriver* cGdalApi::GetDriver(const std::string& aName) +{ + const auto aDriverList = SupportedDrivers(); + auto aDriverIt = aDriverList.find(ToLower(LastPostfix(aName,'.'))); + if (aDriverIt == aDriverList.end()) { MMVII_INTERNAL_ERROR("MMVIITOGDal: Unsupported image format for " + aName); return nullptr; // never happens diff --git a/MMVII/src/MMV1/ImageFilterMMV1.cpp b/MMVII/src/MMV1/ImageFilterMMV1.cpp index fa88d7f074..6ff758a69d 100755 --- a/MMVII/src/MMV1/ImageFilterMMV1.cpp +++ b/MMVII/src/MMV1/ImageFilterMMV1.cpp @@ -2,7 +2,7 @@ #include "MMVII_Matrix.h" #include "MMVII_Linear2DFiltering.h" -// FIXME CM->MPD: Qu'est ce qu'on fait ici pour remplacer ELISE_COPY ? +// FIXME CM->MPD: Mail a MPD ! Qu'est ce qu'on fait ici pour remplacer ELISE_COPY ? /** \file ImageFilterMMV1.cpp \brief file for using MMV1 filters