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

◆ relative_neighborhood_graph()

MAYAFLUX_API EdgeList MayaFlux::Kinesis::relative_neighborhood_graph ( const Eigen::MatrixXd &  points)

Compute relative neighborhood graph.

Parameters
pointsDxN matrix where each column is a point
Returns
Edge list of RNG edges

RNG property: Edge (p,q) exists iff lune(p,q) contains no points. Lune is intersection of two circles centered at p and q, each with radius |p-q|.

Equivalently: max(|p-r|, |q-r|) ≥ |p-q| for all r ∈ P \ {p,q}

The RNG is a subset of Gabriel graph and Delaunay triangulation.

Complexity: O(n³) with geometric tests

Definition at line 504 of file ProximityGraphs.cpp.

505{
506 const auto n = static_cast<size_t>(points.cols());
507 if (n < 2) {
508 return {};
509 }
510
511 const auto dim = static_cast<size_t>(points.rows());
512 const double* base = points.data();
513
514 const std::vector<double> table = build_distance_table(points);
515 const bool resident = !table.empty();
516
517 std::vector<EdgeList> bins(n);
518
519 std::for_each(std::execution::par_unseq,
520 std::views::iota(size_t { 0 }, n).begin(),
521 std::views::iota(size_t { 0 }, n).end(),
522 [&](size_t i) {
523 const double* row_i = resident ? table.data() + i * n : nullptr;
524 const double* pi = base + i * dim;
525 EdgeList& out = bins[i];
526
527 for (size_t j = i + 1; j < n; ++j) {
528 const double pq_sq = resident
529 ? row_i[j]
530 : dist_sq(pi, base + j * dim, dim);
531
532 const bool rejected = resident
533 ? max_below(row_i, table.data() + j * n, n, pq_sq)
534 : max_below_direct(base, dim, n, i, j, pq_sq);
535
536 if (!rejected) {
537 out.emplace_back(i, j);
538 }
539 }
540 });
541
542 EdgeList edges = flatten_bins(bins);
543
544 MF_DEBUG(Journal::Component::Kinesis, Journal::Context::Runtime,
545 "relative_neighborhood_graph: {} points, generated {} edges",
546 n, edges.size());
547
548 return edges;
549}
#define MF_DEBUG(comp, ctx,...)
std::vector< glm::vec2 > * points
std::vector< float > * out
std::vector< std::pair< size_t, size_t > > EdgeList

References MayaFlux::Journal::Kinesis, MF_DEBUG, out, points, and MayaFlux::Journal::Runtime.

Referenced by generate_proximity_graph().

+ Here is the caller graph for this function: