Open3D (C++ API)
VoxelGrid.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <memory>
31 #include <vector>
32 
34 
35 namespace open3d {
36 namespace geometry {
37 
38 class PointCloud;
39 class TriangleMesh;
40 class Octree;
41 
42 class Voxel {
43 public:
44  Voxel() {}
45  Voxel(const Eigen::Vector3i &grid_index) : grid_index_(grid_index) {}
46  Voxel(const Eigen::Vector3i &grid_index, const Eigen::Vector3d &color)
47  : grid_index_(grid_index), color_(color) {}
48  ~Voxel() {}
49 
50 public:
51  Eigen::Vector3i grid_index_ = Eigen::Vector3i(0, 0, 0);
52  Eigen::Vector3d color_ = Eigen::Vector3d(0, 0, 0);
53 };
54 
55 class VoxelGrid : public Geometry3D {
56 public:
58  VoxelGrid(const VoxelGrid &src_voxel_grid);
59  ~VoxelGrid() override {}
60 
61 public:
62  void Clear() override;
63  bool IsEmpty() const override;
64  Eigen::Vector3d GetMinBound() const override;
65  Eigen::Vector3d GetMaxBound() const override;
66  VoxelGrid &Transform(const Eigen::Matrix4d &transformation) override;
67  VoxelGrid &Translate(const Eigen::Vector3d &translation) override;
68  VoxelGrid &Scale(const double scale, bool center = true) override;
69  VoxelGrid &Rotate(const Eigen::Vector3d &rotation,
70  bool center = true,
71  RotationType type = RotationType::XYZ) override;
72 
73 public:
74  VoxelGrid &operator+=(const VoxelGrid &voxelgrid);
75  VoxelGrid operator+(const VoxelGrid &voxelgrid) const;
76 
77 public:
78  bool HasVoxels() const { return voxels_.size() > 0; }
79  bool HasColors() const {
80  return true; // By default, the colors are (0, 0, 0)
81  }
82  Eigen::Vector3i GetVoxel(const Eigen::Vector3d &point) const;
83 
84  void FromOctree(const Octree &octree);
85 
86  std::shared_ptr<geometry::Octree> ToOctree(const size_t &max_depth) const;
87 
88 public:
89  double voxel_size_;
90  Eigen::Vector3d origin_;
91  std::vector<Voxel> voxels_;
92 };
93 
94 std::shared_ptr<VoxelGrid> CreateSurfaceVoxelGridFromPointCloud(
95  const PointCloud &input, double voxel_size);
96 
97 } // namespace geometry
98 } // namespace open3d
double voxel_size_
Definition: VoxelGrid.h:89
Definition: Geometry.h:32
std::shared_ptr< VoxelGrid > CreateSurfaceVoxelGridFromPointCloud(const PointCloud &input, double voxel_size)
Definition: VoxelGridFactory.cpp:71
Voxel(const Eigen::Vector3i &grid_index)
Definition: VoxelGrid.h:45
Definition: PointCloud.h:49
bool HasVoxels() const
Definition: VoxelGrid.h:78
VoxelGrid()
Definition: VoxelGrid.h:57
RotationType
Definition: Geometry3D.h:40
~VoxelGrid() override
Definition: VoxelGrid.h:59
Definition: Geometry3D.h:38
~Voxel()
Definition: VoxelGrid.h:48
Eigen::Vector3d origin_
Definition: VoxelGrid.h:90
bool HasColors() const
Definition: VoxelGrid.h:79
char type
Definition: FilePCD.cpp:56
Definition: PinholeCameraIntrinsic.cpp:34
Eigen::Vector3i grid_index_
Definition: VoxelGrid.h:51
Definition: VoxelGrid.h:55
GeometryType
Definition: Geometry.h:34
Eigen::Vector3d color_
Definition: VoxelGrid.h:52
Definition: Octree.h:129
std::vector< Voxel > voxels_
Definition: VoxelGrid.h:91
Definition: VoxelGrid.h:42
Voxel()
Definition: VoxelGrid.h:44
Voxel(const Eigen::Vector3i &grid_index, const Eigen::Vector3d &color)
Definition: VoxelGrid.h:46