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 <vector>
30 #include <memory>
31 #include <Eigen/Core>
33 
34 namespace open3d {
35 namespace geometry {
36 
37 class PointCloud;
38 class TriangleMesh;
39 
40 class VoxelGrid : public Geometry3D {
41 public:
43  ~VoxelGrid() override{};
44 
45 public:
46  void Clear() override;
47  bool IsEmpty() const override;
48  Eigen::Vector3d GetMinBound() const override;
49  Eigen::Vector3d GetMaxBound() const override;
50  void Transform(const Eigen::Matrix4d &transformation) override;
51 
52 public:
53  VoxelGrid &operator+=(const VoxelGrid &voxelgrid);
54  VoxelGrid operator+(const VoxelGrid &voxelgrid) const;
55 
56 public:
57  bool HasVoxels() const { return voxels_.size() > 0; }
58 
59  bool HasColors() const {
60  return voxels_.size() > 0 && colors_.size() == voxels_.size();
61  }
62 
63 public:
64  double voxel_size_;
65  Eigen::Vector3d origin_;
66  std::vector<Eigen::Vector3i> voxels_;
67  std::vector<Eigen::Vector3d> colors_;
68 };
69 
70 std::shared_ptr<VoxelGrid> CreateSurfaceVoxelGridFromPointCloud(
71  const PointCloud &input, double voxel_size);
72 
73 } // namespace geometry
74 } // namespace open3d
double voxel_size_
Definition: VoxelGrid.h:64
Definition: Geometry.h:32
std::shared_ptr< VoxelGrid > CreateSurfaceVoxelGridFromPointCloud(const PointCloud &input, double voxel_size)
Definition: VoxelGridFactory.cpp:72
std::vector< Eigen::Vector3i > voxels_
Definition: VoxelGrid.h:66
Eigen::Vector3d GetMinBound() const override
Definition: VoxelGrid.cpp:41
Definition: PointCloud.h:47
VoxelGrid operator+(const VoxelGrid &voxelgrid) const
Definition: VoxelGrid.cpp:98
bool HasVoxels() const
Definition: VoxelGrid.h:57
VoxelGrid()
Definition: VoxelGrid.h:42
bool IsEmpty() const override
Definition: VoxelGrid.cpp:39
~VoxelGrid() override
Definition: VoxelGrid.h:43
Definition: Geometry3D.h:35
void Transform(const Eigen::Matrix4d &transformation) override
Definition: VoxelGrid.cpp:89
std::vector< Eigen::Vector3d > colors_
Definition: VoxelGrid.h:67
Eigen::Vector3d origin_
Definition: VoxelGrid.h:65
bool HasColors() const
Definition: VoxelGrid.h:59
Definition: PinholeCameraIntrinsic.cpp:33
Definition: VoxelGrid.h:40
GeometryType
Definition: Geometry.h:34
void Clear() override
Definition: VoxelGrid.cpp:32
VoxelGrid & operator+=(const VoxelGrid &voxelgrid)
Definition: VoxelGrid.cpp:93
Eigen::Vector3d GetMaxBound() const override
Definition: VoxelGrid.cpp:65