Skip to content

Commit

Permalink
RCM: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 24, 2024
1 parent a9377f8 commit 8ad1706
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 284 deletions.
235 changes: 1 addition & 234 deletions frmts/rcm/rcmdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,74 +258,6 @@ RCMRasterBand::RCMRasterBand(RCMDataset *poDSIn, int nBandIn,
}
}

double RCMRasterBand::GetLUT(int)
{
return std::numeric_limits<double>::quiet_NaN();
}

int RCMRasterBand::GetLUTsize()
{
return 0;
}

const char *RCMRasterBand::GetLUTFilename()
{
return nullptr;
}

double RCMRasterBand::GetLUTOffset()
{
return 0.0f;
}

bool RCMRasterBand::IsComplex()
{
if (this->m_eType == GDT_CInt16 || this->m_eType == GDT_CInt32 ||
this->m_eType == GDT_CFloat32 || this->m_eType == GDT_CFloat64)
{
return true;
}
else
{
return false;
}
}

bool RCMRasterBand::IsExistLUT()
{
return false;
}

eCalibration RCMRasterBand::GetCalibration()
{
return this->m_eCalib;
}

void RCMRasterBand::SetPartialLUT(int, int)
{
// nothing to do
}

double RCMRasterBand::GetNoiseLevels(int)
{
return 0.0f;
}

int RCMRasterBand::GetNoiseLevelsSize()
{
return 0;
}

const char *RCMRasterBand::GetNoiseLevelsFilename()
{
return nullptr;
}

bool RCMRasterBand::IsExistNoiseLevels()
{
return false;
}

