From 8894ce2ca25c5c2a82fae3a9686e116b5c96adac Mon Sep 17 00:00:00 2001 From: Brendan Klare Date: Sun, 6 Apr 2014 16:51:42 -0400 Subject: [PATCH] Sub 2 indices function --- openbr/core/common.cpp | 8 ++++++++ openbr/core/common.h | 4 ++++ 2 files changed, 12 insertions(+), 0 deletions(-) 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 -- libgit2 0.21.4