50 hhe->centroid /=
static_cast<float> (hhe->count);
51 pcl::for_each_type <FieldList> (pcl::xNdCopyEigenPointFunctor <PointT> (hhe->centroid, output[op]));
56 float r = hhe->centroid[centroid_size-3],
57 g = hhe->centroid[centroid_size-2],
58 b = hhe->centroid[centroid_size-1];
59 int rgb = (
static_cast<int> (r)) << 16 | (
static_cast<int> (g)) << 8 | (
static_cast<int> (b));
60 memcpy (
reinterpret_cast<char*
> (&output[op]) + rgba_index, &rgb,
sizeof (
float));
68 int centroid_size = 4;
69 if (downsample_all_data_)
70 centroid_size = boost::mpl::size<FieldList>::value;
73 std::vector<pcl::PCLPointField> fields;
75 rgba_index = pcl::getFieldIndex<PointT> (
"rgb", fields);
77 rgba_index = pcl::getFieldIndex<PointT> (
"rgba", fields);
80 rgba_index = fields[rgba_index].offset;
84 for (std::size_t i = 0; i < histsize_; i++)
86 history_[i].count = 0;
87 history_[i].centroid = Eigen::VectorXf::Zero (centroid_size);
89 Eigen::VectorXf scratch = Eigen::VectorXf::Zero (centroid_size);
91 output.resize (input_->size ());
93 for (
const auto& point: *input_)
97 int ix =
static_cast<int> (std::floor (point.x * inverse_leaf_size_[0]));
98 int iy =
static_cast<int> (std::floor (point.y * inverse_leaf_size_[1]));
99 int iz =
static_cast<int> (std::floor (point.z * inverse_leaf_size_[2]));
100 auto hash =
static_cast<unsigned int> ((ix * 7171 + iy * 3079 + iz * 4231) & (histsize_ - 1));
101 he *hhe = &history_[hash];
102 if (hhe->count && ((ix != hhe->ix) || (iy != hhe->iy) || (iz != hhe->iz)))
104 flush (output, op++, hhe, rgba_index, centroid_size);
106 hhe->centroid.setZero ();
119 memcpy (&rgb, (
reinterpret_cast<const char *
> (&point)) + rgba_index,
sizeof (
RGB));
120 scratch[centroid_size-3] = rgb.r;
121 scratch[centroid_size-2] = rgb.g;
122 scratch[centroid_size-1] = rgb.b;
124 pcl::for_each_type <FieldList> (xNdCopyPointEigenFunctor <PointT> (point, scratch));
125 hhe->centroid += scratch;
127 for (std::size_t i = 0; i < histsize_; i++)
129 he *hhe = &history_[i];
131 flush (output, op++, hhe, rgba_index, centroid_size);
134 output.width = output.size ();
136 output.is_dense =
true;
void flush(PointCloud &output, std::size_t op, he *hhe, int rgba_index, int centroid_size)
Write a single point from the hash to the output cloud.