Loading...
Searching...
No Matches
generate.hpp
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2012, Willow Garage, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
#pragma once
#include <pcl/common/generate.h>
#include <pcl/console/print.h>
namespace pcl
{
namespace common
{
template <typename PointT, typename GeneratorT>
CloudGenerator<PointT, GeneratorT>::CloudGenerator ()
: x_generator_ ()
, y_generator_ ()
, z_generator_ ()
{}
template <typename PointT, typename GeneratorT>
CloudGenerator<PointT, GeneratorT>::CloudGenerator (const GeneratorParameters& params)
{
setParameters (params);
}
template <typename PointT, typename GeneratorT>
CloudGenerator<PointT, GeneratorT>::CloudGenerator (const GeneratorParameters& x_params,
const GeneratorParameters& y_params,
const GeneratorParameters& z_params)
: x_generator_ (x_params)
, y_generator_ (y_params)
, z_generator_ (z_params)
{}
template <typename PointT, typename GeneratorT> void
CloudGenerator<PointT, GeneratorT>::setParameters (const GeneratorParameters& params)
{
GeneratorParameters y_params = params;
y_params.seed += 1;
GeneratorParameters z_params = y_params;
z_params.seed += 1;
x_generator_.setParameters (params);
y_generator_.setParameters (y_params);
z_generator_.setParameters (z_params);
}
template <typename PointT, typename GeneratorT> void
CloudGenerator<PointT, GeneratorT>::setParametersForX (const GeneratorParameters& x_params)
{
x_generator_.setParameters (x_params);
}
template <typename PointT, typename GeneratorT> void
CloudGenerator<PointT, GeneratorT>::setParametersForY (const GeneratorParameters& y_params)
{
y_generator_.setParameters (y_params);
}
template <typename PointT, typename GeneratorT> void
CloudGenerator<PointT, GeneratorT>::setParametersForZ (const GeneratorParameters& z_params)
{
z_generator_.setParameters (z_params);
}
template <typename PointT, typename GeneratorT> const typename CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
CloudGenerator<PointT, GeneratorT>::getParametersForX () const
{
return x_generator_.getParameters ();
}
template <typename PointT, typename GeneratorT> const typename CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
CloudGenerator<PointT, GeneratorT>::getParametersForY () const
{
return y_generator_.getParameters ();
}
template <typename PointT, typename GeneratorT> const typename CloudGenerator<PointT, GeneratorT>::GeneratorParameters&
CloudGenerator<PointT, GeneratorT>::getParametersForZ () const
{
return z_generator_.getParameters ();
}
template <typename PointT, typename GeneratorT> PointT
CloudGenerator<PointT, GeneratorT>::get ()
{
PointT p;
p.x = x_generator_.run ();
p.y = y_generator_.run ();
p.z = z_generator_.run ();
return (p);
}
template <typename PointT, typename GeneratorT> int
CloudGenerator<PointT, GeneratorT>::fill (pcl::PointCloud<PointT>& cloud)
{
return (fill (cloud.width, cloud.height, cloud));
}
template <typename PointT, typename GeneratorT> int
CloudGenerator<PointT, GeneratorT>::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.width = width;
cloud.height = height;
cloud.resize (cloud.width * cloud.height);
cloud.is_dense = true;
for (auto& point: cloud)
{
point.x = x_generator_.run ();
point.y = y_generator_.run ();
point.z = z_generator_.run ();
}
return (0);
}
template <typename GeneratorT>
CloudGenerator<pcl::PointXY, GeneratorT>::CloudGenerator ()
: x_generator_ ()
, y_generator_ ()
{}
template <typename GeneratorT>
CloudGenerator<pcl::PointXY, GeneratorT>::CloudGenerator (const GeneratorParameters& x_params,
const GeneratorParameters& y_params)
: x_generator_ (x_params)
, y_generator_ (y_params)
{}
template <typename GeneratorT>
CloudGenerator<pcl::PointXY, GeneratorT>::CloudGenerator (const GeneratorParameters& params)
{
setParameters (params);
}
template <typename GeneratorT> void
CloudGenerator<pcl::PointXY, GeneratorT>::setParameters (const GeneratorParameters& params)
{
x_generator_.setParameters (params);
GeneratorParameters y_params = params;
y_params.seed += 1;
y_generator_.setParameters (y_params);
}
template <typename GeneratorT> void
CloudGenerator<pcl::PointXY, GeneratorT>::setParametersForX (const GeneratorParameters& x_params)
{
x_generator_.setParameters (x_params);
}
template <typename GeneratorT> void
CloudGenerator<pcl::PointXY, GeneratorT>::setParametersForY (const GeneratorParameters& y_params)
{
y_generator_.setParameters (y_params);
}
template <typename GeneratorT> const typename CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
CloudGenerator<pcl::PointXY, GeneratorT>::getParametersForX () const
{
return x_generator_.getParameters ();
}
template <typename GeneratorT> const typename CloudGenerator<pcl::PointXY, GeneratorT>::GeneratorParameters&
CloudGenerator<pcl::PointXY, GeneratorT>::getParametersForY () const
{
return y_generator_.getParameters ();
}
template <typename GeneratorT> pcl::PointXY
CloudGenerator<pcl::PointXY, GeneratorT>::get ()
{
pcl::PointXY p;
p.x = x_generator_.run ();
p.y = y_generator_.run ();
return (p);
}
template <typename GeneratorT> int
CloudGenerator<pcl::PointXY, GeneratorT>::fill (pcl::PointCloud<pcl::PointXY>& cloud)
{
return (fill (cloud.width, cloud.height, cloud));
}
template <typename GeneratorT> int
CloudGenerator<pcl::PointXY, GeneratorT>::fill (int width, int height, pcl::PointCloud<pcl::PointXY>& 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.x = x_generator_.run ();
point.y = y_generator_.run ();
}
return (0);
}
} // namespace common
} // namespace pcl
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 &params)
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 &params)
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