const Production& Definition::getRandomProduction() const { int low = 0; int high = possibleExpansions.size () - 1; // Convert from count to index. int returnIndex = rg.getRandomInteger (low, high); assert (returnIndex >= low && returnIndex <= high); return possibleExpansions.at (returnIndex); }
const Production& Definition::getRandomProduction() const { static RandomGenerator random; int randomIndex = random.getRandomInteger(0, possibleExpansions.size() - 1); return possibleExpansions[randomIndex]; }
void ObjRecRANSAC::doRecognition(vtkPoints* scene, double successProbability, list<PointSetShape*>& out) { if ( scene->GetNumberOfPoints() <= 0 ) return; Stopwatch overallStopwatch(false); overallStopwatch.start(); // Do some initial cleanup and setup mInputScene = scene; this->init_rec(scene); mOccupiedPixelsByShapes.clear(); int i, numOfIterations = this->computeNumberOfIterations(successProbability, (int)scene->GetNumberOfPoints()); vector<OctreeNode*>& fullLeaves = mSceneOctree->getFullLeafs(); if ( (int)fullLeaves.size() < numOfIterations ) numOfIterations = (int)fullLeaves.size(); #ifdef OBJ_REC_RANSAC_VERBOSE printf("ObjRecRANSAC::%s(): recognizing objects [%i iteration(s), %i thread(s)]\n", __func__, numOfIterations, mNumOfThreads); fflush(stdout); #endif OctreeNode** leaves = new OctreeNode*[numOfIterations]; RandomGenerator randgen; // Init the vector with the ids vector<int> ids; ids.reserve(fullLeaves.size()); for ( i = 0 ; i < (int)fullLeaves.size() ; ++i ) ids.push_back(i); // Sample the leaves at random for ( i = 0 ; i < numOfIterations ; ++i ) { // Choose a random position within the array of ids int rand_pos = randgen.getRandomInteger(0, ids.size() - 1); // Get the id at that random position leaves[i] = fullLeaves[ids[rand_pos]]; // Delete the selected id ids.erase(ids.begin() + rand_pos); } // Sample the oriented point pairs this->sampleOrientedPointPairs(leaves, numOfIterations, mSampledPairs); // Generate the object hypotheses this->generateHypotheses(mSampledPairs); list<AcceptedHypothesis> accepted_hypotheses; // Accept hypotheses this->acceptHypotheses(accepted_hypotheses); // Convert the accepted hypotheses to shapes this->hypotheses2Shapes(accepted_hypotheses, mShapes); // Filter the weak hypotheses list<ORRPointSetShape*> detectedShapes; this->gridBasedFiltering(mShapes, detectedShapes); // Save the shapes in 'out' for ( list<ORRPointSetShape*>::iterator it = detectedShapes.begin() ; it != detectedShapes.end() ; ++it ) { PointSetShape* shape = new PointSetShape(*it); // Save the new created shape out.push_back(shape); // Get the nodes of the current shape list<OctreeNode*>& nodes = (*it)->getOctreeSceneNodes(); // For all nodes of the current shape for ( list<OctreeNode*>::iterator node = nodes.begin() ; node != nodes.end() ; ++node ) { ORROctreeNodeData* data = (ORROctreeNodeData*)(*node)->getData(); // Get the ids from the current node for ( list<int>::iterator id = data->getPointIds().begin() ; id != data->getPointIds().end() ; ++id ) shape->getScenePointIds().push_back(*id); } } // Cleanup delete[] leaves; accepted_hypotheses.clear(); if ( mICPRefinement ) { ObjRecICP objrec_icp; objrec_icp.setEpsilon(1.5); objrec_icp.doICP(*this, out); } mLastOverallRecognitionTimeSec = overallStopwatch.stop(); }