Commit b1456fb3 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Rmove TBandNameEnum template parameter from RadiometricIndex class

No related merge requests found
Showing with 18 additions and 22 deletions
+18 -22
...@@ -42,8 +42,7 @@ namespace Functor ...@@ -42,8 +42,7 @@ namespace Functor
* This class is the base class for all radiometric indices. * This class is the base class for all radiometric indices.
* *
* It offers services to: * It offers services to:
* - Indicate which band are required among the list provided by * - Indicate which band are required among CommonBandNames enum
* TBandNameEnum
* - Set indices of each required band * - Set indices of each required band
* - Compute the indice response to a pixel by subclassing the pure * - Compute the indice response to a pixel by subclassing the pure
* virtual operator() * virtual operator()
...@@ -52,12 +51,9 @@ namespace Functor ...@@ -52,12 +51,9 @@ namespace Functor
* best performances use the Value() method when implementing * best performances use the Value() method when implementing
* operator() to avoid branches. * operator() to avoid branches.
* *
* TBandName enum should end with a MAX value that will be used to
* derive the number of bands.
*
* \ingroup OTBIndices * \ingroup OTBIndices
*/ */
template <typename TInput, typename TOutput, typename TBandNameEnum = CommonBandNames> template <typename TInput, typename TOutput>
class RadiometricIndex class RadiometricIndex
{ {
public: public:
...@@ -67,7 +63,7 @@ public: ...@@ -67,7 +63,7 @@ public:
using OutputType = TOutput; using OutputType = TOutput;
/// Enum Among which bands are used /// Enum Among which bands are used
using BandNameType = TBandNameEnum; using BandNameType = CommonBandNames;
/// The number of bands, derived from the Enum MAX value /// The number of bands, derived from the Enum MAX value
static constexpr size_t NumberOfBands = static_cast<size_t>(BandNameType::MAX); static constexpr size_t NumberOfBands = static_cast<size_t>(BandNameType::MAX);
...@@ -75,8 +71,8 @@ public: ...@@ -75,8 +71,8 @@ public:
static constexpr double Epsilon = 0.0000001; static constexpr double Epsilon = 0.0000001;
/** /**
* \param requiredBands the set<TBandNameEnum> of required bands * \param requiredBands the set<CommonBandNames> of required bands
* \throw runtime_error if requiredBands contains TBandNameEnum::MAX * \throw runtime_error if requiredBands contains CommonBandNames::MAX
*/ */
RadiometricIndex(const std::set<BandNameType>& requiredBands) : m_RequiredBands(), m_BandIndices() RadiometricIndex(const std::set<BandNameType>& requiredBands) : m_RequiredBands(), m_BandIndices()
{ {
...@@ -96,7 +92,7 @@ public: ...@@ -96,7 +92,7 @@ public:
} }
/** /**
* \return a set<TBandNameEnum> containing the required bands for * \return a set<CommandBandName> containing the required bands for
* this indice. * this indice.
*/ */
std::set<BandNameType> GetRequiredBands() const std::set<BandNameType> GetRequiredBands() const
...@@ -114,23 +110,23 @@ public: ...@@ -114,23 +110,23 @@ public:
} }
/** /**
* \param band The band to set (value in TBandNameEnum) * \param band The band to set (value in CommandBandName)
* \param index The index of the band to set (starts at 1 for first band) * \param index The index of the band to set (starts at 1 for first band)
* \throw runtime_error if band is TBandNameEnum::MAX * \throw runtime_error if band is CommandBandName::MAX
*/ */
void SetBandIndex(BandNameType band, size_t index) void SetBandIndex(BandNameType band, size_t index)
{ {
if (band == BandNameType::MAX) if (band == BandNameType::MAX)
{ {
throw std::runtime_error("Can not set index for TBandNameEnum::MAX"); throw std::runtime_error("Can not set index for CommandBandName::MAX");
} }
m_BandIndices[static_cast<size_t>(band)] = index; m_BandIndices[static_cast<size_t>(band)] = index;
} }
/** /**
* \param indicesMap a std::map<TBandNameEnum,size_t> containing all * \param indicesMap a std::map<CommandBandName,size_t> containing all
* bands indices to set (starts at 1 for first band) * bands indices to set (starts at 1 for first band)
* \throw runtime_error if indicesMap contains TBandNameEnum::MAX * \throw runtime_error if indicesMap contains CommandBandName::MAX
*/ */
void SetBandsIndices(const std::map<BandNameType, size_t>& indicesMap) void SetBandsIndices(const std::map<BandNameType, size_t>& indicesMap)
{ {
...@@ -143,13 +139,13 @@ public: ...@@ -143,13 +139,13 @@ public:
/** /**
* \param band The band for which to retrieve indice * \param band The band for which to retrieve indice
* \return The indices of the band * \return The indices of the band
* \throw runtime_error if band is TBandNameEnum::MAX * \throw runtime_error if band is CommandBandName::MAX
*/ */
size_t GetBandIndex(BandNameType band) const size_t GetBandIndex(BandNameType band) const
{ {
if (band == BandNameType::MAX) if (band == BandNameType::MAX)
{ {
throw std::runtime_error("Can not get index for TBandNameEnum::MAX"); throw std::runtime_error("Can not get index for CommandBandName::MAX");
} }
return m_BandIndices[static_cast<size_t>(band)]; return m_BandIndices[static_cast<size_t>(band)];
} }
...@@ -166,9 +162,9 @@ protected: ...@@ -166,9 +162,9 @@ protected:
/** /**
* Helper method to retrieve index for band name. With respect to * Helper method to retrieve index for band name. With respect to
* the public method, this method will not throw an exception if * the public method, this method will not throw an exception if
* TBandNameEnum::MAX is used as a parameter. Since it is meant for * CommandBandName::MAX is used as a parameter. Since it is meant for
* internal use in the critical path and not for client code, it * internal use in the critical path and not for client code, it
* will only assert that band is not TBandNameEnum::MAX in debug * will only assert that band is not CommandBandName::MAX in debug
* mode. * mode.
* *
* \param band The band for which to retrieve indice * \param band The band for which to retrieve indice
...@@ -176,7 +172,7 @@ protected: ...@@ -176,7 +172,7 @@ protected:
*/ */
size_t UncheckedBandIndex(BandNameType band) const size_t UncheckedBandIndex(BandNameType band) const
{ {
assert(band != BandNameType::MAX && "Can not retrieve index for band TBandNameEnum::MAX"); assert(band != BandNameType::MAX && "Can not retrieve index for band CommandBandName::MAX");
return m_BandIndices[static_cast<size_t>(band)]; return m_BandIndices[static_cast<size_t>(band)];
} }
...@@ -184,7 +180,7 @@ protected: ...@@ -184,7 +180,7 @@ protected:
* Helper method to parse input itk::VariableLengthVector<TInput> * Helper method to parse input itk::VariableLengthVector<TInput>
* and get the corresponding band value. * and get the corresponding band value.
* For instance: * For instance:
* \snippet auto red = this->Value(CommonBandNames::RED,input); * \snippet auto red = this->Value(CommonBandNamess::RED,input);
* *
* As this function is on the critical performance path, no checks * As this function is on the critical performance path, no checks
* are made to see wether this band is really required for this * are made to see wether this band is really required for this
......
...@@ -226,7 +226,7 @@ int otbRadiometricIndexTest(int, char ** const) ...@@ -226,7 +226,7 @@ int otbRadiometricIndexTest(int, char ** const)
int otbIndicesStackFunctorTest(int, char ** const) int otbIndicesStackFunctorTest(int, char ** const)
{ {
using IndicesType = RadiometricIndex<double, int, CommonBandNames>; using IndicesType = RadiometricIndex<double, int>;
using StackFunctorType = IndicesStackFunctor<IndicesType>; using StackFunctorType = IndicesStackFunctor<IndicesType>;
auto ndvi = NDVI<double, int>(); auto ndvi = NDVI<double, int>();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment