supereight
node.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3  * SPDX-FileCopyrightText: 2019-2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
4  * SPDX-FileCopyrightText: 2019-2021 Nils Funk
5  * SPDX-FileCopyrightText: 2019-2021 Sotiris Papatheodorou
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef SE_NODE_HPP
10 #define SE_NODE_HPP
11 
12 namespace se {
13 
14 
15 
27 template<typename NodeT>
28 inline void
29 get_child_idx(const Eigen::Vector3i& octant_coord, NodeT* node_ptr, unsigned int& child_idx);
30 
31 
32 
33 // Forward Declaration
34 template<typename DataT, typename DerivedT>
35 class NodeMultiRes {
36 };
37 
38 
39 
40 template<Field FldT, Colour ColB, Semantics SemB, typename DerivedT>
41 class NodeMultiRes<se::Data<FldT, ColB, SemB>, DerivedT> {
42 };
43 
44 
45 
50 template<Colour ColB, Semantics SemB, typename DerivedT>
51 class NodeMultiRes<se::Data<se::Field::TSDF, ColB, SemB>, DerivedT> {
52  public:
55 
56  NodeMultiRes(const DataType)
57  {
58  }
59 
60  inline const DataType getData() const
61  {
62  return DataType();
63  }
64  inline DataType getData()
65  {
66  return DataType();
67  }
68 };
69 
70 
71 
75 template<Colour ColB, Semantics SemB, typename DerivedT>
76 class NodeMultiRes<se::Data<se::Field::Occupancy, ColB, SemB>, DerivedT> {
77  public:
79 
85  NodeMultiRes(const DataType init_data)
86  {
87  data_ = init_data;
88  }
89 
97  inline const DataType getData() const
98  {
99  return (data_.observed && this->underlying().children_mask_ == 0) ? data_ : DataType();
100  }
101 
109  inline const DataType getMaxData() const
110  {
111  return data_;
112  }
113 
119  inline void setData(const DataType& data)
120  {
121  data_ = data;
122  }
123 
124  protected:
125  DataType data_;
126 
128  private:
129  // Helper functions to access the derived variables.
130  DerivedT& underlying()
131  {
132  return static_cast<DerivedT&>(*this);
133  }
134  const DerivedT& underlying() const
135  {
136  return static_cast<const DerivedT&>(*this);
137  }
138 };
139 
140 
141 
146 template<typename DataT>
148  public:
149  NodeSingleRes(const DataT)
150  {
151  }
152 
153  inline const DataT getData() const
154  {
155  return DataT();
156  }
157  inline DataT getData()
158  {
159  return DataT();
160  }
161 };
162 
163 
170 template<typename DataT, se::Res ResT = se::Res::Single>
171 class Node : public OctantBase,
172  public std::conditional<ResT == Res::Single,
173  NodeSingleRes<DataT>,
174  NodeMultiRes<DataT, Node<DataT, ResT>>>::type {
175  public:
176  typedef DataT DataType;
177 
186  Node(const Eigen::Vector3i& coord, const int size, const DataT init_data);
187 
194  Node(Node* parent_ptr, const int child_idx, const DataT init_data);
195 
201  inline int getSize() const;
202 
210  inline const se::OctantBase* getChild(const int child_idx) const;
211 
219  inline se::OctantBase* getChild(const int child_idx);
220 
227  inline se::OctantBase* setChild(const int child_idx, se::OctantBase* child_ptr);
228 
229  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
230 
231  private:
232  std::array<se::OctantBase*, 8>
233  children_ptr_;
234  const int size_;
235 };
236 
237 
238 
239 } // namespace se
240 
241 
242 
243 #include "impl/node_impl.hpp"
244 
245 
246 
247 #endif // SE_NODE_HPP
se::Data< se::Field::Occupancy, ColB, SemB > DataType
Definition: node.hpp:78
void get_child_idx(const Eigen::Vector3i &octant_coord, NodeT *node_ptr, unsigned int &child_idx)
Get the child idx for a given child coordinate and pointer to the parent node.
The node type of the octant.
Definition: block.hpp:18
DataT getData()
Definition: node.hpp:157
void setData(const DataType &data)
Set the data / max data of the node.
Definition: node.hpp:119
const DataType getData() const
Definition: node.hpp:60
Definition: data.hpp:95
NodeSingleRes(const DataT)
Definition: node.hpp:149
Single-resolution data of a node.
Definition: node.hpp:147
DataType data_
Holds the max data of the node.
Definition: node.hpp:125
se::Data< se::Field::TSDF, ColB, SemB > DataType
Definition: node.hpp:53
Definition: node.hpp:35
const DataT getData() const
Definition: node.hpp:153
This class only helps to dynamic cast the octant to the right type and builds the base of nodes and b...
Definition: octant.hpp:24
se::DeltaData< se::Field::TSDF, ColB, SemB > PropDataType
Definition: node.hpp:54
DataT DataType
Definition: node.hpp:176
const DataType getData() const
Get the leaf data of the node.
Definition: node.hpp:97
const DataType getMaxData() const
Get the max data of the node.
Definition: node.hpp:109
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17
NodeMultiRes(const DataType init_data)
Set the inital data of the node.
Definition: node.hpp:85