|
1 | | -// Author: Peiyuan Liao (alexander_liao@outlook.com) |
2 | | -// |
3 | | - |
4 | | - |
5 | | -# pragma once |
| 1 | +#pragma once |
6 | 2 |
|
7 | 3 | #include <ATen/ATen.h> |
| 4 | +#include <algorithm> |
8 | 5 | #include <cmath> |
9 | | -#include <vector> |
10 | | -#include <unordered_map> |
| 6 | +#include <iomanip> |
| 7 | +#include <iostream> |
11 | 8 | #include <map> |
12 | | -#include <algorithm> |
13 | 9 | #include <numeric> |
14 | | -#include <iostream> |
15 | | -#include <iomanip> |
| 10 | +#include <unordered_map> |
| 11 | +#include <vector> |
16 | 12 |
|
17 | 13 | #include <time.h> |
18 | 14 |
|
19 | | - |
20 | | -template<typename scalar_t> |
21 | | -struct PointCloud |
22 | | -{ |
23 | | - std::vector<std::vector<scalar_t>*> pts; |
24 | | - |
25 | | - void set(std::vector<scalar_t> new_pts, int dim){ |
26 | | - |
27 | | - std::vector<std::vector<scalar_t>*> temp(new_pts.size()/dim); |
28 | | - for(size_t i=0; i < new_pts.size(); i++){ |
29 | | - if(i%dim == 0){ |
30 | | - std::vector<scalar_t>* point = new std::vector<scalar_t>(dim); |
31 | | - |
32 | | - for (size_t j = 0; j < (size_t)dim; j++) { |
33 | | - (*point)[j]=new_pts[i+j]; |
34 | | - } |
35 | | - temp[i/dim] = point; |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - pts = temp; |
40 | | - } |
41 | | - void set_batch(std::vector<scalar_t> new_pts, size_t begin, long size, int dim){ |
42 | | - std::vector<std::vector<scalar_t>*> temp(size); |
43 | | - for(size_t i=0; i < (size_t)size; i++){ |
44 | | - std::vector<scalar_t>* point = new std::vector<scalar_t>(dim); |
45 | | - for (size_t j = 0; j < (size_t)dim; j++) { |
46 | | - (*point)[j] = new_pts[dim*(begin+i)+j]; |
47 | | - } |
48 | | - |
49 | | - temp[i] = point; |
50 | | - |
51 | | - } |
52 | | - pts = temp; |
53 | | - } |
54 | | - |
55 | | - // Must return the number of data points |
56 | | - inline size_t kdtree_get_point_count() const { return pts.size(); } |
57 | | - |
58 | | - // Returns the dim'th component of the idx'th point in the class: |
59 | | - inline scalar_t kdtree_get_pt(const size_t idx, const size_t dim) const |
60 | | - { |
61 | | - return (*pts[idx])[dim]; |
62 | | - } |
63 | | - |
64 | | - // Optional bounding-box computation: return false to default to a standard bbox computation loop. |
65 | | - // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again. |
66 | | - // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds) |
67 | | - template <class BBOX> |
68 | | - bool kdtree_get_bbox(BBOX& /* bb */) const { return false; } |
69 | | - |
70 | | - |
| 15 | +template <typename scalar_t> struct PointCloud { |
| 16 | + std::vector<std::vector<scalar_t> *> pts; |
| 17 | + |
| 18 | + void set(std::vector<scalar_t> new_pts, int dim) { |
| 19 | + |
| 20 | + std::vector<std::vector<scalar_t> *> temp(new_pts.size() / dim); |
| 21 | + for (size_t i = 0; i < new_pts.size(); i++) { |
| 22 | + if (i % dim == 0) { |
| 23 | + std::vector<scalar_t> *point = new std::vector<scalar_t>(dim); |
| 24 | + |
| 25 | + for (size_t j = 0; j < (size_t)dim; j++) { |
| 26 | + (*point)[j] = new_pts[i + j]; |
| 27 | + } |
| 28 | + temp[i / dim] = point; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + pts = temp; |
| 33 | + } |
| 34 | + void set_batch(std::vector<scalar_t> new_pts, size_t begin, long size, |
| 35 | + int dim) { |
| 36 | + std::vector<std::vector<scalar_t> *> temp(size); |
| 37 | + for (size_t i = 0; i < (size_t)size; i++) { |
| 38 | + std::vector<scalar_t> *point = new std::vector<scalar_t>(dim); |
| 39 | + for (size_t j = 0; j < (size_t)dim; j++) { |
| 40 | + (*point)[j] = new_pts[dim * (begin + i) + j]; |
| 41 | + } |
| 42 | + |
| 43 | + temp[i] = point; |
| 44 | + } |
| 45 | + pts = temp; |
| 46 | + } |
| 47 | + |
| 48 | + // Must return the number of data points. |
| 49 | + inline size_t kdtree_get_point_count() const { return pts.size(); } |
| 50 | + |
| 51 | + // Returns the dim'th component of the idx'th point in the class: |
| 52 | + inline scalar_t kdtree_get_pt(const size_t idx, const size_t dim) const { |
| 53 | + return (*pts[idx])[dim]; |
| 54 | + } |
| 55 | + |
| 56 | + // Optional bounding-box computation: return false to default to a standard |
| 57 | + // bbox computation loop. |
| 58 | + // Return true if the BBOX was already computed by the class and returned in |
| 59 | + // "bb" so it can be avoided to redo it again. Look at bb.size() to find out |
| 60 | + // the expected dimensionality (e.g. 2 or 3 for point clouds) |
| 61 | + template <class BBOX> bool kdtree_get_bbox(BBOX & /* bb */) const { |
| 62 | + return false; |
| 63 | + } |
71 | 64 | }; |
0 commit comments