#include #include namespace PixelInfo { Scan nullScan() { /** * A simple way of returning a scan with zero length. */ Scan null(-1,-1,0); return null; } //------------------------------------------------------ Scan unite(Scan &scan1, Scan &scan2) { /** * Return a scan that includes all pixels from both scans, but * only if they overlap. If they do not, return the null scan. * */ // TEST FOR FAILURES: bool fail = false; fail = fail || (scan1.getY()!=scan2.getY()); fail = fail || ( (scan1.getX() < scan2.getX()) && (scan2.getX() > scan1.getXmax()+1) ); fail = fail || ( (scan2.getX() < scan1.getX()) && (scan1.getX() > scan2.getXmax()+1) ); Scan joined; if(fail){ // std::cerr << "Joining scans failed! (" // << scan1 <<"),("<xmax) xmax=scan2.getXmax(); joined.define(y,x,xmax-x+1); } return joined; } //------------------------------------------------------ Scan intersect(Scan &scan1, Scan &scan2) { /** * Return a scan that includes all pixels that lie in both scans. * * If they do not overlap, return the null scan. * */ bool fail = false; fail = fail || (scan1.getY()!=scan2.getY()); fail = fail || ( (scan1.getX() < scan2.getX()) && (scan2.getX() > scan1.getXmax()+1) ); fail = fail || ( (scan2.getX() < scan1.getX()) && (scan1.getX() > scan2.getXmax()+1) ); Scan intersection; if(fail){ // std::cerr << "Intersecting scans failed! (" // << scan1 <<"),("<x) x=scan2.getX(); long xmax=scan1.getXmax(); if(scan2.getXmax()itsY) && ( (x>= this->itsX) && (x < (this->itsXLen+this->itsX)) ); } //------------------------------------------------------ void mergeList(std::vector scanlist) { std::vector::iterator iter; int counter=0,compCounter; while(counter<(scanlist.size()-1)){ compCounter = counter+1; do{ if(touching(scanlist[counter],scanlist[compCounter])){ Scan temp = unite(scanlist[counter],scanlist[compCounter]); iter = scanlist.begin()+compCounter; scanlist.erase(iter); iter = scanlist.begin()+counter; scanlist.erase(iter); scanlist.push_back(temp); } else compCounter ++; }while(compCounter < scanlist.size()); counter++; } } }