segment_tree.h
Go to the documentation of this file.
1 #ifndef SEGMENT_TREE_H
2 #define SEGMENT_TREE_H
3 
4 #include <Eigen/Core>
5 #include <Eigen/Geometry>
6 
7 #include <utility>
8 #include <vector>
9 #include <memory>
10 #include <array>
11 #include <algorithm>
12 #include <numeric>
13 #include <iostream>
14 #include <iomanip>
15 #include <string>
16 
17 #undef min
18 #undef max
19 
20 namespace scan_tools
21 {
22 
23 using Point = Eigen::Vector2d;
24 struct Segment: std::pair<Point, Point>
25 {
26  // Inherit constructor
27  using std::pair<Point, Point>::pair;
28 
29  void flip() {std::swap(first, second);};
30  Eigen::Vector2d diff() const {return second - first;}
31  Eigen::Vector2d surface_normal() const
32  {
33  const auto d = diff();
34  return Eigen::Vector2d{d[1], -d[0]}/d.norm();
35  }
36 };
37 
38 
40 {
41  private:
42  template<int Axis>
43  struct Node
44  {
45  constexpr static auto leaf_capacity = 64;
46  constexpr static auto ChildAxis = (Axis+1)%2;
48  using Ptr = std::unique_ptr<Node>;
49  using ChildPtr = typename ChildNode::Ptr;
50 
52  double pivot_;
53  std::vector<Segment> segments_;
54 
55  Node(std::vector<Segment> segs);
56 
57  Node() = default;
58  Node(Node&&) = default;
59  Node& operator= (Node&&) = default;
60 
61  Node(const Node&) = delete;
62  Node& operator= (const Node&) = delete;
63 
64  template<class Callback>
65  void segments_within(Point p, double radius, const Callback &cb) const;
66 
67  template<class Callback>
68  void traverse(const Callback &cb, int depth=0) const;
69  };
70 
71  public:
72  SegmentTree(std::vector<Segment> segments);
73 
74  SegmentTree() = default;
75  SegmentTree(SegmentTree&&) = default;
76  SegmentTree& operator= (SegmentTree&&) = default;
77 
78  SegmentTree(const SegmentTree&) = delete;
79  SegmentTree& operator= (const SegmentTree&) = delete;
80 
81  public:
82  std::vector<Segment> segments_within(Point p, double radius) const;
83 
84  public:
85  void dump(std::ostream &os) const;
86 
87  private:
89 };
90 
91 }
92 
93 
94 #endif // KD_TREE_H
scan_tools::SegmentTree::Node::segments_within
void segments_within(Point p, double radius, const Callback &cb) const
Definition: segment_tree.cpp:87
scan_tools::SegmentTree::Node< 0 >::ChildPtr
typename ChildNode::Ptr ChildPtr
Definition: segment_tree.h:49
scan_tools::Point
Eigen::Vector2d Point
Definition: segment_tree.h:23
scan_tools::SegmentTree::Node< 0 >::Ptr
std::unique_ptr< Node > Ptr
Definition: segment_tree.h:48
scan_tools::Segment
Definition: segment_tree.h:24
scan_tools::Segment::flip
void flip()
Definition: segment_tree.h:29
scan_tools::SegmentTree::operator=
SegmentTree & operator=(SegmentTree &&)=default
scan_tools
Definition: laser_scan_matcher.h:72
scan_tools::SegmentTree
Definition: segment_tree.h:39
scan_tools::SegmentTree::Node::traverse
void traverse(const Callback &cb, int depth=0) const
Definition: segment_tree.cpp:114
scan_tools::SegmentTree::Node::pivot_
double pivot_
Definition: segment_tree.h:52
scan_tools::SegmentTree::Node
Definition: segment_tree.h:43
d
d
scan_tools::SegmentTree::Node::ChildAxis
constexpr static auto ChildAxis
Definition: segment_tree.h:46
scan_tools::SegmentTree::segments_within
std::vector< Segment > segments_within(Point p, double radius) const
Definition: segment_tree.cpp:101
scan_tools::SegmentTree::Node::operator=
Node & operator=(Node &&)=default
scan_tools::SegmentTree::Node::leaf_capacity
constexpr static auto leaf_capacity
Definition: segment_tree.h:45
scan_tools::SegmentTree::root_
Node< 0 > root_
Definition: segment_tree.h:88
scan_tools::SegmentTree::Node::Node
Node()=default
scan_tools::SegmentTree::SegmentTree
SegmentTree()=default
scan_tools::Segment::diff
Eigen::Vector2d diff() const
Definition: segment_tree.h:30
scan_tools::SegmentTree::Node::segments_
std::vector< Segment > segments_
Definition: segment_tree.h:53
scan_tools::Segment::surface_normal
Eigen::Vector2d surface_normal() const
Definition: segment_tree.h:31
scan_tools::SegmentTree::Node::right_
ChildPtr right_
Definition: segment_tree.h:51
scan_tools::SegmentTree::Node::left_
ChildPtr left_
Definition: segment_tree.h:51
scan_tools::SegmentTree::dump
void dump(std::ostream &os) const
Definition: segment_tree.cpp:121


lsm_localization
Author(s): Ivan Dryanovski , Ilija Hadzic
autogenerated on Fri Dec 23 2022 03:09:11