1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 10 // * Redistributions in binary form must reproduce the above copyright 11 // notice, this list of conditions and the following disclaimer in the 12 // documentation and/or other materials provided with the distribution. 13 // 14 // * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of 15 // its contributors may be used to endorse or promote products derived 16 // from this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 // POSSIBILITY OF SUCH DAMAGE. 29 // 30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de) 31 32 #ifndef COLMAP_SRC_MVS_MODEL_H_ 33 #define COLMAP_SRC_MVS_MODEL_H_ 34 35 #include <cstdint> 36 #include <fstream> 37 #include <map> 38 #include <set> 39 #include <string> 40 #include <unordered_map> 41 #include <vector> 42 43 #include "mvs/depth_map.h" 44 #include "mvs/image.h" 45 #include "mvs/normal_map.h" 46 47 namespace colmap { 48 namespace mvs { 49 50 // Simple sparse model class. 51 struct Model { 52 struct Point { 53 float x = 0; 54 float y = 0; 55 float z = 0; 56 std::vector<int> track; 57 }; 58 59 // Read the model from different data formats. 60 void Read(const std::string& path, const std::string& format); 61 void ReadFromCOLMAP(const std::string& path); 62 void ReadFromPMVS(const std::string& path); 63 64 // Get the image index for the given image name. 65 int GetImageIdx(const std::string& name) const; 66 std::string GetImageName(const int image_idx) const; 67 68 // For each image, determine the maximally overlapping images, sorted based on 69 // the number of shared points subject to a minimum robust average 70 // triangulation angle of the points. 71 std::vector<std::vector<int>> GetMaxOverlappingImages( 72 const size_t num_images, const double min_triangulation_angle) const; 73 74 // Get the overlapping images defined in the vis.dat file. 75 const std::vector<std::vector<int>>& GetMaxOverlappingImagesFromPMVS() const; 76 77 // Compute the robust minimum and maximum depths from the sparse point cloud. 78 std::vector<std::pair<float, float>> ComputeDepthRanges() const; 79 80 // Compute the number of shared points between all overlapping images. 81 std::vector<std::map<int, int>> ComputeSharedPoints() const; 82 83 // Compute the median triangulation angles between all overlapping images. 84 std::vector<std::map<int, float>> ComputeTriangulationAngles( 85 const float percentile = 50) const; 86 87 // Note that in case the data is read from a COLMAP reconstruction, the index 88 // of an image or point does not correspond to its original identifier in the 89 // reconstruction, but it corresponds to the position in the 90 // images.bin/points3D.bin files. This is mainly done for more efficient 91 // access to the data, which is required during the stereo fusion stage. 92 std::vector<Image> images; 93 std::vector<Point> points; 94 95 private: 96 bool ReadFromBundlerPMVS(const std::string& path); 97 bool ReadFromRawPMVS(const std::string& path); 98 99 std::vector<std::string> image_names_; 100 std::unordered_map<std::string, int> image_name_to_idx_; 101 102 std::vector<std::vector<int>> pmvs_vis_dat_; 103 }; 104 105 } // namespace mvs 106 } // namespace colmap 107 108 #endif // COLMAP_SRC_MVS_MODEL_H_ 109