Open3D (C++ API)  0.17.0
Loading...
Searching...
No Matches
Random.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2023 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include <mutex>
11#include <random>
12
14
15namespace open3d {
16namespace utility {
17namespace random {
18
20void Seed(const int seed);
21
35std::mt19937* GetEngine();
36
39std::mutex* GetMutex();
40
45
63template <typename T>
65public:
71 UniformIntGenerator(const T low, const T high) : distribution_(low, high) {
72 if (low < 0) {
73 utility::LogError("low must be > 0, but got {}.", low);
74 }
75 if (low >= high) {
76 utility::LogError("low must be < high, but got low={} and high={}.",
77 low, high);
78 }
79 }
80
83 std::lock_guard<std::mutex> lock(*GetMutex());
84 return distribution_(*GetEngine());
85 }
86
87protected:
88 std::uniform_int_distribution<T> distribution_;
89};
90
108template <typename T>
110public:
115 UniformRealGenerator(const T low = 0.0, const T high = 1.0)
116 : distribution_(low, high) {
117 if (low >= high) {
118 utility::LogError("low must be < high, but got low={} and high={}.",
119 low, high);
120 }
121 }
122
125 std::lock_guard<std::mutex> lock(*GetMutex());
126 return distribution_(*GetEngine());
127 }
128
129protected:
130 std::uniform_real_distribution<T> distribution_;
131};
132
150template <typename T>
152public:
157 NormalGenerator(const T mean = 0.0, const T stddev = 1.0)
158 : distribution_(mean, stddev) {
159 if (stddev <= 0) {
160 utility::LogError("stddev must be > 0, but got {}.", stddev);
161 }
162 }
163
166 std::lock_guard<std::mutex> lock(*GetMutex());
167 return distribution_(*GetEngine());
168 }
169
170protected:
171 std::normal_distribution<T> distribution_;
172};
173
174} // namespace random
175} // namespace utility
176} // namespace open3d
T operator()()
Call this to generate a normally distributed floating point value.
Definition Random.h:165
NormalGenerator(const T mean=0.0, const T stddev=1.0)
Definition Random.h:157
std::normal_distribution< T > distribution_
Definition Random.h:171
std::uniform_int_distribution< T > distribution_
Definition Random.h:88
UniformIntGenerator(const T low, const T high)
Definition Random.h:71
T operator()()
Call this to generate a uniformly distributed integer.
Definition Random.h:82
T operator()()
Call this to generate a uniformly distributed floating point value.
Definition Random.h:124
std::uniform_real_distribution< T > distribution_
Definition Random.h:130
UniformRealGenerator(const T low=0.0, const T high=1.0)
Definition Random.h:115
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition K4aPlugin.cpp:548
std::mt19937 * GetEngine()
Definition Random.cpp:55
uint32_t RandUint32()
Definition Random.cpp:59
void Seed(const int seed)
Set Open3D global random seed.
Definition Random.cpp:53
std::mutex * GetMutex()
Definition Random.cpp:57
Definition PinholeCameraIntrinsic.cpp:16