@@ -180,6 +180,101 @@ namespace pcl
180
180
GeneratorT x_generator_;
181
181
GeneratorT y_generator_;
182
182
};
183
+
184
+ /* *
185
+ * @brief Allows generation of a point cloud using a random point generator
186
+ *
187
+ * @tparam PointT Type of point cloud (eg: PointNormal, PointXYZRGB, etc.)
188
+ * @tparam GeneratorT A generator following the generator classes as shown in \file common/random.h
189
+ */
190
+ template <typename PointT, typename GeneratorT>
191
+ class PointCloudGenerator {
192
+ public:
193
+ using GeneratorParameters = typename GeneratorT::Parameters;
194
+
195
+ // / Default constructor
196
+ PointCloudGenerator () : point_generator_() {}
197
+
198
+ /* *
199
+ * \brief Constructor with a generator to fill a cloud
200
+ * \details Uniqueness is ensured by incrementing the seed
201
+ * \param params parameters for point generation.
202
+ */
203
+ PointCloudGenerator (const GeneratorParameters& params) : point_generator_(params)
204
+ {}
205
+
206
+ /* * Set parameters for point generation
207
+ * \param x_params parameters for point generation
208
+ */
209
+ void
210
+ setParameters (const GeneratorParameters& pt_params)
211
+ {
212
+ _point_generator.setParameters (pt_params);
213
+ }
214
+
215
+ // / \return Point generation parameters
216
+ const GeneratorParameters&
217
+ getParameters () const
218
+ {
219
+ return point_generator_.getParameters ();
220
+ }
221
+
222
+ // / \return a single random generated point
223
+ PointT
224
+ get ()
225
+ {
226
+ return point_generator_.run ();
227
+ }
228
+
229
+ /* *
230
+ * \brief Generates a cloud with the supplied generator and parameters.
231
+ * \note This function assumes that cloud is properly defined
232
+ * \param[out] cloud cloud to generate coordinates for
233
+ * \return 0 if generation went well else -1.
234
+ */
235
+ int
236
+ fill (pcl::PointCloud<PointT>& cloud)
237
+ {
238
+ return fill (cloud.width , cloud.height , cloud);
239
+ }
240
+
241
+ /* *
242
+ * \brief Generates a cloud with the supplied generator and parameters.
243
+ * \param[in] width width of generated cloud
244
+ * \param[in] height height of generated cloud
245
+ * \param[out] cloud output cloud
246
+ * \return 0 if generation went well else -1.
247
+ */
248
+ int
249
+ fill (int width, int height, pcl::PointCloud<PointT>& cloud)
250
+ {
251
+ if (width < 1 ) {
252
+ PCL_ERROR (" [pcl::common::CloudGenerator] Cloud width must be >= 1!\n " );
253
+ return (-1 );
254
+ }
255
+
256
+ if (height < 1 ) {
257
+ PCL_ERROR (" [pcl::common::CloudGenerator] Cloud height must be >= 1!\n " );
258
+ return (-1 );
259
+ }
260
+
261
+ if (!cloud.empty ()) {
262
+ PCL_WARN (" [pcl::common::CloudGenerator] Cloud data will be erased with new "
263
+ " data!\n " );
264
+ }
265
+
266
+ cloud.resize (width, height);
267
+ cloud.is_dense = true ;
268
+
269
+ for (auto & point : cloud) {
270
+ point = point_generator_.run ();
271
+ }
272
+ return (0 );
273
+ }
274
+
275
+ private:
276
+ GeneratorT point_generator_;
277
+ };
183
278
}
184
279
}
185
280
0 commit comments