Skip to content

Commit 8f356e2

Browse files
committed
Add an actual way to randomly generate a point cloud of arbitary type
1 parent dd2a389 commit 8f356e2

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

common/include/pcl/common/generate.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,101 @@ namespace pcl
180180
GeneratorT x_generator_;
181181
GeneratorT y_generator_;
182182
};
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+
};
183278
}
184279
}
185280

0 commit comments

Comments
 (0)