[301] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // mergeIntoList.cc: Add a Detection to a list, merging with existing |
---|
| 3 | // members if necessary. |
---|
| 4 | // ----------------------------------------------------------------------- |
---|
| 5 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 6 | // |
---|
| 7 | // This program is free software; you can redistribute it and/or modify it |
---|
| 8 | // under the terms of the GNU General Public License as published by the |
---|
| 9 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 10 | // option) any later version. |
---|
| 11 | // |
---|
| 12 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 14 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 15 | // for more details. |
---|
| 16 | // |
---|
| 17 | // You should have received a copy of the GNU General Public License |
---|
| 18 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 19 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 20 | // |
---|
| 21 | // Correspondence concerning Duchamp may be directed to: |
---|
| 22 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 23 | // Postal address: Dr. Matthew Whiting |
---|
| 24 | // Australia Telescope National Facility, CSIRO |
---|
| 25 | // PO Box 76 |
---|
| 26 | // Epping NSW 1710 |
---|
| 27 | // AUSTRALIA |
---|
| 28 | // ----------------------------------------------------------------------- |
---|
[3] | 29 | #include <vector> |
---|
| 30 | #include <Cubes/cubes.hh> |
---|
| 31 | #include <Utils/utils.hh> |
---|
| 32 | |
---|
[301] | 33 | void mergeIntoList(Detection &object, std::vector <Detection> &objList, |
---|
| 34 | Param &par) |
---|
[3] | 35 | { |
---|
| 36 | /** |
---|
[221] | 37 | * A function to add a detection to a list of detections, checking |
---|
| 38 | * first to see if it can be combined with existing members of the |
---|
| 39 | * list. |
---|
[3] | 40 | * |
---|
[258] | 41 | * The areClose testing and combining is now done with the |
---|
| 42 | * parameters as given by the Param set, not just assuming adjacency |
---|
| 43 | * (as previously done). |
---|
[221] | 44 | * |
---|
| 45 | * \param object The Detection to be merged into the list. |
---|
| 46 | * \param objList The vector list of Detections. |
---|
| 47 | * \param par The Param set, used for testing if merging needs to be done. |
---|
[3] | 48 | */ |
---|
| 49 | |
---|
[82] | 50 | bool haveMerged = false; |
---|
[136] | 51 | |
---|
[258] | 52 | std::vector<Detection>::iterator iter; |
---|
| 53 | for(int ctr=0; (!(haveMerged) && (ctr<objList.size())); ctr++){ |
---|
| 54 | |
---|
| 55 | if(areClose(object, objList[ctr], par)){ |
---|
| 56 | Detection newobj = objList[ctr] + object; |
---|
| 57 | iter = objList.begin() + ctr; |
---|
| 58 | objList.erase( iter ); |
---|
| 59 | objList.push_back( newobj ); |
---|
| 60 | haveMerged = true; |
---|
| 61 | } |
---|
| 62 | |
---|
[3] | 63 | } |
---|
[258] | 64 | |
---|
[82] | 65 | if(!haveMerged) objList.push_back(object); |
---|
[3] | 66 | |
---|
| 67 | } |
---|