diff --git a/ColorimetricSegmenter.cpp b/ColorimetricSegmenter.cpp index 1ef35d6..28f6505 100644 --- a/ColorimetricSegmenter.cpp +++ b/ColorimetricSegmenter.cpp @@ -131,7 +131,7 @@ QList ColorimetricSegmenter::getActions() // Here we use the default plugin name, description, and icon, // but each action should have its own. m_action_filterRgbWithSegmentation = new QAction( "Filter RGB", this); - m_action_filterRgbWithSegmentation->setToolTip( "Filter the points on the selected cloud by RGB color" ); + m_action_filterRgbWithSegmentation->setToolTip( "Filter the points on the selected cloud by RGB color using segmentation" ); m_action_filterRgbWithSegmentation->setIcon(getIcon()); // Connect appropriate signal @@ -241,26 +241,41 @@ void knn(ccPointCloud* cloud, const CCVector3* point, unsigned k, CCLib::Referen } void knnRegions(ccPointCloud* basePointCloud, std::vector* regions, const CCLib::ReferenceCloud* region, unsigned k, std::vector* neighbours, unsigned thresholdDistance) { - std::vector distances; ccPointCloud* computedRegion = basePointCloud->partialClone(region); // compute distances CCLib::DistanceComputationTools::Cloud2CloudDistanceComputationParams params = CCLib::DistanceComputationTools::Cloud2CloudDistanceComputationParams(); params.kNNForLocalModel = k; params.maxSearchDist = thresholdDistance; - neighbours = new std::vector(); + std::vector *tempNeighbours = new std::vector(); + std::vector *distances = new std::vector(); for(CCLib::ReferenceCloud* r : *regions) { - CCLib::DistanceComputationTools::computeCloud2CloudDistance(computedRegion, basePointCloud->partialClone(r), params); - neighbours->push_back(r); + distances->push_back(CCLib::DistanceComputationTools::computeCloud2CloudDistance(computedRegion, basePointCloud->partialClone(r), params)); + tempNeighbours->push_back(r); } // sort the vectors + std::vector* index = new std::vector(tempNeighbours->size()); + std::generate(index->begin(), index->end(), + [n=0] + () + mutable + { + return n++; + }); + std::sort( - neighbours->begin(), neighbours->end(), - [&](std::size_t a, std::size_t b) { return distances[a] < distances[b]; }); - while(neighbours->size() > k) + index->begin(), index->end(), + [&](int a, int b) { return distances[a] < distances[b]; }); + + neighbours = new std::vector(); + for(int i : *index) { - neighbours->pop_back(); + if(neighbours->size() < k) + { + neighbours->push_back(tempNeighbours->at(i)); + } } + } double colorimetricalDifference(ccColor::Rgb c1, ccColor::Rgb c2) {