G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsHDomainSliceIter.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsHSplines/gsKdNode.h>
17 #include <gsCore/gsTemplateTools.h>
18 
19 namespace gismo
20 {
21 
34 template<typename node, bool isconst = false>
36 {
37 public:
38  //typedef kdnode<d, index_t> node;
39  typedef typename choose<isconst, const node&, node&>::type reference;
40  typedef typename choose<isconst, const node*, node*>::type pointer;
41 
42  typedef typename node::point::Projection_t point;
43 
44  static const index_t d = point::_Rows;// d is the slice dimension
45 
46 public:
47  reference operator*() const { return *curNode; }
48  pointer operator->() const { return curNode; }
49 
50 public:
51 
53  : m_dir(0), m_pos(0), m_last(0), curNode(0), m_index_level(0)
54  { }
55 
56  gsHDomainSliceIter( node * const root_node,
57  const unsigned _dir,
58  const unsigned _pos,
59  const unsigned _last,
60  const unsigned index_level)
61  : m_dir(m_dir), m_pos(_pos), m_last(_last), m_index_level(index_level)
62  {
63  m_stack.push(root_node);
64 
65  // Go to the first leaf
66  next();
67  }
68 
69  // Next leaf
70  bool next()
71  {
72  while ( ! m_stack.empty() )
73  {
74  curNode = m_stack.top();
75  m_stack.pop();
76 
77  if ( curNode->isLeaf() )
78  {
79  // does this box intersect the slice ?
80  // note: boxes are considered half-open, eg. products
81  // of intervals [a,b), except from the rightmost
82  // interval which is closed
83  // if ( (curNode->box->lowCorner()[m_dir] <= m_pos) &&
84  // (curNode->box->uppCorner()[m_dir] > m_pos ||
85  // (m_pos == m_last && curNode->box->uppCorner()[m_dir] == m_pos) )
86  // )
87  return true;
88  }
89  else // this is a split-node
90  {
91  if ( curNode->axis == m_dir )
92  {
93  if (m_pos < curNode->pos)
94  m_stack.push(curNode->left);
95  else
96  m_stack.push(curNode->right);
97  }
98  else
99  {
100  m_stack.push(curNode->left);
101  m_stack.push(curNode->right);
102  }
103  }
104  }
105 
106  // Leaves exhausted
107  curNode = NULL;
108  return false;
109  }
110 
112  bool good() const { return curNode != 0; }
113 
115  void startFrom( node * const root_node)
116  {
117  m_stack.clear();
118  m_stack.push(root_node);
119  }
120 
121  int level() const { return curNode->level; }
122 
125  point lowerCorner() const
126  {
127  point result;
128  result.topRows (m_dir ) = curNode->box->first.topRows(m_dir );
129  result.bottomRows(d-m_dir) = curNode->box->first.bottomRows(d-m_dir);
130 
131  const int lvl = curNode->level;
132 
133  for ( index_t i = 0; i!= result.size(); ++i )
134  result[i] = result[i] >> (m_index_level-lvl) ;
135 
136  return result;
137  }
138 
141  point upperCorner() const
142  {
143  point result = curNode->box->second;
144  result.topRows (m_dir ) = curNode->box->second.topRows(m_dir );
145  result.bottomRows(d-m_dir) = curNode->box->second.bottomRows(d-m_dir);
146 
147  const int lvl = curNode->level;
148 
149  for ( index_t i = 0; i!=result.size(); ++i )
150  result[i] = result[i] >> (m_index_level-lvl) ;
151 
152  return result;
153  }
154 
155  unsigned indexLevel() const {return m_index_level;}
156 
157 private:
158 
159  // Slice information
160  unsigned m_dir; // direction normal to the slice
161  unsigned m_pos; // slice position index (span-index)
162  unsigned m_last; // last (span-index) in direction \a m_dir --> most likely not needed
163 
164  // current node
165  node * curNode;
166 
168  unsigned m_index_level;
169 
170  // stack of pointers to tree nodes, used in next()
171  std::stack<node*> m_stack;// to do: change type to std::vector
172 };
173 
174 
175 
176 } // end namespace gismo
void startFrom(node *const root_node)
The iteration is done in the sub-tree hanging from node root_node.
Definition: gsHDomainSliceIter.h:115
point upperCorner() const
The upper corner of the sliced box. Note that m_dir is skipped.
Definition: gsHDomainSliceIter.h:141
#define index_t
Definition: gsConfig.h:32
Iterates over the leaves of an gsHDomain (tree) that intersect with a slice position.
Definition: gsHDomainSliceIter.h:35
unsigned m_index_level
The level of the box representation.
Definition: gsHDomainSliceIter.h:168
bool good() const
Returns true iff we are still pointing at a valid leaf.
Definition: gsHDomainSliceIter.h:112
Utilities related to template programming.
Provides declaration of the tree node.
point lowerCorner() const
The lower corner of the sliced box. Note that m_dir is skipped.
Definition: gsHDomainSliceIter.h:125