RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
zip_sort.h
1//
2// Created by RainSure on 2023/11/11.
3//
4
5#ifndef RSMESH_ZIP_SORT_H
6#define RSMESH_ZIP_SORT_H
7
8#include <vector>
9#include <iterator>
10#include <type_traits>
11#include <common/macros.h>
12#include <numeric>
13
14
15namespace rsmesh {
16 namespace common {
17 namespace detail {
18 template <class RandomAccessIterator,
19 class D = typename std::iterator_traits<RandomAccessIterator>::difference_type>
20 static void inverse_permute(RandomAccessIterator begin, RandomAccessIterator end,
21 const std::vector<D>& p) {
22 using std::swap;
23 auto size = std::distance(begin, end);
24
25 std::vector<bool> done(size);
26 for(D i = 0; i < size; i ++) {
27 if(done.at(i)) {
28 continue;
29 }
30
31 auto prev_j = i;
32 auto j = p.at(i);
33
34 while(i != j) {
35 swap(begin[prev_j], begin[j]);
36 done.at(j) = true;
37 prev_j = j;
38 j = p.at(j);
39 }
40 done.at(i) = true;
41 }
42 }
43 } // namespace detail
44 template <class RandomAccessIterator1, class RandomAccessIterator2, class Compare>
45 void zip_sort(RandomAccessIterator1 begin1, RandomAccessIterator1 end1,
46 RandomAccessIterator2 begin2, RandomAccessIterator2 end2, Compare compare) {
47 using D1 = typename std::iterator_traits<RandomAccessIterator1>::difference_type;
48 using D2 = typename std::iterator_traits<RandomAccessIterator2>::difference_type;
49
50 static_assert(std::is_same<D1, D2>::value,
51 "RandomAccessIterator1 and RandomAccessIterator2 must have the same difference_type.");
52 RSMESH_ASSERT(std::distance(begin1, end1) == std::distance(begin2, end2));
53
54 auto size = std::distance(begin1, end1);
55
56 std::vector<D1> permutation(size);
57 std::iota(begin(permutation), end(permutation), 0);
58 std::sort(begin(permutation), end(permutation), [&](int i, int j) {
59 return compare(std::make_pair(begin1[i], begin2[i]), std::make_pair(begin1[j], begin2[j]));
60 });
61
62 detail::inverse_permute(begin1, end1, permutation);
63 detail::inverse_permute(begin2, end2, permutation);
64 }
65 }
66
67
68}
69
70#endif //RSMESH_ZIP_SORT_H
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间