/** * Point Cloud Segmentation using Felzenszwalb-Huttenlocher Algorithm * * Copyright (C) Jacobs University Bremen * * Released under the GPL version 3. * * @author Mihai-Cotizo Sima */ #include #include #include #include using namespace std; FHGraph::FHGraph(std::vector< Point >& ps, double weight(Point, Point), double sigma, double eps, int neighbors, float radius) : points( ps ), V( ps.size() ) { /* * 1. create adjency list using a map > * 2. use get_neighbors(e, max_dist) to get all the edges e' that are at a distance smaller than max_dist than e * 3. using all these edges, compute the gaussian smoothed weight * 4. insert the edges in a new list */ nr_neighbors = neighbors; this->radius = radius; compute_neighbors(weight, eps); if ( sigma > 0.01 ) { do_gauss(sigma); } else { without_gauss(); } adjency_list.clear(); } void FHGraph::compute_neighbors(double weight(Point, Point), double eps) { adjency_list.reserve(points.size()); adjency_list.resize(points.size()); ANNpointArray pa = annAllocPts(points.size(), 3); for (size_t i=0; i 0 && nr_neighbors < nret ) { random_shuffle(n, n+nret); nret = nr_neighbors; } for (int j=0; j& v) { double s = 0; for (size_t i=0; i::iterator k, j; vector gauss_weight, edge_weight; edge e; #pragma omp parallel for private(j, k, e, gauss_weight, edge_weight) schedule(dynamic) for (int i=0; iw, j->w, sigma)); edge_weight.push_back(k->w); } for (k=adjency_list[j->x].begin(); k!=adjency_list[j->x].end(); ++k) { gauss_weight.push_back(gauss(k->w, j->w, sigma)); edge_weight.push_back(k->w); } normalize(gauss_weight); e.a = i; e.b = j->x; e.w = 0; for (size_t k=0; k::iterator j; edge e; for (int i=0; ix; e.w = j->w; edges.push_back(e); } } } edge* FHGraph::getGraph() { edge* ret = new edge[edges.size()]; for (size_t i=0; i void vectorFree(T& t) { T tmp; t.swap(tmp); } void FHGraph::dispose() { vectorFree(edges); vectorFree(points); vectorFree(adjency_list); }