40 #ifndef PCL_FILTERS_IMPL_FAST_BILATERAL_OMP_HPP_
41 #define PCL_FILTERS_IMPL_FAST_BILATERAL_OMP_HPP_
43 #include <pcl/filters/fast_bilateral_omp.h>
44 #include <pcl/common/io.h>
45 #include <pcl/console/time.h>
49 template <
typename Po
intT>
void
52 if (!input_->isOrganized ())
54 PCL_ERROR (
"[pcl::FastBilateralFilterOMP] Input cloud needs to be organized.\n");
59 float base_max = -std::numeric_limits<float>::max (),
60 base_min = std::numeric_limits<float>::max ();
61 bool found_finite =
false;
62 for (
size_t x = 0; x < output.
width; ++x)
64 for (
size_t y = 0; y < output.
height; ++y)
66 if (pcl_isfinite (output (x, y).z))
68 if (base_max < output (x, y).z)
69 base_max = output (x, y).z;
70 if (base_min > output (x, y).z)
71 base_min = output (x, y).z;
78 PCL_WARN (
"[pcl::FastBilateralFilterOMP] Given an empty cloud. Doing nothing.\n");
82 #pragma omp parallel for num_threads (threads_)
84 for (
long int i = 0; i < static_cast<long int> (output.
size ()); ++i)
85 if (!pcl_isfinite (output.
at(i).z))
86 output.
at(i).z = base_max;
88 const float base_delta = base_max - base_min;
90 const size_t padding_xy = 2;
91 const size_t padding_z = 2;
93 const size_t small_width =
static_cast<size_t> (
static_cast<float> (input_->width - 1) / sigma_s_) + 1 + 2 * padding_xy;
94 const size_t small_height =
static_cast<size_t> (
static_cast<float> (input_->height - 1) / sigma_s_) + 1 + 2 * padding_xy;
95 const size_t small_depth =
static_cast<size_t> (base_delta / sigma_r_) + 1 + 2 * padding_z;
97 Array3D data (small_width, small_height, small_depth);
99 #pragma omp parallel for num_threads (threads_)
101 for (
long int i = 0; i < static_cast<long int> (small_width * small_height); ++i)
103 size_t small_x =
static_cast<size_t> (i % small_width);
104 size_t small_y =
static_cast<size_t> (i / small_width);
105 size_t start_x =
static_cast<size_t>(
106 std::max ((static_cast<float> (small_x) - static_cast<float> (padding_xy) - 0.5f) * sigma_s_ + 1, 0.f));
107 size_t end_x =
static_cast<size_t>(
108 std::max ((static_cast<float> (small_x) - static_cast<float> (padding_xy) + 0.5f) * sigma_s_ + 1, 0.f));
109 size_t start_y =
static_cast<size_t>(
110 std::max ((static_cast<float> (small_y) - static_cast<float> (padding_xy) - 0.5f) * sigma_s_ + 1, 0.f));
111 size_t end_y =
static_cast<size_t>(
112 std::max ((static_cast<float> (small_y) - static_cast<float> (padding_xy) + 0.5f) * sigma_s_ + 1, 0.f));
113 for (
size_t x = start_x; x < end_x && x < input_->width; ++x)
115 for (
size_t y = start_y; y < end_y && y < input_->height; ++y)
117 const float z = output (x,y).z - base_min;
118 const size_t small_z =
static_cast<size_t> (
static_cast<float> (z) / sigma_r_ + 0.5f) + padding_z;
119 Eigen::Vector2f& d = data (small_x, small_y, small_z);
120 d[0] += output (x,y).z;
126 std::vector<long int> offset (3);
127 offset[0] = &(data (1,0,0)) - &(data (0,0,0));
128 offset[1] = &(data (0,1,0)) - &(data (0,0,0));
129 offset[2] = &(data (0,0,1)) - &(data (0,0,0));
131 Array3D buffer (small_width, small_height, small_depth);
133 for (
size_t dim = 0; dim < 3; ++dim)
135 for (
size_t n_iter = 0; n_iter < 2; ++n_iter)
137 Array3D* current_buffer = (n_iter % 2 == 1 ? &buffer : &data);
138 Array3D* current_data =(n_iter % 2 == 1 ? &data : &buffer);
140 #pragma omp parallel for num_threads (threads_)
142 for(
long int i = 0; i < static_cast<long int> ((small_width - 2)*(small_height - 2)); ++i)
144 size_t x =
static_cast<size_t> (i % (small_width - 2) + 1);
145 size_t y =
static_cast<size_t> (i / (small_width - 2) + 1);
146 const long int off = offset[dim];
147 Eigen::Vector2f* d_ptr = &(current_data->operator() (x,y,1));
148 Eigen::Vector2f* b_ptr = &(current_buffer->operator() (x,y,1));
150 for(
size_t z = 1; z < small_depth - 1; ++z, ++d_ptr, ++b_ptr)
151 *d_ptr = (*(b_ptr - off) + *(b_ptr + off) + 2.0 * (*b_ptr)) / 4.0;
161 for (std::vector<Eigen::Vector2f >::iterator d = data.
begin (); d != data.
end (); ++d)
162 *d /= ((*d)[0] != 0) ? (*d)[1] : 1;
165 #pragma omp parallel for num_threads (threads_)
167 for (
long int i = 0; i < static_cast<long int> (input_->size ()); ++i)
169 size_t x =
static_cast<size_t> (i % input_->width);
170 size_t y =
static_cast<size_t> (i / input_->width);
171 const float z = output (x,y).z - base_min;
173 static_cast<float> (y) / sigma_s_ + padding_xy,
174 z / sigma_r_ + padding_z);
175 output(x,y).z = D[0];
181 #pragma omp parallel for num_threads (threads_)
183 for (
long i = 0; i < static_cast<long int> (input_->size ()); ++i)
185 size_t x =
static_cast<size_t> (i % input_->width);
186 size_t y =
static_cast<size_t> (i / input_->width);
187 const float z = output (x,y).z - base_min;
189 static_cast<float> (y) / sigma_s_ + padding_xy,
190 z / sigma_r_ + padding_z);
191 output (x,y).z = D[0] / D[1];
Eigen::Vector2f trilinear_interpolation(const float x, const float y, const float z)
std::vector< Eigen::Vector2f >::iterator begin()
std::vector< Eigen::Vector2f >::iterator end()
PCL_EXPORTS void copyPointCloud(const pcl::PCLPointCloud2 &cloud_in, const std::vector< int > &indices, pcl::PCLPointCloud2 &cloud_out)
Extract the indices of a given point cloud as a new point cloud.
uint32_t height
The point cloud height (if organized as an image-structure).
uint32_t width
The point cloud width (if organized as an image-structure).
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void applyFilter(PointCloud &output)
Filter the input data and store the results into output.
const PointT & at(int column, int row) const
Obtain the point given by the (column, row) coordinates.