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 <Core/Integration/TSDFVolume.h>
30 
31 namespace three {
32 
33 class UniformTSDFVolume : public TSDFVolume {
34 public:
35     UniformTSDFVolume(double length, int resolution, double sdf_trunc,
36             bool with_color, const Eigen::Vector3d &origin = Eigen::Vector3d::Zero());
37     ~UniformTSDFVolume() override;
38 
39 public:
40     void Reset() override;
41     void Integrate(const RGBDImage &image,
42             const PinholeCameraIntrinsic &intrinsic,
43             const Eigen::Matrix4d &extrinsic) override;
44     std::shared_ptr<PointCloud> ExtractPointCloud() override;
45     std::shared_ptr<TriangleMesh> ExtractTriangleMesh() override;
46 
47     /// Debug function to extract the voxel data into a point cloud
48     std::shared_ptr<PointCloud> ExtractVoxelPointCloud();
49 
50     /// Faster Integrate function that uses depth_to_camera_distance_multiplier
51     /// precomputed from camera intrinsic
52     void IntegrateWithDepthToCameraDistanceMultiplier(const RGBDImage &image,
53             const PinholeCameraIntrinsic &intrinsic,
54             const Eigen::Matrix4d &extrinsic,
55             const Image &depth_to_camera_distance_multiplier);
56 
IndexOf(int x,int y,int z)57     inline int IndexOf(int x, int y, int z) const {
58         return x * resolution_ * resolution_ + y * resolution_ + z;
59     }
60 
IndexOf(const Eigen::Vector3i & xyz)61     inline int IndexOf(const Eigen::Vector3i &xyz) const {
62         return IndexOf(xyz(0), xyz(1), xyz(2));
63     }
64 
65 public:
66     Eigen::Vector3d origin_;
67     double length_;
68     int resolution_;
69     int voxel_num_;
70     std::vector<float> tsdf_;
71     std::vector<Eigen::Vector3f> color_;
72     std::vector<float> weight_;
73 
74 private:
75     Eigen::Vector3d GetNormalAt(const Eigen::Vector3d &p);
76 
77     double GetTSDFAt(const Eigen::Vector3d &p);
78 };
79 
80 }    // namespace three
81