// ----------------------------------------------------------------------- // Scan.cc: Member functions for the Scan class. // ----------------------------------------------------------------------- // Copyright (C) 2006, Matthew Whiting, ATNF // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your // option) any later version. // // Duchamp is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License // along with Duchamp; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA // // Correspondence concerning Duchamp may be directed to: // Internet email: Matthew.Whiting [at] atnf.csiro.au // Postal address: Dr. Matthew Whiting // Australia Telescope National Facility, CSIRO // PO Box 76 // Epping NSW 1710 // AUSTRALIA // ----------------------------------------------------------------------- #include #include #include namespace PixelInfo { Scan::Scan() { this->itsY=-1; this->itsX=-1; this->itsXLen=0; } Scan::Scan(const Scan& s) { operator=(s); } //------------------------------------------------------ Scan& Scan::operator= (const Scan& s) { if(this == &s) return *this; this->itsY=s.itsY; this->itsX=s.itsX; this->itsXLen=s.itsXLen; return *this; } //------------------------------------------------------ Scan nullScan() { /// A simple way of returning a scan with zero length. Scan null(-1,-1,0); return null; } bool Scan::isNull() { return (itsY==-1 && itsX==-1 && itsXLen==0); } //------------------------------------------------------ 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. Scan joined; if(!touching(scan1,scan2)){ // std::cerr << "Joining scans failed! (" // << scan1 <<"),("<itsY) && ( (x>= this->itsX) && (x < (this->itsXLen+this->itsX)) ); } //------------------------------------------------------ float minSep(Scan &s1, Scan &s2) { if(s1.getX() > s2.getXmax()) return hypot(s1.getX()-s2.getXmax(),s1.getY()-s2.getY()); else if(s2.getX() > s1.getXmax()) return hypot(s2.getX()-s1.getXmax(),s1.getY()-s2.getY()); else return fabsf(s1.getY()-s2.getY()); } //------------------------------------------------------ void mergeList(std::vector scanlist) { std::vector::iterator iter; uint 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++; } } }