Debian Codegraph @

AGENTS.md

raw
1 # AGENTS.md — COLMAP Guide
2
3 ## Project Overview
4
5 COLMAP is a general-purpose Structure-from-Motion (SfM) and Multi-View Stereo (MVS) pipeline that reconstructs 3D models from 2D image collections. Written in C++17 with optional CUDA support. Single binary (colmap) with many subcommands, a Qt GUI, and Python bindings (pycolmap).
6
7 ## Directory Structure
8
9 | Path | Description |
10 |------|-------------|
11 | CMakeLists.txt | Root build config |
12 | cmake/CMakeHelper.cmake | COLMAP_ADD_LIBRARY / _EXECUTABLE / _TEST macros |
13 | cmake/FindDependencies.cmake | All dependency discovery (Eigen, Ceres, CUDA, Qt, etc.) |
14 | cmake/Find*.cmake | Custom find modules |
15 | src/colmap/ | Primary C++ source (see Architecture below) |
16 | src/pycolmap/ | pybind11 C++ bindings |
17 | src/thirdparty/ | Bundled (VLFeat, SiftGPU, PoissonRecon, LSD) and fetched (PoseLib, faiss, ONNX Runtime) |
18 | python/pycolmap/ | Python package (__init__.py, utilities) |
19 | python/CMakeLists.txt | scikit-build-core build for pycolmap |
20 | doc/ | Sphinx/RST documentation |
21 | docker/ | Dockerfile + build/run scripts |
22 | scripts/format/ | c++.sh (clang-format), python.sh (ruff) |
23 | benchmark/ | Reconstruction + runtime benchmarks |
24 | .github/workflows/ | CI: Ubuntu, macOS, Windows, Docker, pycolmap |
25 | vcpkg.json | vcpkg manifest (Windows/macOS deps) |
26 | pyproject.toml | Python build config (scikit-build-core, cibuildwheel) |
27 | .clang-format | C++ formatting style |
28 | ruff.toml | Python linting/formatting config |
29
30 ## Module Dependency Layers (bottom → top)
31
32 | Module | Description |
33 |--------|-------------|
34 | util/ | Threading, logging, caching, PLY I/O, CUDA/OpenGL helpers |
35 | math/ | Random, polynomials, graph algorithms (cuts, union-find, spanning trees) |
36 | geometry/ | Rigid3d, Sim3d, essential/homography matrices, triangulation, GPS |
37 | sensor/ | Camera distortion models, Bitmap (image I/O), Rig, sensor specs DB |
38 | feature/ | SIFT (CPU/GPU), ALIKED (ONNX), LightGlue, descriptor indexing (FAISS) |
39 | optim/ | RANSAC, LO-RANSAC, SPRT, samplers, support measurers |
40 | scene/ | Camera, Image, Frame, Point2D/3D, Track, Reconstruction, Database (SQLite), CorrespondenceGraph |
41 | estimators/ | Bundle adjustment (Ceres), absolute/relative pose, two-view geometry, triangulation, alignment |
42 | estimators/solvers/ | Minimal solvers: P3P, 5-pt essential, 7/8-pt fundamental, homography (via PoseLib) |
43 | estimators/cost_functions/ | Ceres cost functors: reprojection, Sampson, alignment, pose prior |
44 | sfm/ | IncrementalMapper, GlobalMapper, IncrementalTriangulator, ObservationManager |
45 | mvs/ | PatchMatch stereo (CUDA), depth/normal maps, fusion, meshing |
46 | image/ | Image undistortion, warping, line detection |
47 | retrieval/ | Vocabulary tree (VisualIndex), inverted index, vote-and-verify |
48 | controllers/ | AutomaticReconstruction, IncrementalPipeline, GlobalPipeline, HierarchicalPipeline, OptionManager |
49 | exe/ | CLI command implementations (colmap.cc dispatcher + per-domain .cc files) |
50 | ui/ | Qt GUI: MainWindow, ModelViewerWidget, OpenGL painters, config dialogs |
51
52 ## Key Classes & Files
53
54 | Class/File | Location | Purpose |
55 |------------|----------|---------|
56 | Reconstruction | scene/reconstruction.h | Top-level container: cameras, rigs, images, frames, points, tracks |
57 | Camera | scene/camera.h | Intrinsics (focal, principal pt, distortion model) |
58 | Rig | sensor/rig.h | Multi-sensor rig with sensor_from_rig transforms |
59 | Image | scene/image.h | Exposure: name, Point2D observations, camera_id, frame_id |
60 | Frame | scene/frame.h | Posed rig instantiation: rig_from_world + sensor data |
61 | Point3D | scene/point3d.h | Triangulated 3D point: xyz, color, error, Track |
62 | Track | scene/track.h | List of (image_id, point2D_idx) observations |
63 | Database | scene/database.h | Abstract DB interface (SQLite impl in database_sqlite.h) |
64 | DatabaseCache | scene/database_cache.h | In-memory cache + CorrespondenceGraph |
65 | CorrespondenceGraph | scene/correspondence_graph.h | Feature-to-feature correspondences across images |
66 | Rigid3d | geometry/rigid3.h | 6-DOF rigid transform (quaternion + translation) |
67 | Sim3d | geometry/sim3.h | 7-DOF similarity transform (Rigid3d + scale) |
68 | FeatureExtractor | feature/extractor.h | Abstract extractor (SIFT, ALIKED); factory Create() |
69 | FeatureMatcher | feature/matcher.h | Abstract matcher; supports Match() and MatchGuided() |
70 | FeatureKeypoint | feature/types.h | x, y + affine shape (a11, a12, a21, a22) |
71 | BundleAdjuster | estimators/bundle_adjustment.h | Abstract BA; Ceres impl via CreateDefaultBundleAdjuster() |
72 | BundleAdjustmentConfig | estimators/bundle_adjustment.h | What to optimize vs. hold constant |
73 | EstimateAbsolutePose() | estimators/pose.h | P3P RANSAC from 2D-3D correspondences |
74 | EstimateTwoViewGeometry() | estimators/two_view_geometry.h | Essential/fundamental/homography estimation |
75 | EstimateTriangulation() | estimators/triangulation.h | Robust multi-view triangulation |
76 | IncrementalMapper | sfm/incremental_mapper.h | Core incremental SfM engine |
77 | GlobalMapper | sfm/global_mapper.h | Global SfM (rotation averaging + global positioning) |
78 | IncrementalTriangulator | sfm/incremental_triangulator.h | Point creation, track merging/completion |
79 | ObservationManager | sfm/observation_manager.h | Per-image visibility stats, filtering |
80 | PatchMatch | mvs/patch_match.h | CPU wrapper for CUDA PatchMatch stereo |
81 | PatchMatchController | mvs/patch_match.h | Orchestrates multi-GPU depth estimation |
82 | StereoFusion | mvs/fusion.h | Fuses depth maps into 3D point cloud |
83 | AutomaticReconstructionController | controllers/automatic_reconstruction.h | End-to-end pipeline (extract, match, SfM, MVS) |
84 | IncrementalPipeline | controllers/incremental_pipeline.h | Manages incremental SfM loop + multi-model |
85 | OptionManager | controllers/option_manager.h | Centralized CLI option parsing |
86 | Camera models | sensor/models.h | SimplePinhole, Radial, OpenCV, Fisheye, etc. |
87 | Bitmap | sensor/bitmap.h | Image I/O wrapper (OpenImageIO), EXIF extraction |
88
89 CLI entry point: exe/colmap.cc (subcommand dispatcher).
90
91 ## Build Instructions
92
93 ```bash
94 mkdir build && cd build
95 cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../install
96 ninja
97
98 # No GUI, no CUDA (minimal)
99 cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DGUI_ENABLED=OFF -DCUDA_ENABLED=OFF
100
101 # With tests
102 cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DTESTS_ENABLED=ON
103 ```
104
105 ### Build pycolmap
106
107 First build and install the C++ code:
108
109 ```bash
110 mkdir build && cd build
111 cmake .. -GNinja -DCMAKE_INSTALL_PREFIX=../install
112 ninja install
113 ```
114
115 Then build pycolmap (from the repo root):
116
117 ```bash
118 colmap_DIR=./install ./python/incremental_build.sh # Fast incremental build
119 colmap_DIR=./install ./python/build.sh # Clean build (slower)
120 ```
121
122 If there is a local `.python-version` file, use pyenv/uv for Python commands, `pip install`, and building pycolmap.
123
124 ## Testing
125
126 Follow C++ and Python build instructions above.
127
128 Run ctest from the build directory:
129
130 ```bash
131 cd build
132 ctest --output-on-failure # All C++ tests
133 ctest -R "util/cache_test" # Specific test
134 ctest -E "(feature/sift_test)" # Exclude GPU tests
135 ```
136
137 Run Python tests from the repo root:
138
139 ```bash
140 pytest # All Python tests (config in pyproject.toml)
141 ```
142
143 - Test files (`*_test.cc`) across all modules, created via `COLMAP_ADD_TEST()` macro
144 - Framework: GTest/GMock with custom main (`util/gtest_main.cc`)
145 - Test utilities: `util/testing.h`, Eigen matchers: `util/eigen_matchers.h`, transform matchers: `geometry/rigid3_matchers.h`, `geometry/sim3_matchers.h`
146 - CTest names: `module/test_name` (e.g., `estimators/alignment_test`)
147
148 ## Code Style & Conventions
149
150 ### Naming
151
152 - Classes: `PascalCase`
153 - Methods/functions: `PascalCase` (e.g., `FindNextImages()`)
154 - Member variables: `snake_case_` (trailing underscore)
155 - Local variables: `snake_case`
156 - Constants/enums: `kPascalCase` or `UPPER_SNAKE_CASE`
157 - Files: `snake_case.h` / `snake_case.cc` / `snake_case_test.cc`
158 - Transforms: `target_from_source` (e.g., `cam_from_world`)
159 - Coordinates: `x_in_y` (e.g., `point3D_in_world`)
160
161 ### Index and Identifier Types (util/types.h)
162
163 - Generic indexes: int, size_t
164 - Special identifiers: camera_t, image_t, image_pair_t, frame_t, rig_t, point2D_t, point3D_t, sensor_t, data_t, pose_prior_t
165
166 ### Hash containers (util/hash_containers.h)
167
168 Use the `colmap::{Flat,Node}Hash{Map,Set}` aliases, not `std::unordered_map/set`.
169
170 - `FlatHashMap`/`FlatHashSet` — default; fastest, but invalidate element
171 references/iterators on insert/erase, so no iterator-erase loops (erase by key).
172 - `NodeHashMap`/`NodeHashSet` — reference-stable; use when a reference/pointer/
173 iterator to an element is held across a mutation of the same container (e.g.
174 `Reconstruction::points3D_`).
175
176 Custom keys reuse the `std::hash` specializations / `PairHash` in `util/types.h`.
177 Keep `std::map`/`std::set` only when sorted iteration is required (deterministic
178 output, Ceres block order, `lower_bound`).
179
180 ### Formatting
181
182 ```bash
183 scripts/format/c++.sh
184 scripts/format/python.sh
185 ```
186
187 ## External Dependencies
188
189 ### Core
190
191 | Library | Role |
192 |---------|------|
193 | Eigen3 | Linear algebra, matrices, geometry |
194 | Ceres Solver | Nonlinear optimization |
195 | Boost | Graph algorithms, CLI options, etc. |
196 | glog | Structured logging |
197 | SQLite3 | Feature/match database |
198 | OpenImageIO | Image I/O and processing |
199 | CHOLMOD | Sparse Cholesky |
200 | Metis | Graph partitioning |
201 | PoseLib | Minimal pose solvers |
202 | FAISS | Fast ANN for descriptor matching |
203
204 ### Optional
205
206 | Library | Role | Gate |
207 |---------|------|------|
208 | CUDA | GPU PatchMatch, SiftGPU, Ceres GPU BA | CUDA_ENABLED |
209 | ONNX Runtime | ALIKED, LightGlue neural features | ONNX_ENABLED |
210 | Qt5/6 | GUI | GUI_ENABLED |
211 | OpenGL/GLEW | 3D visualization, SiftGPU | OPENGL_ENABLED |
212 | CGAL | Delaunay meshing | CGAL_ENABLED |
213
214 ### Bundled (src/thirdparty/)
215
216 | Library | Role |
217 |---------|------|
218 | VLFeat | CPU SIFT |
219 | SiftGPU | GPU SIFT |
220 | PoissonRecon | Surface reconstruction |
221 | LSD | Line detection |