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