sac_model_line.h
Go to the documentation of this file.
1  /*
2  * Copyright (c) 2008 Radu Bogdan Rusu <rusu -=- cs.tum.edu>
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: sac_model_line.h 20633 2009-08-04 07:19:09Z tfoote $
28  *
29  */
30 
33 #ifndef _SAMPLE_CONSENSUS_SACMODELLINE_H_
34 #define _SAMPLE_CONSENSUS_SACMODELLINE_H_
35 
36 #include <sac_model.h>
37 #include <model_types.h>
38 
40 #define MAX_ITERATIONS_UNIQUE 1000
41 
42 namespace sample_consensus
43 {
46  class SACModelLine : public SACModel
47  {
48  public:
50 
51  SACModelLine () { }
52 
54 
55  virtual ~SACModelLine () { }
56 
57  virtual void getSamples (int &iterations, std::vector<int> &samples);
58 
60 
64  bool testModelCoefficients (const std::vector<double> &model_coefficients) { return true; }
65 
66  virtual bool computeModelCoefficients (const std::vector<int> &samples);
67 
68  virtual void refitModel (const std::vector<int> &inliers, std::vector<double> &refit_coefficients);
69  virtual void getDistancesToModel (const std::vector<double> &model_coefficients, std::vector<double> &distances);
70  virtual void selectWithinDistance (const std::vector<double> &model_coefficients, double threshold, std::vector<int> &inliers);
71 
72  virtual void projectPoints (const std::vector<int> &inliers, const std::vector<double> &model_coefficients, PointCloud &projected_points);
73 
74  virtual void projectPointsInPlace (const std::vector<int> &inliers, const std::vector<double> &model_coefficients);
75  virtual bool doSamplesVerifyModel (const std::set<int> &indices, double threshold);
76 
78 
79  virtual int getModelType () { return (SACMODEL_LINE); }
80 
82 
86  inline pcl::PointXYZ
87  cross (const pcl::PointXYZ &p1, const pcl::PointXYZ &p2)
88  {
89  pcl::PointXYZ r;
90  r.x = p1.y * p2.z - p1.z * p2.y;
91  r.y = p1.z * p2.x - p1.x * p2.z;
92  r.z = p1.x * p2.y - p1.y * p2.x;
93  return (r);
94  }
95 
97 
102  inline void
103  computeCentroid (const PointCloud &points, const std::vector<int> &indices, pcl::PointXYZ &centroid)
104  {
105  centroid.x = centroid.y = centroid.z = 0;
106  // For each point in the cloud
107  for (unsigned int i = 0; i < indices.size (); i++)
108  {
109  centroid.x += points.points.at (indices.at (i)).x;
110  centroid.y += points.points.at (indices.at (i)).y;
111  centroid.z += points.points.at (indices.at (i)).z;
112  }
113 
114  centroid.x /= indices.size ();
115  centroid.y /= indices.size ();
116  centroid.z /= indices.size ();
117  }
118 
120 
128  inline void
129  computeCovarianceMatrix (const PointCloud &points, const std::vector<int> &indices, Eigen::Matrix3d &covariance_matrix, pcl::PointXYZ &centroid)
130  {
131  computeCentroid (points, indices, centroid);
132 
133  // Initialize to 0
134  covariance_matrix = Eigen::Matrix3d::Zero ();
135 
136  for (unsigned int j = 0; j < indices.size (); j++)
137  {
138  covariance_matrix (0, 0) += (points.points[indices.at (j)].x - centroid.x) * (points.points[indices.at (j)].x - centroid.x);
139  covariance_matrix (0, 1) += (points.points[indices.at (j)].x - centroid.x) * (points.points[indices.at (j)].y - centroid.y);
140  covariance_matrix (0, 2) += (points.points[indices.at (j)].x - centroid.x) * (points.points[indices.at (j)].z - centroid.z);
141 
142  covariance_matrix (1, 0) += (points.points[indices.at (j)].y - centroid.y) * (points.points[indices.at (j)].x - centroid.x);
143  covariance_matrix (1, 1) += (points.points[indices.at (j)].y - centroid.y) * (points.points[indices.at (j)].y - centroid.y);
144  covariance_matrix (1, 2) += (points.points[indices.at (j)].y - centroid.y) * (points.points[indices.at (j)].z - centroid.z);
145 
146  covariance_matrix (2, 0) += (points.points[indices.at (j)].z - centroid.z) * (points.points[indices.at (j)].x - centroid.x);
147  covariance_matrix (2, 1) += (points.points[indices.at (j)].z - centroid.z) * (points.points[indices.at (j)].y - centroid.y);
148  covariance_matrix (2, 2) += (points.points[indices.at (j)].z - centroid.z) * (points.points[indices.at (j)].z - centroid.z);
149  }
150  }
151  };
152 }
153 
154 #endif
virtual bool computeModelCoefficients(const std::vector< int > &samples)
Check whether the given index samples can form a valid line model, compute the model coefficients fro...
virtual void projectPoints(const std::vector< int > &inliers, const std::vector< double > &model_coefficients, PointCloud &projected_points)
Create a new point cloud with inliers projected onto the line model.
pcl::PointCloud< pcl::PointXYZ > PointCloud
Definition: sac_model.h:43
virtual void refitModel(const std::vector< int > &inliers, std::vector< double > &refit_coefficients)
Recompute the line coefficients using the given inlier set and return them to the user...
A Sample Consensus Model class for 3D line segmentation.
TFSIMD_FORCE_INLINE const tfScalar & y() const
virtual ~SACModelLine()
Destructor for base SACModelLine.
bool testModelCoefficients(const std::vector< double > &model_coefficients)
Test whether the given model coefficients are valid given the input point cloud data.
virtual void getSamples(int &iterations, std::vector< int > &samples)
Get 2 random points as data samples and return them as point indices.
void computeCovarianceMatrix(const PointCloud &points, const std::vector< int > &indices, Eigen::Matrix3d &covariance_matrix, pcl::PointXYZ &centroid)
Compute the 3x3 covariance matrix of a given set of points using their indices. The result is returne...
#define SACMODEL_LINE
Definition: model_types.h:37
void computeCentroid(const PointCloud &points, const std::vector< int > &indices, pcl::PointXYZ &centroid)
Compute the centroid of a set of points using their indices and return it as a Point32 message...
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
virtual void projectPointsInPlace(const std::vector< int > &inliers, const std::vector< double > &model_coefficients)
Project inliers (in place) onto the given line model.
pcl::PointXYZ cross(const pcl::PointXYZ &p1, const pcl::PointXYZ &p2)
Compute the cross product between two points (vectors).
SACModelLine()
Constructor for base SACModelLine.
virtual int getModelType()
Return an unique id for this model (SACMODEL_LINE).
virtual void getDistancesToModel(const std::vector< double > &model_coefficients, std::vector< double > &distances)
Compute all distances from the cloud data to a given line model.
virtual void selectWithinDistance(const std::vector< double > &model_coefficients, double threshold, std::vector< int > &inliers)
Select all the points which respect the given model coefficients as inliers.
virtual bool doSamplesVerifyModel(const std::set< int > &indices, double threshold)
Verify whether a subset of indices verifies the internal line model coefficients. ...


semantic_point_annotator
Author(s): Radu Bogdan Rusu
autogenerated on Mon Jun 10 2019 14:29:03