#include "TxsPyramid.h" using namespace TXS; void TxsPyramid::getClosestPyramid(TiffImage &loLev, TiffImage &hiLev, int hiLevelNum, int &xHiOut, int &yHiOut, int midOfs) { if(loLev.getWidth() >= hiLev.getWidth()) { __ERROR__("bad pyramids given for search! " << " lo width: " << loLev.getWidth() << " hi width: " << hiLev.getWidth()); return; } TiffImage *myLo = this->getLevel(hiLevelNum - 1); TiffImage *myHi = this->getLevel(hiLevelNum); //__LOG__("myLo dims: " << myLo->getWidth() << "x" << myLo->getHeight()); //__LOG__("loLev dims: " << loLev.getWidth() << "x" << loLev.getHeight()); const int lastX = myHi->getWidth() - hiLev.getWidth(); const int lastY = myHi->getHeight() - hiLev.getHeight(); if(lastX != lastY) { __ERROR__("search pyramid isn't symetric!" << " hi lev dimensions: " << hiLev.getWidth() << "x" << hiLev.getHeight()); return; } TXS_REAL ssdMin = 0.0; bool firstIter = true; for(int xHi = 0; xHi <= lastX ; ++xHi) { for(int yHi = 0; yHi <= lastY; ++yHi) { // calculate the lofi level coordinates // use integer divide int xLo = xHi / 2; int yLo = yHi / 2; // get the SSD for both lo and hi // note that we don't give a mid offset - // it shouldn't ignore the center pixel const TXS_REAL ssdLo = myLo->calcRegionSSD(loLev, xLo, yLo); // note that for the second one, we pass in the midOfs // this is so the SSD calc ignores the middle pixel const TXS_REAL ssdHi = myHi->calcRegionSSD(hiLev, xHi, yHi, midOfs); TXS_REAL ssdTotal = ssdLo + ssdHi; /* __LOG__("ssd: " << ssdTotal << " ssdMin: " << ssdMin << " ssdLo: " << ssdLo << " ssdHi: " << ssdHi << " x/yHi: (" << xHi << ", " << (myHi->getHeight()-yHi-1) << ")"); __LOG__(" x/yLo: (" << xLo << ", " << (myLo->getHeight()-yLo-1) << ")"); */ if(firstIter || ssdTotal < ssdMin) { ssdMin = ssdTotal; xHiOut = xHi; yHiOut = yHi; firstIter = false; //__LOG__(" better!"); } } } }