Commit 8894ce2ca25c5c2a82fae3a9686e116b5c96adac

Authored by Brendan Klare
1 parent fd639bc1

Sub 2 indices function

openbr/core/common.cpp
... ... @@ -76,3 +76,11 @@ QList<float> Common::linspace(float start, float stop, int n) {
76 76 spaced.append(stop);
77 77 return spaced;
78 78 }
  79 +
  80 +QList<int> Common::ind2sub(int dims, int nPerDim, int idx) {
  81 + QList<int> subIndices;
  82 + for (int j = 0; j < dims; j++) {
  83 + subIndices.append(((int)floor( idx / pow((float)nPerDim, j))) % nPerDim);
  84 + }
  85 + return subIndices;
  86 +}
... ...
openbr/core/common.h
... ... @@ -335,6 +335,10 @@ V&lt;T&gt; Downsample(V&lt;T&gt; vals, int k)
335 335 return newVals;
336 336 }
337 337  
  338 +/*! \brief Converts index into subdimensions.
  339 +*/
  340 +QList<int> ind2sub(int dims, int nPerDim, int idx);
  341 +
338 342 }
339 343  
340 344 #endif // COMMON_COMMON_H
... ...