Point Cloud Library (PCL)  1.9.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 #ifndef PCL_COMMON_RANDOM_HPP_
41 #define PCL_COMMON_RANDOM_HPP_
42 
43 /////////////////////////////////////////////////////////////////////////////////////////////////////////
44 template <typename T>
45 pcl::common::UniformGenerator<T>::UniformGenerator(T min, T max, pcl::uint32_t seed)
46  : distribution_ (min, max)
47 {
48  parameters_ = Parameters (min, max, seed);
49  if(parameters_.seed != static_cast<pcl::uint32_t> (-1))
50  rng_.seed (seed);
51 }
52 
53 
54 /////////////////////////////////////////////////////////////////////////////////////////////////////////
55 template <typename T>
57  : parameters_ (parameters)
58  , distribution_ (parameters_.min, parameters_.max)
59 {
60  if(parameters_.seed != static_cast<pcl::uint32_t> (-1))
61  rng_.seed (parameters_.seed);
62 }
63 
64 /////////////////////////////////////////////////////////////////////////////////////////////////////////
65 template <typename T> void
67 {
68  if (seed != static_cast<pcl::uint32_t> (-1))
69  {
70  parameters_.seed = seed;
71  rng_.seed(parameters_.seed);
72  }
73 }
74 
75 /////////////////////////////////////////////////////////////////////////////////////////////////////////
76 template <typename T> void
77 pcl::common::UniformGenerator<T>::setParameters (T min, T max, pcl::uint32_t seed)
78 {
79  parameters_.min = min;
80  parameters_.max = max;
81  parameters_.seed = seed;
82  typename DistributionType::param_type params (parameters_.min, parameters_.max);
83  distribution_.param (params);
84  distribution_.reset ();
85  if (seed != static_cast<pcl::uint32_t> (-1))
86  {
87  parameters_.seed = seed;
88  rng_.seed (parameters_.seed);
89  }
90 }
91 
92 /////////////////////////////////////////////////////////////////////////////////////////////////////////
93 template <typename T> void
95 {
96  parameters_ = parameters;
97  typename DistributionType::param_type params (parameters_.min, parameters_.max);
98  distribution_.param (params);
99  distribution_.reset ();
100  if (parameters_.seed != static_cast<pcl::uint32_t> (-1))
101  rng_.seed (parameters_.seed);
102 }
103 
104 /////////////////////////////////////////////////////////////////////////////////////////////////////////
105 template <typename T>
106 pcl::common::NormalGenerator<T>::NormalGenerator(T mean, T sigma, pcl::uint32_t seed)
107  : distribution_ (mean, sigma)
108 {
109  parameters_ = Parameters (mean, sigma, seed);
110  if(parameters_.seed != static_cast<pcl::uint32_t> (-1))
111  rng_.seed (seed);
112 }
113 
114 
115 /////////////////////////////////////////////////////////////////////////////////////////////////////////
116 template <typename T>
118  : parameters_ (parameters)
119  , distribution_ (parameters_.mean, parameters_.sigma)
120 {
121  if(parameters_.seed != static_cast<pcl::uint32_t> (-1))
122  rng_.seed (parameters_.seed);
123 }
124 
125 /////////////////////////////////////////////////////////////////////////////////////////////////////////
126 template <typename T> void
128 {
129  if (seed != static_cast<pcl::uint32_t> (-1))
130  {
131  parameters_.seed = seed;
132  rng_.seed(seed);
133  }
134 }
135 
136 /////////////////////////////////////////////////////////////////////////////////////////////////////////
137 template <typename T> void
138 pcl::common::NormalGenerator<T>::setParameters (T mean, T sigma, pcl::uint32_t seed)
139 {
140  parameters_.mean = mean;
141  parameters_.sigma = sigma;
142  parameters_.seed = seed;
143  typename DistributionType::param_type params (parameters_.mean, parameters_.sigma);
144  distribution_.param (params);
145  distribution_.reset ();
146  if (seed != static_cast<pcl::uint32_t> (-1))
147  rng_.seed (parameters_.seed);
148 }
149 
150 /////////////////////////////////////////////////////////////////////////////////////////////////////////
151 template <typename T> void
153 {
154  parameters_ = parameters;
155  typename DistributionType::param_type params (parameters_.mean, parameters_.sigma);
156  distribution_.param (params);
157  distribution_.reset ();
158  if (parameters_.seed != static_cast<pcl::uint32_t> (-1))
159  rng_.seed (parameters_.seed);
160 }
161 
162 #endif
Parameters parameters_
parameters
Definition: random.h:208
NormalGenerator(T mean=0, T sigma=1, pcl::uint32_t seed=-1)
Constructor.
Definition: random.hpp:106
void setParameters(T min, T max, pcl::uint32_t seed=-1)
Set the uniform number generator parameters.
Definition: random.hpp:77
void setSeed(pcl::uint32_t seed)
Change seed value.
Definition: random.hpp:127
std::mt19937 rng_
random number generator
Definition: random.h:210
DistributionType distribution_
normal distribution
Definition: random.h:212
void setSeed(pcl::uint32_t seed)
Change seed value.
Definition: random.hpp:66
void setParameters(T mean, T sigma, pcl::uint32_t seed=-1)
Set the normal number generator parameters.
Definition: random.hpp:138
UniformGenerator(T min=0, T max=1, pcl::uint32_t seed=-1)
Constructor.
Definition: random.hpp:45