Point Cloud Library (PCL)  1.7.1
generate.h
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_GENERATE_H_
41 #define PCL_COMMON_GENERATE_H_
42 
43 #include <pcl/point_cloud.h>
44 #include <pcl/point_types.h>
45 #include <pcl/common/random.h>
46 
47 namespace pcl
48 {
49 
50  namespace common
51  {
52  /** \brief CloudGenerator class generates a point cloud using some randoom number generator.
53  * Generators can be found in \file common/random.h and easily extensible.
54  *
55  * \ingroup common
56  * \author Nizar Sallem
57  */
58  template <typename PointT, typename GeneratorT>
60  {
61  public:
62  typedef typename GeneratorT::Parameters GeneratorParameters;
63 
64  /// Default constructor
65  CloudGenerator ();
66 
67  /** Consttructor with single generator to ensure all X, Y and Z values are within same range
68  * \param params paramteres for X, Y and Z values generation. Uniqueness is ensured through
69  * seed incrementation
70  */
71  CloudGenerator (const GeneratorParameters& params);
72 
73  /** Constructor with independant generators per axis
74  * \param x_params parameters for x values generation
75  * \param y_params parameters for y values generation
76  * \param z_params parameters for z values generation
77  */
78  CloudGenerator (const GeneratorParameters& x_params,
79  const GeneratorParameters& y_params,
80  const GeneratorParameters& z_params);
81 
82  /** Set parameters for x, y and z values. Uniqueness is ensured through seed incrementation.
83  * \param params parameteres for X, Y and Z values generation.
84  */
85  void
86  setParameters (const GeneratorParameters& params);
87 
88  /** Set parameters for x values generation
89  * \param x_params paramters for x values generation
90  */
91  void
92  setParametersForX (const GeneratorParameters& x_params);
93 
94  /** Set parameters for y values generation
95  * \param y_params paramters for y values generation
96  */
97  void
98  setParametersForY (const GeneratorParameters& y_params);
99 
100  /** Set parameters for z values generation
101  * \param z_params paramters for z values generation
102  */
103  void
104  setParametersForZ (const GeneratorParameters& z_params);
105 
106  /// \return x values generation parameters
107  const GeneratorParameters&
108  getParametersForX () const;
109 
110  /// \return y values generation parameters
111  const GeneratorParameters&
112  getParametersForY () const;
113 
114  /// \return z values generation parameters
115  const GeneratorParameters&
116  getParametersForZ () const;
117 
118  /// \return a single random generated point
119  PointT
120  get ();
121 
122  /** Generates a cloud with X Y Z picked within given ranges. This function assumes that
123  * cloud is properly defined else it raises errors and does nothing.
124  * \param[out] cloud cloud to generate coordinates for
125  * \return 0 if generation went well else -1.
126  */
127  int
128  fill (pcl::PointCloud<PointT>& cloud);
129 
130  /** Generates a cloud of specified dimensions with X Y Z picked within given ranges.
131  * \param[in] width width of generated cloud
132  * \param[in] height height of generated cloud
133  * \param[out] cloud output cloud
134  * \return 0 if generation went well else -1.
135  */
136  int
137  fill (int width, int height, pcl::PointCloud<PointT>& cloud);
138 
139  private:
140  GeneratorT x_generator_, y_generator_, z_generator_;
141  };
142 
143  template <typename GeneratorT>
144  class CloudGenerator<pcl::PointXY, GeneratorT>
145  {
146  public:
147  typedef typename GeneratorT::Parameters GeneratorParameters;
148 
149  CloudGenerator ();
150 
151  CloudGenerator (const GeneratorParameters& params);
152 
153  CloudGenerator (const GeneratorParameters& x_params,
154  const GeneratorParameters& y_params);
155 
156  void
157  setParameters (const GeneratorParameters& params);
158 
159  void
160  setParametersForX (const GeneratorParameters& x_params);
161 
162  void
163  setParametersForY (const GeneratorParameters& y_params);
164 
165  const GeneratorParameters&
166  getParametersForX () const;
167 
168  const GeneratorParameters&
169  getParametersForY () const;
170 
172  get ();
173 
174  int
176 
177  int
178  fill (int width, int height, pcl::PointCloud<pcl::PointXY>& cloud);
179 
180  private:
181  GeneratorT x_generator_;
182  GeneratorT y_generator_;
183  };
184  }
185 }
186 
187 #include <pcl/common/impl/generate.hpp>
188 
189 #endif