ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
model.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 <cstdint>
11 #include <fstream>
12 #include <map>
13 #include <set>
14 #include <string>
15 #include <unordered_map>
16 #include <vector>
17 
18 #include "mvs/depth_map.h"
19 #include "mvs/image.h"
20 #include "mvs/normal_map.h"
21 
22 namespace colmap {
23 namespace mvs {
24 
25 // Simple sparse model class.
26 struct Model {
27  struct Point {
28  float x = 0;
29  float y = 0;
30  float z = 0;
31  std::vector<int> track;
32  };
33 
34  // Read the model from different data formats.
35  void Read(const std::string& path, const std::string& format);
36  void ReadFromCOLMAP(const std::string& path,
37  const std::string& sparse_path = "sparse",
38  const std::string& images_path = "images");
39  void ReadFromPMVS(const std::string& path);
40 
41  // Get the image index for the given image name.
42  int GetImageIdx(const std::string& name) const;
43  std::string GetImageName(const int image_idx) const;
44 
45  // For each image, determine the maximally overlapping images, sorted based
46  // on the number of shared points subject to a minimum robust average
47  // triangulation angle of the points.
48  std::vector<std::vector<int>> GetMaxOverlappingImages(
49  const size_t num_images,
50  const double min_triangulation_angle) const;
51 
52  // Get the overlapping images defined in the vis.dat file.
53  const std::vector<std::vector<int>>& GetMaxOverlappingImagesFromPMVS()
54  const;
55 
56  // Compute the robust minimum and maximum depths from the sparse point
57  // cloud.
58  std::vector<std::pair<float, float>> ComputeDepthRanges() const;
59 
60  // Compute the number of shared points between all overlapping images.
61  std::vector<std::map<int, int>> ComputeSharedPoints() const;
62 
63  // Compute the median triangulation angles between all overlapping images.
64  std::vector<std::map<int, float>> ComputeTriangulationAngles(
65  const float percentile = 50) const;
66 
67  // Note that in case the data is read from a COLMAP reconstruction, the
68  // index of an image or point does not correspond to its original identifier
69  // in the reconstruction, but it corresponds to the position in the
70  // images.bin/points3D.bin files. This is mainly done for more efficient
71  // access to the data, which is required during the stereo fusion stage.
72  std::vector<Image> images;
73  std::vector<Point> points;
74 
75 private:
76  bool ReadFromBundlerPMVS(const std::string& path);
77  bool ReadFromRawPMVS(const std::string& path);
78 
79  std::vector<std::string> image_names_;
80  std::unordered_map<std::string, int> image_name_to_idx_;
81 
82  std::vector<std::vector<int>> pmvs_vis_dat_;
83 };
84 
85 } // namespace mvs
86 } // namespace colmap
filament::Texture::InternalFormat format
std::string name
static const std::string path
Definition: PointCloud.cpp:59
std::vector< int > track
Definition: model.h:31
std::vector< Point > points
Definition: model.h:73
std::string GetImageName(const int image_idx) const
Definition: model.cc:133
int GetImageIdx(const std::string &name) const
Definition: model.cc:127
std::vector< std::pair< float, float > > ComputeDepthRanges() const
Definition: model.cc:196
void ReadFromCOLMAP(const std::string &path, const std::string &sparse_path="sparse", const std::string &images_path="images")
Definition: model.cc:56
std::vector< Image > images
Definition: model.h:72
std::vector< std::vector< int > > GetMaxOverlappingImages(const size_t num_images, const double min_triangulation_angle) const
Definition: model.cc:139
std::vector< std::map< int, float > > ComputeTriangulationAngles(const float percentile=50) const
Definition: model.cc:255
void Read(const std::string &path, const std::string &format)
Definition: model.cc:44
void ReadFromPMVS(const std::string &path)
Definition: model.cc:117
const std::vector< std::vector< int > > & GetMaxOverlappingImagesFromPMVS() const
Definition: model.cc:191
std::vector< std::map< int, int > > ComputeSharedPoints() const
Definition: model.cc:238