/************************************************************************/
/* RCMRasterBand() */
/************************************************************************/
Expand Down Expand Up @@ -672,7 +604,7 @@ RCMCalibRasterBand::RCMCalibRasterBand(
RCMDataset *poDataset, const char *pszPolarization, GDALDataType eType,
GDALDataset *poBandDataset, eCalibration eCalib, const char *pszLUT,
const char *pszNoiseLevels, GDALDataType eOriginalType)
: m_eCalib(eCalib), m_poBandDataset(poBandDataset), m_eType(eType),
: m_eCalib(eCalib), m_poBandDataset(poBandDataset),
m_eOriginalType(eOriginalType), m_pszLUTFile(VSIStrdup(pszLUT)),
m_pszNoiseLevelsFile(VSIStrdup(pszNoiseLevels))
{
Expand All @@ -683,8 +615,6 @@ RCMCalibRasterBand::RCMCalibRasterBand(
SetMetadataItem("POLARIMETRIC_INTERP", pszPolarization);
}

// this->eDataType = eType;

if ((eType == GDT_CInt16) || (eType == GDT_CFloat32))
this->eDataType = GDT_CFloat32;
else
Expand All @@ -697,169 +627,6 @@ RCMCalibRasterBand::RCMCalibRasterBand(
ReadNoiseLevels();
}

double RCMCalibRasterBand::GetNoiseLevels(int pixel)
{
return this->m_nfTableNoiseLevels[pixel];
}

int RCMCalibRasterBand::GetNoiseLevelsSize()
{
return this->m_nTableNoiseLevelsSize;
}

const char *RCMCalibRasterBand::GetNoiseLevelsFilename()
{
return this->m_pszNoiseLevelsFile;
}

bool RCMCalibRasterBand::IsExistNoiseLevels()
{
if (this->m_nfTableNoiseLevels == nullptr ||
this->m_pszNoiseLevelsFile == nullptr ||
strlen(this->m_pszNoiseLevelsFile) == 0 ||
this->m_nTableNoiseLevelsSize == 0)
{
return false;
}
else
{
return true;
}
}

bool RCMCalibRasterBand::IsComplex()
{
if (this->m_eType == GDT_CInt16 || this->m_eType == GDT_CInt32 ||
this->m_eType == GDT_CFloat32 || this->m_eType == GDT_CFloat64)
{
return true;
}
else
{
return false;
}
}

eCalibration RCMCalibRasterBand::GetCalibration()
{
return this->m_eCalib;
}

double RCMCalibRasterBand::GetLUT(int pixel)
{
return this->m_nfTable[pixel];
}

int RCMCalibRasterBand::GetLUTsize()
{
return this->m_nTableSize;
}

const char *RCMCalibRasterBand::GetLUTFilename()
{
return this->m_pszLUTFile;
}

double RCMCalibRasterBand::GetLUTOffset()
{
return this->m_nfOffset;
}

bool RCMCalibRasterBand::IsExistLUT()
{
if (this->m_nfTable == nullptr || this->m_pszLUTFile == nullptr ||
strlen(this->m_pszLUTFile) == 0 || this->m_nTableSize == 0)
{
return false;
}
else
{
return true;
}
}

void RCMCalibRasterBand::SetPartialLUT(int pixel_offset, int pixel_width)
{
/* Alway start from 0 */
if (pixel_offset < 0)
{
pixel_offset = 0;
}

if (pixel_offset < this->GetLUTsize())
{
/* Can only change if the starting pixel in the raster width range */
if ((pixel_offset + pixel_width) > this->GetLUTsize() - 1)
{
/* Ya but the width is way too large based on the raster width range
when beginning from a different offset Recalculate the true relative
width
*/
pixel_width = this->GetLUTsize() - pixel_offset - 1;
}

if (pixel_width > 0)
{
/* Prepare a buffer */
double *nfTableBuffer =
static_cast<double *>(CPLMalloc(sizeof(double) * pixel_width));
memset(nfTableBuffer, 0, sizeof(double) * pixel_width);

/* Copy a range */
int j = 0;
for (int i = pixel_offset; i < (pixel_offset + pixel_width); i++)
{
nfTableBuffer[j++] = this->GetLUT(i);
}

const size_t nLen =
pixel_width *
max_space_for_string; // 12 max + space + 11 reserved
char *lut_gains = static_cast<char *>(CPLMalloc(nLen));
memset(lut_gains, 0, nLen);

for (int i = 0; i < pixel_width; i++)
{
char lut[max_space_for_string];
// 2.390641e+02 %e Scientific annotation
snprintf(lut, sizeof(lut), "%e ", nfTableBuffer[i]);
strcat(lut_gains, lut);
}

char bandNumber[12];
snprintf(bandNumber, sizeof(bandNumber), "%d", this->GetBand());

poDS->SetMetadataItem(
CPLString("LUT_GAINS_").append(bandNumber).c_str(), lut_gains);
// Can free this because the function SetMetadataItem takes a copy
CPLFree(lut_gains);

/* and Set new LUT size */
char snum[12];
snprintf(snum, sizeof(snum), "%d", pixel_width);
poDS->SetMetadataItem(
CPLString("LUT_SIZE_").append(bandNumber).c_str(), snum);

/* Change the internal value now */
/* Free the old gains value table, not valid anymore */
CPLFree(this->m_nfTable);

/* New gains value table size */
this->m_nTableSize = pixel_width;

/* Realoocate and have new gain values from the buffer */
this->m_nfTable = reinterpret_cast<double *>(
CPLMalloc(sizeof(double) * this->m_nTableSize));
memset(this->m_nfTable, 0, sizeof(double) * this->m_nTableSize);
memcpy(this->m_nfTable, nfTableBuffer,
sizeof(double) * this->m_nTableSize);

/* Free our buffer */
CPLFree(nfTableBuffer);
}
}
}

/************************************************************************/
/* ~RCMCalibRasterBand() */
/************************************************************************/
Expand Down
50 changes: 0 additions & 50 deletions frmts/rcm/rcmdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class RCMRasterBand final : public GDALPamRasterBand
GDALDataset *poBandFile = nullptr;
RCMDataset *poRCMDataset = nullptr;
GDALDataset *m_poBandDataset = nullptr;
GDALDataType m_eType = GDT_Unknown; /* data type of data being ingested */

double *m_nfTable = nullptr;
int m_nTableSize = 0;
Expand Down Expand Up @@ -160,30 +159,6 @@ class RCMRasterBand final : public GDALPamRasterBand

virtual CPLErr IReadBlock(int, int, void *) override;

static bool IsExistLUT();

static double GetLUT(int pixel);

static const char *GetLUTFilename();

static int GetLUTsize();

static double GetLUTOffset();

static void SetPartialLUT(int pixel_offset, int pixel_width);

bool IsComplex();

static bool IsExistNoiseLevels();

static double GetNoiseLevels(int pixel);

static const char *GetNoiseLevelsFilename();

static int GetNoiseLevelsSize();

eCalibration GetCalibration();

static GDALDataset *Open(GDALOpenInfo *);
};

Expand All @@ -201,7 +176,6 @@ class RCMCalibRasterBand final : public GDALPamRasterBand
private:
eCalibration m_eCalib = eCalibration::Uncalib;
GDALDataset *m_poBandDataset = nullptr;
GDALDataType m_eType = GDT_Unknown; /* data type of data being ingested */
/* data type that used to be before transformation */
GDALDataType m_eOriginalType = GDT_Unknown;

Expand Down Expand Up @@ -233,30 +207,6 @@ class RCMCalibRasterBand final : public GDALPamRasterBand
~RCMCalibRasterBand();

CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;

bool IsExistLUT();

double GetLUT(int pixel);

const char *GetLUTFilename();

int GetLUTsize();

double GetLUTOffset();

void SetPartialLUT(int pixel_offset, int pixel_width);

bool IsExistNoiseLevels();

double GetNoiseLevels(int pixel);

const char *GetNoiseLevelsFilename();

int GetNoiseLevelsSize();

bool IsComplex();

eCalibration GetCalibration();
};

#endif /* ndef GDAL_RCM_H_INCLUDED */

0 comments on commit 8ad1706

Please sign in to comment.