source: branches/pixelmap-refactor-branch/src/Detection/mergeIntoList.cc @ 1441

Last change on this file since 1441 was 541, checked in by MatthewWhiting, 15 years ago

Changing all calls of uint to unsigned int, as there are sometimes compilers that don't know about that typedef. Also added an include call for stdlib.h to fitsHeader.cc so that it knows about calloc.

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    /// @details
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    bool haveMerged = false;
53
54    std::vector<Detection>::iterator iter;
55    for(unsigned int ctr=0; (!(haveMerged) && (ctr<objList.size())); ctr++){
56   
57      if(areClose(object, objList[ctr], par)){
58        Detection newobj = objList[ctr] + object;
59        iter = objList.begin() + ctr;
60        objList.erase( iter );
61        objList.push_back( newobj );
62        haveMerged = true;
63      }
64   
65    }
66 
67    if(!haveMerged) objList.push_back(object);
68
69  }
70
71}
Note: See TracBrowser for help on using the repository browser.