source: tags/release-1.1.12/src/Detection/mergeIntoList.cc

Last change on this file was 770, checked in by MatthewWhiting, 14 years ago

A large bunch of changes related to #102. The starting point was fixing the way the merging worked, to avoid using erase() and do the addition of sources in-place. This led on to optimising the testing functions that look at whether objects should be merged, and a number of new in-class functions were created to do this more transparently. The file areClose.cc now doesn't contain anything useful, and can be deleted. Code is a lot quicker now :)

File size: 2.4 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, Param &par)
37  {
38    /// @details
39    /// A function to add a detection to a list of detections, checking
40    /// first to see if it can be combined with existing members of the
41    /// list.
42    ///
43    /// The areClose testing and combining is done with the
44    /// parameters as given by the Param set.
45    ///
46    /// \param object The Detection to be merged into the list.
47    /// \param objList The vector list of Detections.
48    /// \param par The Param set, used for testing if merging needs to be done.
49
50    bool haveMerged = false;
51
52    std::vector<Detection>::iterator iter;
53
54    for(iter=objList.begin(); (!haveMerged && iter<objList.end()); iter++) {
55      if(iter->canMerge(object,par)){
56        iter->addDetection(object);
57        haveMerged = true;
58      } 
59    }
60 
61    if(!haveMerged) objList.push_back(object);
62
63  }
64
65}
Note: See TracBrowser for help on using the repository browser.