Super4PCS Library  V1.1.2(719f5c0)
sampling.h
1 // Copyright 2017 Nicolas Mellado
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -------------------------------------------------------------------------- //
16 //
17 // Authors: Nicolas Mellado, Dror Aiger
18 //
19 // An implementation of the Super 4-points Congruent Sets (Super 4PCS)
20 // algorithm presented in:
21 //
22 // Super 4PCS: Fast Global Pointcloud Registration via Smart Indexing
23 // Nicolas Mellado, Dror Aiger, Niloy J. Mitra
24 // Symposium on Geometry Processing 2014.
25 //
26 // Data acquisition in large-scale scenes regularly involves accumulating
27 // information across multiple scans. A common approach is to locally align scan
28 // pairs using Iterative Closest Point (ICP) algorithm (or its variants), but
29 // requires static scenes and small motion between scan pairs. This prevents
30 // accumulating data across multiple scan sessions and/or different acquisition
31 // modalities (e.g., stereo, depth scans). Alternatively, one can use a global
32 // registration algorithm allowing scans to be in arbitrary initial poses. The
33 // state-of-the-art global registration algorithm, 4PCS, however has a quadratic
34 // time complexity in the number of data points. This vastly limits its
35 // applicability to acquisition of large environments. We present Super 4PCS for
36 // global pointcloud registration that is optimal, i.e., runs in linear time (in
37 // the number of data points) and is also output sensitive in the complexity of
38 // the alignment problem based on the (unknown) overlap across scan pairs.
39 // Technically, we map the algorithm as an 'instance problem' and solve it
40 // efficiently using a smart indexing data organization. The algorithm is
41 // simple, memory-efficient, and fast. We demonstrate that Super 4PCS results in
42 // significant speedup over alternative approaches and allows unstructured
43 // efficient acquisition of scenes at scales previously not possible. Complete
44 // source code and datasets are available for research use at
45 // http://geometry.cs.ucl.ac.uk/projects/2014/super4PCS/.
46 
47 #ifndef _PCS_UTILS_H_
48 #define _PCS_UTILS_H_
49 
50 #include <vector>
51 #include <array>
52 #include "super4pcs/shared4pcs.h"
53 
54 
55 namespace GlobalRegistration {
56 namespace Sampling {
57 
58 
60 private:
61  template <typename _Scalar>
62  class HashTable {
63  public:
64  using Scalar = _Scalar;
65 
66  private:
67  const uint64_t MAGIC1 = 100000007;
68  const uint64_t MAGIC2 = 161803409;
69  const uint64_t MAGIC3 = 423606823;
70  const uint64_t NO_DATA = 0xffffffffu;
71  Scalar voxel_;
72  Scalar scale_;
73  using VoxelType = std::array<int,3>;
74  std::vector<VoxelType> voxels_;
75  std::vector<uint64_t> data_;
76 
77  public:
78  HashTable(int maxpoints, Scalar voxel) : voxel_(voxel), scale_(1.0f / voxel) {
79  uint64_t n = maxpoints;
80  voxels_.resize(n);
81  data_.resize(n, NO_DATA);
82  }
83  template <typename Point>
84  uint64_t& operator[](const Point& p) {
85  // TODO: use eigen power here.
86  VoxelType c {int(floor(p.x() * scale_)),
87  int(floor(p.y() * scale_)),
88  int(floor(p.z() * scale_))};
89 
90  uint64_t key = (MAGIC1 * c[0] + MAGIC2 * c[1] + MAGIC3 * c[2]) % data_.size();
91  while (1) {
92  if (data_[key] == NO_DATA) {
93  voxels_[key] = c;
94  break;
95  } else if (voxels_[key] == c) {
96  break;
97  }
98  key++;
99  if (key == data_.size()) key = 0;
100  }
101  return data_[key];
102  }
103  };
104 public:
105  template <typename Point>
106  inline
107  void operator() (const std::vector<Point>& inputset,
108  const Match4PCSOptions& options,
109  std::vector<Point>& output) const {
110  int num_input = inputset.size();
111  output.clear();
112  HashTable<typename Point::Scalar> hash(num_input, options.delta);
113  for (int i = 0; i < num_input; i++) {
114  uint64_t& ind = hash[inputset[i]];
115  if (ind >= num_input) {
116  output.push_back(inputset[i]);
117  ind = output.size();
118  }
119  }
120  }
121 };
122 
123 
124 } // namespace Sampling
125 } // namespace Super4PCS
126 
127 
128 #endif
Definition: bbox.h:54
Scalar delta
The delta for the LCP (see the paper).
Definition: shared4pcs.h:153
void operator()(const std::vector< Point > &inputset, const Match4PCSOptions &options, std::vector< Point > &output) const
Definition: sampling.h:107
delta and overlap_estimation are the application parameters. All other parameters are more likely to ...
Definition: shared4pcs.h:148