Point Cloud Library (PCL)  1.14.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 #pragma once
41 
42 #include <pcl/common/generate.h>
43 #include <pcl/console/print.h>
44 
45 
46 namespace pcl
47 {
48 
49 namespace common
50 {
51 
52 template <typename PointT, typename GeneratorT>
54  : x_generator_ ()
55  , y_generator_ ()
56  , z_generator_ ()
57 {}
58 
59 
60 template <typename PointT, typename GeneratorT>
62 {
63  setParameters (params);
64 }
65 
66 
67 template <typename PointT, typename GeneratorT>
69  const GeneratorParameters& y_params,
70  const GeneratorParameters& z_params)
71  : x_generator_ (x_params)
72  , y_generator_ (y_params)
73  , z_generator_ (z_params)
74 {}
75 
76 
77 template <typename PointT, typename GeneratorT> void
79 {
80  GeneratorParameters y_params = params;
81  y_params.seed += 1;
82  GeneratorParameters z_params = y_params;
83  z_params.seed += 1;
84  x_generator_.setParameters (params);
85  y_generator_.setParameters (y_params);
86  z_generator_.setParameters (z_params);
87 }
88 
89 
90 template <typename PointT, typename GeneratorT> void
92 {
93  x_generator_.setParameters (x_params);
94 }
95 
96 
97 template <typename PointT, typename GeneratorT> void
99 {
100  y_generator_.setParameters (y_params);
101 }
102 
103 
104 template <typename PointT, typename GeneratorT> void
106 {
107  z_generator_.setParameters (z_params);
108 }
109 
110 
111 template <typename PointT, typename GeneratorT> const typename CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
113 {
114  return x_generator_.getParameters ();
115 }
116 
117 
118 template <typename PointT, typename GeneratorT> const typename CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
120 {
121  return y_generator_.getParameters ();
122 }
123 
124 
125 template <typename PointT, typename GeneratorT> const typename CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
127 {
128  return z_generator_.getParameters ();
129 }
130 
131 
132 template <typename PointT, typename GeneratorT> PointT
134 {
135  PointT p;
136  p.x = x_generator_.run ();
137  p.y = y_generator_.run ();
138  p.z = z_generator_.run ();
139  return (p);
140 }
141 
142 
143 template <typename PointT, typename GeneratorT> int
145 {
146  return (fill (cloud.width, cloud.height, cloud));
147 }
148 
149 
150 template <typename PointT, typename GeneratorT> int
152 {
153  if (width < 1)
154  {
155  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud width must be >= 1!\n");
156  return (-1);
157  }
158 
159  if (height < 1)
160  {
161  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud height must be >= 1!\n");
162  return (-1);
163  }
164 
165  if (!cloud.empty ())
166  {
167  PCL_WARN ("[pcl::common::CloudGenerator] Cloud data will be erased with new data!\n");
168  }
169 
170  cloud.width = width;
171  cloud.height = height;
172  cloud.resize (cloud.width * cloud.height);
173  cloud.is_dense = true;
174  for (auto& point: cloud)
175  {
176  point.x = x_generator_.run ();
177  point.y = y_generator_.run ();
178  point.z = z_generator_.run ();
179  }
180  return (0);
181 }
182 
183 
184 template <typename GeneratorT>
186  : x_generator_ ()
187  , y_generator_ ()
188 {}
189 
190 
191 template <typename GeneratorT>
193  const GeneratorParameters& y_params)
194  : x_generator_ (x_params)
195  , y_generator_ (y_params)
196 {}
197 
198 
199 template <typename GeneratorT>
201 {
202  setParameters (params);
203 }
204 
205 
206 template <typename GeneratorT> void
208 {
209  x_generator_.setParameters (params);
210  GeneratorParameters y_params = params;
211  y_params.seed += 1;
212  y_generator_.setParameters (y_params);
213 }
214 
215 
216 template <typename GeneratorT> void
218 {
219  x_generator_.setParameters (x_params);
220 }
221 
222 
223 template <typename GeneratorT> void
225 {
226  y_generator_.setParameters (y_params);
227 }
228 
229 
230 template <typename GeneratorT> const typename CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
232 {
233  return x_generator_.getParameters ();
234 }
235 
236 
237 template <typename GeneratorT> const typename CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
239 {
240  return y_generator_.getParameters ();
241 }
242 
243 
244 template <typename GeneratorT> pcl::PointXY
246 {
247  pcl::PointXY p;
248  p.x = x_generator_.run ();
249  p.y = y_generator_.run ();
250  return (p);
251 }
252 
253 
254 template <typename GeneratorT> int
256 {
257  return (fill (cloud.width, cloud.height, cloud));
258 }
259 
260 
261 template <typename GeneratorT> int
263 {
264  if (width < 1)
265  {
266  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud width must be >= 1\n!");
267  return (-1);
268  }
269 
270  if (height < 1)
271  {
272  PCL_ERROR ("[pcl::common::CloudGenerator] Cloud height must be >= 1\n!");
273  return (-1);
274  }
275 
276  if (!cloud.empty ())
277  PCL_WARN ("[pcl::common::CloudGenerator] Cloud data will be erased with new data\n!");
278 
279  cloud.width = width;
280  cloud.height = height;
281  cloud.resize (cloud.width * cloud.height);
282  cloud.is_dense = true;
283 
284  for (auto &point : cloud)
285  {
286  point.x = x_generator_.run ();
287  point.y = y_generator_.run ();
288  }
289  return (0);
290 }
291 
292 } // namespace common
293 } // namespace pcl
294 
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
bool empty() const
Definition: point_cloud.h:446
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:403
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:462
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
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
A 2D point structure representing Euclidean xy coordinates.
A point structure representing Euclidean xyz coordinates, and the RGB color.