diff --git a/openbr/core/common.cpp b/openbr/core/common.cpp index bfd38fb..d6c445a 100644 --- a/openbr/core/common.cpp +++ b/openbr/core/common.cpp @@ -76,3 +76,11 @@ QList Common::linspace(float start, float stop, int n) { spaced.append(stop); return spaced; } + +QList Common::ind2sub(int dims, int nPerDim, int idx) { + QList subIndices; + for (int j = 0; j < dims; j++) { + subIndices.append(((int)floor( idx / pow((float)nPerDim, j))) % nPerDim); + } + return subIndices; +} diff --git a/openbr/core/common.h b/openbr/core/common.h index 15516d0..09c171e 100644 --- a/openbr/core/common.h +++ b/openbr/core/common.h @@ -335,6 +335,10 @@ V Downsample(V vals, int k) return newVals; } +/*! \brief Converts index into subdimensions. +*/ +QList ind2sub(int dims, int nPerDim, int idx); + } #endif // COMMON_COMMON_H