source: tags/release-1.0.2/src/Cubes/Merger.cc @ 1455

Last change on this file since 1455 was 108, checked in by Matthew Whiting, 18 years ago

Changed source tree structure: added a src/ directory that contains all the
code. Makefile.in and configure.ac changed to match.

File size: 4.6 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <math.h>
4#include <vector>
5#include <Cubes/cubes.hh>
6#include <Detection/detection.hh>
7#include <Utils/utils.hh>
8
9/**
10 * Cube::ObjectMerger():
11 *   A Function that takes a Cube's list of Detections and
12 *   combines those that are close (according to the
13 *   thresholds specified in the parameter list par).
14 *   It also excludes those that do not make the minimum
15 *   number of channels requirement.
16 */
17void Cube::ObjectMerger()
18{
19
20  if(this->objectList.size() > 0){
21
22    // make a vector "currentList", which starts as a copy of the Cube's objectList,
23    //  but is the one worked on.
24    vector <Detection> *currentList = new vector <Detection>(this->objectList.size());
25    *currentList = this->objectList;
26    vector <Detection>::iterator iter;
27
28    // The Cube's objectList is cleared, and then the final objects are added to it at the end.
29    this->objectList.clear();
30 
31    int counter, compCounter,numLoops;
32    bool areNear,isMatch;
33    long gap;
34
35    bool isVerb = this->par.isVerbose();
36
37    if(this->par.getFlagGrowth()) numLoops=2;
38    else numLoops = 1;
39
40    for(int nloop = 0; nloop < numLoops; nloop++){
41
42      counter=0;
43      while( counter < (currentList->size()-1) ){
44        if(isVerb){
45          std::cout.setf(std::ios::right);
46          if(nloop>0) std::cout << "Progress#2: " << std::setw(6) << counter << "/" ;
47          else std::cout << "Progress: " << std::setw(6) << counter << "/" ;
48          std::cout.unsetf(std::ios::right);
49          std::cout.setf(std::ios::left);
50          std::cout << std::setw(6) << currentList->size()
51                    << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" << std::flush;
52          if(nloop>0) std::cout << "\b\b" << std::flush; ;
53          std::cout.unsetf(std::ios::left);
54        }
55
56        compCounter = counter + 1;
57        do {
58
59          Detection *obj1 = new Detection;
60//        *obj1 = currentList->at(counter);
61          *obj1 = (*currentList)[counter];
62          Detection *obj2 = new Detection;
63//        *obj2 = currentList->at(compCounter);
64          *obj2 = (*currentList)[compCounter];
65
66          if(areClose(*obj1, *obj2, this->par)){
67            obj1->addAnObject( *obj2 );
68            iter = currentList->begin() + compCounter;
69            currentList->erase(iter);
70            iter = currentList->begin() + counter;
71            currentList->erase(iter);
72            currentList->push_back( *obj1 );
73
74            if(isVerb){
75              std::cout.setf(std::ios::right);
76              std::cout << "Progress: "
77                        << std::setw(6) << counter << "/";
78              std::cout.unsetf(std::ios::right);
79              std::cout.setf(std::ios::left);
80              std::cout << std::setw(6) << currentList->size()
81                        << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" << std::flush;
82              std::cout.unsetf(std::ios::left);
83            }
84            compCounter = counter + 1;
85
86          }
87          else compCounter++;
88
89          delete obj2;
90          delete obj1;
91
92        } while( (compCounter<currentList->size()) );
93
94        counter++;
95
96      }  // end of while(counter<(currentList->size()-1)) loop
97
98      if( (nloop==0) && (this->par.getFlagGrowth()) ) {
99        std::cout << "Growing objects...     "<< std::flush;
100        this->setCubeStats();
101        vector <Detection> *newList = new vector <Detection>;
102        std::cout<< "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"<<std::flush;
103        std::cout << " Growing object #      "<< std::flush;
104        std::cout.setf(std::ios::left);
105        for(int i=0;i<currentList->size();i++){
106          std::cout<< "\b\b\b\b\b\b"<<std::setw(6)<<i+1<<std::flush;
107          Detection *obj = new Detection;
108//        *obj = currentList->at(i);
109          *obj = (*currentList)[i];
110          growObject(*obj,*this);
111          newList->push_back(*obj);
112          delete obj;
113        }
114        delete currentList;
115        currentList = newList;
116        std::cout.unsetf(std::ios::left);
117        std::cout<< "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"<<std::flush;
118      }
119
120    }
121    // when you get here, every detection in the input list has been
122    // examined and compared to every other detection.
123
124    int listCounter = 0;
125    while(listCounter < currentList->size()){
126
127      (*currentList)[listCounter].addOffsets(this->par);
128      (*currentList)[listCounter].calcParams();
129
130      // Now, for each object in the newly modified list, we need to check if
131      // they pass the requirements on the minimum no. of channels and minimum
132      // number of spatial pixels
133      // If not, remove from list.
134
135      if( (*currentList)[listCounter].hasEnoughChannels(this->par.getMinChannels())
136          && ((*currentList)[listCounter].getSpatialSize() >= this->par.getMinPix()) ){
137        listCounter++;
138        if(isVerb){
139          std::cout << "Final total:"<<std::setw(5)<<listCounter<<"      "
140                    << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"<<std::flush;
141        }
142      }     
143      else currentList->erase(currentList->begin()+listCounter);
144
145    }
146
147    this->objectList = *currentList;
148    currentList->clear();
149    delete currentList;
150
151  }
152
153}
154
Note: See TracBrowser for help on using the repository browser.