9 #include <unordered_map>
24 static const std::unordered_map<std::string, std::string>
26 {
"filename",
"Path to file."},
29 "Set to ``True`` to write in compressed format."},
31 "The format of the input file. When not specified or set as "
32 "``auto``, the format is inferred from file extension name."},
34 "If true, all points that include a NaN are removed from "
36 {
"remove_infinite_points",
37 "If true, all points that include an infinite value are "
38 "removed from the PointCloud."},
39 {
"quality",
"Quality of the output file."},
41 "Set to ``True`` to output in ascii format, otherwise binary "
42 "format will be used."},
43 {
"write_vertex_normals",
44 "Set to ``False`` to not write any vertex normals, even if "
45 "present on the mesh."},
46 {
"write_vertex_colors",
47 "Set to ``False`` to not write any vertex colors, even if "
48 "present on the mesh."},
49 {
"write_triangle_uvs",
50 "Set to ``False`` to not write any triangle uvs, even if "
51 "present on the mesh. For ``obj`` format, mtl file is saved "
52 "only when ``True`` is set."},
54 {
"config",
"AzureKinectSensor's config file."},
55 {
"pointcloud",
"The ``PointCloud`` object for I/O."},
56 {
"mesh",
"The ``TriangleMesh`` object for I/O."},
57 {
"line_set",
"The ``LineSet`` object for I/O."},
58 {
"image",
"The ``Image`` object for I/O."},
59 {
"voxel_grid",
"The ``VoxelGrid`` object for I/O."},
61 "The ``PinholeCameraTrajectory`` object for I/O."},
62 {
"intrinsic",
"The ``PinholeCameraIntrinsic`` object for I/O."},
64 "The ``PinholeCameraParameters`` object for I/O."},
65 {
"pose_graph",
"The ``PoseGraph`` object for I/O."},
66 {
"feature",
"The ``Feature`` object for I/O."},
68 "If set to true a progress bar is visualized in the console."},
76 py::gil_scoped_release release;
81 "Function to read image from file.",
"filename"_a);
89 py::gil_scoped_release release;
92 "Function to write Image to file.",
"filename"_a,
"image"_a,
101 bool remove_nan_points,
bool remove_infinite_points,
102 bool print_progress) {
103 py::gil_scoped_release release;
106 {format, remove_nan_points,
107 remove_infinite_points, print_progress});
110 "Function to read PointCloud with tensor attributes from file.",
111 "filename"_a,
"format"_a =
"auto",
"remove_nan_points"_a =
false,
112 "remove_infinite_points"_a =
false,
"print_progress"_a =
false);
121 py::gil_scoped_release release;
124 {write_ascii, compressed, print_progress});
126 "Function to write PointCloud with tensor attributes to file.",
127 "filename"_a,
"pointcloud"_a,
"write_ascii"_a =
false,
128 "compressed"_a =
false,
"print_progress"_a =
false);
134 "read_triangle_mesh",
136 bool print_progress) {
137 py::gil_scoped_release release;
145 "Function to read TriangleMesh from file",
"filename"_a,
146 "enable_post_processing"_a =
false,
"print_progress"_a =
false,
147 R
"doc(The general entrance for reading a TriangleMesh from a file.
148 The function calls read functions based on the extension name of filename.
149 Supported formats are `obj, ply, stl, off, gltf, glb, fbx`.
151 The following example reads a triangle mesh with the .ply extension::
152 import cloudViewer as cv3d
153 mesh = cv3d.t.io.read_triangle_mesh('mesh.ply')
156 filename (str): Path to the mesh file.
157 enable_post_processing (bool): If True enables post-processing.
159 - triangulate meshes with polygonal faces
160 - remove redundant materials
161 - pretransform vertices
162 - generate face normals if needed
164 For more information see ASSIMPs documentation on the flags
165 `aiProcessPreset_TargetRealtime_Fast, aiProcess_RemoveRedundantMaterials,
166 aiProcess_OptimizeMeshes, aiProcess_PreTransformVertices`.
168 Note that identical vertices will always be joined regardless of whether
169 post-processing is enabled or not, which changes the number of vertices
172 The `ply`-format is not affected by the post-processing.
174 print_progress (bool): If True print the reading progress to the terminal.
177 Returns the mesh object. On failure an empty mesh is returned.
181 "write_triangle_mesh",
184 bool write_vertex_colors,
bool write_triangle_uvs,
185 bool print_progress) {
186 py::gil_scoped_release release;
190 write_triangle_uvs, print_progress);
192 "Function to write TriangleMesh to file",
"filename"_a,
"mesh"_a,
193 "write_ascii"_a =
false,
"compressed"_a =
false,
194 "write_vertex_normals"_a =
true,
"write_vertex_colors"_a =
true,
195 "write_triangle_uvs"_a =
true,
"print_progress"_a =
false);
203 py::gil_scoped_release release;
206 "Read a numpy .npy file into a Tensor.",
"filename"_a);
213 py::gil_scoped_release release;
216 "Write a Tensor to a numpy .npy file.",
"filename"_a,
"tensor"_a);
223 py::gil_scoped_release release;
226 "Read a numpy .npz file into a dict[str, Tensor].",
"filename"_a);
233 const std::unordered_map<std::string, core::Tensor>
235 py::gil_scoped_release release;
238 "Write a dict[str, Tensor] to a numpy .npz file.",
"filename"_a,
244 py::class_<DepthNoiseSimulator> depth_noise_simulator(
245 m_io,
"DepthNoiseSimulator",
246 R
"(Simulate depth image noise from a given noise distortion model. The distortion model is based on *Teichman et. al. "Unsupervised intrinsic calibration of depth sensors via SLAM" RSS 2009*. Also see <http://redwood-data.org/indoor/dataset.html>__
250 import cloudViewer as cv3d
252 # Redwood Indoor LivingRoom1 (Augmented ICL-NUIM)
253 # http://redwood-data.org/indoor/
254 data = cv3d.data.RedwoodIndoorLivingRoom1()
255 noise_model_path = data.noise_model_path
256 im_src_path = data.depth_paths[0]
259 # Read clean depth image (uint16)
260 im_src = cv3d.t.io.read_image(im_src_path)
262 # Run noise model simulation
263 simulator = cv3d.t.io.DepthNoiseSimulator(noise_model_path)
264 im_dst = simulator.simulate(im_src, depth_scale=depth_scale)
266 # Save noisy depth image (uint16)
267 cv3d.t.io.write_image("noisy_depth.png", im_dst)
269 depth_noise_simulator.def(py::init([](const fs::path &fielname) {
272 "noise_model_path"_a);
274 "im_src"_a,
"depth_scale"_a = 1000.0f,
275 "Apply noise model to a depth image.");
276 depth_noise_simulator.def(
277 "enable_deterministic_debug_mode",
279 "Enable deterministic debug mode. All normally distributed noise "
280 "will be replaced by 0.");
281 depth_noise_simulator.def_property_readonly(
283 "The noise model tensor.");
285 m_io,
"DepthNoiseSimulator",
"__init__",
286 {{
"noise_model_path",
287 "Path to the noise model file. See "
288 "http://redwood-data.org/indoor/dataset.html for the format. Or, "
289 "you may use one of our example datasets, e.g., "
290 "RedwoodIndoorLivingRoom1."}});
292 m_io,
"DepthNoiseSimulator",
"simulate",
294 "Source depth image, must be with dtype UInt16 or Float32, "
297 "Scale factor to the depth image. As a sanity check, if the "
298 "dtype is Float32, the depth_scale must be 1.0. If the dtype is "
299 "is UInt16, the depth_scale is typically larger than 1.0, e.g. "
300 "it can be 1000.0."}});
302 "enable_deterministic_debug_mode");
std::shared_ptr< core::Tensor > image
filament::Texture::InternalFormat format
The Image class stores image with customizable rows, cols, channels, dtype and device.
A point cloud contains a list of 3D points.
A triangle mesh contains vertices and triangles.
void EnableDeterministicDebugMode()
Enable deterministic debug mode. All normally distributed noise will be replaced by 0.
core::Tensor GetNoiseModel() const
Return the noise model.
geometry::Image Simulate(const geometry::Image &im_src, float depth_scale=1000.0)
Apply noise model to a depth image.
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
void FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
static const std::string path
bool ReadTriangleMesh(const std::string &filename, geometry::TriangleMesh &mesh, cloudViewer::io::ReadTriangleMeshOptions params)
std::unordered_map< std::string, core::Tensor > ReadNpz(const std::string &file_name)
bool WritePointCloud(const std::string &filename, const geometry::PointCloud &pointcloud, const cloudViewer::io::WritePointCloudOption ¶ms)
constexpr int kCloudViewerImageIODefaultQuality
core::Tensor ReadNpy(const std::string &file_name)
bool ReadImage(const std::string &filename, geometry::Image &image)
void WriteNpz(const std::string &file_name, const std::unordered_map< std::string, core::Tensor > &tensor_map)
static const std::unordered_map< std::string, std::string > map_shared_argument_docstrings
bool ReadPointCloud(const std::string &filename, geometry::PointCloud &pointcloud, const cloudViewer::io::ReadPointCloudOption ¶ms)
void pybind_class_io(py::module &m_io)
bool WriteImage(const std::string &filename, const geometry::Image &image, int quality)
bool WriteTriangleMesh(const std::string &filename, const geometry::TriangleMesh &mesh, bool write_ascii, bool compressed, bool write_vertex_normals, bool write_vertex_colors, bool write_triangle_uvs, bool print_progress)
void WriteNpy(const std::string &file_name, const core::Tensor &tensor)
Generic file read and write utility for python interface.
bool enable_post_processing
Enables post-processing on the mesh.