TTK
Loading...
Searching...
No Matches
GaussianPointCloud.h
Go to the documentation of this file.
1
10
11#pragma once
12
13// base code includes
14#include <Debug.h>
15#include <random>
16
17namespace ttk {
18
19 class GaussianPointCloud : virtual public Debug {
20 public:
22
23 template <class dataType>
24 int castSample(const int &dimension,
25 std::mt19937 &gen,
26 dataType &x,
27 dataType &y,
28 dataType &z) const;
29
30 // Execute the sampling
31 template <class dataType>
32 int generate(const int &dimension,
33 const int &numberOfSamples,
34 const int &seed,
35 dataType *const outputData) const;
36 };
37} // namespace ttk
38
39template <class dataType>
40int ttk::GaussianPointCloud::castSample(const int &dimension,
41 std::mt19937 &gen,
42 dataType &x,
43 dataType &y,
44 dataType &z) const {
45
46 dataType u, v, w;
47
48 std::uniform_real_distribution<dataType> uniformDistribution(-1, 1);
49 u = uniformDistribution(gen);
50 v = (dimension >= 2 ? uniformDistribution(gen) : 0);
51 w = (dimension == 3 ? uniformDistribution(gen) : 0);
52
53 dataType norm = std::sqrt(u * u + v * v + w * w);
54
55 std::normal_distribution<dataType> normalDistribution{0, 1};
56
57 dataType gaussianScale = normalDistribution(gen);
58
59 x = (u / norm) * gaussianScale;
60 y = (v / norm) * gaussianScale;
61 z = (w / norm) * gaussianScale;
62
63 return 0;
64}
65
66template <class dataType>
67int ttk::GaussianPointCloud::generate(const int &dimension,
68 const int &numberOfSamples,
69 const int &seed,
70 dataType *const outputData) const {
71
72 Timer t;
73
74 std::mt19937 gen{};
75 gen.seed(seed);
76
77 for(int i = 0; i < numberOfSamples; i++) {
78 this->castSample(dimension, gen, outputData[3 * i], outputData[3 * i + 1],
79 outputData[3 * i + 2]);
80 }
81
82 this->printMsg(std::vector<std::vector<std::string>>{
83 {"#Samples", std::to_string(numberOfSamples)}});
84 this->printMsg("Samples generated in " + std::to_string(dimension) + "D", 1.0,
85 t.getElapsedTime(), 1);
86
87 return 0;
88}
Minimalist debugging class.
Definition Debug.h:88
TTK gaussianPointCloud processing package that generates a 1D, 2D or 3D point cloud by randomly casti...
int castSample(const int &dimension, std::mt19937 &gen, dataType &x, dataType &y, dataType &z) const
int generate(const int &dimension, const int &numberOfSamples, const int &seed, dataType *const outputData) const
double getElapsedTime()
Definition Timer.h:15
std::string to_string(__int128)
Definition ripserpy.cpp:99
The Topology ToolKit.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)