1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// Copyright (c) 2018-2024 www.open3d.org
// SPDX-License-Identifier: MIT
// ----------------------------------------------------------------------------
#include "pybind/pipelines/integration/integration.h"
#include "open3d/geometry/VoxelGrid.h"
#include "open3d/pipelines/integration/ScalableTSDFVolume.h"
#include "open3d/pipelines/integration/TSDFVolume.h"
#include "open3d/pipelines/integration/UniformTSDFVolume.h"
#include "pybind/docstring.h"
namespace open3d {
namespace pipelines {
namespace integration {
template <class TSDFVolumeBase = TSDFVolume>
class PyTSDFVolume : public TSDFVolumeBase {
public:
using TSDFVolumeBase::TSDFVolumeBase;
void Reset() override { PYBIND11_OVERLOAD_PURE(void, TSDFVolumeBase, ); }
void Integrate(const geometry::RGBDImage &image,
const camera::PinholeCameraIntrinsic &intrinsic,
const Eigen::Matrix4d &extrinsic) override {
PYBIND11_OVERLOAD_PURE(void, TSDFVolumeBase, image, intrinsic,
extrinsic);
}
std::shared_ptr<geometry::PointCloud> ExtractPointCloud() override {
PYBIND11_OVERLOAD_PURE(std::shared_ptr<geometry::PointCloud>,
TSDFVolumeBase, );
}
std::shared_ptr<geometry::TriangleMesh> ExtractTriangleMesh() override {
PYBIND11_OVERLOAD_PURE(std::shared_ptr<geometry::TriangleMesh>,
TSDFVolumeBase, );
}
};
void pybind_integration_declarations(py::module &m) {
py::module m_integration =
m.def_submodule("integration", "Integration pipeline.");
// open3d.integration.TSDFVolumeColorType
py::enum_<TSDFVolumeColorType> tsdf_volume_color_type(
m_integration, "TSDFVolumeColorType", py::arithmetic());
tsdf_volume_color_type.value("NoColor", TSDFVolumeColorType::NoColor)
.value("RGB8", TSDFVolumeColorType::RGB8)
.value("Gray32", TSDFVolumeColorType::Gray32)
.export_values();
// Trick to write docs without listing the members in the enum class again.
tsdf_volume_color_type.attr("__doc__") = docstring::static_property(
py::cpp_function([](py::handle arg) -> std::string {
return "Enum class for TSDFVolumeColorType.";
}),
py::none(), py::none(), "");
py::class_<TSDFVolume, PyTSDFVolume<TSDFVolume>> tsdfvolume(
m_integration, "TSDFVolume", R"(Base class of the Truncated
Signed Distance Function (TSDF) volume This volume is usually used to integrate
surface data (e.g., a series of RGB-D images) into a Mesh or PointCloud. The
basic technique is presented in the following paper:
A volumetric method for building complex models from range images
B. Curless and M. Levoy
In SIGGRAPH, 1996)");
py::class_<UniformTSDFVolume, PyTSDFVolume<UniformTSDFVolume>, TSDFVolume>
uniform_tsdfvolume(
m_integration, "UniformTSDFVolume",
"UniformTSDFVolume implements the classic TSDF "
"volume with uniform voxel grid (Curless and Levoy 1996).");
py::class_<ScalableTSDFVolume, PyTSDFVolume<ScalableTSDFVolume>, TSDFVolume>
scalable_tsdfvolume(m_integration, "ScalableTSDFVolume", R"(The
ScalableTSDFVolume implements a more memory efficient data structure for
volumetric integration.
This implementation is based on the following repository:
https://github.com/qianyizh/ElasticReconstruction/tree/master/Integrate
An observed depth pixel gives two types of information: (a) an approximation
of the nearby surface, and (b) empty space from the camera to the surface.
They induce two core concepts of volumetric integration: weighted average of
a truncated signed distance function (TSDF), and carving. The weighted
average of TSDF is great in addressing the Gaussian noise along surface
normal and producing a smooth surface output. The carving is great in
removing outlier structures like floating noise pixels and bumps along
structure edges.
Ref: Dense Scene Reconstruction with Points of Interest
Q.-Y. Zhou and V. Koltun
In SIGGRAPH, 2013)");
}
void pybind_integration_definitions(py::module &m) {
auto m_integration = static_cast<py::module>(m.attr("integration"));
// open3d.integration.TSDFVolume
auto tsdfvolume =
static_cast<py::class_<TSDFVolume, PyTSDFVolume<TSDFVolume>>>(
m_integration.attr("TSDFVolume"));
tsdfvolume
.def("reset", &TSDFVolume::Reset,
"Function to reset the TSDFVolume")
.def("integrate", &TSDFVolume::Integrate,
"Function to integrate an RGB-D image into the volume",
"image"_a, "intrinsic"_a, "extrinsic"_a)
.def("extract_point_cloud", &TSDFVolume::ExtractPointCloud,
"Function to extract a point cloud with normals")
.def("extract_triangle_mesh", &TSDFVolume::ExtractTriangleMesh,
"Function to extract a triangle mesh")
.def_readwrite("voxel_length", &TSDFVolume::voxel_length_,
"float: Length of the voxel in meters.")
.def_readwrite("sdf_trunc", &TSDFVolume::sdf_trunc_,
"float: Truncation value for signed distance "
"function (SDF).")
.def_readwrite("color_type", &TSDFVolume::color_type_,
"integration.TSDFVolumeColorType: Color type of the "
"TSDF volume.");
docstring::ClassMethodDocInject(m_integration, "TSDFVolume",
"extract_point_cloud");
docstring::ClassMethodDocInject(m_integration, "TSDFVolume",
"extract_triangle_mesh");
docstring::ClassMethodDocInject(
m_integration, "TSDFVolume", "integrate",
{{"image", "RGBD image."},
{"intrinsic", "Pinhole camera intrinsic parameters."},
{"extrinsic", "Extrinsic parameters."}});
docstring::ClassMethodDocInject(m_integration, "TSDFVolume", "reset");
// open3d.integration.UniformTSDFVolume: open3d.integration.TSDFVolume
auto uniform_tsdfvolume = static_cast<py::class_<
UniformTSDFVolume, PyTSDFVolume<UniformTSDFVolume>, TSDFVolume>>(
m_integration.attr("UniformTSDFVolume"));
py::detail::bind_copy_functions<UniformTSDFVolume>(uniform_tsdfvolume);
uniform_tsdfvolume
.def(py::init([](double length, int resolution, double sdf_trunc,
TSDFVolumeColorType color_type) {
return new UniformTSDFVolume(length, resolution, sdf_trunc,
color_type);
}),
"length"_a, "resolution"_a, "sdf_trunc"_a, "color_type"_a)
.def(py::init([](double length, int resolution, double sdf_trunc,
TSDFVolumeColorType color_type,
Eigen::Vector3d origin) {
return new UniformTSDFVolume(length, resolution, sdf_trunc,
color_type, origin);
}),
"length"_a, "resolution"_a, "sdf_trunc"_a, "color_type"_a,
"origin"_a)
.def("__repr__",
[](const UniformTSDFVolume &vol) {
return std::string(
""
"UniformTSDFVolume ") +
(vol.color_type_ == TSDFVolumeColorType::NoColor
? std::string("without color.")
: std::string("with color."));
}) // todo: extend
.def("extract_voxel_point_cloud",
&UniformTSDFVolume::ExtractVoxelPointCloud,
"Debug function to extract the voxel data into a point cloud.")
.def("extract_voxel_grid", &UniformTSDFVolume::ExtractVoxelGrid,
"Debug function to extract the voxel data VoxelGrid.")
.def("extract_volume_tsdf", &UniformTSDFVolume::ExtractVolumeTSDF,
"Debug function to extract the volume TSDF data.")
.def("extract_volume_color", &UniformTSDFVolume::ExtractVolumeColor,
"Debug function to extract the volume color data.")
.def("inject_volume_tsdf", &UniformTSDFVolume::InjectVolumeTSDF,
"Debug function to inject the voxel TSDF data.", "tsdf"_a)
.def("inject_volume_color", &UniformTSDFVolume::InjectVolumeColor,
"Debug function to inject the voxel Color data.", "color"_a)
.def_readwrite("length", &UniformTSDFVolume::length_,
"Total length, where ``voxel_length = length / "
"resolution``.")
.def_readwrite("resolution", &UniformTSDFVolume::resolution_,
"Resolution over the total length, where "
"``voxel_length = length / resolution``");
docstring::ClassMethodDocInject(m_integration, "UniformTSDFVolume",
"extract_voxel_point_cloud");
// open3d.integration.ScalableTSDFVolume: open3d.integration.TSDFVolume
auto scalable_tsdfvolume = static_cast<py::class_<
ScalableTSDFVolume, PyTSDFVolume<ScalableTSDFVolume>, TSDFVolume>>(
m_integration.attr("ScalableTSDFVolume"));
py::detail::bind_copy_functions<ScalableTSDFVolume>(scalable_tsdfvolume);
scalable_tsdfvolume
.def(py::init([](double voxel_length, double sdf_trunc,
TSDFVolumeColorType color_type,
int volume_unit_resolution,
int depth_sampling_stride) {
return new ScalableTSDFVolume(
voxel_length, sdf_trunc, color_type,
volume_unit_resolution, depth_sampling_stride);
}),
"voxel_length"_a, "sdf_trunc"_a, "color_type"_a,
"volume_unit_resolution"_a = 16, "depth_sampling_stride"_a = 4)
.def("__repr__",
[](const ScalableTSDFVolume &vol) {
return std::string(
""
"ScalableTSDFVolume ") +
(vol.color_type_ == TSDFVolumeColorType::NoColor
? std::string("without color.")
: std::string("with color."));
})
.def("extract_voxel_point_cloud",
&ScalableTSDFVolume::ExtractVoxelPointCloud,
"Debug function to extract the voxel data into a point "
"cloud.");
docstring::ClassMethodDocInject(m_integration, "ScalableTSDFVolume",
"extract_voxel_point_cloud");
}
} // namespace integration
} // namespace pipelines
} // namespace open3d
|