Point Cloud Library (PCL)  1.14.1-dev
random.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/common/random.h>
43 
44 
45 namespace pcl
46 {
47 
48 namespace common
49 {
50 
51 
52 template <typename T>
53 UniformGenerator<T>::UniformGenerator(T min, T max, std::uint32_t seed)
54  : parameters_ ({min, max, seed})
55  , distribution_ (min, max)
56 {
57  if(parameters_.seed != static_cast<std::uint32_t> (-1))
58  rng_.seed (seed);
59 }
60 
61 
62 template <typename T>
64  : parameters_ (parameters)
65  , distribution_ (parameters_.min, parameters_.max)
66 {
67  if(parameters_.seed != static_cast<std::uint32_t> (-1))
68  rng_.seed (parameters_.seed);
69 }
70 
71 
72 template <typename T> void
73 UniformGenerator<T>::setSeed (std::uint32_t seed)
74 {
75  if (seed != static_cast<std::uint32_t> (-1))
76  {
77  parameters_.seed = seed;
78  rng_.seed(parameters_.seed);
79  }
80 }
81 
82 
83 template <typename T> void
84 UniformGenerator<T>::setParameters (T min, T max, std::uint32_t seed)
85 {
86  parameters_.min = min;
87  parameters_.max = max;
88  parameters_.seed = seed;
89  typename DistributionType::param_type params (parameters_.min, parameters_.max);
90  distribution_.param (params);
91  distribution_.reset ();
92  if (seed != static_cast<std::uint32_t> (-1))
93  {
94  parameters_.seed = seed;
95  rng_.seed (parameters_.seed);
96  }
97 }
98 
99 
100 template <typename T> void
102 {
103  parameters_ = parameters;
104  typename DistributionType::param_type params (parameters_.min, parameters_.max);
105  distribution_.param (params);
106  distribution_.reset ();
107  if (parameters_.seed != static_cast<std::uint32_t> (-1))
108  rng_.seed (parameters_.seed);
109 }
110 
111 
112 template <typename T>
113 NormalGenerator<T>::NormalGenerator(T mean, T sigma, std::uint32_t seed)
114  : parameters_ ({mean, sigma, seed})
115  , distribution_ (mean, sigma)
116 {
117  if(parameters_.seed != static_cast<std::uint32_t> (-1))
118  rng_.seed (seed);
119 }
120 
121 
122 template <typename T>
124  : parameters_ (parameters)
125  , distribution_ (parameters_.mean, parameters_.sigma)
126 {
127  if(parameters_.seed != static_cast<std::uint32_t> (-1))
128  rng_.seed (parameters_.seed);
129 }
130 
131 
132 template <typename T> void
133 NormalGenerator<T>::setSeed (std::uint32_t seed)
134 {
135  if (seed != static_cast<std::uint32_t> (-1))
136  {
137  parameters_.seed = seed;
138  rng_.seed(seed);
139  }
140 }
141 
142 
143 template <typename T> void
144 NormalGenerator<T>::setParameters (T mean, T sigma, std::uint32_t seed)
145 {
146  parameters_.mean = mean;
147  parameters_.sigma = sigma;
148  parameters_.seed = seed;
149  typename DistributionType::param_type params (parameters_.mean, parameters_.sigma);
150  distribution_.param (params);
151  distribution_.reset ();
152  if (seed != static_cast<std::uint32_t> (-1))
153  rng_.seed (parameters_.seed);
154 }
155 
156 
157 template <typename T> void
159 {
160  parameters_ = parameters;
161  typename DistributionType::param_type params (parameters_.mean, parameters_.sigma);
162  distribution_.param (params);
163  distribution_.reset ();
164  if (parameters_.seed != static_cast<std::uint32_t> (-1))
165  rng_.seed (parameters_.seed);
166 }
167 
168 } // namespace common
169 } // namespace pcl
170 
void setParameters(T mean, T sigma, std::uint32_t seed=-1)
Set the normal number generator parameters.
Definition: random.hpp:144
void setSeed(std::uint32_t seed)
Change seed value.
Definition: random.hpp:133
std::mt19937 rng_
random number generator
Definition: random.h:210
Parameters parameters_
parameters
Definition: random.h:208
NormalGenerator(T mean=0, T sigma=1, std::uint32_t seed=-1)
Constructor.
Definition: random.hpp:113
void setParameters(T min, T max, std::uint32_t seed=-1)
Set the uniform number generator parameters.
Definition: random.hpp:84
void setSeed(std::uint32_t seed)
Change seed value.
Definition: random.hpp:73
UniformGenerator(T min=0, T max=1, std::uint32_t seed=-1)
Constructor.
Definition: random.hpp:53
CloudGenerator class generates a point cloud using some random number generator.