13 #include <unordered_map>
15 #include "VoxelGrid.h"
24 const Eigen::Vector3d &
color,
29 auto output = std::make_shared<VoxelGrid>();
32 int num_d = int(std::round(depth /
voxel_size));
35 for (
int widx = 0; widx < num_w; widx++) {
36 for (
int hidx = 0; hidx < num_h; hidx++) {
37 for (
int didx = 0; didx < num_d; didx++) {
49 const Eigen::Vector3d &min_bound,
50 const Eigen::Vector3d &max_bound,
52 auto output = std::make_shared<VoxelGrid>();
57 if (
voxel_size * std::numeric_limits<int>::max() <
58 (max_bound - min_bound).maxCoeff()) {
62 output->origin_ = min_bound;
65 voxelindex_to_accpoint;
66 Eigen::Vector3d ref_coord;
69 for (
size_t i = 0; i < input.
size(); i++) {
74 int(
floor(ref_coord(2)));
82 for (
auto accpoint : voxelindex_to_accpoint) {
84 const Eigen::Vector3d &
color =
86 ? accpoint.second.GetAverageColor()
88 ? accpoint.second.GetMinColor()
90 ? accpoint.second.GetMaxColor()
92 ? accpoint.second.GetSumColor()
93 : Eigen::Vector3d::Zero())
94 : Eigen::Vector3d::Zero();
98 "Pointcloud is voxelized from {:d} points to {:d} voxels.",
99 (
int)input.
size(), (
int)output->voxels_.size());
108 Eigen::Vector3d min_bound = input.
GetMinBound() - voxel_size3 * 0.5;
109 Eigen::Vector3d max_bound = input.
GetMaxBound() + voxel_size3 * 0.5;
111 max_bound, pooling_mode);
117 const Eigen::Vector3d &min_bound,
118 const Eigen::Vector3d &max_bound) {
119 auto output = std::make_shared<VoxelGrid>();
124 if (
voxel_size * std::numeric_limits<int>::max() <
125 (max_bound - min_bound).maxCoeff()) {
129 output->origin_ = min_bound;
133 unsigned int triNum = input.
size();
134 for (
unsigned int i = 0; i < triNum; ++i) {
135 Eigen::Vector3d v0, v1, v2;
137 double minx, miny, minz, maxx, maxy, maxz;
138 int num_w, num_h, num_d, inix, iniy, iniz;
139 minx = std::min(v0[0], std::min(v1[0], v2[0]));
140 miny = std::min(v0[1], std::min(v1[1], v2[1]));
141 minz = std::min(v0[2], std::min(v1[2], v2[2]));
142 maxx = std::max(v0[0], std::max(v1[0], v2[0]));
143 maxy = std::max(v0[1], std::max(v1[1], v2[1]));
144 maxz = std::max(v0[2], std::max(v1[2], v2[2]));
148 num_w =
static_cast<int>((std::round((maxx - minx) /
voxel_size))) + 2;
149 num_h =
static_cast<int>((std::round((maxy - miny) /
voxel_size))) + 2;
150 num_d =
static_cast<int>((std::round((maxz - minz) /
voxel_size))) + 2;
151 for (
int widx = inix; widx < inix + num_w; widx++) {
152 for (
int hidx = iniy; hidx < iniy + num_h; hidx++) {
153 for (
int didx = iniz; didx < iniz + num_d; didx++) {
154 const Eigen::Vector3d box_center =
155 min_bound + box_half_size +
156 Eigen::Vector3d(widx, hidx, didx) *
voxel_size;
158 box_center, box_half_size, v0, v1, v2)) {
175 Eigen::Vector3d min_bound = input.
GetMinBound() - voxel_size3 * 0.5;
176 Eigen::Vector3d max_bound = input.
GetMaxBound() + voxel_size3 * 0.5;
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
virtual unsigned size() const override
Returns the number of triangles.
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const override
Returns the vertices of a given triangle.
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
bool hasColors() const override
Returns whether colors are enabled or not.
Eigen::Vector3d getEigenColor(size_t index) const
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
unsigned size() const override
Eigen::Vector3d getEigenPoint(size_t index) const
Class to aggregate color values from different votes in one voxel Computes the average color value in...
static std::shared_ptr< VoxelGrid > CreateFromTriangleMesh(const ccMesh &input, double voxel_size)
static std::shared_ptr< VoxelGrid > CreateFromPointCloudWithinBounds(const ccPointCloud &input, double voxel_size, const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound, VoxelPoolingMode color_mode=VoxelPoolingMode::AVG)
static std::shared_ptr< VoxelGrid > CreateFromTriangleMeshWithinBounds(const ccMesh &input, double voxel_size, const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound)
static std::shared_ptr< VoxelGrid > CreateDense(const Eigen::Vector3d &origin, const Eigen::Vector3d &color, double voxel_size, double width, double height, double depth)
VoxelPoolingMode
Possible ways of determining voxel color from PointCloud.
static std::shared_ptr< VoxelGrid > CreateFromPointCloud(const ccPointCloud &input, double voxel_size, VoxelPoolingMode color_mode=VoxelPoolingMode::AVG)
Base Voxel class, containing grid id and color.
static bool TriangleAABB(const Eigen::Vector3d &box_center, const Eigen::Vector3d &box_half_size, const Eigen::Vector3d &vert0, const Eigen::Vector3d &vert1, const Eigen::Vector3d &vert2)
MiniVec< float, N > floor(const MiniVec< float, N > &a)
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 3, 1 > Vector3i