ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
texturing_controller.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "base/reconstruction.h"
15 #include "mvs/workspace.h"
16 #include "util/alignment.h"
17 #include "util/misc.h"
18 #include "util/threading.h"
19 
20 // Forward declarations for CloudViewer types
21 class ccMesh;
22 
23 namespace cloudViewer {
24 namespace camera {
25 class PinholeCameraTrajectory;
26 }
27 } // namespace cloudViewer
28 
29 namespace colmap {
30 
31 class Reconstruction;
32 
33 // Options for mesh texturing
35  // Show verbose information
36  bool verbose = true;
37 
38  // Textured mesh file path (input)
39  std::string meshed_file_path = "";
40 
41  // Textured mesh output path
42  std::string textured_file_path = "";
43 
44  // Use depth maps and normal maps for visibility testing
45  bool use_depth_normal_maps = true;
46 
47  // Depth map type: "photometric" or "geometric"
48  std::string depth_map_type = "geometric";
49 
50  // Maximum depth error threshold for visibility check (relative)
51  double max_depth_error = 0.01;
52 
53  // Minimum normal consistency threshold (cosine of angle)
54  double min_normal_consistency = 0.1;
55 
56  // Maximum viewing angle in degrees for texture view selection
57  double max_viewing_angle_deg = 75.0;
58 
59  // Use gradient magnitude image (GMI) for texture quality
60  bool use_gradient_magnitude = false;
61 
62  // Mesh source: "poisson", "delaunay", or "auto"
63  std::string mesh_source = "auto";
64 
65  // Check if options are valid
66  bool Check() const;
67 
68  // Print the options to stdout
69  void Print() const;
70 };
71 
72 // Mesh texturing reconstruction controller
73 // Uses MVS depth/normal maps for improved texturing quality
75 public:
77  const TexturingOptions& options,
78  const Reconstruction& reconstruction,
79  const std::string& image_path,
80  const std::string& output_path,
81  const std::vector<image_t>& image_ids = std::vector<image_t>());
82 
83 private:
84  void Run();
85 
86  bool Texturing(const image_t image_id, std::size_t index);
87 
88  // Get image index in workspace from image_id
89  int GetWorkspaceImageIdx(const image_t image_id) const;
90 
91  // Check if a 3D point is visible in a view using depth map
92  bool IsPointVisible(const Eigen::Vector3d& point3d,
93  const Image& image,
94  const Camera& camera,
95  int workspace_image_idx) const;
96 
97  // Compute view quality score using normal map
98  float ComputeViewQuality(const Eigen::Vector3d& point3d,
99  const Eigen::Vector3d& face_normal,
100  const Image& image,
101  const Camera& camera,
102  int workspace_image_idx) const;
103 
104  // Filter camera trajectory based on depth/normal maps visibility
105  std::shared_ptr<cloudViewer::camera::PinholeCameraTrajectory>
106  FilterCameraTrajectory(ccMesh* mesh) const;
107 
108  TexturingOptions options_;
109  const std::string image_path_;
110  const std::string output_path_;
111  const std::vector<image_t> image_ids_;
112  const Reconstruction& reconstruction_;
113  std::unique_ptr<mvs::Workspace> workspace_;
114  std::vector<std::string> image_names_;
115  std::shared_ptr<cloudViewer::camera::PinholeCameraTrajectory>
116  camera_trajectory_;
117 };
118 
119 } // namespace colmap
std::shared_ptr< core::Tensor > image
Triangular mesh.
Definition: ecvMesh.h:35
TexturingReconstruction(const TexturingOptions &options, const Reconstruction &reconstruction, const std::string &image_path, const std::string &output_path, const std::vector< image_t > &image_ids=std::vector< image_t >())
Generic file read and write utility for python interface.
uint32_t image_t
Definition: types.h:61