GlobeEngine
ArrayTreeNode.h
Go to the documentation of this file.
1 //
2 // Created by Matthias Thöny on 1/11/12.
3 // Copyright (c) 2012 University of Zuerich. All rights reserved.
4 //
5 #ifndef VMML_ArrayTreeNode_h
6 #define VMML_ArrayTreeNode_h
7 
8 #include <vector>
9 #include "CullableSpatialKey.h"
10 #include "ArrayTree.h"
11 
12 namespace geData {
13  template <short TREESIZE, class KEYTYPE, short HALFTREESIZE>
15  {
16  public:
17  ;
18  ArrayTreeNode(int _uid = -1, int _parent = -1) {
19  this->key = std::make_shared< KEYTYPE >();
20  this->setBasic(_uid, _parent);
21  }
22  ArrayTreeNode(int _uid, std::shared_ptr<KEYTYPE> _key, int _parent){
23  this->setBasic(_uid, _parent);
24  this->key = std::move(_key);
25  }
26  ArrayTreeNode(int _uid, short _lod, int _parent){
27  this->setBasic(_uid, _parent);
28  this->key = std::make_shared< KEYTYPE >();
29  this->setLod(_lod);
30  }
32 
33  void clear() {
34  this->setBasic(-1, -1);
35  }
36 
37  inline void setArrayNodeProperties(int _uid, std::shared_ptr<KEYTYPE> _key, int _parent, bool _isParent){
38  this->setArrayNodeProperties(_uid, _parent, _isParent);
39  key = std::move(_key);
40  }
41 
42  inline void setArrayNodeProperties(int _uid, short _lod, int _parent, bool _isParent){
43  this->setArrayNodeProperties(_uid, _parent, _isParent);
44  this->setLod(_lod);
45  }
46 
47  inline void setArrayNodeProperties(int _uid, int _parent, bool _isParent){
48  this->setBasic(_uid, _parent);
49  parent = _isParent;
50  }
51 
52  /* sets the childid of the node according to
53  the incoming key */
54  //void setChildByKey(KEYTYPE _key, int _childid)
55  void setChildByKey(std::shared_ptr< KEYTYPE > const& _key, int _childid)
56  {
57  // if child is a Left child
58  if(this->key->getX()*2 == _key->getX()){
59  if(this->key->getY()*2 == _key->getY()){
60  children[0] = _childid;
61  }else{
62  children[2] = _childid;
63  }
64  }else{
65  if(this->key->getY()*2 == _key->getY()){
66  children[1] = _childid;
67  }else{
68  children[3] = _childid;
69  }
70  }
71  }
72 
73  int locateKeyInChild(std::shared_ptr<KEYTYPE> const& _key){
74  double powOfDiff = pow(2.0f, _key->getLod() - this->key->getLod());
75  int nodesProj[HALFTREESIZE];
76  for (int i = 0; i < HALFTREESIZE; i++){
77  nodesProj[i] = this->key->getCoord()[i] * powOfDiff;
78  }
79  int sidelenghtOfChild = (int)(powOfDiff / 2.0f);
80  if (nodesProj[0] <= _key->getX() && _key->getX() < nodesProj[0] + sidelenghtOfChild) {
81  if (nodesProj[1] <= _key->getY() && _key->getY() < nodesProj[1] + sidelenghtOfChild) {
82  return children[0];
83  }
84  else {
85  return children[2];
86  }
87  }
88  else {
89  if (nodesProj[1] <= _key->getY() && _key->getY() < nodesProj[1] + sidelenghtOfChild) {
90  return children[1];
91  }
92  else {
93  return children[3];
94  }
95  }
96  }
97 
98  inline void setLod(short _lod){
99  this->key->setLod(_lod);
100  }
101 
102  inline void setBasic(int _uid, int _parent){
103  uid = _uid;
104  parentID = _parent;
105  parent = false;
107  }
108 
109  inline std::shared_ptr< KEYTYPE > const& getKey() const{
110  return this->key;
111  }
112 
113  inline void setKey(std::shared_ptr< KEYTYPE > _key){
114  this->key = std::move(_key);
115  }
116 
117  // use (shared) pointer to avoid this
118 // inline void isAvailable(bool _in){
119 // this->key.isAvailable(_in);
120 // }
121 //
122 // inline bool isAvailable(){
123 // return this->key.isAvailable();
124 // }
125 
126  inline int getUID() const { return uid; }
127  inline void setUID(int _uid) { uid = _uid; }
128  inline const int getChildIdx(short _childIdx) const { return children[_childIdx]; }
129  inline void setChildIdx(short _childIdx, int _idx) { children[_childIdx] = _idx; }
130  inline void repairChildIdx(int _nodeid) {
131  for (int i = 0; i<TREESIZE; i++){
132  if(children[i] > _nodeid){
133  children[i] = children[i]-1;
134  }
135  if(children[i] == _nodeid){
136  std::cout << "there is a problem with the nodeids while delete" << std::endl;
137  }
138  }
139  }
140 
141  inline bool isParent() const { return parent; }
142  inline void isParent(bool _input){
143  parent = _input;
144  }
145  inline void setParentID(int _parent) { parentID = _parent; }
146  inline int getParentID() const { return parentID; }
147 
148  inline const int* getChildren() const { return children; }
149 
150  inline void clearChildIndices() {
151  for (int i = 0; i<TREESIZE; i++){
152  this->children[i] = -1;
153  }
154  }
155 
156  void print(){
157  std::cout << this->uid << " | ";
158  std::cout << *this->key << " | ";
159  std::cout << this->parent << " | ";
160  std::cout << this->parentID << " | ";
161  std::cout << this->getChildIdx(0);
162  for (int i = 1; i<TREESIZE; i++){
163  std::cout << "," << this->getChildIdx(i);
164  }
165  std::cout << " | ";
166  }
167 
168  protected:
169  int children[TREESIZE];
170  std::shared_ptr< KEYTYPE > key;
171 
172  private:
173  int uid;
174  int parentID;
175  bool parent;
176  };
177 
180 
183 
184 }
185 #endif
void setChildByKey(std::shared_ptr< KEYTYPE > const &_key, int _childid)
Definition: ArrayTreeNode.h:55
void print()
Definition: ArrayTreeNode.h:156
expr pow(half base, half exp)
Definition: Half.h:2231
void setKey(std::shared_ptr< KEYTYPE > _key)
Definition: ArrayTreeNode.h:113
Definition: AvalancheTrainingSimulationEngine.h:39
Definition: ArrayTree.h:13
void setUID(int _uid)
Definition: ArrayTreeNode.h:127
void setLod(short _lod)
Definition: ArrayTreeNode.h:98
ArrayTreeNode< 2, geSpatial::BinaryTreeKey, 1 > ArrayBinTreeNode
Definition: ArrayTreeNode.h:179
typedef int(CALL_CONVENTION *func_type_com_asprise_ocr_setup)(bool)
int getParentID() const
Definition: ArrayTreeNode.h:146
std::shared_ptr< KEYTYPE > const & getKey() const
Definition: ArrayTreeNode.h:109
int children[TREESIZE]
Definition: ArrayTreeNode.h:169
void setBasic(int _uid, int _parent)
Definition: ArrayTreeNode.h:102
void setParentID(int _parent)
Definition: ArrayTreeNode.h:145
ArrayTreeNode< 4, geSpatial::CullableSpatialKey, 2 > ArrayQuadTreeNode
Definition: ArrayTreeNode.h:178
std::shared_ptr< KEYTYPE > key
Definition: ArrayTreeNode.h:170
ArrayTree< ArrayBinTreeNode > ArrayBinTree
Definition: ArrayTreeNode.h:182
void setArrayNodeProperties(int _uid, std::shared_ptr< KEYTYPE > _key, int _parent, bool _isParent)
Definition: ArrayTreeNode.h:37
ArrayTreeNode(int _uid, short _lod, int _parent)
Definition: ArrayTreeNode.h:26
void setArrayNodeProperties(int _uid, short _lod, int _parent, bool _isParent)
Definition: ArrayTreeNode.h:42
Definition: ArrayTreeNode.h:14
bool isParent() const
Definition: ArrayTreeNode.h:141
ArrayTreeNode(int _uid, std::shared_ptr< KEYTYPE > _key, int _parent)
Definition: ArrayTreeNode.h:22
void setArrayNodeProperties(int _uid, int _parent, bool _isParent)
Definition: ArrayTreeNode.h:47
void clear()
Definition: ArrayTreeNode.h:33
~ArrayTreeNode()
Definition: ArrayTreeNode.h:31
void setChildIdx(short _childIdx, int _idx)
Definition: ArrayTreeNode.h:129
int getUID() const
Definition: ArrayTreeNode.h:126
void isParent(bool _input)
Definition: ArrayTreeNode.h:142
int locateKeyInChild(std::shared_ptr< KEYTYPE > const &_key)
Definition: ArrayTreeNode.h:73
void clearChildIndices()
Definition: ArrayTreeNode.h:150
const int getChildIdx(short _childIdx) const
Definition: ArrayTreeNode.h:128
ArrayTreeNode(int _uid=-1, int _parent=-1)
Definition: ArrayTreeNode.h:18
ArrayTree< ArrayQuadTreeNode > ArrayQuadTree
Definition: ArrayTreeNode.h:181
const int * getChildren() const
Definition: ArrayTreeNode.h:148
void repairChildIdx(int _nodeid)
Definition: ArrayTreeNode.h:130