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_GENERATE_H_ 00041 #define PCL_COMMON_GENERATE_H_ 00042 00043 #include <pcl/point_cloud.h> 00044 #include <pcl/point_types.h> 00045 #include <pcl/common/random.h> 00046 00047 namespace pcl 00048 { 00049 00050 namespace common 00051 { 00052 /** \brief CloudGenerator class generates a point cloud using some randoom number generator. 00053 * Generators can be found in \file common/random.h and easily extensible. 00054 * 00055 * \ingroup common 00056 * \author Nizar Sallem 00057 */ 00058 template <typename PointT, typename GeneratorT> 00059 class CloudGenerator 00060 { 00061 public: 00062 typedef typename GeneratorT::Parameters GeneratorParameters; 00063 00064 /// Default constructor 00065 CloudGenerator (); 00066 00067 /** Consttructor with single generator to ensure all X, Y and Z values are within same range 00068 * \param params paramteres for X, Y and Z values generation. Uniqueness is ensured through 00069 * seed incrementation 00070 */ 00071 CloudGenerator (const GeneratorParameters& params); 00072 00073 /** Constructor with independant generators per axis 00074 * \param x_params parameters for x values generation 00075 * \param y_params parameters for y values generation 00076 * \param z_params parameters for z values generation 00077 */ 00078 CloudGenerator (const GeneratorParameters& x_params, 00079 const GeneratorParameters& y_params, 00080 const GeneratorParameters& z_params); 00081 00082 /** Set parameters for x, y and z values. Uniqueness is ensured through seed incrementation. 00083 * \param params parameteres for X, Y and Z values generation. 00084 */ 00085 void 00086 setParameters (const GeneratorParameters& params); 00087 00088 /** Set parameters for x values generation 00089 * \param x_params paramters for x values generation 00090 */ 00091 void 00092 setParametersForX (const GeneratorParameters& x_params); 00093 00094 /** Set parameters for y values generation 00095 * \param y_params paramters for y values generation 00096 */ 00097 void 00098 setParametersForY (const GeneratorParameters& y_params); 00099 00100 /** Set parameters for z values generation 00101 * \param z_params paramters for z values generation 00102 */ 00103 void 00104 setParametersForZ (const GeneratorParameters& z_params); 00105 00106 /// \return x values generation parameters 00107 const GeneratorParameters& 00108 getParametersForX () const; 00109 00110 /// \return y values generation parameters 00111 const GeneratorParameters& 00112 getParametersForY () const; 00113 00114 /// \return z values generation parameters 00115 const GeneratorParameters& 00116 getParametersForZ () const; 00117 00118 /// \return a single random generated point 00119 PointT 00120 get (); 00121 00122 /** Generates a cloud with X Y Z picked within given ranges. This function assumes that 00123 * cloud is properly defined else it raises errors and does nothing. 00124 * \param[out] cloud cloud to generate coordinates for 00125 * \return 0 if generation went well else -1. 00126 */ 00127 int 00128 fill (pcl::PointCloud<PointT>& cloud); 00129 00130 /** Generates a cloud of specified dimensions with X Y Z picked within given ranges. 00131 * \param[in] width width of generated cloud 00132 * \param[in] height height of generated cloud 00133 * \param[out] cloud output cloud 00134 * \return 0 if generation went well else -1. 00135 */ 00136 int 00137 fill (int width, int height, pcl::PointCloud<PointT>& cloud); 00138 00139 private: 00140 GeneratorT x_generator_, y_generator_, z_generator_; 00141 }; 00142 00143 template <typename GeneratorT> 00144 class CloudGenerator<pcl::PointXY, GeneratorT> 00145 { 00146 public: 00147 typedef typename GeneratorT::Parameters GeneratorParameters; 00148 00149 CloudGenerator (); 00150 00151 CloudGenerator (const GeneratorParameters& params); 00152 00153 CloudGenerator (const GeneratorParameters& x_params, 00154 const GeneratorParameters& y_params); 00155 00156 void 00157 setParameters (const GeneratorParameters& params); 00158 00159 void 00160 setParametersForX (const GeneratorParameters& x_params); 00161 00162 void 00163 setParametersForY (const GeneratorParameters& y_params); 00164 00165 const GeneratorParameters& 00166 getParametersForX () const; 00167 00168 const GeneratorParameters& 00169 getParametersForY () const; 00170 00171 pcl::PointXY 00172 get (); 00173 00174 int 00175 fill (pcl::PointCloud<pcl::PointXY>& cloud); 00176 00177 int 00178 fill (int width, int height, pcl::PointCloud<pcl::PointXY>& cloud); 00179 00180 private: 00181 GeneratorT x_generator_; 00182 GeneratorT y_generator_; 00183 }; 00184 } 00185 } 00186 00187 #include <pcl/common/impl/generate.hpp> 00188 00189 #endif