diff --git a/main.cpp b/main.cpp index 5c64e9e..95ccfb0 100644 --- a/main.cpp +++ b/main.cpp @@ -11,8 +11,37 @@ #include "Euclidean.hpp" +#define MIN(x,y) ((x)<(y)?(x):(y)) +#define MAX(x,y) ((x)>(y)?(x):(y)) + using namespace cimg_library; +double min(std::vector vect) { + double min = (*vect.begin()).getDistance(); + std::vector::iterator it; + + for (it = vect.begin() + 1; it != vect.end(); it++) { + if ((*it).getDistance() < min) { + min = (*it).getDistance(); + } + } + + return min; +} + +double max(std::vector vect) { + double max = (*vect.begin()).getDistance(); + std::vector::iterator it; + + for (it = vect.begin() + 1; it != vect.end(); it++) { + if ((*it).getDistance() > max) { + max = (*it).getDistance(); + } + } + + return max; +} + /******************************************************************************* Main *******************************************************************************/ @@ -121,6 +150,12 @@ int main() } // Calculate the window size + double d1 = MIN(min(vectEMax), min(vectEMin)); + double d2 = MAX(min(vectEMax), min(vectEMin)); + double d3 = MIN(max(vectEMax), max(vectEMin)); + double d4 = MAX(max(vectEMax), max(vectEMin)); + + int w = ((int)ceil(MIN(MIN(d1, d2), MIN(d3, d4)))) % 2 ? w + 1 : w; // Order filters with source image