source: tags/release-1.1.2b/src/Detection/mergeIntoList.cc

Last change on this file was 392, checked in by MatthewWhiting, 17 years ago

Fixed up headers -- should have been done before tagging.

File size: 2.5 KB
Line 
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// -----------------------------------------------------------------------
29#include <vector>
30#include <duchamp/Cubes/cubes.hh>
31#include <duchamp/Utils/utils.hh>
32
33namespace duchamp
34{
35
36  void mergeIntoList(Detection &object, std::vector <Detection> &objList,
37                     Param &par)
38  {
39    /**
40     * A function to add a detection to a list of detections, checking
41     * first to see if it can be combined with existing members of the
42     * list.
43     *
44     * The areClose testing and combining is now done with the
45     * parameters as given by the Param set, not just assuming adjacency
46     * (as previously done).
47     *
48     * \param object The Detection to be merged into the list.
49     * \param objList The vector list of Detections.
50     * \param par The Param set, used for testing if merging needs to be done.
51     */
52
53    bool haveMerged = false;
54
55    std::vector<Detection>::iterator iter;
56    for(int ctr=0; (!(haveMerged) && (ctr<objList.size())); ctr++){
57   
58      if(areClose(object, objList[ctr], par)){
59        Detection newobj = objList[ctr] + object;
60        iter = objList.begin() + ctr;
61        objList.erase( iter );
62        objList.push_back( newobj );
63        haveMerged = true;
64      }
65   
66    }
67 
68    if(!haveMerged) objList.push_back(object);
69
70  }
71
72}
Note: See TracBrowser for help on using the repository browser.