Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of the copyright holder(s) nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id$ 00037 * 00038 */ 00039 00040 #ifndef PCL_COMMON_RANDOM_HPP_ 00041 #define PCL_COMMON_RANDOM_HPP_ 00042 00043 #include <boost/version.hpp> 00044 #include <pcl/pcl_macros.h> 00045 00046 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00047 template <typename T> 00048 pcl::common::UniformGenerator<T>::UniformGenerator(T min, T max, pcl::uint32_t seed) 00049 : distribution_ (min, max) 00050 , generator_ (rng_, distribution_) 00051 { 00052 parameters_ = Parameters (min, max, seed); 00053 if(parameters_.seed != -1) 00054 rng_.seed (seed); 00055 } 00056 00057 00058 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00059 template <typename T> 00060 pcl::common::UniformGenerator<T>::UniformGenerator(const Parameters& parameters) 00061 : parameters_ (parameters) 00062 , distribution_ (parameters_.min, parameters_.max) 00063 , generator_ (rng_, distribution_) 00064 { 00065 if(parameters_.seed != -1) 00066 rng_.seed (parameters_.seed); 00067 } 00068 00069 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00070 template <typename T> void 00071 pcl::common::UniformGenerator<T>::setSeed (pcl::uint32_t seed) 00072 { 00073 if (seed != -1) 00074 { 00075 parameters_.seed = seed; 00076 rng_.seed(parameters_.seed); 00077 } 00078 } 00079 00080 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00081 template <typename T> void 00082 pcl::common::UniformGenerator<T>::setParameters (T min, T max, pcl::uint32_t seed) 00083 { 00084 parameters_.min = min; 00085 parameters_.max = max; 00086 parameters_.seed = seed; 00087 #if BOOST_VERSION >= 104700 00088 typename DistributionType::param_type params (parameters_.min, parameters_.max); 00089 distribution_.param (params); 00090 #else 00091 distribution_ = DistributionType (parameters_.min, parameters_.max); 00092 #endif 00093 distribution_.reset (); 00094 generator_.distribution () = distribution_; 00095 if (seed != -1) 00096 { 00097 parameters_.seed = seed; 00098 rng_.seed (parameters_.seed); 00099 } 00100 } 00101 00102 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00103 template <typename T> void 00104 pcl::common::UniformGenerator<T>::setParameters (const Parameters& parameters) 00105 { 00106 parameters_ = parameters; 00107 #if BOOST_VERSION >= 104700 00108 typename DistributionType::param_type params (parameters_.min, parameters_.max); 00109 distribution_.param (params); 00110 #else 00111 distribution_ = DistributionType (parameters_.min, parameters_.max); 00112 #endif 00113 distribution_.reset (); 00114 generator_.distribution () = distribution_; 00115 if (parameters_.seed != -1) 00116 rng_.seed (parameters_.seed); 00117 } 00118 00119 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00120 template <typename T> 00121 pcl::common::NormalGenerator<T>::NormalGenerator(T mean, T sigma, pcl::uint32_t seed) 00122 : distribution_ (mean, sigma) 00123 , generator_ (rng_, distribution_) 00124 { 00125 parameters_ = Parameters (mean, sigma, seed); 00126 if(parameters_.seed != -1) 00127 rng_.seed (seed); 00128 } 00129 00130 00131 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00132 template <typename T> 00133 pcl::common::NormalGenerator<T>::NormalGenerator(const Parameters& parameters) 00134 : parameters_ (parameters) 00135 , distribution_ (parameters_.mean, parameters_.sigma) 00136 , generator_ (rng_, distribution_) 00137 { 00138 if(parameters_.seed != -1) 00139 rng_.seed (parameters_.seed); 00140 } 00141 00142 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00143 template <typename T> void 00144 pcl::common::NormalGenerator<T>::setSeed (pcl::uint32_t seed) 00145 { 00146 if (seed != -1) 00147 { 00148 parameters_.seed = seed; 00149 rng_.seed(seed); 00150 } 00151 } 00152 00153 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00154 template <typename T> void 00155 pcl::common::NormalGenerator<T>::setParameters (T mean, T sigma, pcl::uint32_t seed) 00156 { 00157 parameters_.mean = mean; 00158 parameters_.sigma = sigma; 00159 parameters_.seed = seed; 00160 #if BOOST_VERSION >= 104700 00161 typename DistributionType::param_type params (parameters_.mean, parameters_.sigma); 00162 distribution_.param (params); 00163 #else 00164 distribution_ = DistributionType (parameters_.mean, parameters_.sigma); 00165 #endif 00166 distribution_.reset (); 00167 generator_.distribution () = distribution_; 00168 if (seed != -1) 00169 rng_.seed (parameters_.seed); 00170 } 00171 00172 ///////////////////////////////////////////////////////////////////////////////////////////////////////// 00173 template <typename T> void 00174 pcl::common::NormalGenerator<T>::setParameters (const Parameters& parameters) 00175 { 00176 parameters_ = parameters; 00177 #if BOOST_VERSION >= 104700 00178 typename DistributionType::param_type params (parameters_.mean, parameters_.sigma); 00179 distribution_.param (params); 00180 #else 00181 distribution_ = DistributionType (parameters_.mean, parameters_.sigma); 00182 #endif 00183 distribution_.reset (); 00184 generator_.distribution () = distribution_; 00185 if (parameters_.seed != -1) 00186 rng_.seed (parameters_.seed); 00187 } 00188 00189 #endif