Point Cloud Library (PCL) 1.14.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
68 using Ptr = shared_ptr<PlaneRefinementComparator<PointT, PointNT, PointLT> >;
69 using ConstPtr = shared_ptr<const PlaneRefinementComparator<PointT, PointNT, PointLT> >;
70
75
76
77 /** \brief Empty constructor for PlaneCoefficientComparator. */
79 : labels_ ()
80 , depth_dependent_ (false)
81 {
82 }
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_ ()
92 , refine_labels_ (refine_labels)
93 , depth_dependent_ (false)
94 {
95 }
96
97 /** \brief Destructor for PlaneCoefficientComparator. */
98 ~PlaneRefinementComparator () override = default;
99
100 /** \brief Set the vector of model coefficients to which we will compare.
101 * \param[in] models a vector of model coefficients produced by the initial segmentation step.
102 */
103 void
104 setModelCoefficients (shared_ptr<std::vector<pcl::ModelCoefficients> >& models)
105 {
106 models_ = models;
107 }
108
109 /** \brief Set the vector of model coefficients to which we will compare.
110 * \param[in] models a vector of model coefficients produced by the initial segmentation step.
111 */
112 void
113 setModelCoefficients (std::vector<pcl::ModelCoefficients>& models)
114 {
115 models_ = pcl::make_shared<std::vector<pcl::ModelCoefficients> >(models);
116 }
117
118 /** \brief Set which labels should be refined. This is a vector of bools 0-max_label, true if the label should be refined.
119 * \param[in] refine_labels A vector of bools 0-max_label, true if the label should be refined.
120 */
121 void
122 setRefineLabels (shared_ptr<std::vector<bool> >& refine_labels)
123 {
124 refine_labels_ = refine_labels;
125 }
126
127 /** \brief Set which labels should be refined. This is a vector of bools 0-max_label, true if the label should be refined.
128 * \param[in] refine_labels A vector of bools 0-max_label, true if the label should be refined.
129 */
130 void
131 setRefineLabels (std::vector<bool>& refine_labels)
132 {
133 refine_labels_ = pcl::make_shared<std::vector<bool> >(refine_labels);
134 }
135
136 /** \brief A mapping from label to index in the vector of models, allowing the model coefficients of a label to be accessed.
137 * \param[in] label_to_model A vector of size max_label, with the index of each corresponding model in models
138 */
139 inline void
140 setLabelToModel (shared_ptr<std::vector<int> >& label_to_model)
141 {
142 label_to_model_ = label_to_model;
143 }
144
145 /** \brief A mapping from label to index in the vector of models, allowing the model coefficients of a label to be accessed.
146 * \param[in] label_to_model A vector of size max_label, with the index of each corresponding model in models
147 */
148 inline void
149 setLabelToModel (std::vector<int>& label_to_model)
150 {
151 label_to_model_ = pcl::make_shared<std::vector<int> >(label_to_model);
152 }
153
154 /** \brief Get the vector of model coefficients to which we will compare. */
155 inline shared_ptr<std::vector<pcl::ModelCoefficients> >
157 {
158 return (models_);
159 }
160
161 /** \brief ...
162 * \param[in] labels
163 */
164 inline void
166 {
167 labels_ = labels;
168 }
169
170 /** \brief Compare two neighboring points
171 * \param[in] idx1 The index of the first point.
172 * \param[in] idx2 The index of the second point.
173 */
174 bool
175 compare (int idx1, int idx2) const override
176 {
177 int current_label = (*labels_)[idx1].label;
178 int next_label = (*labels_)[idx2].label;
179
180 if (!((*refine_labels_)[current_label] && !(*refine_labels_)[next_label]))
181 return (false);
182
183 const pcl::ModelCoefficients& model_coeff = (*models_)[(*label_to_model_)[current_label]];
184
185 PointT pt = (*input_)[idx2];
186 double ptp_dist = std::fabs (model_coeff.values[0] * pt.x +
187 model_coeff.values[1] * pt.y +
188 model_coeff.values[2] * pt.z +
189 model_coeff.values[3]);
190
191 // depth dependent
192 float threshold = distance_threshold_;
194 {
195 //Eigen::Vector4f origin = input_->sensor_origin_;
196 Eigen::Vector3f vec = (*input_)[idx1].getVector3fMap ();// - origin.head<3> ();
197
198 float z = vec.dot (z_axis_);
199 threshold *= z * z;
200 }
201
202 return (ptp_dist < threshold);
203 }
204
205 protected:
206 shared_ptr<std::vector<pcl::ModelCoefficients> > models_;
208 shared_ptr<std::vector<bool> > refine_labels_;
209 shared_ptr<std::vector<int> > label_to_model_;
212 };
213}
PointCloudConstPtr input_
Definition comparator.h:98
typename PointCloud::ConstPtr PointCloudConstPtr
Definition comparator.h:59
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.
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() override=default
Destructor for PlaneCoefficientComparator.
PlaneRefinementComparator()
Empty constructor for PlaneCoefficientComparator.
shared_ptr< const PlaneRefinementComparator< PointT, PointNT, PointLT > > ConstPtr
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.
std::vector< float > values
A point structure representing Euclidean xyz coordinates, and the RGB color.