Open3D (C++ API)
0.19.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp
open3d
utility
Random.h
Go to the documentation of this file.
1
// ----------------------------------------------------------------------------
2
// - Open3D: www.open3d.org -
3
// ----------------------------------------------------------------------------
4
// Copyright (c) 2018-2024 www.open3d.org
5
// SPDX-License-Identifier: MIT
6
// ----------------------------------------------------------------------------
7
8
#pragma once
9
10
#include <mutex>
11
#include <random>
12
13
#include "
open3d/utility/Logging.h
"
14
15
namespace
open3d
{
16
namespace
utility
{
17
namespace
random
{
18
20
void
Seed
(
const
int
seed);
21
35
std::mt19937*
GetEngine
();
36
39
std::mutex*
GetMutex
();
40
44
uint32_t
RandUint32
();
45
63
template
<
typename
T>
64
class
UniformIntGenerator
{
65
public
:
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
82
T
operator()
() {
83
std::lock_guard<std::mutex> lock(*
GetMutex
());
84
return
distribution_
(*
GetEngine
());
85
}
86
87
protected
:
88
std::uniform_int_distribution<T>
distribution_
;
89
};
90
108
template
<
typename
T>
109
class
UniformRealGenerator
{
110
public
:
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
124
T
operator()
() {
125
std::lock_guard<std::mutex> lock(*
GetMutex
());
126
return
distribution_
(*
GetEngine
());
127
}
128
129
protected
:
130
std::uniform_real_distribution<T>
distribution_
;
131
};
132
150
template
<
typename
T>
151
class
NormalGenerator
{
152
public
:
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
165
T
operator()
() {
166
std::lock_guard<std::mutex> lock(*
GetMutex
());
167
return
distribution_
(*
GetEngine
());
168
}
169
170
protected
:
171
std::normal_distribution<T>
distribution_
;
172
};
173
193
template
<
typename
T>
194
class
DiscreteGenerator
{
195
public
:
202
template
<
typename
InputIt>
203
DiscreteGenerator
(InputIt first, InputIt last)
204
:
distribution_
(first, last) {
205
if
(first > last) {
206
utility::LogError(
"first must be <= last."
);
207
}
208
}
209
211
T
operator()
() {
212
std::lock_guard<std::mutex> lock(*
GetMutex
());
213
return
distribution_
(*
GetEngine
());
214
}
215
216
protected
:
217
std::discrete_distribution<T>
distribution_
;
218
};
219
220
}
// namespace random
221
}
// namespace utility
222
}
// namespace open3d
Logging.h
open3d::utility::random::DiscreteGenerator::distribution_
std::discrete_distribution< T > distribution_
Definition
Random.h:217
open3d::utility::random::DiscreteGenerator::operator()
T operator()()
Call this to generate a discretely distributed integer value.
Definition
Random.h:211
open3d::utility::random::DiscreteGenerator::DiscreteGenerator
DiscreteGenerator(InputIt first, InputIt last)
Definition
Random.h:203
open3d::utility::random::NormalGenerator::operator()
T operator()()
Call this to generate a normally distributed floating point value.
Definition
Random.h:165
open3d::utility::random::NormalGenerator::NormalGenerator
NormalGenerator(const T mean=0.0, const T stddev=1.0)
Definition
Random.h:157
open3d::utility::random::NormalGenerator::distribution_
std::normal_distribution< T > distribution_
Definition
Random.h:171
open3d::utility::random::UniformIntGenerator::distribution_
std::uniform_int_distribution< T > distribution_
Definition
Random.h:88
open3d::utility::random::UniformIntGenerator::UniformIntGenerator
UniformIntGenerator(const T low, const T high)
Definition
Random.h:71
open3d::utility::random::UniformIntGenerator::operator()
T operator()()
Call this to generate a uniformly distributed integer.
Definition
Random.h:82
open3d::utility::random::UniformRealGenerator::operator()
T operator()()
Call this to generate a uniformly distributed floating point value.
Definition
Random.h:124
open3d::utility::random::UniformRealGenerator::distribution_
std::uniform_real_distribution< T > distribution_
Definition
Random.h:130
open3d::utility::random::UniformRealGenerator::UniformRealGenerator
UniformRealGenerator(const T low=0.0, const T high=1.0)
Definition
Random.h:115
open3d::io::k4a_plugin::uint32_t
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
open3d::utility::random
Definition
Random.cpp:14
open3d::utility::random::GetEngine
std::mt19937 * GetEngine()
Definition
Random.cpp:55
open3d::utility::random::RandUint32
uint32_t RandUint32()
Definition
Random.cpp:59
open3d::utility::random::Seed
void Seed(const int seed)
Set Open3D global random seed.
Definition
Random.cpp:53
open3d::utility::random::GetMutex
std::mutex * GetMutex()
Definition
Random.cpp:57
open3d::utility
Definition
Dispatch.h:91
open3d
Definition
PinholeCameraIntrinsic.cpp:16
Generated by
1.17.0