| 174 | } |
| 175 | |
| 176 | void SupervoxelFilter::filter(PointView& view) { |
| 177 | const point_count_t n_points = view.size(); |
| 178 | KD3Index& kdi = view.build3dIndex(); |
| 179 | size_t ncluster = estimateClusterCount(view); |
| 180 | log()->get(LogLevel::Info) << getName() << ": number of clusters: " |
| 181 | << ncluster << std::endl; |
| 182 | DisjointSet djset(n_points); |
| 183 | std::set<PointId> roots; |
| 184 | std::vector<bool> visited(n_points, false); |
| 185 | std::vector<unsigned int> c(n_points, 1); |
| 186 | |
| 187 | // Initialise neighbour list and cluster roots |
| 188 | std::vector<PointIdList> G(n_points); |
| 189 | for (PointId idx = 0; idx < n_points; ++idx) |
| 190 | { |
| 191 | G[idx] = kdi.neighbors(idx, m_knn); |
| 192 | roots.insert(idx); |
| 193 | } |
| 194 | |
| 195 | double lambda = lambda0(view, G); |
| 196 | log()->get(LogLevel::Debug) << getName() << ": initial lambda value: " |
| 197 | << lambda << std::endl; |
| 198 | |
| 199 | //////////////////////////// |
| 200 | // Fusion based minimization |
| 201 | //////////////////////////// |
| 202 | unsigned int front, back; |
| 203 | PointId rj; |
| 204 | PointRef ri_ref(view); |
| 205 | PointRef rj_ref(view); |
| 206 | PointIdList queue(n_points); |
| 207 | while (roots.size() > ncluster) { |
| 208 | for (auto ri : roots) |
| 209 | { |
| 210 | if (G[ri].empty()) continue; |
| 211 | |
| 212 | front = 0; back = 1; |
| 213 | visited[ri] = true; |
| 214 | queue[front++] = ri; |
| 215 | for (PointId j : G[ri]) |
| 216 | { |
| 217 | j = djset.find(j); |
| 218 | if (!visited[j]) |
| 219 | { |
| 220 | visited[j] = true; |
| 221 | queue[back++] = j; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | PointIdList Gi; |
| 226 | while (front < back) |
| 227 | { |
| 228 | rj = queue[front++]; |
| 229 | ri_ref.setPointId(ri); |
| 230 | rj_ref.setPointId(rj); |
| 231 | if ((lambda - c[rj] * dist(ri_ref, rj_ref)) > 0) |
| 232 | { |
| 233 | djset.unite(ri, rj); // Merge rj into ri |
nothing calls this directly
no test coverage detected