Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
plane_refinement_comparator.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2010-2012, Willow Garage, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the copyright holder(s) nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * $Id: extract_clusters.h 5027 2012-03-12 03:10:45Z rusu $
37 *
38 */
39
40#pragma once
41
42#include <pcl/memory.h> // for pcl::make_shared
43#include <pcl/segmentation/plane_coefficient_comparator.h>
44
45namespace pcl
46{
47 /** \brief PlaneRefinementComparator is a Comparator that operates on plane coefficients,
48 * for use in planar segmentation.
49 * In conjunction with OrganizedConnectedComponentSegmentation, this allows planes to be segmented from organized data.
50 *
51 * \author Alex Trevor, Suat Gedikli
52 */
53 template<typename PointT, typename PointNT, typename PointLT>
55 {
56 public:
59
63
65 using PointCloudLPtr = typename PointCloudL::Ptr;
66 using PointCloudLConstPtr = typename PointCloudL::ConstPtr;
67
70
75
76
77 /** \brief Empty constructor for PlaneCoefficientComparator. */
83
84 /** \brief Empty constructor for PlaneCoefficientComparator.
85 * \param[in] models
86 * \param[in] refine_labels
87 */
88 PlaneRefinementComparator (shared_ptr<std::vector<pcl::ModelCoefficients> >& models,
89 shared_ptr<std::vector<bool> >& refine_labels)
90 : models_ (models)
91 , labels_ ()
94 {
95 }
96
97 /** \brief Destructor for PlaneCoefficientComparator. */
101
102 /** \brief Set the vector of model coefficients to which we will compare.
103 * \param[in] models a vector of model coefficients produced by the initial segmentation step.
104 */
105 void
106 setModelCoefficients (shared_ptr<std::vector<pcl::ModelCoefficients> >& models)
107 {
108 models_ = models;
109 }
110
111 /** \brief Set the vector of model coefficients to which we will compare.
112 * \param[in] models a vector of model coefficients produced by the initial segmentation step.
113 */
114 void
115 setModelCoefficients (std::vector<pcl::ModelCoefficients>& models)
116 {
118 }
119
120 /** \brief Set which labels should be refined. This is a vector of bools 0-max_label, true if the label should be refined.
121 * \param[in] refine_labels A vector of bools 0-max_label, true if the label should be refined.
122 */
123 void
124 setRefineLabels (shared_ptr<std::vector<bool> >& refine_labels)
125 {
127 }
128
129 /** \brief Set which labels should be refined. This is a vector of bools 0-max_label, true if the label should be refined.
130 * \param[in] refine_labels A vector of bools 0-max_label, true if the label should be refined.
131 */
132 void
137
138 /** \brief A mapping from label to index in the vector of models, allowing the model coefficients of a label to be accessed.
139 * \param[in] label_to_model A vector of size max_label, with the index of each corresponding model in models
140 */
141 inline void
142 setLabelToModel (shared_ptr<std::vector<int> >& label_to_model)
143 {
145 }
146
147 /** \brief A mapping from label to index in the vector of models, allowing the model coefficients of a label to be accessed.
148 * \param[in] label_to_model A vector of size max_label, with the index of each corresponding model in models
149 */
150 inline void
155
156 /** \brief Get the vector of model coefficients to which we will compare. */
159 {
160 return (models_);
161 }
162
163 /** \brief ...
164 * \param[in] labels
165 */
166 inline void
168 {
169 labels_ = labels;
170 }
171
172 /** \brief Compare two neighboring points
173 * \param[in] idx1 The index of the first point.
174 * \param[in] idx2 The index of the second point.
175 */
176 bool
177 compare (int idx1, int idx2) const override
178 {
179 int current_label = (*labels_)[idx1].label;
180 int next_label = (*labels_)[idx2].label;
181
183 return (false);
184
185 const pcl::ModelCoefficients& model_coeff = (*models_)[(*label_to_model_)[current_label]];
186
187 PointT pt = (*input_)[idx2];
188 double ptp_dist = std::fabs (model_coeff.values[0] * pt.x +
189 model_coeff.values[1] * pt.y +
190 model_coeff.values[2] * pt.z +
191 model_coeff.values[3]);
192
193 // depth dependent
194 float threshold = distance_threshold_;
196 {
197 //Eigen::Vector4f origin = input_->sensor_origin_;
198 Eigen::Vector3f vec = (*input_)[idx1].getVector3fMap ();// - origin.head<3> ();
199
200 float z = vec.dot (z_axis_);
201 threshold *= z * z;
202 }
203
204 return (ptp_dist < threshold);
205 }
206
207 protected:
214 };
215}
PointCloudConstPtr input_
Definition comparator.h:100
typename PointCloud::ConstPtr PointCloudConstPtr
Definition comparator.h:59
Iterator class for point clouds with or without given indices.
PlaneCoefficientComparator is a Comparator that operates on plane coefficients, for use in planar seg...
shared_ptr< std::vector< float > > plane_coeff_d_
PlaneRefinementComparator is a Comparator that operates on plane coefficients, for use in planar segm...
shared_ptr< std::vector< pcl::ModelCoefficients > > models_
void setModelCoefficients(std::vector< pcl::ModelCoefficients > &models)
Set the vector of model coefficients to which we will compare.
void setModelCoefficients(shared_ptr< std::vector< pcl::ModelCoefficients > > &models)
Set the vector of model coefficients to which we will compare.
~PlaneRefinementComparator()
Destructor for PlaneCoefficientComparator.
typename Comparator< PointT >::PointCloud PointCloud
typename PointCloudN::ConstPtr PointCloudNConstPtr
PlaneRefinementComparator(shared_ptr< std::vector< pcl::ModelCoefficients > > &models, shared_ptr< std::vector< bool > > &refine_labels)
Empty constructor for PlaneCoefficientComparator.
shared_ptr< PlaneRefinementComparator< PointT, PointNT, PointLT > > Ptr
shared_ptr< std::vector< int > > label_to_model_
shared_ptr< std::vector< bool > > refine_labels_
PlaneRefinementComparator()
Empty constructor for PlaneCoefficientComparator.
void setLabelToModel(std::vector< int > &label_to_model)
A mapping from label to index in the vector of models, allowing the model coefficients of a label to ...
shared_ptr< std::vector< pcl::ModelCoefficients > > getModelCoefficients() const
Get the vector of model coefficients to which we will compare.
void setRefineLabels(std::vector< bool > &refine_labels)
Set which labels should be refined.
typename Comparator< PointT >::PointCloudConstPtr PointCloudConstPtr
void setRefineLabels(shared_ptr< std::vector< bool > > &refine_labels)
Set which labels should be refined.
void setLabelToModel(shared_ptr< std::vector< int > > &label_to_model)
A mapping from label to index in the vector of models, allowing the model coefficients of a label to ...
void setLabels(PointCloudLPtr &labels)
...
typename PointCloudL::ConstPtr PointCloudLConstPtr
bool compare(int idx1, int idx2) const override
Compare two neighboring points.
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointNT > > Ptr
shared_ptr< const PointCloud< PointNT > > ConstPtr
Defines functions, macros and traits for allocating and using memory.
A point structure representing Euclidean xyz coordinates, and the RGB color.