Loading...
Searching...
No Matches
sac_model_parallel_plane.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
* Copyright (c) 2012-, Open Perception, 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/sample_consensus/sac_model_plane.h>
namespace pcl
{
/** \brief @b SampleConsensusModelParallelPlane defines a model for 3D plane segmentation using additional
* angular constraints. The plane must be parallel to a user-specified axis
* (\ref setAxis) within a user-specified angle threshold (\ref setEpsAngle).
* In other words, the plane <b>normal</b> must be (nearly) <b>perpendicular</b> to the specified axis.
*
* Code example for a plane model, parallel (within a 15 degrees tolerance) with the Z axis:
* \code
* SampleConsensusModelParallelPlane<pcl::PointXYZ> model (cloud);
* model.setAxis (Eigen::Vector3f (0.0, 0.0, 1.0));
* model.setEpsAngle (pcl::deg2rad (15));
* \endcode
*
* \note Please remember that you need to specify an angle > 0 in order to activate the axis-angle constraint!
*
* \author Radu B. Rusu, Nico Blodow
* \ingroup sample_consensus
*/
template <typename PointT>
class SampleConsensusModelParallelPlane : public SampleConsensusModelPlane<PointT>
{
public:
using SampleConsensusModel<PointT>::model_name_;
using PointCloud = typename SampleConsensusModelPlane<PointT>::PointCloud;
using PointCloudPtr = typename SampleConsensusModelPlane<PointT>::PointCloudPtr;
using PointCloudConstPtr = typename SampleConsensusModelPlane<PointT>::PointCloudConstPtr;
using Ptr = shared_ptr<SampleConsensusModelParallelPlane<PointT> >;
using ConstPtr = shared_ptr<const SampleConsensusModelParallelPlane<PointT>>;
/** \brief Constructor for base SampleConsensusModelParallelPlane.
* \param[in] cloud the input point cloud dataset
* \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
*/
SampleConsensusModelParallelPlane (const PointCloudConstPtr &cloud,
bool random = false)
: SampleConsensusModelPlane<PointT> (cloud, random)
, axis_ (Eigen::Vector3f::Zero ())
, eps_angle_ (0.0)
, sin_angle_ (-1.0)
{
model_name_ = "SampleConsensusModelParallelPlane";
sample_size_ = 3;
model_size_ = 4;
}
/** \brief Constructor for base SampleConsensusModelParallelPlane.
* \param[in] cloud the input point cloud dataset
* \param[in] indices a vector of point indices to be used from \a cloud
* \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
*/
SampleConsensusModelParallelPlane (const PointCloudConstPtr &cloud,
const Indices &indices,
bool random = false)
: SampleConsensusModelPlane<PointT> (cloud, indices, random)
, axis_ (Eigen::Vector3f::Zero ())
, eps_angle_ (0.0)
, sin_angle_ (-1.0)
{
model_name_ = "SampleConsensusModelParallelPlane";
sample_size_ = 3;
model_size_ = 4;
}
/** \brief Empty destructor */
~SampleConsensusModelParallelPlane () override = default;
/** \brief Set the axis along which we need to search for a plane perpendicular to.
* \param[in] ax the axis along which we need to search for a plane perpendicular to
*/
inline void
setAxis (const Eigen::Vector3f &ax) { axis_ = ax; }
/** \brief Get the axis along which we need to search for a plane perpendicular to. */
inline Eigen::Vector3f
getAxis () const { return (axis_); }
/** \brief Set the angle epsilon (delta) threshold.
* \param[in] ea the maximum allowed difference between the plane normal and the given axis.
* \note You need to specify an angle > 0 in order to activate the axis-angle constraint!
*/
inline void
setEpsAngle (const double ea) { eps_angle_ = ea; sin_angle_ = std::abs (sin (ea));}
/** \brief Get the angle epsilon (delta) threshold. */
inline double
getEpsAngle () const { return (eps_angle_); }
/** \brief Select all the points which respect the given model coefficients as inliers.
* \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
* \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
* \param[out] inliers the resultant model inliers
*/
void
selectWithinDistance (const Eigen::VectorXf &model_coefficients,
const double threshold,
Indices &inliers) override;
/** \brief Count all the points which respect the given model coefficients as inliers.
*
* \param[in] model_coefficients the coefficients of a model that we need to compute distances to
* \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
* \return the resultant number of inliers
*/
std::size_t
countWithinDistance (const Eigen::VectorXf &model_coefficients,
const double threshold) const override;
/** \brief Compute all distances from the cloud data to a given plane model.
* \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
* \param[out] distances the resultant estimated distances
*/
void
getDistancesToModel (const Eigen::VectorXf &model_coefficients,
std::vector<double> &distances) const override;
/** \brief Return a unique id for this model (SACMODEL_PARALLEL_PLANE). */
inline pcl::SacModel
getModelType () const override { return (SACMODEL_PARALLEL_PLANE); }
protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;
/** \brief Check whether a model is valid given the user constraints.
* \param[in] model_coefficients the set of model coefficients
*/
bool
isModelValid (const Eigen::VectorXf &model_coefficients) const override;
/** \brief The axis along which we need to search for a plane perpendicular to. */
Eigen::Vector3f axis_;
/** \brief The maximum allowed difference between the plane and the given axis. */
double eps_angle_;
/** \brief The sine of the angle*/
double sin_angle_;
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/sample_consensus/impl/sac_model_parallel_plane.hpp>
#endif
pcl::SampleConsensusModel
SampleConsensusModel represents the base model class.
Definition sac_model.h:71
pcl::SampleConsensusModel::sample_size_
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition sac_model.h:589
pcl::SampleConsensusModel::model_name_
std::string model_name_
The model name.
Definition sac_model.h:551
pcl::SampleConsensusModel::model_size_
unsigned int model_size_
The number of coefficients in the model.
Definition sac_model.h:592
pcl::SampleConsensusModelParallelPlane
SampleConsensusModelParallelPlane defines a model for 3D plane segmentation using additional angular ...
Definition sac_model_parallel_plane.h:66
pcl::SampleConsensusModelParallelPlane::Ptr
shared_ptr< SampleConsensusModelParallelPlane< PointT > > Ptr
Definition sac_model_parallel_plane.h:74
pcl::SampleConsensusModelParallelPlane::getEpsAngle
double getEpsAngle() const
Get the angle epsilon (delta) threshold.
Definition sac_model_parallel_plane.h:133
pcl::SampleConsensusModelParallelPlane::isModelValid
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
Definition sac_model_parallel_plane.hpp:92
pcl::SampleConsensusModelParallelPlane::~SampleConsensusModelParallelPlane
~SampleConsensusModelParallelPlane() override=default
Empty destructor.
pcl::SampleConsensusModelParallelPlane::axis_
Eigen::Vector3f axis_
The axis along which we need to search for a plane perpendicular to.
Definition sac_model_parallel_plane.h:178
pcl::SampleConsensusModelParallelPlane::eps_angle_
double eps_angle_
The maximum allowed difference between the plane and the given axis.
Definition sac_model_parallel_plane.h:181
pcl::SampleConsensusModelParallelPlane::PointCloudConstPtr
typename SampleConsensusModelPlane< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition sac_model_parallel_plane.h:72
pcl::SampleConsensusModelParallelPlane::sin_angle_
double sin_angle_
The sine of the angle.
Definition sac_model_parallel_plane.h:184
pcl::SampleConsensusModelParallelPlane::PointCloud
typename SampleConsensusModelPlane< PointT >::PointCloud PointCloud
Definition sac_model_parallel_plane.h:70
pcl::SampleConsensusModelParallelPlane::setEpsAngle
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
Definition sac_model_parallel_plane.h:129
pcl::SampleConsensusModelParallelPlane::SampleConsensusModelParallelPlane
SampleConsensusModelParallelPlane(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelParallelPlane.
Definition sac_model_parallel_plane.h:98
pcl::SampleConsensusModelParallelPlane::getAxis
Eigen::Vector3f getAxis() const
Get the axis along which we need to search for a plane perpendicular to.
Definition sac_model_parallel_plane.h:122
pcl::SampleConsensusModelParallelPlane::countWithinDistance
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
Definition sac_model_parallel_plane.hpp:63
pcl::SampleConsensusModelParallelPlane::getDistancesToModel
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given plane model.
Definition sac_model_parallel_plane.hpp:77
pcl::SampleConsensusModelParallelPlane::ConstPtr
shared_ptr< const SampleConsensusModelParallelPlane< PointT > > ConstPtr
Definition sac_model_parallel_plane.h:75
pcl::SampleConsensusModelParallelPlane::SampleConsensusModelParallelPlane
SampleConsensusModelParallelPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelParallelPlane.
Definition sac_model_parallel_plane.h:81
pcl::SampleConsensusModelParallelPlane::setAxis
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a plane perpendicular to.
Definition sac_model_parallel_plane.h:118
pcl::SampleConsensusModelParallelPlane::getModelType
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_PARALLEL_PLANE).
Definition sac_model_parallel_plane.h:165
pcl::SampleConsensusModelParallelPlane::selectWithinDistance
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
Definition sac_model_parallel_plane.hpp:48
pcl::SampleConsensusModelParallelPlane::PointCloudPtr
typename SampleConsensusModelPlane< PointT >::PointCloudPtr PointCloudPtr
Definition sac_model_parallel_plane.h:71
pcl::SampleConsensusModelPlane
SampleConsensusModelPlane defines a model for 3D plane segmentation.
Definition sac_model_plane.h:143
pcl::SampleConsensusModelPlane::PointCloud
typename SampleConsensusModel< PointT >::PointCloud PointCloud
Definition sac_model_plane.h:151
pcl::SampleConsensusModelPlane::PointCloudConstPtr
typename SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition sac_model_plane.h:153
pcl::SampleConsensusModelPlane::PointCloudPtr
typename SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
Definition sac_model_plane.h:152
Eigen
Definition bfgs.h:10
pcl
Definition convolution.h:46
pcl::SacModel
SacModel
Definition model_types.h:46
pcl::SACMODEL_PARALLEL_PLANE
@ SACMODEL_PARALLEL_PLANE
Definition model_types.h:62
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition point_types.hpp:623