Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
mesh
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
;
52
axis_
=
dimension
+
depth
;
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
* Constructor
126
*
127
* Set class members
128
* @param depth Depth of node in tree.
129
*/
130
//BIHNode(unsigned int depth);
131
132
/**
133
* Set depth of node to axes_ class members
134
*
135
* @param depth Depth of node in tree.
136
*/
137
void
set_depth
(
unsigned
int
depth
) {
138
axis_
= depth +
dimension
;
139
}
140
141
/// child nodes indexes
142
unsigned
int
child_
[
child_count
];
143
144
/**
145
* A non-leaf node has two childs (left and right). Their bounding boxes are created from the bounding box of parent
146
* so that in one direction the left child set max to its bound_ and the right child set its min to bound_.
147
* This way we can always repcreate bounding box of every node when traversing the tree from the root.
148
*/
149
double
bound_
;
150
151
/**
152
* Value stores coordination of splitting area for inner nodes or depth for leaf nodes
153
* - values 0,1,2 indicate inner node of tree and coordination of splitting area
154
* - values 3 and greater indicate leaf node of tree and store depth of node (depth = axes_ - 3)
155
*/
156
unsigned
char
axis_
;
157
158
};
159
160
#endif
/* BIH_NODE_HH_ */
Generated on Thu May 29 2014 23:14:48 for Flow123d by
1.8.4