|
39 | 39 |
|
40 | 40 | #pragma once
|
41 | 41 |
|
42 |
| -#include <pcl/point_types.h> |
43 |
| -#include <pcl/point_cloud.h> |
| 42 | +#include <pcl/gpu/containers/device_array.h> |
| 43 | +#include <pcl/gpu/octree/octree.hpp> |
44 | 44 | #include <pcl/PointIndices.h>
|
45 | 45 | #include <pcl/pcl_macros.h>
|
46 |
| -#include <pcl/gpu/octree/octree.hpp> |
47 |
| -#include <pcl/gpu/containers/device_array.h> |
| 46 | +#include <pcl/point_cloud.h> |
| 47 | +#include <pcl/point_types.h> |
48 | 48 |
|
49 |
| -namespace pcl |
50 |
| -{ |
51 |
| - namespace gpu |
| 49 | +namespace pcl { |
| 50 | +namespace gpu { |
| 51 | +template <typename PointT> |
| 52 | +void |
| 53 | +extractEuclideanClusters(const typename pcl::PointCloud<PointT>::Ptr& host_cloud_, |
| 54 | + const pcl::gpu::Octree::Ptr& tree, |
| 55 | + float tolerance, |
| 56 | + std::vector<PointIndices>& clusters, |
| 57 | + unsigned int min_pts_per_cluster, |
| 58 | + unsigned int max_pts_per_cluster); |
| 59 | + |
| 60 | +/** \brief @b EuclideanClusterExtraction represents a segmentation class for cluster |
| 61 | + * extraction in an Euclidean sense, depending on pcl::gpu::octree |
| 62 | + * \author Koen Buys, Radu Bogdan Rusu |
| 63 | + * \ingroup segmentation |
| 64 | + */ |
| 65 | +template <typename PointT> |
| 66 | +class EuclideanClusterExtraction { |
| 67 | +public: |
| 68 | + using PointCloudHost = pcl::PointCloud<PointT>; |
| 69 | + using PointCloudHostPtr = typename PointCloudHost::Ptr; |
| 70 | + using PointCloudHostConstPtr = typename PointCloudHost::ConstPtr; |
| 71 | + |
| 72 | + using PointIndicesPtr = PointIndices::Ptr; |
| 73 | + using PointIndicesConstPtr = PointIndices::ConstPtr; |
| 74 | + |
| 75 | + using GPUTree = pcl::gpu::Octree; |
| 76 | + using GPUTreePtr = pcl::gpu::Octree::Ptr; |
| 77 | + |
| 78 | + using CloudDevice = pcl::gpu::Octree::PointCloud; |
| 79 | + |
| 80 | + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 81 | + /** \brief Empty constructor. */ |
| 82 | + EuclideanClusterExtraction() = default; |
| 83 | + |
| 84 | + /** \brief the destructor */ |
| 85 | + /* ~EuclideanClusterExtraction () |
| 86 | + { |
| 87 | + tree_.clear(); |
| 88 | + }; |
| 89 | + */ |
| 90 | + /** \brief Provide a pointer to the search object. |
| 91 | + * \param tree a pointer to the spatial search object. |
| 92 | + */ |
| 93 | + inline void |
| 94 | + setSearchMethod(GPUTreePtr& tree) |
| 95 | + { |
| 96 | + tree_ = tree; |
| 97 | + } |
| 98 | + |
| 99 | + /** \brief Get a pointer to the search method used. |
| 100 | + * @todo fix this for a generic search tree |
| 101 | + */ |
| 102 | + inline GPUTreePtr |
| 103 | + getSearchMethod() |
| 104 | + { |
| 105 | + return (tree_); |
| 106 | + } |
| 107 | + |
| 108 | + /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space |
| 109 | + * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean |
| 110 | + * space |
| 111 | + */ |
| 112 | + inline void |
| 113 | + setClusterTolerance(double tolerance) |
| 114 | + { |
| 115 | + cluster_tolerance_ = tolerance; |
| 116 | + } |
| 117 | + |
| 118 | + /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. |
| 119 | + */ |
| 120 | + inline double |
| 121 | + getClusterTolerance() |
| 122 | + { |
| 123 | + return (cluster_tolerance_); |
| 124 | + } |
| 125 | + |
| 126 | + /** \brief Set the minimum number of points that a cluster needs to contain in order |
| 127 | + * to be considered valid. |
| 128 | + * \param min_cluster_size the minimum cluster size |
| 129 | + */ |
| 130 | + inline void |
| 131 | + setMinClusterSize(int min_cluster_size) |
| 132 | + { |
| 133 | + min_pts_per_cluster_ = min_cluster_size; |
| 134 | + } |
| 135 | + |
| 136 | + /** \brief Get the minimum number of points that a cluster needs to contain in order |
| 137 | + * to be considered valid. */ |
| 138 | + inline int |
| 139 | + getMinClusterSize() |
52 | 140 | {
|
53 |
| - template <typename PointT> void |
54 |
| - extractEuclideanClusters (const typename pcl::PointCloud<PointT>::Ptr &host_cloud_, |
55 |
| - const pcl::gpu::Octree::Ptr &tree, |
56 |
| - float tolerance, |
57 |
| - std::vector<PointIndices> &clusters, |
58 |
| - unsigned int min_pts_per_cluster, |
59 |
| - unsigned int max_pts_per_cluster); |
60 |
| - |
61 |
| - /** \brief @b EuclideanClusterExtraction represents a segmentation class for cluster extraction in an Euclidean sense, depending on pcl::gpu::octree |
62 |
| - * \author Koen Buys, Radu Bogdan Rusu |
63 |
| - * \ingroup segmentation |
64 |
| - */ |
65 |
| - template <typename PointT> |
66 |
| - class EuclideanClusterExtraction |
67 |
| - { |
68 |
| - public: |
69 |
| - using PointCloudHost = pcl::PointCloud<PointT>; |
70 |
| - using PointCloudHostPtr = typename PointCloudHost::Ptr; |
71 |
| - using PointCloudHostConstPtr = typename PointCloudHost::ConstPtr; |
72 |
| - |
73 |
| - using PointIndicesPtr = PointIndices::Ptr; |
74 |
| - using PointIndicesConstPtr = PointIndices::ConstPtr; |
75 |
| - |
76 |
| - using GPUTree = pcl::gpu::Octree; |
77 |
| - using GPUTreePtr = pcl::gpu::Octree::Ptr; |
78 |
| - |
79 |
| - using CloudDevice = pcl::gpu::Octree::PointCloud; |
80 |
| - |
81 |
| - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
82 |
| - /** \brief Empty constructor. */ |
83 |
| - EuclideanClusterExtraction () = default; |
84 |
| - |
85 |
| - /** \brief the destructor */ |
86 |
| -/* ~EuclideanClusterExtraction () |
87 |
| - { |
88 |
| - tree_.clear(); |
89 |
| - }; |
90 |
| -*/ |
91 |
| - /** \brief Provide a pointer to the search object. |
92 |
| - * \param tree a pointer to the spatial search object. |
93 |
| - */ |
94 |
| - inline void setSearchMethod (GPUTreePtr &tree) { tree_ = tree; } |
95 |
| - |
96 |
| - /** \brief Get a pointer to the search method used. |
97 |
| - * @todo fix this for a generic search tree |
98 |
| - */ |
99 |
| - inline GPUTreePtr getSearchMethod () { return (tree_); } |
100 |
| - |
101 |
| - /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space |
102 |
| - * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space |
103 |
| - */ |
104 |
| - inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; } |
105 |
| - |
106 |
| - /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */ |
107 |
| - inline double getClusterTolerance () { return (cluster_tolerance_); } |
108 |
| - |
109 |
| - /** \brief Set the minimum number of points that a cluster needs to contain in order to be considered valid. |
110 |
| - * \param min_cluster_size the minimum cluster size |
111 |
| - */ |
112 |
| - inline void setMinClusterSize (int min_cluster_size) { min_pts_per_cluster_ = min_cluster_size; } |
113 |
| - |
114 |
| - /** \brief Get the minimum number of points that a cluster needs to contain in order to be considered valid. */ |
115 |
| - inline int getMinClusterSize () { return (min_pts_per_cluster_); } |
116 |
| - |
117 |
| - /** \brief Set the maximum number of points that a cluster needs to contain in order to be considered valid. |
118 |
| - * \param max_cluster_size the maximum cluster size |
119 |
| - */ |
120 |
| - inline void setMaxClusterSize (int max_cluster_size) { max_pts_per_cluster_ = max_cluster_size; } |
121 |
| - |
122 |
| - /** \brief Get the maximum number of points that a cluster needs to contain in order to be considered valid. */ |
123 |
| - inline int getMaxClusterSize () { return (max_pts_per_cluster_); } |
124 |
| - |
125 |
| - inline void setInput (CloudDevice input) {input_ = input;} |
126 |
| - |
127 |
| - inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;} |
128 |
| - |
129 |
| - /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()> |
130 |
| - * \param clusters the resultant point clusters |
131 |
| - */ |
132 |
| - void extract (std::vector<pcl::PointIndices> &clusters); |
133 |
| - |
134 |
| - protected: |
135 |
| - /** \brief the input cloud on the GPU */ |
136 |
| - CloudDevice input_; |
137 |
| - |
138 |
| - /** \brief the original cloud the Host */ |
139 |
| - PointCloudHostPtr host_cloud_; |
140 |
| - |
141 |
| - /** \brief A pointer to the spatial search object. */ |
142 |
| - GPUTreePtr tree_; |
143 |
| - |
144 |
| - /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */ |
145 |
| - double cluster_tolerance_ {0}; |
146 |
| - |
147 |
| - /** \brief The minimum number of points that a cluster needs to contain in order to be considered valid (default = 1). */ |
148 |
| - int min_pts_per_cluster_ {1}; |
149 |
| - |
150 |
| - /** \brief The maximum number of points that a cluster needs to contain in order to be considered valid (default = MAXINT). */ |
151 |
| - int max_pts_per_cluster_ {std::numeric_limits<int>::max()}; |
152 |
| - |
153 |
| - /** \brief Class getName method. */ |
154 |
| - virtual std::string getClassName () const { return ("gpu::EuclideanClusterExtraction"); } |
155 |
| - }; |
156 |
| - /** \brief Sort clusters method (for std::sort). |
157 |
| - * \ingroup segmentation |
158 |
| - */ |
159 |
| - inline bool |
160 |
| - comparePointClusters (const pcl::PointIndices &a, const pcl::PointIndices &b) |
161 |
| - { |
162 |
| - return (a.indices.size () < b.indices.size ()); |
163 |
| - } |
| 141 | + return (min_pts_per_cluster_); |
164 | 142 | }
|
| 143 | + |
| 144 | + /** \brief Set the maximum number of points that a cluster needs to contain in order |
| 145 | + * to be considered valid. |
| 146 | + * \param max_cluster_size the maximum cluster size |
| 147 | + */ |
| 148 | + inline void |
| 149 | + setMaxClusterSize(int max_cluster_size) |
| 150 | + { |
| 151 | + max_pts_per_cluster_ = max_cluster_size; |
| 152 | + } |
| 153 | + |
| 154 | + /** \brief Get the maximum number of points that a cluster needs to contain in order |
| 155 | + * to be considered valid. */ |
| 156 | + inline int |
| 157 | + getMaxClusterSize() |
| 158 | + { |
| 159 | + return (max_pts_per_cluster_); |
| 160 | + } |
| 161 | + |
| 162 | + inline void |
| 163 | + setInput(CloudDevice input) |
| 164 | + { |
| 165 | + input_ = input; |
| 166 | + } |
| 167 | + |
| 168 | + inline void |
| 169 | + setHostCloud(PointCloudHostPtr host_cloud) |
| 170 | + { |
| 171 | + host_cloud_ = host_cloud; |
| 172 | + } |
| 173 | + |
| 174 | + /** \brief extract clusters of a PointCloud given by <setInputCloud(), setIndices()> |
| 175 | + * \param clusters the resultant point clusters |
| 176 | + */ |
| 177 | + void |
| 178 | + extract(std::vector<pcl::PointIndices>& clusters); |
| 179 | + |
| 180 | +protected: |
| 181 | + /** \brief the input cloud on the GPU */ |
| 182 | + CloudDevice input_; |
| 183 | + |
| 184 | + /** \brief the original cloud the Host */ |
| 185 | + PointCloudHostPtr host_cloud_; |
| 186 | + |
| 187 | + /** \brief A pointer to the spatial search object. */ |
| 188 | + GPUTreePtr tree_; |
| 189 | + |
| 190 | + /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */ |
| 191 | + double cluster_tolerance_{0}; |
| 192 | + |
| 193 | + /** \brief The minimum number of points that a cluster needs to contain in order to be |
| 194 | + * considered valid (default = 1). */ |
| 195 | + int min_pts_per_cluster_{1}; |
| 196 | + |
| 197 | + /** \brief The maximum number of points that a cluster needs to contain in order to be |
| 198 | + * considered valid (default = MAXINT). */ |
| 199 | + int max_pts_per_cluster_{std::numeric_limits<int>::max()}; |
| 200 | + |
| 201 | + /** \brief Class getName method. */ |
| 202 | + virtual std::string |
| 203 | + getClassName() const |
| 204 | + { |
| 205 | + return ("gpu::EuclideanClusterExtraction"); |
| 206 | + } |
| 207 | +}; |
| 208 | +/** \brief Sort clusters method (for std::sort). |
| 209 | + * \ingroup segmentation |
| 210 | + */ |
| 211 | +inline bool |
| 212 | +comparePointClusters(const pcl::PointIndices& a, const pcl::PointIndices& b) |
| 213 | +{ |
| 214 | + return (a.indices.size() < b.indices.size()); |
165 | 215 | }
|
| 216 | +} // namespace gpu |
| 217 | +} // namespace pcl |
0 commit comments