36template <
int D,
class T,
int max_capacity,
int max_depth >
59template <
int D,
class T,
int max_capacity,
int max_depth >
65 while ( node_ >= ntree_->nodes_.size() )
80template <
int D,
class T,
int max_capacity,
int max_depth >
86 while ( ntree_ and ( ntree_ != top_ ) and ntree_->my_subquad_ ==
N - 1 )
88 ntree_ = ntree_->parent_;
92 assert( ntree_ != 0 );
102 ntree_ = ntree_->parent_->children_[ ntree_->my_subquad_ + 1 ];
105 while ( not ntree_->is_leaf() )
107 ntree_ = ntree_->children_[ 0 ];
115 x = std::fmod( x, p );
123template <
int D,
class T,
int max_capacity,
int max_depth >
134 , current_anchor_( 0 )
141 for (
int i = 0; i < D; ++i )
153 for (
int i = 0; i < D; ++i )
160 for (
int j = 0; j < n; ++j )
174template <
int D,
class T,
int max_capacity,
int max_depth >
182 if ( mask_->outside(
Box< D >( ntree_->lower_left_ - anchor_, ntree_->lower_left_ - anchor_ + ntree_->extent_ ) ) )
190 if ( mask_->inside(
Box< D >( ntree_->lower_left_ - anchor_, ntree_->lower_left_ - anchor_ + ntree_->extent_ ) ) )
192 first_leaf_inside_();
199 if ( ntree_->nodes_.empty() or ( not mask_->inside( ntree_->nodes_[ node_ ].first - anchor_ ) ) )
206template <
int D,
class T,
int max_capacity,
int max_depth >
211 if ( current_anchor_ >= anchors_.size() )
219 anchor_ = anchors_[ current_anchor_ ];
224template <
int D,
class T,
int max_capacity,
int max_depth >
246 while ( ntree_ and ( ntree_ != allin_top_ ) and ntree_->my_subquad_ ==
N - 1 )
248 ntree_ = ntree_->parent_;
252 assert( ntree_ != 0 );
255 if ( ntree_ != allin_top_ )
259 ntree_ = ntree_->parent_->children_[ ntree_->my_subquad_ + 1 ];
262 while ( not ntree_->is_leaf() )
264 ntree_ = ntree_->children_[ 0 ];
279 while ( ntree_ and ( ntree_ != top_ ) and ntree_->my_subquad_ ==
N - 1 )
281 ntree_ = ntree_->parent_;
285 assert( ntree_ != 0 );
288 if ( ntree_ == top_ )
290 return next_anchor_();
294 ntree_ = ntree_->parent_->children_[ ntree_->my_subquad_ + 1 ];
296 anchored_position_ = ntree_->lower_left_;
297 anchored_position_ -= anchor_;
299 if ( mask_->inside(
Box< D >( anchored_position_, anchored_position_ + ntree_->extent_ ) ) )
301 return first_leaf_inside_();
304 }
while ( mask_->outside(
Box< D >( anchored_position_, anchored_position_ + ntree_->extent_ ) ) );
306 return first_leaf_();
309template <
int D,
class T,
int max_capacity,
int max_depth >
313 while ( not ntree_->is_leaf() )
316 ntree_ = ntree_->children_[ 0 ];
318 if ( mask_->inside(
Box< D >( ntree_->lower_left_ - anchor_, ntree_->lower_left_ - anchor_ + ntree_->extent_ ) ) )
320 return first_leaf_inside_();
323 if ( mask_->outside(
Box< D >( ntree_->lower_left_ - anchor_, ntree_->lower_left_ - anchor_ + ntree_->extent_ ) ) )
331template <
int D,
class T,
int max_capacity,
int max_depth >
338 while ( not ntree_->is_leaf() )
340 ntree_ = ntree_->children_[ 0 ];
344template <
int D,
class T,
int max_capacity,
int max_depth >
350 if ( allin_top_ == 0 )
353 ( node_ < ntree_->
nodes_.size() ) and ( not anchored_position_inside_mask( ntree_->nodes_[ node_ ].first ) ) )
359 while ( node_ >= ntree_->nodes_.size() )
369 if ( allin_top_ == 0 )
372 ( node_ < ntree_->
nodes_.size() ) and ( not anchored_position_inside_mask( ntree_->nodes_[ node_ ].first ) ) )
382template <
int D,
class T,
int max_capacity,
int max_depth >
387 for (
int i = 0; i < D; ++i )
392 const bool in_left_half =
393 ( (
lower_left_[ i ] +
extent_[ i ] / 2 ) - pos[ i ] ) > -std::numeric_limits< double >::epsilon();
394 r += ( 1 << i ) * ( in_left_half ? 0 : 1 );
400template <
int D,
class T,
int max_capacity,
int max_depth >
406 std::copy(
nodes_.begin(),
nodes_.end(), std::back_inserter( v ) );
410 for (
int i = 0; i <
N; ++i )
417template <
int D,
class T,
int max_capacity,
int max_depth >
420 const Mask< D >& mask,
421 const Position< D >& anchor )
434 for (
typename std::vector< std::pair< Position< D >, T > >::iterator i =
nodes_.begin(); i !=
nodes_.end(); ++i )
436 if (
mask.inside( i->first - anchor ) )
444 for (
int i = 0; i <
N; ++i )
451template <
int D,
class T,
int max_capacity,
int max_depth >
452typename Ntree< D, T, max_capacity, max_depth >::iterator
460 for (
int i = 0; i < D; ++i )
480 for (
int i = 0; i < D; ++i )
485 assert( ( pos -
lower_left_ )[ i ] > -std::numeric_limits< double >::epsilon()
486 and (
lower_left_ +
extent_ - pos )[ i ] > -std::numeric_limits< double >::epsilon() );
500template <
int D,
class T,
int max_capacity,
int max_depth >
506 for (
int j = 0; j <
N; ++j )
509 for (
int i = 0; i < D; ++i )
511 if ( j & ( 1 << i ) )
513 lower_left[ i ] +=
extent_[ i ] * 0.5;
Abstract base class for masks with given dimension.
Definition mask.h:101
Iterator iterating the nodes in a Quadtree.
Definition ntree.h:69
iterator & operator++()
Move the iterator to the next node within the tree.
Definition ntree_impl.h:61
Ntree * ntree_
Definition ntree.h:144
iterator()
Initialize an invalid iterator.
Definition ntree.h:74
void next_leaf_()
Move to the next leaf quadrant, or set ntree_ to 0 if there are no more leaves.
Definition ntree_impl.h:82
Iterator iterating the nodes in a Quadtree inside a Mask.
Definition ntree.h:153
Ntree * ntree_
Definition ntree.h:262
std::vector< Position< D > > anchors_
Definition ntree.h:269
void first_leaf_inside_()
Set the allin_top_ to the current quadrant, and find the first leaf below the current quadrant.
Definition ntree_impl.h:333
void init_()
Initialize.
Definition ntree_impl.h:176
masked_iterator & operator++()
Move the iterator to the next node inside the mask within the tree.
Definition ntree_impl.h:346
const Mask< D > * mask_
Definition ntree.h:266
masked_iterator()
Initialize an invalid iterator.
Definition ntree.h:163
Position< D > anchor_
Definition ntree.h:267
void next_leaf_()
Find the next leaf which is not outside the mask.
Definition ntree_impl.h:226
void next_anchor_()
Go to the next anchor image.
Definition ntree_impl.h:208
void first_leaf_()
Find the first leaf which is not outside the mask.
Definition ntree_impl.h:311
A Ntree object represents a subtree or leaf in a Ntree structure.
Definition ntree.h:55
iterator insert(Position< D > pos, const T &node)
Traverse quadtree structure from current ntree.
Definition ntree_impl.h:453
Position< D > lower_left_
Definition ntree.h:392
bool is_leaf() const
Definition ntree.h:457
Position< D > extent_
Definition ntree.h:393
void split_()
Change a leaf ntree to a regular ntree with four children regions.
Definition ntree_impl.h:502
int my_depth_
This Ntree's depth in the tree.
Definition ntree.h:401
int subquad_(const Position< D > &)
Definition ntree_impl.h:384
static const int N
Definition ntree.h:57
Ntree * children_[N]
Definition ntree.h:402
std::vector< value_type > nodes_
Definition ntree.h:397
std::bitset< D > periodic_
periodic b.c.
Definition ntree.h:403
void append_nodes_(std::vector< value_type > &)
Append this ntree's nodes to the vector.
bool leaf_
Definition ntree.h:395
const std::string mask("mask")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
static double mod(double x, double p)
Definition ntree_impl.h:113
A box is defined by the lower left corner (minimum coordinates) and the upper right corner (maximum c...
Definition position.h:321
Position< D > lower_left
Definition position.h:331
Position< D > upper_right
Definition position.h:332