-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.cpp
62 lines (50 loc) · 1.29 KB
/
tree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "tree.h"
void Tree::set_root(Cell *root)
{
assert(m_dim == root->get_dimension());
m_root = root;
}
Tree::Tree(unsigned int dim):
m_dim(dim)
{}
Tree::~Tree() {}
Cell* Tree::get_root()
{
return m_root;
}
const Cell* Tree::get_root() const
{
return m_root;
}
const std::vector<Cell*> & Tree::get_leaves() const
{
return m_leaves;
}
std::vector<Cell *> & Tree::get_leaves()
{
return m_leaves;
}
const std::vector<Cell*> & Tree::get_cells() const
{
return m_cells;
}
Point Tree::get_cell_grid_pos(Point const & cell_center,
unsigned int lvl,
Point const & root_cell_center,
double root_cell_size)
{
#if DEBUG
assert(cell_center.get_dimension() == root_cell_center.get_dimension());
#endif
Point center_shift(root_cell_center);
for (int i = 0; i<center_shift.get_dimension(); i++) {
center_shift[i] = root_cell_size/2 - root_cell_center[i];
}
Point shiftet_cell_center = cell_center + center_shift;
double cell_size = root_cell_size/(1<<lvl);
Point grid_coords(cell_center.get_dimension());
for (int i = 0; i<root_cell_center.get_dimension(); i++) {
grid_coords[i] = (int)(shiftet_cell_center[i]/cell_size);
}
return grid_coords;
}