Flow123d  jenkins-Flow123d-linux-release-multijob-282
bih_node.hh
Go to the documentation of this file.
1 /**!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id: bih_node.hh 1567 2012-02-28 13:24:58Z jan.brezina $
21  * $Revision: 1567 $
22  * $LastChangedBy: jan.brezina $
23  * $LastChangedDate: 2012-02-28 14:24:58 +0100 (Tue, 28 Feb 2012) $
24  *
25  *
26  */
27 
28 #ifndef BIH_NODE_HH_
29 #define BIH_NODE_HH_
30 
31 #include "system/system.hh"
32 #include "mesh/bounding_box.hh"
33 #include <armadillo>
34 #include <algorithm>
35 #include "input/accessors.hh"
36 
37 class BIHNode {
38 public:
39 
40  /// count of subareas - don't change
41  static const unsigned int child_count = 2;
42  /// count of dimensions
43  static const unsigned char dimension = 3;
44 
45  /**
46  * Set leaf node.
47  */
48  void set_leaf(unsigned int begin, unsigned int end, double bound,unsigned int depth) {
49  child_[0]=begin;
50  child_[1]=end;
51  bound_ = bound;
53  }
54 
55  /**
56  * Set non-leaf node.
57  */
58  void set_non_leaf(unsigned int left, unsigned int right, unsigned int axis) {
59  ASSERT(axis < dimension," ");
60  ASSERT(is_leaf(), " "); // first must be leaf node (must set bound_)
61  axis_=axis;
62  child_[0]=left;
63  child_[1]=right;
64  }
65 
66  /// return true if node is leaf
67  bool is_leaf() const
68  { return axis_ >= dimension; }
69 
70  /// return depth of leaf node
71 
72  inline unsigned char depth() const
73  {
74  ASSERT( is_leaf(), "Not leaf node.");
75  return axis_ - dimension;
76  }
77 
78  unsigned int leaf_begin() const
79  {
80  ASSERT( is_leaf(), "Not leaf node.");
81  return child_[0];
82  }
83 
84  unsigned int leaf_end() const
85  {
86  ASSERT( is_leaf(), "Not leaf node.");
87  return child_[1];
88  }
89 
90  /**
91  * Get count of elements stored in
92  *
93  * @return Count of elements contained in node
94  */
95  unsigned int leaf_size() const
96  {
97  ASSERT( is_leaf(), "Not leaf node.");
98  return child_[1] - child_[0];
99  }
100 
101  /// return axes (coordination of splitting) of inner node
102  unsigned int axis() const
103  {
104  ASSERT(!is_leaf(), "Not in branch node.\n");
105  return axis_;
106  }
107 
108  double bound() const
109  {
110  return bound_;
111  }
112 
113  /// Return index of child node.
114  unsigned int child(unsigned int i_child) const
115  {
116  ASSERT(!is_leaf(), "Not in branch node.\n");
117  ASSERT_LESS( i_child, child_count );
118  return child_[i_child];
119 
120  }
121 private:
122 
123 
124  /**
125  * Set depth of node to axes_ class members
126  *
127  * @param depth Depth of node in tree.
128  */
129  void set_depth(unsigned int depth) {
130  axis_ = depth + dimension;
131  }
132 
133  /// child nodes indexes
134  unsigned int child_[child_count];
135 
136  /**
137  * A non-leaf node has two childs (left and right). Their bounding boxes are created from the bounding box of parent
138  * so that in one direction the left child set max to its bound_ and the right child set its min to bound_.
139  * This way we can always repcreate bounding box of every node when traversing the tree from the root.
140  */
141  double bound_;
142 
143  /**
144  * Value stores coordination of splitting area for inner nodes or depth for leaf nodes
145  * - values 0,1,2 indicate inner node of tree and coordination of splitting area
146  * - values 3 and greater indicate leaf node of tree and store depth of node (depth = axes_ - 3)
147  */
148  unsigned char axis_;
149 
150 };
151 
152 #endif /* BIH_NODE_HH_ */
unsigned int leaf_end() const
Definition: bih_node.hh:84
double bound() const
Definition: bih_node.hh:108
unsigned int child(unsigned int i_child) const
Return index of child node.
Definition: bih_node.hh:114
void set_non_leaf(unsigned int left, unsigned int right, unsigned int axis)
Definition: bih_node.hh:58
void set_depth(unsigned int depth)
Definition: bih_node.hh:129
unsigned char axis_
Definition: bih_node.hh:148
#define ASSERT(...)
Definition: global_defs.h:121
static const unsigned char dimension
count of dimensions
Definition: bih_node.hh:43
#define ASSERT_LESS(a, b)
Definition: global_defs.h:164
unsigned int child_[child_count]
child nodes indexes
Definition: bih_node.hh:134
unsigned char depth() const
return depth of leaf node
Definition: bih_node.hh:72
double bound_
Definition: bih_node.hh:141
unsigned int leaf_size() const
Definition: bih_node.hh:95
unsigned int axis() const
return axes (coordination of splitting) of inner node
Definition: bih_node.hh:102
static const unsigned int child_count
count of subareas - don&#39;t change
Definition: bih_node.hh:41
bool is_leaf() const
return true if node is leaf
Definition: bih_node.hh:67
void set_leaf(unsigned int begin, unsigned int end, double bound, unsigned int depth)
Definition: bih_node.hh:48
unsigned int leaf_begin() const
Definition: bih_node.hh:78