Skip to content

Commit

Permalink
MMVII: GDAL: light refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
meynardc committed Dec 5, 2024
1 parent ae7db2c commit 45eac7f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
4 changes: 3 additions & 1 deletion MMVII/include/MMVII_Image2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions MMVII/include/V1VII.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MakeStdIm8BIts(cIm2D<tREAL4> 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 Type> class cMMV1_Conv
{
public :
Expand All @@ -64,8 +64,6 @@ template <class Type> class cMMV1_Conv
#endif
};

std::string V1NameMasqOfIm(const std::string & aName);

// Call V1 Fast kth value extraction
double KthVal(std::vector<double> &, double aProportion);
// Idem but indicate a number and not a proportion
Expand Down
6 changes: 6 additions & 0 deletions MMVII/src/DenseMatch/EpipGenDenseMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?
Expand Down
16 changes: 5 additions & 11 deletions MMVII/src/ImagesBase/FileImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -229,9 +223,7 @@ void cDataFileIm2D::SetCreatedNoUpdate() const

bool cDataFileIm2D::IsPostFixNameImage(const std::string & aPost)
{
static std::vector<std::string> aVNames({"jpg","jpeg","tif","tiff"});

return UCaseMember(aVNames,aPost);
return cGdalApi::IsPostFixNameImage(aPost);
}

bool cDataFileIm2D::IsNameWith_PostFixImage(const std::string & aName)
Expand Down Expand Up @@ -468,13 +460,15 @@ template <class Type> void cIm2D<Type>::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<tREAL8>::FromFile(aN1);
auto aIm2 = cIm2D<tREAL8>::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");
Expand Down
25 changes: 21 additions & 4 deletions MMVII/src/ImagesBase/cGdalApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<std::string, std::string> &SupportedDrivers();
static bool GDalDriverCanCreate(GDALDriver *aGdalDriver);

static CPLStringList GetCreateOptions(GDALDriver* aGdalDriver, const cDataFileIm2D::tOptions& aOptions);
Expand Down Expand Up @@ -608,9 +611,10 @@ void cGdalApi::CloseDataset(GDALDataset *aGdalDataset)
GDALClose(GDALDataset::ToHandle(aGdalDataset));
}

GDALDriver* cGdalApi::GetDriver(const std::string& aName)

const std::map<std::string, std::string> &cGdalApi::SupportedDrivers()
{
static std::map<std::string, std::string> DriverNames = {
static std::map<std::string, std::string> cSupportedDrivers= {
{"tif", "GTiff"},
{"tiff", "GTiff"},
{"dng", "GTiff"},
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion MMVII/src/MMV1/ImageFilterMMV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 45eac7f

Please sign in to comment.