Point Cloud Library (PCL)  1.7.1
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 #include <boost/version.hpp>
44 #include <pcl/pcl_macros.h>
45 
46 /////////////////////////////////////////////////////////////////////////////////////////////////////////
47 template <typename T>
48 pcl::common::UniformGenerator<T>::UniformGenerator(T min, T max, pcl::uint32_t seed)
49  : distribution_ (min, max)
50  , generator_ (rng_, distribution_)
51 {
52  parameters_ = Parameters (min, max, seed);
53  if(parameters_.seed != -1)
54  rng_.seed (seed);
55 }
56 
57 
58 /////////////////////////////////////////////////////////////////////////////////////////////////////////
59 template <typename T>
61  : parameters_ (parameters)
62  , distribution_ (parameters_.min, parameters_.max)
63  , generator_ (rng_, distribution_)
64 {
65  if(parameters_.seed != -1)
66  rng_.seed (parameters_.seed);
67 }
68 
69 /////////////////////////////////////////////////////////////////////////////////////////////////////////
70 template <typename T> void
72 {
73  if (seed != -1)
74  {
75  parameters_.seed = seed;
76  rng_.seed(parameters_.seed);
77  }
78 }
79 
80 /////////////////////////////////////////////////////////////////////////////////////////////////////////
81 template <typename T> void
82 pcl::common::UniformGenerator<T>::setParameters (T min, T max, pcl::uint32_t seed)
83 {
84  parameters_.min = min;
85  parameters_.max = max;
86  parameters_.seed = seed;
87 #if BOOST_VERSION >= 104700
88  typename DistributionType::param_type params (parameters_.min, parameters_.max);
89  distribution_.param (params);
90 #else
91  distribution_ = DistributionType (parameters_.min, parameters_.max);
92 #endif
93  distribution_.reset ();
94  generator_.distribution () = distribution_;
95  if (seed != -1)
96  {
97  parameters_.seed = seed;
98  rng_.seed (parameters_.seed);
99  }
100 }
101 
102 /////////////////////////////////////////////////////////////////////////////////////////////////////////
103 template <typename T> void
105 {
106  parameters_ = parameters;
107 #if BOOST_VERSION >= 104700
108  typename DistributionType::param_type params (parameters_.min, parameters_.max);
109  distribution_.param (params);
110 #else
111  distribution_ = DistributionType (parameters_.min, parameters_.max);
112 #endif
113  distribution_.reset ();
114  generator_.distribution () = distribution_;
115  if (parameters_.seed != -1)
116  rng_.seed (parameters_.seed);
117 }
118 
119 /////////////////////////////////////////////////////////////////////////////////////////////////////////
120 template <typename T>
121 pcl::common::NormalGenerator<T>::NormalGenerator(T mean, T sigma, pcl::uint32_t seed)
122  : distribution_ (mean, sigma)
123  , generator_ (rng_, distribution_)
124 {
125  parameters_ = Parameters (mean, sigma, seed);
126  if(parameters_.seed != -1)
127  rng_.seed (seed);
128 }
129 
130 
131 /////////////////////////////////////////////////////////////////////////////////////////////////////////
132 template <typename T>
134  : parameters_ (parameters)
135  , distribution_ (parameters_.mean, parameters_.sigma)
136  , generator_ (rng_, distribution_)
137 {
138  if(parameters_.seed != -1)
139  rng_.seed (parameters_.seed);
140 }
141 
142 /////////////////////////////////////////////////////////////////////////////////////////////////////////
143 template <typename T> void
145 {
146  if (seed != -1)
147  {
148  parameters_.seed = seed;
149  rng_.seed(seed);
150  }
151 }
152 
153 /////////////////////////////////////////////////////////////////////////////////////////////////////////
154 template <typename T> void
155 pcl::common::NormalGenerator<T>::setParameters (T mean, T sigma, pcl::uint32_t seed)
156 {
157  parameters_.mean = mean;
158  parameters_.sigma = sigma;
159  parameters_.seed = seed;
160 #if BOOST_VERSION >= 104700
161  typename DistributionType::param_type params (parameters_.mean, parameters_.sigma);
162  distribution_.param (params);
163 #else
164  distribution_ = DistributionType (parameters_.mean, parameters_.sigma);
165 #endif
166  distribution_.reset ();
167  generator_.distribution () = distribution_;
168  if (seed != -1)
169  rng_.seed (parameters_.seed);
170 }
171 
172 /////////////////////////////////////////////////////////////////////////////////////////////////////////
173 template <typename T> void
175 {
176  parameters_ = parameters;
177 #if BOOST_VERSION >= 104700
178  typename DistributionType::param_type params (parameters_.mean, parameters_.sigma);
179  distribution_.param (params);
180 #else
181  distribution_ = DistributionType (parameters_.mean, parameters_.sigma);
182 #endif
183  distribution_.reset ();
184  generator_.distribution () = distribution_;
185  if (parameters_.seed != -1)
186  rng_.seed (parameters_.seed);
187 }
188 
189 #endif