Point Cloud Library (PCL)  1.9.0-dev
generate.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_GENERATE_HPP_
41 #define PCL_COMMON_GENERATE_HPP_
42 
43 #include <pcl/console/print.h>
44 
45 /////////////////////////////////////////////////////////////////////////////////////////////////////////
46 template <typename PointT, typename GeneratorT>
48  : x_generator_ ()
49  , y_generator_ ()
50  , z_generator_ ()
51 {}
52 
53 /////////////////////////////////////////////////////////////////////////////////////////////////////////
54 template <typename PointT, typename GeneratorT>
56 {
57  setParameters (params);
58 }
59 
60 
61 /////////////////////////////////////////////////////////////////////////////////////////////////////////
62 template <typename PointT, typename GeneratorT>
64  const GeneratorParameters& y_params,
65  const GeneratorParameters& z_params)
66  : x_generator_ (x_params)
67  , y_generator_ (y_params)
68  , z_generator_ (z_params)
69 {}
70 
71 /////////////////////////////////////////////////////////////////////////////////////////////////////////
72 template <typename PointT, typename GeneratorT> void
74 {
75  GeneratorParameters y_params = params;
76  y_params.seed += 1;
77  GeneratorParameters z_params = y_params;
78  z_params.seed += 1;
79  x_generator_.setParameters (params);
80  y_generator_.setParameters (y_params);
81  z_generator_.setParameters (z_params);
82 }
83 
84 /////////////////////////////////////////////////////////////////////////////////////////////////////////
85 template <typename PointT, typename GeneratorT> void
87 {
88  x_generator_.setParameters (x_params);
89 }
90 
91 /////////////////////////////////////////////////////////////////////////////////////////////////////////
92 template <typename PointT, typename GeneratorT> void
94 {
95  y_generator_.setParameters (y_params);
96 }
97 
98 /////////////////////////////////////////////////////////////////////////////////////////////////////////
99 template <typename PointT, typename GeneratorT> void
101 {
102  z_generator_.setParameters (z_params);
103 }
104 
105 /////////////////////////////////////////////////////////////////////////////////////////////////////////
106 template <typename PointT, typename GeneratorT> const typename pcl::common::CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
108 {
109  x_generator_.getParameters ();
110 }
111 
112 /////////////////////////////////////////////////////////////////////////////////////////////////////////
113 template <typename PointT, typename GeneratorT> const typename pcl::common::CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
115 {
116  y_generator_.getParameters ();
117 }
118 
119 /////////////////////////////////////////////////////////////////////////////////////////////////////////
120 template <typename PointT, typename GeneratorT> const typename pcl::common::CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
122 {
123  z_generator_.getParameters ();
124 }
125 
126 /////////////////////////////////////////////////////////////////////////////////////////////////////////
127 template <typename PointT, typename GeneratorT> PointT
129 {
130  PointT p;
131  p.x = x_generator_.run ();
132  p.y = y_generator_.run ();
133  p.z = z_generator_.run ();
134  return (p);
135 }
136 
137 /////////////////////////////////////////////////////////////////////////////////////////////////////////
138 template <typename PointT, typename GeneratorT> int
140 {
141  return (fill (cloud.width, cloud.height, cloud));
142 }
143 
144 /////////////////////////////////////////////////////////////////////////////////////////////////////////
145 template <typename PointT, typename GeneratorT> int
147 {
148  if (width < 1)
149  {
150  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud width must be >= 1!\n");
151  return (-1);
152  }
153 
154  if (height < 1)
155  {
156  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud height must be >= 1!\n");
157  return (-1);
158  }
159 
160  if (!cloud.empty ())
161  {
162  PCL_WARN ("[pcl::common::CloudGenerator] Cloud data will be erased with new data!\n");
163  }
164 
165  cloud.width = width;
166  cloud.height = height;
167  cloud.resize (cloud.width * cloud.height);
168  cloud.is_dense = true;
169  for (typename pcl::PointCloud<PointT>::iterator points_it = cloud.begin ();
170  points_it != cloud.end ();
171  ++points_it)
172  {
173  points_it->x = x_generator_.run ();
174  points_it->y = y_generator_.run ();
175  points_it->z = z_generator_.run ();
176  }
177  return (0);
178 }
179 
180 /////////////////////////////////////////////////////////////////////////////////////////////////////////
181 template <typename GeneratorT>
183  : x_generator_ ()
184  , y_generator_ ()
185 {}
186 
187 /////////////////////////////////////////////////////////////////////////////////////////////////////////
188 template <typename GeneratorT>
190  const GeneratorParameters& y_params)
191  : x_generator_ (x_params)
192  , y_generator_ (y_params)
193 {}
194 
195 /////////////////////////////////////////////////////////////////////////////////////////////////////////
196 template <typename GeneratorT>
198 {
199  setParameters (params);
200 }
201 
202 /////////////////////////////////////////////////////////////////////////////////////////////////////////
203 template <typename GeneratorT> void
205 {
206  x_generator_.setParameters (params);
207  GeneratorParameters y_params = params;
208  y_params.seed += 1;
209  y_generator_.setParameters (y_params);
210 }
211 
212 /////////////////////////////////////////////////////////////////////////////////////////////////////////
213 template <typename GeneratorT> void
215 {
216  x_generator_.setParameters (x_params);
217 }
218 
219 /////////////////////////////////////////////////////////////////////////////////////////////////////////
220 template <typename GeneratorT> void
222 {
223  y_generator_.setParameters (y_params);
224 }
225 
226 /////////////////////////////////////////////////////////////////////////////////////////////////////////
227 template <typename GeneratorT> const typename pcl::common::CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
229 {
230  x_generator_.getParameters ();
231 }
232 
233 /////////////////////////////////////////////////////////////////////////////////////////////////////////
234 template <typename GeneratorT> const typename pcl::common::CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
236 {
237  y_generator_.getParameters ();
238 }
239 
240 /////////////////////////////////////////////////////////////////////////////////////////////////////////
241 template <typename GeneratorT> pcl::PointXY
243 {
244  pcl::PointXY p;
245  p.x = x_generator_.run ();
246  p.y = y_generator_.run ();
247  return (p);
248 }
249 
250 /////////////////////////////////////////////////////////////////////////////////////////////////////////
251 template <typename GeneratorT> int
253 {
254  return (fill (cloud.width, cloud.height, cloud));
255 }
256 
257 /////////////////////////////////////////////////////////////////////////////////////////////////////////
258 template <typename GeneratorT> int
260 {
261  if (width < 1)
262  {
263  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud width must be >= 1\n!");
264  return (-1);
265  }
266 
267  if (height < 1)
268  {
269  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud height must be >= 1\n!");
270  return (-1);
271  }
272 
273  if (!cloud.empty ())
274  PCL_WARN ("[pcl::common::CloudGenerator] Cloud data will be erased with new data\n!");
275 
276  cloud.width = width;
277  cloud.height = height;
278  cloud.resize (cloud.width * cloud.height);
279  cloud.is_dense = true;
280 
281  for (pcl::PointCloud<pcl::PointXY>::iterator points_it = cloud.begin ();
282  points_it != cloud.end ();
283  ++points_it)
284  {
285  points_it->x = x_generator_.run ();
286  points_it->y = y_generator_.run ();
287  }
288  return (0);
289 }
290 
291 #endif
void setParametersForX(const GeneratorParameters &x_params)
Set parameters for x values generation.
Definition: generate.hpp:86
GeneratorT::Parameters GeneratorParameters
Definition: generate.h:62
iterator end()
Definition: point_cloud.h:443
VectorType::iterator iterator
Definition: point_cloud.h:440
A 2D point structure representing Euclidean xy coordinates.
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:415
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:413
const GeneratorParameters & getParametersForY() const
Definition: generate.hpp:114
CloudGenerator()
Default constructor.
Definition: generate.hpp:47
const GeneratorParameters & getParametersForX() const
Definition: generate.hpp:107
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void setParametersForY(const GeneratorParameters &y_params)
Set parameters for y values generation.
Definition: generate.hpp:93
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields)...
Definition: point_cloud.h:418
void setParameters(const GeneratorParameters &params)
Set parameters for x, y and z values.
Definition: generate.hpp:73
iterator begin()
Definition: point_cloud.h:442
void resize(size_t n)
Resize the cloud.
Definition: point_cloud.h:455
void setParametersForZ(const GeneratorParameters &z_params)
Set parameters for z values generation.
Definition: generate.hpp:100
A point structure representing Euclidean xyz coordinates, and the RGB color.
const GeneratorParameters & getParametersForZ() const
Definition: generate.hpp:121
int fill(pcl::PointCloud< PointT > &cloud)
Generates a cloud with X Y Z picked within given ranges.
Definition: generate.hpp:139
bool empty() const
Definition: point_cloud.h:450