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_MESHING_H_
33 #define COLMAP_SRC_MVS_MESHING_H_
34 
35 #include <string>
36 
37 namespace colmap {
38 namespace mvs {
39 
40 struct PoissonMeshingOptions {
41   // This floating point value specifies the importance that interpolation of
42   // the point samples is given in the formulation of the screened Poisson
43   // equation. The results of the original (unscreened) Poisson Reconstruction
44   // can be obtained by setting this value to 0.
45   double point_weight = 1.0;
46 
47   // This integer is the maximum depth of the tree that will be used for surface
48   // reconstruction. Running at depth d corresponds to solving on a voxel grid
49   // whose resolution is no larger than 2^d x 2^d x 2^d. Note that since the
50   // reconstructor adapts the octree to the sampling density, the specified
51   // reconstruction depth is only an upper bound.
52   int depth = 13;
53 
54   // If specified, the reconstruction code assumes that the input is equipped
55   // with colors and will extrapolate the color values to the vertices of the
56   // reconstructed mesh. The floating point value specifies the relative
57   // importance of finer color estimates over lower ones.
58   double color = 32.0;
59 
60   // This floating point values specifies the value for mesh trimming. The
61   // subset of the mesh with signal value less than the trim value is discarded.
62   double trim = 10.0;
63 
64   // The number of threads used for the Poisson reconstruction.
65   int num_threads = -1;
66 
67   bool Check() const;
68 };
69 
70 struct DelaunayMeshingOptions {
71   // Unify input points into one cell in the Delaunay triangulation that fall
72   // within a reprojected radius of the given pixels.
73   double max_proj_dist = 20.0;
74 
75   // Maximum relative depth difference between input point and a vertex of an
76   // existing cell in the Delaunay triangulation, otherwise a new vertex is
77   // created in the triangulation.
78   double max_depth_dist = 0.05;
79 
80   // The standard deviation of wrt. the number of images seen by each point.
81   // Increasing this value decreases the influence of points seen in few images.
82   double visibility_sigma = 3.0;
83 
84   // The factor that is applied to the computed distance sigma, which is
85   // automatically computed as the 25th percentile of edge lengths. A higher
86   // value will increase the smoothness of the surface.
87   double distance_sigma_factor = 1.0;
88 
89   // A higher quality regularization leads to a smoother surface.
90   double quality_regularization = 1.0;
91 
92   // Filtering thresholds for outlier surface mesh faces. If the longest side of
93   // a mesh face (longest out of 3) exceeds the side lengths of all faces at a
94   // certain percentile by the given factor, then it is considered an outlier
95   // mesh face and discarded.
96   double max_side_length_factor = 25.0;
97   double max_side_length_percentile = 95.0;
98 
99   // The number of threads to use for reconstruction. Default is all threads.
100   int num_threads = -1;
101 
102   bool Check() const;
103 };
104 
105 // Perform Poisson surface reconstruction and return true if successful.
106 bool PoissonMeshing(const PoissonMeshingOptions& options,
107                     const std::string& input_path,
108                     const std::string& output_path);
109 
110 
111 #ifdef CGAL_ENABLED
112 
113 // Delaunay meshing of sparse and dense COLMAP reconstructions. This is an
114 // implementation of the approach described in:
115 //
116 //    P. Labatut, J‐P. Pons, and R. Keriven. "Robust and efficient surface
117 //    reconstruction from range data". Computer graphics forum, 2009.
118 //
119 // In case of sparse input, the path should point to a sparse COLMAP
120 // reconstruction. In case of dense input, the path should point to a dense
121 // COLMAP workspace folder, which has been fully processed by the stereo and
122 // fusion pipeline.
123 void SparseDelaunayMeshing(const DelaunayMeshingOptions& options,
124                            const std::string& input_path,
125                            const std::string& output_path);
126 void DenseDelaunayMeshing(const DelaunayMeshingOptions& options,
127                            const std::string& input_path,
128                            const std::string& output_path);
129 
130 #endif  // CGAL_ENABLED
131 
132 }  // namespace mvs
133 }  // namespace colmap
134 
135 #endif  // COLMAP_SRC_MVS_MESHING_H_
136