GlobeEngine
GeometricBalancedArrayTreeNode.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_GeometricBalancedArrayTreeNode_h
6 #define VMML_GeometricBalancedArrayTreeNode_h
7 
8 #include <vector>
10 
11 namespace geData {
12  template <short TREESIZE, class KEYTYPE, short HALFTREESIZE>
13  class GeometricBalancedArrayTreeNode : public BalancedArrayTreeNode<TREESIZE, KEYTYPE, HALFTREESIZE>
14  {
15  public:
17  bounds[0] = 0.0f;
18  bounds[1] = 0.0f;
19  bounds[2] = 0.0f;
20  bounds[3] = 0.0f;
21  edgelength = 0;
22  visible = false;
23  midPoint.set(0.0f,0.0f);
24  }
26  virtual void printValue() const {
27  std::cout << edgelength << " ";
28  std::cout << boundsIdx[0] << " ";
29  std::cout << boundsIdx[1] << " ";
30  }
31 
32  const double* getBounds() const {
33  return bounds;
34  }
35 
36  // set bound information
37  void setBounds(vmml::Vector4d _bound)
38  {
39  this->bounds = _bound;
40  this->calculateMidpoint();
41  }
42 
43  // the bound index is the information which position a quadtree
44  // leave would have if the quadtree would be complete and the lowest
45  // level is used as a 2D grid.
46  // TODO FIX THIS SHIT!! with this->root->getMaxDepth();
47  void setBoundIndex(int _maxTreeDepth)
48  {
49  //int maxDepth = 15;
50  int stepSizeIdx = (int)(pow(2.0, _maxTreeDepth) / pow(2.0, this->key->getLod()));
51  this->setBoundsIndex(this->key->getX() * stepSizeIdx, this->key->getY() * stepSizeIdx);
52  }
53 
54  vmml::Vector2d getOrigin() const {
55  vmml::Vector2d pt;
56  pt.set(this->bounds[0], this->bounds[2]);
57  return pt;
58  }
59 
60  vmml::Vector2d getMidpoint() const {
61  return this->midPoint;
62  }
63 
64  bool inside( vmml::Vector2d _coord ) const {
65  double const x = _coord.x(), y = _coord.y();
66  return x >= bounds[0] && x <= bounds[1] && y >= bounds[2] && y <= bounds[3];
67  }
68 
69  int locateChildIDForCoordinates(vmml::Vector2d _coord) const {
70  /* First (in DEBUG mode), ensure that we're inside the node. This
71  * assert would be similar to the final assert() in the original
72  * code.
73  */
74  assert( inside( _coord ) );
75 
76  /* Now, assume that we're inside; we can do better than the
77  * original code, since we can omit a whole bunch of checks.
78  */
79  double const childEdge = this->edgelength * 0.5;
80 
81  double const x = _coord.x(), y = _coord.y();
82  double const midX = bounds[0] + childEdge, midY = bounds[2] + childEdge;
83 
84 
85  int index = 0;
86  if( x >= midX ) index |= 1;
87  if( y >= midY ) index |= 2;
88  return this->children[index];
89 
90 # if 0
91  double childEdge = this->edgelength / 2.0;
92  if (_coord.x() >= bounds[0] && _coord.x() < bounds[0] + childEdge
93  && _coord.y() >= bounds[2] && _coord.y() < bounds[2] + childEdge)
94  {
95  return this->children[0];
96  }
97  else if (_coord.x() >= bounds[0] + childEdge && _coord.x() < bounds[1]
98  && _coord.y() >= bounds[2] && _coord.y() < bounds[2] + childEdge)
99  {
100  return this->children[1];
101  }
102  else if (_coord.x() >= bounds[0] && _coord.x() < bounds[0] + childEdge
103  && _coord.y() >= bounds[2] + childEdge && _coord.y() < bounds[3])
104  {
105  return this->children[2];
106  }
107  else if (_coord.x() >= bounds[0] + childEdge && _coord.x() < bounds[1]
108  && _coord.y() >= bounds[2] + childEdge && _coord.y() < bounds[3])
109  {
110  return this->children[3];
111  }
112  assert(false);
113 # endif
114  }
115 
116  double getEdgelenght() const {
117  return edgelength;
118  }
119 
120  void setEdgelenght(double _edgelength) {
121  this->edgelength = _edgelength;
122  }
123 
124  void setBoundsIndex(GLuint _min_x, GLuint _min_y) {
125  boundsIdx[0] = _min_x;
126  boundsIdx[1] = _min_y;
127  }
128 
129  const GLuint* getBoundsIndex() const {
130  return boundsIdx;
131  }
132 
133  bool isVisible() const {
134  return visible;
135  }
136 
137  void isVisible(bool _input) {
138  visible = _input;
139  }
140 
141  void print() {
143  std::cout << this->visible << " | ";
144  std::cout << this->edgelength << " | ";
145  std::cout << this->boundsIdx[0] << " , ";
146  std::cout << this->boundsIdx[1] << " | ";
147  std::cout << this->bounds[0];
148  for (int i = 1; i < 4; i++){
149  std::cout << "," << this->bounds[i];
150  }
151  std::cout << " | ";
152  }
153 
154  protected:
155 
160  edgelength = this->bounds[1] - this->bounds[0];
161  this->midPoint.set(this->bounds[0] + (edgelength / 2.0), this->bounds[2] + (edgelength / 2.0));
162  }
163 
164  //double bounds[4]; // min_x/max_x min_y/max_y
165  vmml::Vector4d bounds;
166  GLuint boundsIdx[2];
167  vmml::Vector2d midPoint;
168  double edgelength;
169  bool visible;
170  };
171 
174 
175 }
176 #endif
void calculateMidpoint()
Definition: GeometricBalancedArrayTreeNode.h:159
void print()
Definition: BalancedArrayTreeNode.h:25
bool isVisible() const
Definition: GeometricBalancedArrayTreeNode.h:133
void setEdgelenght(double _edgelength)
Definition: GeometricBalancedArrayTreeNode.h:120
vmml::Vector2d midPoint
Definition: GeometricBalancedArrayTreeNode.h:167
~GeometricBalancedArrayTreeNode()
Definition: GeometricBalancedArrayTreeNode.h:25
expr pow(half base, half exp)
Definition: Half.h:2231
Definition: GeometricBalancedArrayTreeNode.h:13
GeometricBalancedArrayTreeNode()
Definition: GeometricBalancedArrayTreeNode.h:16
Definition: AvalancheTrainingSimulationEngine.h:39
typedef int(CALL_CONVENTION *func_type_com_asprise_ocr_setup)(bool)
bool visible
Definition: GeometricBalancedArrayTreeNode.h:169
virtual void printValue() const
Definition: GeometricBalancedArrayTreeNode.h:26
const GLuint * getBoundsIndex() const
Definition: GeometricBalancedArrayTreeNode.h:129
int children[TREESIZE]
Definition: ArrayTreeNode.h:169
vmml::Vector2d getOrigin() const
Definition: GeometricBalancedArrayTreeNode.h:54
vmml::Vector2d getMidpoint() const
Definition: GeometricBalancedArrayTreeNode.h:60
GLuint boundsIdx[2]
Definition: GeometricBalancedArrayTreeNode.h:166
std::shared_ptr< KEYTYPE > key
Definition: ArrayTreeNode.h:170
bool inside(vmml::Vector2d _coord) const
Definition: GeometricBalancedArrayTreeNode.h:64
GeometricBalancedArrayTreeNode< 4, geSpatial::CullableSpatialKey, 2 > GeometricBalancedArrayQuadTreeNode
Definition: GeometricBalancedArrayTreeNode.h:172
void print()
Definition: GeometricBalancedArrayTreeNode.h:141
void setBoundsIndex(GLuint _min_x, GLuint _min_y)
Definition: GeometricBalancedArrayTreeNode.h:124
void isVisible(bool _input)
Definition: GeometricBalancedArrayTreeNode.h:137
GeometricBalancedArrayTreeNode< 2, geSpatial::BinaryTreeKey, 1 > GeometricBalancedArrayBinTreeNode
Definition: GeometricBalancedArrayTreeNode.h:173
int locateChildIDForCoordinates(vmml::Vector2d _coord) const
Definition: GeometricBalancedArrayTreeNode.h:69
void setBounds(vmml::Vector4d _bound)
Definition: GeometricBalancedArrayTreeNode.h:37
void setBoundIndex(int _maxTreeDepth)
Definition: GeometricBalancedArrayTreeNode.h:47
double edgelength
Definition: GeometricBalancedArrayTreeNode.h:168
const double * getBounds() const
Definition: GeometricBalancedArrayTreeNode.h:32
vmml::Vector4d bounds
Definition: GeometricBalancedArrayTreeNode.h:165
Definition: BalancedArrayTreeNode.h:13
double getEdgelenght() const
Definition: GeometricBalancedArrayTreeNode.h:116