Point Cloud Library (PCL)  1.9.1-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 (auto& point: cloud)
170  {
171  point.x = x_generator_.run ();
172  point.y = y_generator_.run ();
173  point.z = z_generator_.run ();
174  }
175  return (0);
176 }
177 
178 /////////////////////////////////////////////////////////////////////////////////////////////////////////
179 template <typename GeneratorT>
181  : x_generator_ ()
182  , y_generator_ ()
183 {}
184 
185 /////////////////////////////////////////////////////////////////////////////////////////////////////////
186 template <typename GeneratorT>
188  const GeneratorParameters& y_params)
189  : x_generator_ (x_params)
190  , y_generator_ (y_params)
191 {}
192 
193 /////////////////////////////////////////////////////////////////////////////////////////////////////////
194 template <typename GeneratorT>
196 {
197  setParameters (params);
198 }
199 
200 /////////////////////////////////////////////////////////////////////////////////////////////////////////
201 template <typename GeneratorT> void
203 {
204  x_generator_.setParameters (params);
205  GeneratorParameters y_params = params;
206  y_params.seed += 1;
207  y_generator_.setParameters (y_params);
208 }
209 
210 /////////////////////////////////////////////////////////////////////////////////////////////////////////
211 template <typename GeneratorT> void
213 {
214  x_generator_.setParameters (x_params);
215 }
216 
217 /////////////////////////////////////////////////////////////////////////////////////////////////////////
218 template <typename GeneratorT> void
220 {
221  y_generator_.setParameters (y_params);
222 }
223 
224 /////////////////////////////////////////////////////////////////////////////////////////////////////////
225 template <typename GeneratorT> const typename pcl::common::CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
227 {
228  x_generator_.getParameters ();
229 }
230 
231 /////////////////////////////////////////////////////////////////////////////////////////////////////////
232 template <typename GeneratorT> const typename pcl::common::CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
234 {
235  y_generator_.getParameters ();
236 }
237 
238 /////////////////////////////////////////////////////////////////////////////////////////////////////////
239 template <typename GeneratorT> pcl::PointXY
241 {
242  pcl::PointXY p;
243  p.x = x_generator_.run ();
244  p.y = y_generator_.run ();
245  return (p);
246 }
247 
248 /////////////////////////////////////////////////////////////////////////////////////////////////////////
249 template <typename GeneratorT> int
251 {
252  return (fill (cloud.width, cloud.height, cloud));
253 }
254 
255 /////////////////////////////////////////////////////////////////////////////////////////////////////////
256 template <typename GeneratorT> int
258 {
259  if (width < 1)
260  {
261  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud width must be >= 1\n!");
262  return (-1);
263  }
264 
265  if (height < 1)
266  {
267  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud height must be >= 1\n!");
268  return (-1);
269  }
270 
271  if (!cloud.empty ())
272  PCL_WARN ("[pcl::common::CloudGenerator] Cloud data will be erased with new data\n!");
273 
274  cloud.width = width;
275  cloud.height = height;
276  cloud.resize (cloud.width * cloud.height);
277  cloud.is_dense = true;
278 
279  for (auto &point : cloud)
280  {
281  point.x = x_generator_.run ();
282  point.y = y_generator_.run ();
283  }
284  return (0);
285 }
286 
287 #endif
const GeneratorParameters & getParametersForZ() const
Definition: generate.hpp:121
void setParametersForX(const GeneratorParameters &x_params)
Set parameters for x values generation.
Definition: generate.hpp:86
void resize(std::size_t n)
Resize the cloud.
Definition: point_cloud.h:438
const GeneratorParameters & getParametersForY() const
Definition: generate.hpp:114
A 2D point structure representing Euclidean xy coordinates.
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:396
typename GeneratorT::Parameters GeneratorParameters
Definition: generate.h:146
CloudGenerator()
Default constructor.
Definition: generate.hpp:47
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:398
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:401
const GeneratorParameters & getParametersForX() const
Definition: generate.hpp:107
void setParameters(const GeneratorParameters &params)
Set parameters for x, y and z values.
Definition: generate.hpp:73
typename GeneratorT::Parameters GeneratorParameters
Definition: generate.h:61
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.
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:433