MayaFlux 0.5.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 506 of file ProximityGraphs.cpp.

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

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

Referenced by generate_proximity_graph().

+ Here is the caller graph for this function: