ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
scene_clustering.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 <list>
11 #include <vector>
12 
13 #include "base/database.h"
14 #include "util/types.h"
15 
16 namespace colmap {
17 
18 // Scene clustering approach using normalized cuts on the scene graph. The scene
19 // is hierarchically partitioned into overlapping clusters until a maximum
20 // number of images is in a leaf node.
22 public:
23  struct Options {
24  // Flag for hierarchical vs flat clustering
25  bool is_hierarchical = true;
26 
27  // The branching factor of the hierarchical clustering.
28  int branching = 2;
29 
30  // The number of overlapping images between child clusters.
31  int image_overlap = 50;
32 
33  // The max related images matches to look for in a flat cluster
35 
36  // The maximum number of images in a leaf node cluster, otherwise the
37  // cluster is further partitioned using the given branching factor. Note
38  // that a cluster leaf node will have at most `leaf_max_num_images +
39  // overlap` images to satisfy the overlap constraint.
41 
42  bool Check() const;
43  };
44 
45  struct Cluster {
46  std::vector<image_t> image_ids;
47  std::vector<Cluster> child_clusters;
48  };
49 
50  SceneClustering(const Options& options);
51 
52  void Partition(const std::vector<std::pair<image_t, image_t>>& image_pairs,
53  const std::vector<int>& num_inliers);
54 
55  const Cluster* GetRootCluster() const;
56  std::vector<const Cluster*> GetLeafClusters() const;
57 
58  static SceneClustering Create(const Options& options,
59  const Database& database);
60 
61 private:
62  void PartitionHierarchicalCluster(
63  const std::vector<std::pair<int, int>>& edges,
64  const std::vector<int>& weights,
65  Cluster* cluster);
66 
67  void PartitionFlatCluster(const std::vector<std::pair<int, int>>& edges,
68  const std::vector<int>& weights);
69 
70  const Options options_;
71  std::unique_ptr<Cluster> root_cluster_;
72 };
73 
74 } // namespace colmap
const Cluster * GetRootCluster() const
SceneClustering(const Options &options)
void Partition(const std::vector< std::pair< image_t, image_t >> &image_pairs, const std::vector< int > &num_inliers)
static SceneClustering Create(const Options &options, const Database &database)
std::vector< const Cluster * > GetLeafClusters() const
std::vector< image_t > image_ids
std::vector< Cluster > child_clusters