|
| 1 | +// |
| 2 | +// |
| 3 | +// 0==========================0 |
| 4 | +// | Local feature test | |
| 5 | +// 0==========================0 |
| 6 | +// |
| 7 | +// version 1.0 : |
| 8 | +// > |
| 9 | +// |
| 10 | +//--------------------------------------------------- |
| 11 | +// |
| 12 | +// Cloud header |
| 13 | +// |
| 14 | +//---------------------------------------------------- |
| 15 | +// |
| 16 | +// Hugues THOMAS - 10/02/2017 |
| 17 | +// |
| 18 | + |
| 19 | + |
| 20 | +# pragma once |
| 21 | + |
| 22 | +#include <cmath> |
| 23 | +#include <vector> |
| 24 | +#include <unordered_map> |
| 25 | +#include <map> |
| 26 | +#include <algorithm> |
| 27 | +#include <numeric> |
| 28 | +#include <iostream> |
| 29 | +#include <iomanip> |
| 30 | + |
| 31 | +#include <time.h> |
| 32 | + |
| 33 | + |
| 34 | +template<typename scalar_t> |
| 35 | +struct PointCloud |
| 36 | +{ |
| 37 | + struct PointXYZ { |
| 38 | + scalar_t x,y,z; |
| 39 | + }; |
| 40 | + |
| 41 | + std::vector<PointXYZ> pts; |
| 42 | + |
| 43 | + void set(std::vector<scalar_t> new_pts){ |
| 44 | + |
| 45 | + // pts = std::vector<PointXYZ>((PointXYZ*)new_pts, (PointXYZ*)new_pts+new_pts.size()/3); |
| 46 | + std::vector<PointXYZ> temp(new_pts.size()/3); |
| 47 | + for(unsigned int i=0; i < new_pts.size(); i++){ |
| 48 | + if(i%3 == 0){ |
| 49 | + |
| 50 | + PointXYZ point; |
| 51 | + point.x = new_pts[i]; |
| 52 | + point.y = new_pts[i+1]; |
| 53 | + point.z = new_pts[i+2]; |
| 54 | + temp[i/3] = point; |
| 55 | + } |
| 56 | + } |
| 57 | + pts = temp; |
| 58 | + } |
| 59 | + void set_batch(std::vector<scalar_t> new_pts, int begin, int size){ |
| 60 | + std::vector<PointXYZ> temp(size); |
| 61 | + for(int i=0; i < size; i++){ |
| 62 | + PointXYZ point; |
| 63 | + point.x = new_pts[3*(begin+i)]; |
| 64 | + point.y = new_pts[3*(begin+i) + 1]; |
| 65 | + point.z = new_pts[3*(begin+i) + 2]; |
| 66 | + temp[i] = point; |
| 67 | + |
| 68 | + } |
| 69 | + pts = temp; |
| 70 | + } |
| 71 | + |
| 72 | + // Must return the number of data points |
| 73 | + inline size_t kdtree_get_point_count() const { return pts.size(); } |
| 74 | + |
| 75 | + // Returns the dim'th component of the idx'th point in the class: |
| 76 | + // Since this is inlined and the "dim" argument is typically an immediate value, the |
| 77 | + // "if/else's" are actually solved at compile time. |
| 78 | + inline scalar_t kdtree_get_pt(const size_t idx, const size_t dim) const |
| 79 | + { |
| 80 | + if (dim == 0) return pts[idx].x; |
| 81 | + else if (dim == 1) return pts[idx].y; |
| 82 | + else return pts[idx].z; |
| 83 | + } |
| 84 | + |
| 85 | + // Optional bounding-box computation: return false to default to a standard bbox computation loop. |
| 86 | + // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again. |
| 87 | + // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds) |
| 88 | + template <class BBOX> |
| 89 | + bool kdtree_get_bbox(BBOX& /* bb */) const { return false; } |
| 90 | + |
| 91 | + |
| 92 | +}; |
0 commit comments