Point Cloud Library (PCL)
1.12.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
segmentation
organized_connected_component_segmentation.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
*
37
*
38
*/
39
40
#pragma once
41
42
#include <pcl/pcl_base.h>
43
#include <pcl/PointIndices.h>
44
#include <pcl/segmentation/comparator.h>
45
46
namespace
pcl
47
{
48
/** \brief OrganizedConnectedComponentSegmentation allows connected
49
* components to be found within organized point cloud data, given a
50
* comparison function. Given an input cloud and a comparator, it will
51
* output a PointCloud of labels, giving each connected component a unique
52
* id, along with a vector of PointIndices corresponding to each component.
53
* See OrganizedMultiPlaneSegmentation for an example application.
54
*
55
* \author Alex Trevor, Suat Gedikli
56
*/
57
template
<
typename
Po
int
T,
typename
Po
int
LT>
58
class
OrganizedConnectedComponentSegmentation
:
public
PCLBase
<PointT>
59
{
60
using
PCLBase
<PointT>
::input_
;
61
using
PCLBase
<PointT>
::indices_
;
62
using
PCLBase
<PointT>
::initCompute
;
63
using
PCLBase
<PointT>
::deinitCompute
;
64
65
public
:
66
using
PointCloud
=
pcl::PointCloud<PointT>
;
67
using
PointCloudPtr
=
typename
PointCloud::Ptr
;
68
using
PointCloudConstPtr
=
typename
PointCloud::ConstPtr
;
69
70
using
PointCloudL
=
pcl::PointCloud<PointLT>
;
71
using
PointCloudLPtr
=
typename
PointCloudL::Ptr
;
72
using
PointCloudLConstPtr
=
typename
PointCloudL::ConstPtr
;
73
74
using
Comparator
=
pcl::Comparator<PointT>
;
75
using
ComparatorPtr
=
typename
Comparator::Ptr
;
76
using
ComparatorConstPtr
=
typename
Comparator::ConstPtr
;
77
78
/** \brief Constructor for OrganizedConnectedComponentSegmentation
79
* \param[in] compare A pointer to the comparator to be used for segmentation. Must be an instance of pcl::Comparator.
80
*/
81
OrganizedConnectedComponentSegmentation
(
const
ComparatorConstPtr
& compare)
82
:
compare_
(compare)
83
{
84
}
85
86
/** \brief Destructor for OrganizedConnectedComponentSegmentation. */
87
88
~OrganizedConnectedComponentSegmentation
()
89
{
90
}
91
92
/** \brief Provide a pointer to the comparator to be used for segmentation.
93
* \param[in] compare the comparator
94
*/
95
void
96
setComparator
(
const
ComparatorConstPtr
& compare)
97
{
98
compare_
= compare;
99
}
100
101
/** \brief Get the comparator.*/
102
ComparatorConstPtr
103
getComparator
()
const
{
return
(
compare_
); }
104
105
/** \brief Perform the connected component segmentation.
106
* \param[out] labels a PointCloud of labels: each connected component will have a unique id.
107
* \param[out] label_indices a vector of PointIndices corresponding to each label / component id.
108
*/
109
void
110
segment
(
pcl::PointCloud<PointLT>
& labels, std::vector<pcl::PointIndices>& label_indices)
const
;
111
112
/** \brief Find the boundary points / contour of a connected component
113
* \param[in] start_idx the first (lowest) index of the connected component for which a boundary should be returned
114
* \param[in] labels the Label cloud produced by segmentation
115
* \param[out] boundary_indices the indices of the boundary points for the label corresponding to start_idx
116
*/
117
static
void
118
findLabeledRegionBoundary
(
int
start_idx,
PointCloudLPtr
labels,
pcl::PointIndices
& boundary_indices);
119
120
121
protected
:
122
ComparatorConstPtr
compare_
;
123
124
inline
unsigned
125
findRoot
(
const
std::vector<unsigned>& runs,
unsigned
index)
const
126
{
127
unsigned
idx = index;
128
while
(runs[idx] != idx)
129
idx = runs[idx];
130
131
return
(idx);
132
}
133
134
private
:
135
struct
Neighbor
136
{
137
Neighbor (
int
dx,
int
dy,
int
didx)
138
: d_x (dx)
139
, d_y (dy)
140
, d_index (didx)
141
{}
142
143
int
d_x;
144
int
d_y;
145
int
d_index;
// = dy * width + dx: pre-calculated
146
};
147
};
148
}
149
150
#ifdef PCL_NO_PRECOMPILE
151
#include <pcl/segmentation/impl/organized_connected_component_segmentation.hpp>
152
#endif
pcl::Comparator
Comparator is the base class for comparators that compare two points given some function.
Definition
comparator.h:55
pcl::Comparator::Ptr
shared_ptr< Comparator< PointT > > Ptr
Definition
comparator.h:61
pcl::Comparator::ConstPtr
shared_ptr< const Comparator< PointT > > ConstPtr
Definition
comparator.h:62
pcl::OrganizedConnectedComponentSegmentation::findLabeledRegionBoundary
static void findLabeledRegionBoundary(int start_idx, PointCloudLPtr labels, pcl::PointIndices &boundary_indices)
Find the boundary points / contour of a connected component.
Definition
organized_connected_component_segmentation.hpp:53
pcl::OrganizedConnectedComponentSegmentation::~OrganizedConnectedComponentSegmentation
~OrganizedConnectedComponentSegmentation()
Destructor for OrganizedConnectedComponentSegmentation.
Definition
organized_connected_component_segmentation.h:88
pcl::OrganizedConnectedComponentSegmentation::getComparator
ComparatorConstPtr getComparator() const
Get the comparator.
Definition
organized_connected_component_segmentation.h:103
pcl::OrganizedConnectedComponentSegmentation::findRoot
unsigned findRoot(const std::vector< unsigned > &runs, unsigned index) const
Definition
organized_connected_component_segmentation.h:125
pcl::OrganizedConnectedComponentSegmentation::PointCloudLConstPtr
typename PointCloudL::ConstPtr PointCloudLConstPtr
Definition
organized_connected_component_segmentation.h:72
pcl::OrganizedConnectedComponentSegmentation::setComparator
void setComparator(const ComparatorConstPtr &compare)
Provide a pointer to the comparator to be used for segmentation.
Definition
organized_connected_component_segmentation.h:96
pcl::OrganizedConnectedComponentSegmentation::PointCloudLPtr
typename PointCloudL::Ptr PointCloudLPtr
Definition
organized_connected_component_segmentation.h:71
pcl::OrganizedConnectedComponentSegmentation::segment
void segment(pcl::PointCloud< PointLT > &labels, std::vector< pcl::PointIndices > &label_indices) const
Perform the connected component segmentation.
Definition
organized_connected_component_segmentation.hpp:118
pcl::OrganizedConnectedComponentSegmentation::compare_
ComparatorConstPtr compare_
Definition
organized_connected_component_segmentation.h:122
pcl::OrganizedConnectedComponentSegmentation::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition
organized_connected_component_segmentation.h:67
pcl::OrganizedConnectedComponentSegmentation::ComparatorConstPtr
typename Comparator::ConstPtr ComparatorConstPtr
Definition
organized_connected_component_segmentation.h:76
pcl::OrganizedConnectedComponentSegmentation::ComparatorPtr
typename Comparator::Ptr ComparatorPtr
Definition
organized_connected_component_segmentation.h:75
pcl::OrganizedConnectedComponentSegmentation::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition
organized_connected_component_segmentation.h:66
pcl::OrganizedConnectedComponentSegmentation::Comparator
pcl::Comparator< PointT > Comparator
Definition
organized_connected_component_segmentation.h:74
pcl::OrganizedConnectedComponentSegmentation::PointCloudL
pcl::PointCloud< PointLT > PointCloudL
Definition
organized_connected_component_segmentation.h:70
pcl::OrganizedConnectedComponentSegmentation::OrganizedConnectedComponentSegmentation
OrganizedConnectedComponentSegmentation(const ComparatorConstPtr &compare)
Constructor for OrganizedConnectedComponentSegmentation.
Definition
organized_connected_component_segmentation.h:81
pcl::OrganizedConnectedComponentSegmentation::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition
organized_connected_component_segmentation.h:68
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition
pcl_base.h:147
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition
pcl_base.h:150
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition
pcl_base.hpp:138
pcl::PCLBase::PCLBase
PCLBase()
Empty constructor.
Definition
pcl_base.hpp:46
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition
pcl_base.hpp:174
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition
point_cloud.h:173
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition
point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition
point_cloud.h:414
pcl
Definition
convolution.h:46
pcl::PointIndices
Definition
PointIndices.h:12