15 #include <unordered_map>
27 class PinholeCameraParameters;
51 : grid_index_(grid_index), color_(
color) {}
58 Eigen::Vector3d color_ = Eigen::Vector3d(0, 0, 0);
82 inline virtual bool IsEmpty()
const override {
return !HasVoxels(); }
94 const Eigen::Matrix4d &transformation)
override;
96 bool relative =
true)
override;
98 const Eigen::Vector3d ¢er)
override;
100 const Eigen::Vector3d ¢er)
override;
116 auto it = voxels_.find(idx);
117 if (it != voxels_.end()) {
118 auto voxel = it->second;
119 Eigen::Vector3d
local = (voxel.grid_index_.cast<
double>() +
120 Eigen::Vector3d(0.5, 0.5, 0.5)) *
122 return origin_ + rotation_ *
local;
124 return Eigen::Vector3d::Zero();
141 const std::vector<Eigen::Vector3d> &queries);
153 const Image &depth_map,
155 bool keep_voxels_outside_image);
167 const Image &silhouette_mask,
169 bool keep_voxels_outside_image);
179 std::shared_ptr<geometry::Octree>
ToOctree(
const size_t &max_depth)
const;
190 static std::shared_ptr<VoxelGrid>
CreateDense(
const Eigen::Vector3d &origin,
191 const Eigen::Vector3d &
color,
230 const Eigen::Vector3d &min_bound,
231 const Eigen::Vector3d &max_bound,
241 const ccMesh &input,
double voxel_size);
254 const Eigen::Vector3d &min_bound,
255 const Eigen::Vector3d &max_bound);
264 double voxel_size_ = 0.0;
266 Eigen::Vector3d origin_ = Eigen::Vector3d::Zero();
269 Eigen::Matrix3d rotation_ = Eigen::Matrix3d::Identity();
285 color_(0.0, 0.0, 0.0),
286 min_color_(
Eigen::Vector3d::Constant(
287 std::numeric_limits<double>::
max())),
288 max_color_(
Eigen::Vector3d::Constant(
289 std::numeric_limits<double>::lowest())) {}
293 if (num_of_points_ > 0 && voxel_index != voxel_index_) {
295 "Tried to aggregate ColorVoxel with different "
298 voxel_index_ = voxel_index;
310 if (num_of_points_ > 0) {
311 return color_ / double(num_of_points_);
329 Eigen::Vector3d min_color_;
330 Eigen::Vector3d max_color_;
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
void Add(const double in1[2], const double in2[2], double out[2])
Hierarchical CLOUDVIEWER Object.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Contains both intrinsic and extrinsic pinhole camera parameters.
Class to aggregate color values from different votes in one voxel Computes the average color value in...
Eigen::Vector3d GetSumColor() const
void Add(const Eigen::Vector3i &voxel_index, const Eigen::Vector3d &color)
Eigen::Vector3d GetAverageColor() const
void Add(const Eigen::Vector3i &voxel_index)
Eigen::Vector3d GetMaxColor() const
Eigen::Vector3d GetMinColor() const
Eigen::Vector3i voxel_index_
Eigen::Vector3i GetVoxelIndex() const
The Image class stores image with customizable width, height, num of channels and bytes per channel.
VoxelGrid is a collection of voxels which are aligned in grid.
void CreateFromOctree(const Octree &octree)
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
std::unordered_map< Eigen::Vector3i, Voxel, cloudViewer::utility::hash_eigen< Eigen::Vector3i > > voxels_
Voxels contained in voxel grid.
VoxelGrid & CarveDepthMap(const Image &depth_map, const camera::PinholeCameraParameters &camera_parameter, bool keep_voxels_outside_image)
std::vector< Eigen::Vector3d > GetAllVoxelCorners() const
Returns the 3D coordinates of all corners of every voxel in the grid.
static std::shared_ptr< VoxelGrid > CreateFromTriangleMesh(const ccMesh &input, double voxel_size)
Eigen::Vector3d GetVoxelCenterCoordinate(const Eigen::Vector3i &idx) const
Function that returns the 3d coordinates of the queried voxel center.
VoxelGrid & CarveSilhouette(const Image &silhouette_mask, const camera::PinholeCameraParameters &camera_parameter, bool keep_voxels_outside_image)
static std::shared_ptr< VoxelGrid > CreateFromPointCloud(const ccPointCloud &input, double voxel_size, VoxelPoolingMode color_mode=VoxelPoolingMode::AVG)
virtual VoxelGrid & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d ¢er) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
virtual bool IsEmpty() const override
bool HasColors() const
Returns true if the voxel grid contains voxel colors.
bool HasVoxels() const
Returns true if the voxel grid contains voxels.
std::shared_ptr< geometry::Octree > ToOctree(const size_t &max_depth) const
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)
VoxelGrid operator+(const VoxelGrid &voxelgrid) const
std::vector< bool > CheckIfIncluded(const std::vector< Eigen::Vector3d > &queries)
VoxelPoolingMode
Possible ways of determining voxel color from PointCloud.
VoxelGrid(const VoxelGrid &src_voxel_grid, const char *name="VoxelGrid")
Copy Constructor.
virtual VoxelGrid & Scale(const double s, const Eigen::Vector3d ¢er) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
VoxelGrid(const char *name="VoxelGrid")
Default Constructor.
std::vector< Eigen::Vector3d > GetVoxelBoundingPoints(const Eigen::Vector3i &index) const
Return a vector of 3D coordinates that define the indexed voxel cube.
virtual VoxelGrid & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Eigen::Vector3i GetVoxel(const Eigen::Vector3d &point) const
Returns voxel index given query point.
VoxelGrid & operator+=(const VoxelGrid &voxelgrid)
virtual VoxelGrid & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
static std::shared_ptr< VoxelGrid > CreateDense(const Eigen::Vector3d &origin, const Eigen::Vector3d &color, double voxel_size, double width, double height, double depth)
void RemoveVoxel(const Eigen::Vector3i &idx)
Remove a voxel with specified grid index.
virtual bool isSerializable() const override
Returns whether object is serializable of not.
void AddVoxel(const Voxel &voxel)
Add a voxel with specified grid index and color.
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
std::vector< Voxel > GetVoxels() const
static std::shared_ptr< VoxelGrid > CreateFromTriangleMeshWithinBounds(const ccMesh &input, double voxel_size, const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound)
virtual CV_CLASS_ENUM getClassID() const override
Returns unique class ID.
Base Voxel class, containing grid id and color.
Voxel()
Default Constructor.
Voxel(const Eigen::Vector3i &grid_index)
Parameterized Constructor.
Voxel(const Eigen::Vector3i &grid_index, const Eigen::Vector3d &color)
Parameterized Constructor.
Helper functions for the ml ops.
Generic file read and write utility for python interface.
Eigen::Matrix< Index, 3, 1 > Vector3i