source: branches/pixel-map-branch/src/Cubes/Merger.cc @ 1441

Last change on this file since 1441 was 252, checked in by Matthew Whiting, 17 years ago
  • Have put all classes in the files in src/PixelMap/ into a PixelInfo? namespace.
  • Added "using namespace PixelInfo?" to all necessary files.
  • Removed "friend class Detection" from Voxel and Object3D classes -- not necessary and complicated now by them being in the namespace
  • Various minor changes, including fixing up commentary.
File size: 4.9 KB
RevLine 
[3]1#include <iostream>
[244]2#include <fstream>
[3]3#include <iomanip>
4#include <math.h>
5#include <vector>
[243]6#include <PixelMap/Object3D.hh>
[3]7#include <Cubes/cubes.hh>
8#include <Detection/detection.hh>
9#include <Utils/utils.hh>
[213]10#include <Utils/feedback.hh>
[3]11
[232]12using std::vector;
[252]13using namespace PixelInfo;
[232]14
[3]15void Cube::ObjectMerger()
16{
[138]17  /**
[220]18   * A Function that takes a Cube's list of Detections and
19   * combines those that are close (according to the
20   * thresholds specified in the parameter list par).
21   * It also excludes those that do not make the minimum
22   * number of channels requirement.
23   * A front end to simpler functions mergeList and finaliseList,
24   *  with code to cover the option of growing objects.
[138]25   */
[3]26
[243]27  int startSize = this->objectList.size();
[3]28
[243]29  if(startSize > 0){
30
[175]31    // make a vector "currentList", which starts as a copy of the Cube's
32    //  objectList, but is the one worked on.
[243]33    vector <Detection> *currentList = new vector <Detection>(startSize);
[3]34    *currentList = this->objectList;
35    this->objectList.clear();
36
[137]37    mergeList(*currentList, this->par);
[3]38
[137]39    // Do growth stuff
40    if(this->par.getFlagGrowth()) {
41      std::cout << "Growing objects...     "<< std::flush;
42      vector <Detection> *newList = new vector <Detection>;
[175]43      printBackSpace(23);
[137]44      std::cout << " Growing object #      "<< std::flush;
45      std::cout.setf(std::ios::left);
46      for(int i=0;i<currentList->size();i++){
[175]47        printBackSpace(6);
48        std::cout << std::setw(6) << i+1 << std::flush;
[137]49        Detection *obj = new Detection;
50        *obj = (*currentList)[i];
51        growObject(*obj,*this);
52        newList->push_back(*obj);
53        delete obj;
54      }
55      delete currentList;
56      currentList = newList;
57      std::cout.unsetf(std::ios::left);
[175]58      printBackSpace(23);
59      std::cout << std::flush;
[3]60
[137]61      // and do the merging again to pick up objects that have
62      //  grown into each other.
63      mergeList(*currentList, this->par);
64    }
[3]65
[137]66    finaliseList(*currentList, this->par);
[3]67
[137]68    this->objectList = *currentList;
69    currentList->clear();
70    delete currentList;
[3]71
[137]72  }
73}
[3]74
[138]75void ObjectMerger(vector<Detection> &objList, Param &par)
76{
77  /**
[221]78   *   A simple front-end to the mergeList() and finaliseList() functions,
[138]79   *    so that if you want to merge a single list, it will
80   *    do both the merging and the cleaning up afterwards.
81   */
82  mergeList(objList, par);
83  finaliseList(objList, par);
84}
85
[137]86void mergeList(vector<Detection> &objList, Param &par)
87{
[138]88  /**
89   *   A function that merges any objects in the list of
90   *    Detections that are within stated threshold distances.
91   *   Determination of whether objects are close is done by
92   *    the function areClose.
93   */
[86]94
[137]95  if(objList.size() > 0){
[3]96
[137]97    bool isVerb = par.isVerbose();
98    vector <Detection>::iterator iter;
[3]99
[137]100    int counter=0, compCounter;
101    while( counter < (objList.size()-1) ){
102      if(isVerb){
103        std::cout.setf(std::ios::right);
[251]104        std::cout << "Progress: " << std::setw(6) << counter+1 << "/" ;
[137]105        std::cout.unsetf(std::ios::right);
106        std::cout.setf(std::ios::left);
[175]107        std::cout << std::setw(6) << objList.size();
108        printBackSpace(23);
109        std::cout << std::flush;
[137]110        std::cout.unsetf(std::ios::left);
111      }
[3]112
[137]113      compCounter = counter + 1;
[3]114
[137]115      do {
[3]116
[243]117        Detection obj1 = objList[counter];
118        Detection obj2 = objList[compCounter];
[3]119
[244]120        bool close = areClose(obj1, obj2, par);
121
122        if(close){
123          obj1 = obj1 + obj2 ;
[137]124          iter = objList.begin() + compCounter;
125          objList.erase(iter);
126          iter = objList.begin() + counter;
127          objList.erase(iter);
[244]128          objList.push_back( obj1 );
[137]129
130          if(isVerb){
131            std::cout.setf(std::ios::right);
132            std::cout << "Progress: "
133                      << std::setw(6) << counter << "/";
134            std::cout.unsetf(std::ios::right);
135            std::cout.setf(std::ios::left);
[175]136            std::cout << std::setw(6) << objList.size();
137            printBackSpace(23);
138            std::cout << std::flush;
[137]139            std::cout.unsetf(std::ios::left);
140          }
141
142          compCounter = counter + 1;
143
[3]144        }
[137]145        else compCounter++;
[3]146
[137]147      } while( (compCounter<objList.size()) );
[3]148
[137]149      counter++;
[3]150
[137]151    }  // end of while(counter<(objList.size()-1)) loop
152  }
153}
[3]154
155
[137]156void finaliseList(vector<Detection> &objList, Param &par)
157{
[138]158  /**
[221]159   *  A function that looks at each object in the Detection vector
[138]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.
[139]163   *   If it does not pass, it is removed from the list.
[138]164   *   In the process, the object parameters are calculated and offsets
165   *    are added.
166   */
[3]167
[137]168  int listCounter = 0;
169  while(listCounter < objList.size()){
[3]170
[221]171    objList[listCounter].setOffsets(par);
[137]172
[244]173    if( (objList[listCounter].hasEnoughChannels(par.getMinChannels()))
[137]174        && (objList[listCounter].getSpatialSize() >= par.getMinPix()) ){
[139]175
[137]176      listCounter++;
177      if(par.isVerbose()){
[175]178        std::cout << "Final total:" << std::setw(5) << listCounter;
179        printSpace(6);
180        printBackSpace(23);
181        std::cout << std::flush;
[137]182      }
183    }     
184    else objList.erase(objList.begin()+listCounter);
185
[3]186  }
187}
188
[137]189
Note: See TracBrowser for help on using the repository browser.