PointSampler library (C++)
Loading...
Searching...
No Matches
function_rejection_filter.hpp
Go to the documentation of this file.
1/* Copyright (c) 2025 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4#pragma once
5#include <optional>
6#include <random>
7
9
10namespace ps
11{
12
35template <typename T, size_t N, typename DensityFn>
36std::vector<Point<T, N>> function_rejection_filter(
37 const std::vector<Point<T, N>> &points,
38 DensityFn density_fn,
39 std::optional<unsigned int> seed = std::nullopt)
40{
41 std::mt19937 gen(seed ? *seed : std::random_device{}());
42 std::uniform_real_distribution<T> accept_dist(0.0, 1.0);
43
44 std::vector<Point<T, N>> result;
45 result.reserve(points.size());
46
47 for (const auto &p : points)
48 {
49 T prob = density_fn(p);
50 T threshold = accept_dist(gen);
51
52 if (prob >= threshold)
53 result.push_back(p);
54 }
55
56 return result;
57}
58
59} // namespace ps
Definition dbscan_clustering.hpp:11
std::vector< Point< T, N > > function_rejection_filter(const std::vector< Point< T, N > > &points, DensityFn density_fn, std::optional< unsigned int > seed=std::nullopt)
Filters points based on a spatial probability (density) function.
Definition function_rejection_filter.hpp:36
A fixed-size N-dimensional point/vector class.
Definition point.hpp:39