sac_model_perpendicular_plane.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  * $Id$
00038  *
00039  */
00040 
00041 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PERPENDICULAR_PLANE_H_
00042 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PERPENDICULAR_PLANE_H_
00043 
00044 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
00045 
00047 template <typename PointT> void
00048 pcl::SampleConsensusModelPerpendicularPlane<PointT>::selectWithinDistance (
00049       const Eigen::VectorXf &model_coefficients, const double threshold, std::vector<int> &inliers)
00050 {
00051   // Check if the model is valid given the user constraints
00052   if (!isModelValid (model_coefficients))
00053   {
00054     inliers.clear ();
00055     return;
00056   }
00057 
00058   SampleConsensusModelPlane<PointT>::selectWithinDistance (model_coefficients, threshold, inliers);
00059 }
00060 
00062 template <typename PointT> int
00063 pcl::SampleConsensusModelPerpendicularPlane<PointT>::countWithinDistance (
00064       const Eigen::VectorXf &model_coefficients, const double threshold)
00065 {
00066   // Check if the model is valid given the user constraints
00067   if (!isModelValid (model_coefficients))
00068     return (0);
00069 
00070   return (SampleConsensusModelPlane<PointT>::countWithinDistance (model_coefficients, threshold));
00071 }
00072 
00074 template <typename PointT> void
00075 pcl::SampleConsensusModelPerpendicularPlane<PointT>::getDistancesToModel (
00076       const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
00077 {
00078   // Check if the model is valid given the user constraints
00079   if (!isModelValid (model_coefficients))
00080   {
00081     distances.clear ();
00082     return;
00083   }
00084 
00085   SampleConsensusModelPlane<PointT>::getDistancesToModel (model_coefficients, distances);
00086 }
00087 
00089 template <typename PointT> bool
00090 pcl::SampleConsensusModelPerpendicularPlane<PointT>::isModelValid (const Eigen::VectorXf &model_coefficients)
00091 {
00092   // Needs a valid model coefficients
00093   if (model_coefficients.size () != 4)
00094   {
00095     PCL_ERROR ("[pcl::SampleConsensusModelPerpendicularPlane::isModelValid] Invalid number of model coefficients given (%zu)!\n", model_coefficients.size ());
00096     return (false);
00097   }
00098 
00099   // Check against template, if given
00100   if (eps_angle_ > 0.0)
00101   {
00102     // Obtain the plane normal
00103     Eigen::Vector4f coeff = model_coefficients;
00104     coeff[3] = 0;
00105 
00106     Eigen::Vector4f axis (axis_[0], axis_[1], axis_[2], 0);
00107     double angle_diff = fabs (getAngle3D (axis, coeff));
00108     angle_diff = (std::min) (angle_diff, M_PI - angle_diff);
00109     // Check whether the current plane model satisfies our angle threshold criterion with respect to the given axis
00110     if (angle_diff > eps_angle_)
00111       return (false);
00112   }
00113 
00114   return (true);
00115 }
00116 
00117 #define PCL_INSTANTIATE_SampleConsensusModelPerpendicularPlane(T) template class PCL_EXPORTS pcl::SampleConsensusModelPerpendicularPlane<T>;
00118 
00119 #endif    // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PERPENDICULAR_PLANE_H_
00120 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:32:17