Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an actual way to randomly generate a point cloud of arbitary type #5102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions common/include/pcl/common/generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,101 @@ namespace pcl
GeneratorT x_generator_;
GeneratorT y_generator_;
};

/**
* @brief Allows generation of a point cloud using a random point generator
*
* @tparam PointT Type of point cloud (eg: PointNormal, PointXYZRGB, etc.)
* @tparam GeneratorT A generator following the generator classes as shown in \file common/random.h
*/
template <typename PointT, typename GeneratorT>
class PointCloudGenerator {
public:
using GeneratorParameters = typename GeneratorT::Parameters;

/// Default constructor
PointCloudGenerator() : point_generator_() {}

/**
* \brief Constructor with a generator to fill a cloud
* \details Uniqueness is ensured by incrementing the seed
* \param params parameters for point generation.
*/
PointCloudGenerator(const GeneratorParameters& params) : point_generator_(params)
{}

/** Set parameters for point generation
* \param x_params parameters for point generation
*/
void
setParameters(const GeneratorParameters& pt_params)
{
point_generator_.setParameters(pt_params);
}

/// \return Point generation parameters
const GeneratorParameters&
getParameters() const
{
return point_generator_.getParameters();
}

/// \return a single random generated point
PointT
get()
{
return point_generator_.run();
}

/**
* \brief Generates a cloud with the supplied generator and parameters.
* \note This function assumes that cloud is properly defined
* \param[out] cloud cloud to generate coordinates for
* \return 0 if generation went well else -1.
*/
int
fill(pcl::PointCloud<PointT>& cloud)
{
return fill(cloud.width, cloud.height, cloud);
}

/**
* \brief Generates a cloud with the supplied generator and parameters.
* \param[in] width width of generated cloud
* \param[in] height height of generated cloud
* \param[out] cloud output cloud
* \return 0 if generation went well else -1.
*/
int
fill(int width, int height, pcl::PointCloud<PointT>& cloud)
{
if (width < 1) {
PCL_ERROR("[pcl::common::CloudGenerator] Cloud width must be >= 1!\n");
return (-1);
}

if (height < 1) {
PCL_ERROR("[pcl::common::CloudGenerator] Cloud height must be >= 1!\n");
return (-1);
}

if (!cloud.empty()) {
PCL_WARN("[pcl::common::CloudGenerator] Cloud data will be erased with new "
"data!\n");
}

cloud.resize(width, height);
cloud.is_dense = true;

for (auto& point : cloud) {
point = point_generator_.run();
}
return (0);
}

private:
GeneratorT point_generator_;
};
}
}

Expand Down