#include #include #include #include #include #include #include /** * Cube::ObjectMerger(): * A Function that takes a Cube's list of Detections and * combines those that are close (according to the * thresholds specified in the parameter list par). * It also excludes those that do not make the minimum * number of channels requirement. */ void Cube::ObjectMerger() { if(this->objectList.size() > 0){ // make a vector "currentList", which starts as a copy of the Cube's objectList, // but is the one worked on. vector *currentList = new vector (this->objectList.size()); *currentList = this->objectList; vector ::iterator iter; // for(int i=0;iobjectList.size();i++) currentList->push_back( this->objectList[i] ); // The Cube's objectList is cleared, and then the final objects are added to it at the end. this->objectList.clear(); int counter, compCounter,numLoops; bool areNear,isMatch; long gap; bool isVerb = this->par.isVerbose(); if(this->par.getFlagGrowth()) numLoops=2; else numLoops = 1; for(int nloop = 0; nloop < numLoops; nloop++){ counter=0; while( counter < (currentList->size()-1) ){ if(isVerb){ std::cout.setf(std::ios::right); if(nloop>0) std::cout << "Progress#2: " << std::setw(6) << counter << "/" ; else std::cout << "Progress: " << std::setw(6) << counter << "/" ; std::cout.unsetf(std::ios::right); std::cout.setf(std::ios::left); std::cout << std::setw(6) << currentList->size() << "\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; if(nloop>0) std::cout << "\b\b" << std::flush; ; std::cout.unsetf(std::ios::left); } compCounter = counter + 1; do { Detection *obj1 = new Detection; *obj1 = currentList->at(counter); Detection *obj2 = new Detection; *obj2 = currentList->at(compCounter); if(areClose(*obj1, *obj2, this->par)){ obj1->addAnObject( *obj2 ); iter = currentList->begin() + compCounter; currentList->erase(iter); iter = currentList->begin() + counter; currentList->erase(iter); currentList->push_back( *obj1 ); // currentList->insert(iter, *obj1 ); if(isVerb){ std::cout.setf(std::ios::right); std::cout << "Progress: " << std::setw(6) << counter << "/"; std::cout.unsetf(std::ios::right); std::cout.setf(std::ios::left); std::cout << std::setw(6) << currentList->size() << "\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; std::cout.unsetf(std::ios::left); } compCounter = counter + 1; } else compCounter++; delete obj2; delete obj1; } while( (compCountersize()) ); counter++; } // end of while(counter<(currentList->size()-1)) loop if( (nloop==0) && (this->par.getFlagGrowth()) ) { std::cout << "Growing objects... "<< std::flush; this->setCubeStats(); vector *newList = new vector ; 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"<size();i++){ std::cout<< "\b\b\b\b\b\b"<at(i); growObject(*obj,*this); newList->push_back(*obj); delete obj; } delete currentList; currentList = newList; std::cout.unsetf(std::ios::left); 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"<size()){ (*currentList)[listCounter].addOffsets(this->par); (*currentList)[listCounter].calcParams(); // Now, for each object in the newly modified list, we need to check if // they pass the requirements on the minimum no. of channels and minimum // number of spatial pixels // If not, remove from list. if( (*currentList)[listCounter].hasEnoughChannels(this->par.getMinChannels()) && ((*currentList)[listCounter].getSpatialSize() >= this->par.getMinPix()) ){ listCounter++; if(isVerb){ std::cout << "Final total:"<erase(currentList->begin()+listCounter); } this->objectList = *currentList; currentList->clear(); delete currentList; } // vector *finalList = new vector; // for(int listCounter = 0; listCounter < currentList->size(); listCounter++){ // Detection *currentObject = new Detection; // *currentObject = currentList->at(listCounter); // currentObject->addOffsets(this->par); // currentObject->calcParams(); // // Now, for each object in the newly modified list, we need to check if // // they pass the minimum no. of channels requirement // int numChannels = currentObject->getZmax() - currentObject->getZmin() + 1; // if( numChannels >= this->par.getMinChannels() ){ // /* // // Now remove any multiply-appearing pixels in each good object // // and add to the output list // Detection *newObject = new Detection; // // the first pixel gets included -- then compare all others... // newObject->addPixel(currentObject->getPixel(0)); // for(int pix = 1; pix < currentObject->getSize(); pix++){ // bool addThisOne = true; // for(int newpix = 0; newpix < newObject->getSize(); newpix++){ // bool newOneMatches = ( newObject->getX(newpix) == currentObject->getX(pix) ) // && ( newObject->getY(newpix) == currentObject->getY(pix) ) // && ( newObject->getZ(newpix) == currentObject->getZ(pix) ); // addThisOne = addThisOne && !newOneMatches; // } // if(addThisOne) newObject->addPixel(currentObject->getPixel(pix)); // } // newObject->addOffsets(this->par); // newObject->calcParams(); // this->objectList.push_back(*newObject); // */ // finalList->push_back(*currentObject); // if(isVerb){ // std::cout << "Final total:"<size() // << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"<clear(); // delete currentList; // this->objectList = *finalList; // finalList->clear(); // delete finalList; // } }