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 | */ |
---|
17 | void 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 | Detection *obj2 = new Detection; |
---|
62 | *obj2 = currentList->at(compCounter); |
---|
63 | |
---|
64 | if(areClose(*obj1, *obj2, this->par)){ |
---|
65 | obj1->addAnObject( *obj2 ); |
---|
66 | iter = currentList->begin() + compCounter; |
---|
67 | currentList->erase(iter); |
---|
68 | iter = currentList->begin() + counter; |
---|
69 | currentList->erase(iter); |
---|
70 | currentList->push_back( *obj1 ); |
---|
71 | |
---|
72 | if(isVerb){ |
---|
73 | std::cout.setf(std::ios::right); |
---|
74 | std::cout << "Progress: " |
---|
75 | << std::setw(6) << counter << "/"; |
---|
76 | std::cout.unsetf(std::ios::right); |
---|
77 | std::cout.setf(std::ios::left); |
---|
78 | std::cout << std::setw(6) << currentList->size() |
---|
79 | << "\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; |
---|
80 | std::cout.unsetf(std::ios::left); |
---|
81 | } |
---|
82 | compCounter = counter + 1; |
---|
83 | |
---|
84 | } |
---|
85 | else compCounter++; |
---|
86 | |
---|
87 | delete obj2; |
---|
88 | delete obj1; |
---|
89 | |
---|
90 | } while( (compCounter<currentList->size()) ); |
---|
91 | |
---|
92 | counter++; |
---|
93 | |
---|
94 | } // end of while(counter<(currentList->size()-1)) loop |
---|
95 | |
---|
96 | if( (nloop==0) && (this->par.getFlagGrowth()) ) { |
---|
97 | std::cout << "Growing objects... "<< std::flush; |
---|
98 | this->setCubeStats(); |
---|
99 | vector <Detection> *newList = new vector <Detection>; |
---|
100 | 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; |
---|
101 | std::cout << " Growing object # "<< std::flush; |
---|
102 | std::cout.setf(std::ios::left); |
---|
103 | for(int i=0;i<currentList->size();i++){ |
---|
104 | std::cout<< "\b\b\b\b\b\b"<<std::setw(6)<<i+1<<std::flush; |
---|
105 | Detection *obj = new Detection; |
---|
106 | *obj = currentList->at(i); |
---|
107 | growObject(*obj,*this); |
---|
108 | newList->push_back(*obj); |
---|
109 | delete obj; |
---|
110 | } |
---|
111 | delete currentList; |
---|
112 | currentList = newList; |
---|
113 | std::cout.unsetf(std::ios::left); |
---|
114 | 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; |
---|
115 | } |
---|
116 | |
---|
117 | } |
---|
118 | // when you get here, every detection in the input list has been |
---|
119 | // examined and compared to every other detection. |
---|
120 | |
---|
121 | int listCounter = 0; |
---|
122 | while(listCounter < currentList->size()){ |
---|
123 | |
---|
124 | (*currentList)[listCounter].addOffsets(this->par); |
---|
125 | (*currentList)[listCounter].calcParams(); |
---|
126 | |
---|
127 | // Now, for each object in the newly modified list, we need to check if |
---|
128 | // they pass the requirements on the minimum no. of channels and minimum |
---|
129 | // number of spatial pixels |
---|
130 | // If not, remove from list. |
---|
131 | |
---|
132 | if( (*currentList)[listCounter].hasEnoughChannels(this->par.getMinChannels()) |
---|
133 | && ((*currentList)[listCounter].getSpatialSize() >= this->par.getMinPix()) ){ |
---|
134 | listCounter++; |
---|
135 | if(isVerb){ |
---|
136 | std::cout << "Final total:"<<std::setw(5)<<listCounter<<" " |
---|
137 | << "\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; |
---|
138 | } |
---|
139 | } |
---|
140 | else currentList->erase(currentList->begin()+listCounter); |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | this->objectList = *currentList; |
---|
145 | currentList->clear(); |
---|
146 | delete currentList; |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | } |
---|
151 | |
---|