supereight
Loading...
Searching...
No Matches
iterator.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020-2024 Smart Robotics Lab, Imperial College London, Technical University of Munich
3 * SPDX-FileCopyrightText: 2020-2021 Nils Funk
4 * SPDX-FileCopyrightText: 2019-2024 Sotiris Papatheodorou
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef SE_ITERATOR_HPP
9#define SE_ITERATOR_HPP
10
12#include <stack>
13
14
15
16namespace se {
17
18template<typename DerivedT>
20
36template<typename DerivedT>
39 typedef typename OctreeType::NodeType NodeType;
40
42
44
46
48
49 bool operator==(const BaseIterator& other) const;
50
51 bool operator!=(const BaseIterator& other) const;
52
54
55 // Iterator traits
60 using iterator_category = std::forward_iterator_tag;
61
62 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
63
64 protected:
65 void init();
66
67 private:
68 DerivedT* underlying()
69 {
70 return static_cast<DerivedT*>(this);
71 }
72
73 const DerivedT* underlying() const
74 {
75 return static_cast<const DerivedT*>(this);
76 }
77
78 // Find the next Volume with valid data.
79 void nextData();
80
81 // Reset the iterator state to invalid. Used when finished iterating.
82 void clear();
83
84 // The 3 stacks should always be kept in sync.
85 // Pointers to the Nodes that haven't been checked yet.
86 std::stack<OctantBase*> octant_stack_;
87
88 OctantBase* octant_;
89
90 OctreeType* octree_ptr_ = nullptr;
91};
92
93
94
95template<typename OctreeT>
96struct OctreeIterator : public BaseIterator<OctreeIterator<OctreeT>> {
98
103
104 bool isNext(OctantBase* /* octant_ptr */)
105 {
106 return true;
107 }
108
109 static constexpr bool has_ignore_condition = false;
110};
111
112
113
114template<typename OctreeT>
115struct NodesIterator : public BaseIterator<NodesIterator<OctreeT>> {
117
122
124 {
125 return !octant_ptr->is_block;
126 }
127
128 static constexpr bool has_ignore_condition = false;
129};
130
131
132
133template<typename OctreeT>
134struct BlocksIterator : public BaseIterator<BlocksIterator<OctreeT>> {
136
141
143 {
144 return octant_ptr->is_block;
145 }
146
147 static constexpr bool has_ignore_condition = false;
148};
149
150
151
152template<typename OctreeT>
153struct LeavesIterator : public BaseIterator<LeavesIterator<OctreeT>> {
155
160
162 {
163 return octant_ptr->isLeaf();
164 }
165
166 static constexpr bool has_ignore_condition = false;
167};
168
169
170
171template<typename OctreeT>
172struct UpdateIterator : public BaseIterator<UpdateIterator<OctreeT>> {
174
180
182 {
183 return octant_ptr->is_block && octant_ptr->timestamp >= time_stamp_;
184 }
185
187 {
188 return octant_ptr->timestamp < time_stamp_;
189 }
190
192
193 static constexpr bool has_ignore_condition = true;
194};
195
196
197template<typename MapT, typename SensorT>
198struct FrustumIterator : public BaseIterator<FrustumIterator<MapT, SensorT>> {
199 typedef typename MapT::OctreeType OctreeType;
200
202
203 FrustumIterator(MapT& map, const SensorT& sensor, const Eigen::Isometry3f& T_SM) :
204 BaseIterator<FrustumIterator<MapT, SensorT>>(&map.getOctree()),
205 map_ptr_(&map),
206 sensor_ptr_(&sensor),
207 T_SM_(T_SM)
208 {
209 this->init();
210 }
211
213 {
214 return octant_ptr->is_block;
215 }
216
218 {
219 Eigen::Vector3f octant_centre_point_M;
220 const int octant_size = octantops::octant_to_size<typename MapT::OctreeType>(octant_ptr);
222 // Convert it to the sensor frame.
223 const Eigen::Vector3f octant_centre_point_S = T_SM_ * octant_centre_point_M;
224
225 float octant_radius = std::sqrt(3.0f) / 2.0f * map_ptr_->getRes() * octant_size;
226 bool do_ignore = !sensor_ptr_->sphereInFrustum(octant_centre_point_S, octant_radius);
227 return do_ignore;
228 }
229
230 static constexpr bool has_ignore_condition = true;
231
232 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
233
234 protected:
237 const Eigen::Isometry3f T_SM_; // TODO: Needs to be ref?
238};
239
240
241// Declare and define a base_traits specialization for the octree iterator:
242template<typename OctreeT>
246
247
248
249// Declare and define a base_traits specialization for the nodes iterator:
250template<typename OctreeT>
254
255
256
257// Declare and define a base_traits specialization for the block iterator:
258template<typename OctreeT>
262
263
264
265// Declare and define a base_traits specialization for the leaves iterator:
266template<typename OctreeT>
270
271
272
273// Declare and define a base_traits specialization for the update iterator:
274template<typename OctreeT>
278
279// Declare and define a base_traits specialization for the update iterator:
280template<typename MapT, typename SensorT>
282 typedef typename MapT::OctreeType OctreeType;
283};
284
285
286} // namespace se
287
288#include "impl/iterator_impl.hpp"
289
290#endif // SE_ITERATOR_HPP
Definition image.hpp:19
The base class of all octants (se::Node and se::Block) in an se::Octree.
Definition octant.hpp:19
Helper wrapper to allocate and de-allocate octants in the octree.
Definition bounded_vector.hpp:14
int timestamp_t
The type of the time stamp.
Definition type_util.hpp:55
Iterates over all valid data in the octree at the last scale it was updated at.
Definition iterator.hpp:37
bool operator!=(const BaseIterator &other) const
BaseIterator(OctreeType *octree_ptr)
bool operator==(const BaseIterator &other) const
BaseIterator operator++(int)
OctantBase * operator*() const
OctreeType::NodeType NodeType
Definition iterator.hpp:39
BaseIterator & operator++()
BaseTraits< DerivedT >::OctreeType OctreeType
Definition iterator.hpp:38
std::forward_iterator_tag iterator_category
Definition iterator.hpp:60
OctreeT OctreeType
Definition iterator.hpp:260
MapT::OctreeType OctreeType
Definition iterator.hpp:282
OctreeT OctreeType
Definition iterator.hpp:268
OctreeT OctreeType
Definition iterator.hpp:252
OctreeT OctreeType
Definition iterator.hpp:244
OctreeT OctreeType
Definition iterator.hpp:276
Definition iterator.hpp:19
Definition iterator.hpp:134
BlocksIterator()
Definition iterator.hpp:135
BlocksIterator(OctreeT *octree_ptr)
Definition iterator.hpp:137
bool isNext(OctantBase *octant_ptr)
Definition iterator.hpp:142
static constexpr bool has_ignore_condition
Definition iterator.hpp:147
Definition iterator.hpp:198
MapT::OctreeType OctreeType
Definition iterator.hpp:199
bool isNext(OctantBase *octant_ptr)
Definition iterator.hpp:212
FrustumIterator(MapT &map, const SensorT &sensor, const Eigen::Isometry3f &T_SM)
Definition iterator.hpp:203
static constexpr bool has_ignore_condition
Definition iterator.hpp:230
const SensorT * sensor_ptr_
Definition iterator.hpp:236
bool doIgnore(OctantBase *octant_ptr)
Definition iterator.hpp:217
MapT * map_ptr_
Definition iterator.hpp:235
const Eigen::Isometry3f T_SM_
Definition iterator.hpp:237
FrustumIterator()
Definition iterator.hpp:201
Definition iterator.hpp:153
LeavesIterator()
Definition iterator.hpp:154
LeavesIterator(OctreeT *octree_ptr)
Definition iterator.hpp:156
bool isNext(OctantBase *octant_ptr)
Definition iterator.hpp:161
static constexpr bool has_ignore_condition
Definition iterator.hpp:166
Definition iterator.hpp:115
NodesIterator()
Definition iterator.hpp:116
NodesIterator(OctreeT *octree_ptr)
Definition iterator.hpp:118
static constexpr bool has_ignore_condition
Definition iterator.hpp:128
bool isNext(OctantBase *octant_ptr)
Definition iterator.hpp:123
Definition iterator.hpp:96
OctreeIterator(OctreeT *octree_ptr)
Definition iterator.hpp:99
OctreeIterator()
Definition iterator.hpp:97
static constexpr bool has_ignore_condition
Definition iterator.hpp:109
bool isNext(OctantBase *)
Definition iterator.hpp:104
Definition iterator.hpp:172
static constexpr bool has_ignore_condition
Definition iterator.hpp:193
UpdateIterator()
Definition iterator.hpp:173
UpdateIterator(OctreeT *octree_ptr, timestamp_t time_stamp)
Definition iterator.hpp:175
const timestamp_t time_stamp_
Definition iterator.hpp:191
bool doIgnore(OctantBase *octant_ptr)
Definition iterator.hpp:186
bool isNext(OctantBase *octant_ptr)
Definition iterator.hpp:181