Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
common
impl
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
Po
int
T,
typename
GeneratorT>
53
CloudGenerator<PointT, GeneratorT>::CloudGenerator
()
54
: x_generator_ ()
55
, y_generator_ ()
56
, z_generator_ ()
57
{}
58
59
60
template
<
typename
Po
int
T,
typename
GeneratorT>
61
CloudGenerator<PointT, GeneratorT>::CloudGenerator
(
const
GeneratorParameters
& params)
62
{
63
setParameters
(params);
64
}
65
66
67
template
<
typename
Po
int
T,
typename
GeneratorT>
68
CloudGenerator<PointT, GeneratorT>::CloudGenerator
(
const
GeneratorParameters
& x_params,
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
Po
int
T,
typename
GeneratorT>
void
78
CloudGenerator<PointT, GeneratorT>::setParameters
(
const
GeneratorParameters
& params)
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
Po
int
T,
typename
GeneratorT>
void
91
CloudGenerator<PointT, GeneratorT>::setParametersForX
(
const
GeneratorParameters
& x_params)
92
{
93
x_generator_.setParameters (x_params);
94
}
95
96
97
template
<
typename
Po
int
T,
typename
GeneratorT>
void
98
CloudGenerator<PointT, GeneratorT>::setParametersForY
(
const
GeneratorParameters
& y_params)
99
{
100
y_generator_.setParameters (y_params);
101
}
102
103
104
template
<
typename
Po
int
T,
typename
GeneratorT>
void
105
CloudGenerator<PointT, GeneratorT>::setParametersForZ
(
const
GeneratorParameters
& z_params)
106
{
107
z_generator_.setParameters (z_params);
108
}
109
110
111
template
<
typename
Po
int
T,
typename
GeneratorT>
const
typename
CloudGenerator<PointT, GeneratorT>::GeneratorParameters
&
112
CloudGenerator<PointT, GeneratorT>::getParametersForX
()
const
113
{
114
return
x_generator_.getParameters ();
115
}
116
117
118
template
<
typename
Po
int
T,
typename
GeneratorT>
const
typename
CloudGenerator<PointT, GeneratorT>::GeneratorParameters
&
119
CloudGenerator<PointT, GeneratorT>::getParametersForY
()
const
120
{
121
return
y_generator_.getParameters ();
122
}
123
124
125
template
<
typename
Po
int
T,
typename
GeneratorT>
const
typename
CloudGenerator<PointT, GeneratorT>::GeneratorParameters
&
126
CloudGenerator<PointT, GeneratorT>::getParametersForZ
()
const
127
{
128
return
z_generator_.getParameters ();
129
}
130
131
132
template
<
typename
Po
int
T,
typename
GeneratorT> PointT
133
CloudGenerator<PointT, GeneratorT>::get
()
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
Po
int
T,
typename
GeneratorT>
int
144
CloudGenerator<PointT, GeneratorT>::fill
(
pcl::PointCloud<PointT>
& cloud)
145
{
146
return
(
fill
(cloud.
width
, cloud.
height
, cloud));
147
}
148
149
150
template
<
typename
Po
int
T,
typename
GeneratorT>
int
151
CloudGenerator<PointT, GeneratorT>::fill
(
int
width,
int
height,
pcl::PointCloud<PointT>
& cloud)
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>
185
CloudGenerator<pcl::PointXY, GeneratorT>::CloudGenerator
()
186
: x_generator_ ()
187
, y_generator_ ()
188
{}
189
190
191
template
<
typename
GeneratorT>
192
CloudGenerator<pcl::PointXY, GeneratorT>::CloudGenerator
(
const
GeneratorParameters
& x_params,
193
const
GeneratorParameters
& y_params)
194
: x_generator_ (x_params)
195
, y_generator_ (y_params)
196
{}
197
198
199
template
<
typename
GeneratorT>
200
CloudGenerator<pcl::PointXY, GeneratorT>::CloudGenerator
(
const
GeneratorParameters
& params)
201
{
202
setParameters
(params);
203
}
204
205
206
template
<
typename
GeneratorT>
void
207
CloudGenerator<pcl::PointXY, GeneratorT>::setParameters
(
const
GeneratorParameters
& params)
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
217
CloudGenerator<pcl::PointXY, GeneratorT>::setParametersForX
(
const
GeneratorParameters
& x_params)
218
{
219
x_generator_.setParameters (x_params);
220
}
221
222
223
template
<
typename
GeneratorT>
void
224
CloudGenerator<pcl::PointXY, GeneratorT>::setParametersForY
(
const
GeneratorParameters
& y_params)
225
{
226
y_generator_.setParameters (y_params);
227
}
228
229
230
template
<
typename
GeneratorT>
const
typename
CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters
&
231
CloudGenerator<pcl::PointXY, GeneratorT>::getParametersForX
()
const
232
{
233
return
x_generator_.getParameters ();
234
}
235
236
237
template
<
typename
GeneratorT>
const
typename
CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters
&
238
CloudGenerator<pcl::PointXY, GeneratorT>::getParametersForY
()
const
239
{
240
return
y_generator_.getParameters ();
241
}
242
243
244
template
<
typename
GeneratorT>
pcl::PointXY
245
CloudGenerator<pcl::PointXY, GeneratorT>::get
()
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
255
CloudGenerator<pcl::PointXY, GeneratorT>::fill
(
pcl::PointCloud<pcl::PointXY>
& cloud)
256
{
257
return
(
fill
(cloud.
width
, cloud.
height
, cloud));
258
}
259
260
261
template
<
typename
GeneratorT>
int
262
CloudGenerator<pcl::PointXY, GeneratorT>::fill
(
int
width,
int
height,
pcl::PointCloud<pcl::PointXY>
& cloud)
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.
resize
(width, height);
280
cloud.
is_dense
=
true
;
281
282
for
(
auto
&point : cloud)
283
{
284
point.x = x_generator_.run ();
285
point.y = y_generator_.run ();
286
}
287
return
(0);
288
}
289
290
}
// namespace common
291
}
// namespace pcl
292
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition
point_cloud.h:174
pcl::PointCloud::empty
bool empty() const
Definition
point_cloud.h:447
pcl::PointCloud::is_dense
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:404
pcl::PointCloud::resize
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition
point_cloud.h:463
pcl::PointCloud::width
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition
point_cloud.h:399
pcl::PointCloud::height
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition
point_cloud.h:401
pcl::common::CloudGenerator< pcl::PointXY, GeneratorT >::GeneratorParameters
typename GeneratorT::Parameters GeneratorParameters
Definition
generate.h:146
pcl::common::CloudGenerator< pcl::PointXY, GeneratorT >::fill
int fill(pcl::PointCloud< pcl::PointXY > &cloud)
Definition
generate.hpp:255
pcl::common::CloudGenerator< pcl::PointXY, GeneratorT >::setParameters
void setParameters(const GeneratorParameters ¶ms)
Definition
generate.hpp:207
pcl::common::CloudGenerator::fill
int fill(pcl::PointCloud< PointT > &cloud)
Generates a cloud with X Y Z picked within given ranges.
Definition
generate.hpp:144
pcl::common::CloudGenerator::getParametersForX
const GeneratorParameters & getParametersForX() const
Definition
generate.hpp:112
pcl::common::CloudGenerator::setParametersForY
void setParametersForY(const GeneratorParameters &y_params)
Set parameters for y values generation.
Definition
generate.hpp:98
pcl::common::CloudGenerator::getParametersForY
const GeneratorParameters & getParametersForY() const
Definition
generate.hpp:119
pcl::common::CloudGenerator::setParametersForZ
void setParametersForZ(const GeneratorParameters &z_params)
Set parameters for z values generation.
Definition
generate.hpp:105
pcl::common::CloudGenerator::setParameters
void setParameters(const GeneratorParameters ¶ms)
Set parameters for x, y and z values.
Definition
generate.hpp:78
pcl::common::CloudGenerator::GeneratorParameters
typename GeneratorT::Parameters GeneratorParameters
Definition
generate.h:61
pcl::common::CloudGenerator::get
PointT get()
Definition
generate.hpp:133
pcl::common::CloudGenerator::setParametersForX
void setParametersForX(const GeneratorParameters &x_params)
Set parameters for x values generation.
Definition
generate.hpp:91
pcl::common::CloudGenerator::getParametersForZ
const GeneratorParameters & getParametersForZ() const
Definition
generate.hpp:126
pcl::common::CloudGenerator::CloudGenerator
CloudGenerator()
Default constructor.
Definition
generate.hpp:53
pcl::common
Definition
generate.h:50
pcl
Definition
convolution.h:46
pcl::PointXY
A 2D point structure representing Euclidean xy coordinates.
Definition
point_types.hpp:716
pcl::PointXY::y
float y
Definition
point_types.hpp:723
pcl::PointXY::x
float x
Definition
point_types.hpp:722