MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ radius_threshold_graph()

MAYAFLUX_API EdgeList MayaFlux::Kinesis::radius_threshold_graph ( const Eigen::MatrixXd &  points,
double  radius 
)

Compute radius threshold graph.

Parameters
pointsDx N matrix where each column is a point
radiusMaximum connection distance
Returns
Edge list (point index pairs)

Connects all point pairs within radius distance. Undirected graph: if (i,j) exists, edge appears once.

Complexity: O(n²) brute force

Definition at line 305 of file ProximityGraphs.cpp.

308{
309 const auto n = static_cast<size_t>(points.cols());
310 if (n < 2) {
311 return {};
312 }
313
314 const double radius_sq = radius * radius;
315 const auto dim = static_cast<size_t>(points.rows());
316 const double* base = points.data();
317
318 std::vector<size_t> offsets(n + 1, 0);
319
320 std::for_each(std::execution::par_unseq,
321 std::views::iota(size_t { 0 }, n).begin(),
322 std::views::iota(size_t { 0 }, n).end(),
323 [&](size_t i) {
324 const double* pi = base + i * dim;
325 size_t count = 0;
326 for (size_t j = i + 1; j < n; ++j) {
327 if (dist_sq(pi, base + j * dim, dim) <= radius_sq) {
328 ++count;
329 }
330 }
331 offsets[i + 1] = count;
332 });
333
334 for (size_t i = 0; i < n; ++i) {
335 offsets[i + 1] += offsets[i];
336 }
337
338 EdgeList edges(offsets[n]);
339
340 std::for_each(std::execution::par_unseq,
341 std::views::iota(size_t { 0 }, n).begin(),
342 std::views::iota(size_t { 0 }, n).end(),
343 [&](size_t i) {
344 const double* pi = base + i * dim;
345 size_t at = offsets[i];
346 for (size_t j = i + 1; j < n; ++j) {
347 if (dist_sq(pi, base + j * dim, dim) <= radius_sq) {
348 edges[at++] = { i, j };
349 }
350 }
351 });
352
353 MF_DEBUG(Journal::Component::Kinesis, Journal::Context::Runtime,
354 "radius_threshold_graph: {} points, radius={:.3f}, generated {} edges",
355 n, radius, edges.size());
356
357 return edges;
358}
#define MF_DEBUG(comp, ctx,...)
std::vector< glm::vec2 > * points
float radius
size_t count
std::vector< std::pair< size_t, size_t > > EdgeList
auto at(const B &anchor, F &&factory, Args &&... args) -> decltype(std::forward< F >(factory)(Kinesis::bounds_of(anchor), std::forward< Args >(args)...))
Call a bounds-taking factory with an anchor's region.
Definition Geometry.hpp:152

References count, MayaFlux::Journal::Kinesis, MF_DEBUG, points, radius, and MayaFlux::Journal::Runtime.

Referenced by generate_proximity_graph().

+ Here is the caller graph for this function: