40 #ifndef PCL_FILTERS_CONVOLUTION_3D_IMPL_HPP
41 #define PCL_FILTERS_CONVOLUTION_3D_IMPL_HPP
43 #include <pcl/search/organized.h>
44 #include <pcl/search/kdtree.h>
45 #include <pcl/pcl_config.h>
58 template <
typename Po
intT>
64 n.normal_x = n.normal_y = n.normal_z = std::numeric_limits<float>::quiet_NaN ();
68 template <
typename Po
intT>
class
74 p.
x = p.
y = std::numeric_limits<float>::quiet_NaN ();
81 template<
typename Po
intInT,
typename Po
intOutT>
bool
86 PCL_ERROR (
"Sigma is not set or equal to 0!\n", sigma_);
89 sigma_sqr_ = sigma_ * sigma_;
91 if (sigma_coefficient_)
93 if ((*sigma_coefficient_) > 6 || (*sigma_coefficient_) < 3)
95 PCL_ERROR (
"Sigma coefficient (%f) out of [3..6]!\n", (*sigma_coefficient_));
99 threshold_ = (*sigma_coefficient_) * (*sigma_coefficient_) * sigma_sqr_;
106 template<
typename Po
intInT,
typename Po
intOutT> PointOutT
108 const std::vector<float>& distances)
112 float total_weight = 0;
113 std::vector<float>::const_iterator dist_it = distances.begin ();
115 for (Indices::const_iterator idx_it = indices.begin ();
116 idx_it != indices.end ();
119 if (*dist_it <= threshold_ &&
isFinite ((*input_) [*idx_it]))
121 float weight = std::exp (-0.5f * (*dist_it) / sigma_sqr_);
122 result += weight * (*input_) [*idx_it];
123 total_weight += weight;
126 if (total_weight != 0)
127 result /= total_weight;
129 makeInfinite (result);
135 template<
typename Po
intInT,
typename Po
intOutT> PointOutT
140 float total_weight = 0;
141 float r = 0, g = 0, b = 0;
142 std::vector<float>::const_iterator dist_it = distances.begin ();
144 for (Indices::const_iterator idx_it = indices.begin ();
145 idx_it != indices.end ();
148 if (*dist_it <= threshold_ &&
isFinite ((*input_) [*idx_it]))
150 float weight = std::exp (-0.5f * (*dist_it) / sigma_sqr_);
151 result.x += weight * (*input_) [*idx_it].x;
152 result.y += weight * (*input_) [*idx_it].y;
153 result.z += weight * (*input_) [*idx_it].z;
154 r += weight *
static_cast<float> ((*input_) [*idx_it].r);
155 g += weight *
static_cast<float> ((*input_) [*idx_it].g);
156 b += weight *
static_cast<float> ((*input_) [*idx_it].b);
157 total_weight += weight;
160 if (total_weight != 0)
162 total_weight = 1.f/total_weight;
163 r*= total_weight; g*= total_weight; b*= total_weight;
164 result.x*= total_weight; result.y*= total_weight; result.z*= total_weight;
165 result.r =
static_cast<std::uint8_t
> (r);
166 result.g =
static_cast<std::uint8_t
> (g);
167 result.b =
static_cast<std::uint8_t
> (b);
170 makeInfinite (result);
176 template <
typename Po
intInT,
typename Po
intOutT,
typename KernelT>
185 template <
typename Po
intInT,
typename Po
intOutT,
typename KernelT>
bool
190 PCL_ERROR (
"[pcl::filters::Convlution3D::initCompute] init failed!\n");
196 if (input_->isOrganized ())
205 tree_->setInputCloud (surface_);
207 if (search_radius_ <= 0.0)
209 PCL_ERROR (
"[pcl::filters::Convlution3D::initCompute] search radius (%f) must be > 0\n",
216 PCL_ERROR (
"[pcl::filters::Convlution3D::initCompute] init failed : ");
217 PCL_ERROR (
"kernel_ must implement ConvolvingKernel interface\n!");
220 kernel_.setInputCloud (surface_);
222 if (!kernel_.initCompute ())
224 PCL_ERROR (
"[pcl::filters::Convlution3D::initCompute] kernel initialization failed!\n");
231 template <
typename Po
intInT,
typename Po
intOutT,
typename KernelT>
void
236 PCL_ERROR (
"[pcl::filters::Convlution3D::convolve] init failed!\n");
239 output.
resize (surface_->size ());
240 output.
width = surface_->width;
241 output.
height = surface_->height;
242 output.
is_dense = surface_->is_dense;
244 std::vector<float> nn_distances;
246 #pragma omp parallel for \
249 firstprivate(nn_indices, nn_distances) \
250 num_threads(threads_)
251 for (std::int64_t point_idx = 0; point_idx < static_cast<std::int64_t> (surface_->size ()); ++point_idx)
253 const PointInT& point_in = surface_->points [point_idx];
254 PointOutT& point_out = output [point_idx];
256 tree_->radiusSearch (point_in, search_radius_, nn_indices, nn_distances))
258 point_out = kernel_ (nn_indices, nn_distances);
262 kernel_.makeInfinite (point_out);
PointCloud represents the base class in PCL for storing collections of 3D points.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
void resize(std::size_t count)
Resizes the container to contain count elements.
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
bool initCompute()
initialize computation
void convolve(PointCloudOut &output)
Convolve point cloud.
Convolution3D()
Constructor.
Class ConvolvingKernel base class for all convolving kernels.
static void makeInfinite(PointOutT &p)
Utility function that annihilates a point making it fail the pcl::isFinite test.
virtual PointOutT operator()(const Indices &indices, const std::vector< float > &distances)
Convolve point at the center of this local information.
bool initCompute()
Must call this method before doing any computation.
PointOutT operator()(const Indices &indices, const std::vector< float > &distances)
Convolve point at the center of this local information.
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
OrganizedNeighbor is a class for optimized nearest neighbor search in organized point clouds.
Defines all the PCL implemented PointT point type structures.
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
IndicesAllocator<> Indices
Type used for indices in PCL.
A point structure representing normal coordinates and the surface curvature estimate.
A 2D point structure representing Euclidean xy coordinates.
A point structure representing Euclidean xyz coordinates, and the RGB color.