source: trunk/src/Cubes/Merger.cc @ 208

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

Large commit. The addition of a new Statistics namespace & class, plus a number of changes to the code to make the cube-wide statistics calculation work. The FDR calculations are incorporated into the new class, and a number of functions have been made into templates to ease the calculations. Details follow:

  • New namespace and class (StatsContainer? -- templated) in Statistics.hh, that holds mean,median,stddev & madfm, and provide accessor and calculator functions for these. It also holds the threshold values for sigma-clipping and FDR methods, as well as the PValue evaluation functions
  • The correctionFactor incorporated into the namespace, and given a conversion function that other functions can call (eg. the atrous_Xd_reconstruct functions).
  • Templated the statistics functions in getStats.cc.
  • Templated the sort functions, and made swap an inline one defined in utils.hh.
  • A number of changes to cubes.cc and cubes.hh:
    • DataArray? gains a StatsContainer? object, to store stats info.
    • Image has lost its pValue array (not needed as we calculate on the fly) and mask array (not used).
    • Image has also lost all its stats members, but keeps minPix.
    • Functions to go are Image::maskObject, Image::findStats. Removed calls to the former. Latter never used.
    • Cube::setCubeStats does the cube-wide stats calculations, including setupFDR (now a Cube function).
    • Cube loses the specMean etc arrays.
  • The Search functions (ReconSearch? and CubicSearch?) changed to accommodate the exchange of StatsContainer? objects. This changed the prototypes as well.
  • The growObject function incorporates the new StatsContainer? object.
  • Minor change to Merger, in the preparation for calling growObject.
  • A new par introduced: flagUserThreshold -- set to true when the user enters a value for the threshold.
  • Removed thresholding_functions.cc and incorporated its functions into cubes.cc and cubes.hh.
File size: 5.0 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <math.h>
4#include <vector>
5#include <duchamp.hh>
6#include <Cubes/cubes.hh>
7#include <Detection/detection.hh>
8#include <Utils/utils.hh>
9
10void Cube::ObjectMerger()
11{
12  /**
13   * Cube::ObjectMerger():
14   *   A Function that takes a Cube's list of Detections and
15   *   combines those that are close (according to the
16   *   thresholds specified in the parameter list par).
17   *   It also excludes those that do not make the minimum
18   *   number of channels requirement.
19   *   A front end to simpler functions mergeList and finaliseList,
20   *    with code to cover the option of growing objects.
21   */
22
23  if(this->objectList.size() > 0){
24
25    // make a vector "currentList", which starts as a copy of the Cube's
26    //  objectList, but is the one worked on.
27    vector <Detection> *currentList = new vector <Detection>(this->objectList.size());
28    *currentList = this->objectList;
29    this->objectList.clear();
30
31    mergeList(*currentList, this->par);
32
33    // Do growth stuff
34    if(this->par.getFlagGrowth()) {
35      std::cout << "Growing objects...     "<< std::flush;
36      vector <Detection> *newList = new vector <Detection>;
37      printBackSpace(23);
38      std::cout << " Growing object #      "<< std::flush;
39      std::cout.setf(std::ios::left);
40      for(int i=0;i<currentList->size();i++){
41        printBackSpace(6);
42        std::cout << std::setw(6) << i+1 << std::flush;
43        Detection *obj = new Detection;
44        *obj = (*currentList)[i];
45        growObject(*obj,*this);
46        newList->push_back(*obj);
47        delete obj;
48      }
49      delete currentList;
50      currentList = newList;
51      std::cout.unsetf(std::ios::left);
52      printBackSpace(23);
53      std::cout << std::flush;
54
55      // and do the merging again to pick up objects that have
56      //  grown into each other.
57      mergeList(*currentList, this->par);
58    }
59
60    finaliseList(*currentList, this->par);
61
62    this->objectList = *currentList;
63    currentList->clear();
64    delete currentList;
65
66  }
67}
68
69void ObjectMerger(vector<Detection> &objList, Param &par)
70{
71  /**
72   *  ObjectMerger(objList, par)
73   *   A simple front-end to the two following functions,
74   *    so that if you want to merge a single list, it will
75   *    do both the merging and the cleaning up afterwards.
76   */
77  mergeList(objList, par);
78  finaliseList(objList, par);
79}
80
81void mergeList(vector<Detection> &objList, Param &par)
82{
83  /**
84   *  mergeList(objList, par)
85   *   A function that merges any objects in the list of
86   *    Detections that are within stated threshold distances.
87   *   Determination of whether objects are close is done by
88   *    the function areClose.
89   */
90
91  if(objList.size() > 0){
92
93    bool isVerb = par.isVerbose();
94    vector <Detection>::iterator iter;
95
96    int counter=0, compCounter;
97    while( counter < (objList.size()-1) ){
98      if(isVerb){
99        std::cout.setf(std::ios::right);
100        std::cout << "Progress: " << std::setw(6) << counter << "/" ;
101        std::cout.unsetf(std::ios::right);
102        std::cout.setf(std::ios::left);
103        std::cout << std::setw(6) << objList.size();
104        printBackSpace(23);
105        std::cout << std::flush;
106        std::cout.unsetf(std::ios::left);
107      }
108
109      compCounter = counter + 1;
110
111      do {
112
113        Detection *obj1 = new Detection;
114        *obj1 = objList[counter];
115        Detection *obj2 = new Detection;
116        *obj2 = objList[compCounter];
117
118        if(areClose(*obj1, *obj2, par)){
119          obj1->addAnObject( *obj2 );
120          iter = objList.begin() + compCounter;
121          objList.erase(iter);
122          iter = objList.begin() + counter;
123          objList.erase(iter);
124          objList.push_back( *obj1 );
125
126          if(isVerb){
127            std::cout.setf(std::ios::right);
128            std::cout << "Progress: "
129                      << std::setw(6) << counter << "/";
130            std::cout.unsetf(std::ios::right);
131            std::cout.setf(std::ios::left);
132            std::cout << std::setw(6) << objList.size();
133            printBackSpace(23);
134            std::cout << std::flush;
135            std::cout.unsetf(std::ios::left);
136          }
137
138          compCounter = counter + 1;
139
140        }
141        else compCounter++;
142
143        delete obj2;
144        delete obj1;
145
146      } while( (compCounter<objList.size()) );
147
148      counter++;
149
150    }  // end of while(counter<(objList.size()-1)) loop
151  }
152}
153
154
155void finaliseList(vector<Detection> &objList, Param &par)
156{
157  /**
158   *  finaliseList(objList, par)
159   *   A function that looks at each object in the Detection vector
160   *    and determines whether is passes the requirements for the
161   *    minimum number of channels and spatial pixels, as provided by
162   *    the Param set par.
163   *   If it does not pass, it is removed from the list.
164   *   In the process, the object parameters are calculated and offsets
165   *    are added.
166   */
167
168  int listCounter = 0;
169  while(listCounter < objList.size()){
170
171    objList[listCounter].addOffsets(par);
172    objList[listCounter].calcParams();
173
174    if( objList[listCounter].hasEnoughChannels(par.getMinChannels())
175        && (objList[listCounter].getSpatialSize() >= par.getMinPix()) ){
176
177      listCounter++;
178      if(par.isVerbose()){
179        std::cout << "Final total:" << std::setw(5) << listCounter;
180        printSpace(6);
181        printBackSpace(23);
182        std::cout << std::flush;
183      }
184    }     
185    else objList.erase(objList.begin()+listCounter);
186
187  }
188}
189
190
Note: See TracBrowser for help on using the repository browser.