Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sac_model_parallel_line.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id: sac_model_parallel_line.hpp 5026 2012-03-12 02:51:44Z rusu $
35  *
36  */
37 
38 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PARALLEL_LINE_H_
39 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PARALLEL_LINE_H_
40 
42 
44 template <typename PointT> void
46  const Eigen::VectorXf &model_coefficients, const double threshold, std::vector<int> &inliers)
47 {
48  // Check if the model is valid given the user constraints
49  if (!isModelValid (model_coefficients))
50  {
51  inliers.clear ();
52  return;
53  }
54 
55  SampleConsensusModelLine<PointT>::selectWithinDistance (model_coefficients, threshold, inliers);
56 }
57 
59 template <typename PointT> int
61  const Eigen::VectorXf &model_coefficients, const double threshold)
62 {
63  // Check if the model is valid given the user constraints
64  if (!isModelValid (model_coefficients))
65  return (0);
66 
67  return (SampleConsensusModelLine<PointT>::countWithinDistance (model_coefficients, threshold));
68 }
69 
71 template <typename PointT> void
73  const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
74 {
75  // Check if the model is valid given the user constraints
76  if (!isModelValid (model_coefficients))
77  {
78  distances.clear ();
79  return;
80  }
81 
82  SampleConsensusModelLine<PointT>::getDistancesToModel (model_coefficients, distances);
83 }
84 
86 template <typename PointT> bool
87 pcl::SampleConsensusModelParallelLine<PointT>::isModelValid (const Eigen::VectorXf &model_coefficients)
88 {
89  // Needs a valid model coefficients
90  if (model_coefficients.size () != 6)
91  {
92  PCL_ERROR ("[pcl::SampleConsensusParallelLine::isModelValid] Invalid number of model coefficients given (%zu)!\n", model_coefficients.size ());
93  return (false);
94  }
95 
96  // Check against template, if given
97  if (eps_angle_ > 0.0)
98  {
99  // Obtain the line direction
100  Eigen::Vector4f line_dir (model_coefficients[3], model_coefficients[4], model_coefficients[5], 0);
101 
102  Eigen::Vector4f axis (axis_[0], axis_[1], axis_[2], 0);
103  double angle_diff = fabs (getAngle3D (axis, line_dir));
104  //angle_diff = (std::min) (angle_diff, M_PI - angle_diff);
105  angle_diff = fabs (angle_diff - (M_PI/2.0));
106  // Check whether the current plane model satisfies our angle threshold criterion with respect to the given axis
107  if (angle_diff > eps_angle_)
108  return (false);
109  }
110 
111  return (true);
112 }
113 
114 #define PCL_INSTANTIATE_SampleConsensusModelParallelLine(T) template class PCL_EXPORTS pcl::SampleConsensusModelParallelLine<T>;
115 
116 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PARALLEL_LINE_H_
117