GlobeEngine
ArrayTriangle.h
Go to the documentation of this file.
1 //
2 // VBOVertex.h
3 // GlobeEngine
4 //
5 // Created by Mathias Thöny on 27.12.11.
6 // Copyright (c) 2011 University of Zurich. All rights reserved.
7 //
8 
9 #ifndef GlobeEngine_ArrayTriangle_h
10 #define GlobeEngine_ArrayTriangle_h
11 
12 #include "VBOVertex.h"
13 #include "OpenGL_Includes.h"
14 #include <iostream>
15 
16 namespace geData {
23  // D = Dimension of point vector, T = precission type of coordinates
24  template <int D, class T> class ArrayTriangle
25  {
26  public:
28 
29  ArrayTriangle(const T* _data){
30  memcpy ( this->data, _data, 3 * D * sizeof(T) );
31  }
32 
34 
35  void setArray(const T* _data){
36  memcpy ( this->data, _data, 3 * D * sizeof(T) );
37  }
38 
39  const T* getArray(){
40  return data;
41  }
42 
43  friend std::ostream& operator<< (std::ostream &out, const ArrayTriangle<D,T> &triangle) {
44  int l = 3*D;
45  out << "Array: " << triangle.data[0];
46  for (int i=1; i < l; i++)
47  {
48  out << ", " << triangle.data[i];
49  }
50  return out;
51  }
52 
53  protected:
54  T data[3*D];
55  };
56 
57  template <class T> class ArrayTriangle2D : public ArrayTriangle<2,T>
58  {
59  public:
62  set(_p1, _p2, _p3);
63  }
64 
66  set(_data);
67  }
68 
69  void set(const ge::Vertex2<T> _p1, const ge::Vertex2<T> _p2,const ge::Vertex2<T> _p3){
70  this->data[0] = _p1.x();
71  this->data[1] = _p1.y();
72  this->data[2] = _p2.x();
73  this->data[3] = _p2.y();
74  this->data[4] = _p3.x();
75  this->data[5] = _p3.y();
76  }
77 
78  void set(const ge::Vertex2<T>* _data){
79  for(short i=0; i < 2; i++)
80  {
81  this->data[i*2] = _data[i].x();
82  this->data[i*2+1] = _data[i].y();
83  }
84  }
85  };
86 
95 
96  template <class T> class ArrayTriangle3D : public ArrayTriangle<3,T>
97  {
98  public:
101  set(_p1, _p2, _p3);
102  }
103 
105  set(_data);
106  }
107 
108  void set(const ge::VBOVertex3<T> _p1, const ge::VBOVertex3<T> _p2,const ge::VBOVertex3<T> _p3){
109  this->data[0] = _p1.x();
110  this->data[1] = _p1.y();
111  this->data[2] = _p1.z();
112  this->data[3] = _p2.x();
113  this->data[4] = _p2.y();
114  this->data[5] = _p2.z();
115  this->data[6] = _p3.x();
116  this->data[7] = _p3.y();
117  this->data[8] = _p3.z();
118  }
119 
120  void set(const ge::VBOVertex3<T>* _data){
121  for(short i=0; i < 3; i++)
122  {
123  this->data[i*3] = _data[i].x();
124  this->data[i*3+1] = _data[i].y();
125  this->data[i*3+2] = _data[i].z();
126  }
127  }
128  };
129 
138 
139  template <class T> class ArrayTriangle4D : public ArrayTriangle<4,T>
140  {
141  public:
144  set(_p1, _p2, _p3);
145  }
146 
148  set(_data);
149  }
150 
151  void set(const ge::VBOVertex4<T> _p1, const ge::VBOVertex4<T> _p2,const ge::VBOVertex4<T> _p3){
152  this->data[0] = _p1.x();
153  this->data[1] = _p1.y();
154  this->data[2] = _p1.z();
155  this->data[3] = _p1.w();
156  this->data[4] = _p2.x();
157  this->data[5] = _p2.y();
158  this->data[6] = _p2.z();
159  this->data[7] = _p2.w();
160  this->data[8] = _p3.x();
161  this->data[9] = _p3.y();
162  this->data[10] = _p3.z();
163  this->data[11] = _p3.w();
164  }
165 
166  void set(const ge::VBOVertex4<T>* _data){
167  for(short i=0; i < 4; i++)
168  {
169  this->data[i*4] = _data[i].x();
170  this->data[i*4+1] = _data[i].y();
171  this->data[i*4+2] = _data[i].z();
172  this->data[i*4+3] = _data[i].z();
173  }
174  }
175  };
176 
185 
186 
187  // D = Dimension of point vector, T = precision type of coordinates
188  template <int D, class T> class TriangleArray
189  {
190  public:
192  data = NULL;
193  }
194 
195  TriangleArray(int _triangleCount, const T* _data){
196  allocateMemory(_triangleCount);
197  memcpy ( this->data, _data, _triangleCount * 3 * D * sizeof(T) );
198  }
199 
201  clear();
202  }
203 
204  void create(int _triangleCount){
205  allocateMemory(_triangleCount);
206  }
207 
208  void setAt(int _idx, const T _data){
209  this->data[_idx] = _data;
210  }
211 
212  void setRangeArray(int _startIndex, int _pointCount, const T* _data){
213  memcpy(this->data[_startIndex], _data, _pointCount * 3 * D * sizeof(T));
214  }
215 
216  void setArray(int _triangleCount, const T* _data){
217  allocateMemory(_triangleCount);
218  memcpy(this->data, _data, _triangleCount * 3 * D * sizeof(T) );
219  }
220 
221  const T* getArray(){
222  return data;
223  }
224 
225  const int getTriangleCount(){
226  return triangleCount;
227  }
228 
229  friend std::ostream& operator<< (std::ostream &out, const TriangleArray<D,T> &triangle) {
230  int l = triangle.getTriangleCount() * 3 * D;
231  out << "Array: " << triangle.data[0];
232  for (int i=1; i < l; i++)
233  {
234  out << ", " << triangle.data[i];
235  }
236  return out;
237  }
238 
239  private:
240  void allocateMemory(int _triangleCount){
241  clear();
242  triangleCount = _triangleCount;
243  data = new T(_triangleCount * 3 * D);
244  }
245 
246  void clear(){
247  if (data != NULL)
248  {
249  delete [] data;
250  }
251  data = NULL;
252  triangleCount = 0;
253  }
254 
255  protected:
257  T* data;
258  };
259 
261 }
262 #endif
const T * getArray()
Definition: ArrayTriangle.h:221
T y() const
Definition: VBOVertex.h:247
ArrayTriangle4D(const ge::VBOVertex4< T > *_data)
Definition: ArrayTriangle.h:147
ArrayTriangle4D< GLint > ArrayTriangle4Di
Definition: ArrayTriangle.h:181
T x() const
Definition: VBOVertex.h:79
void set(const ge::VBOVertex4< T > _p1, const ge::VBOVertex4< T > _p2, const ge::VBOVertex4< T > _p3)
Definition: ArrayTriangle.h:151
void set(const ge::VBOVertex3< T > _p1, const ge::VBOVertex3< T > _p2, const ge::VBOVertex3< T > _p3)
Definition: ArrayTriangle.h:108
ArrayTriangle4D< GLushort > ArrayTriangle4Dus
Definition: ArrayTriangle.h:180
void set(const ge::Vertex2< T > _p1, const ge::Vertex2< T > _p2, const ge::Vertex2< T > _p3)
Definition: ArrayTriangle.h:69
ArrayTriangle2D< GLint > ArrayTriangle2Di
Definition: ArrayTriangle.h:91
Definition: ArrayTriangle.h:24
Definition: AvalancheTrainingSimulationEngine.h:39
~TriangleArray()
Definition: ArrayTriangle.h:200
TriangleArray< 3, GLdouble > TriangleArray3Dd
Definition: ArrayTriangle.h:260
ArrayTriangle3D< GLshort > ArrayTriangle3Ds
Definition: ArrayTriangle.h:132
ArrayTriangle3D< GLubyte > ArrayTriangle3Dub
Definition: ArrayTriangle.h:131
ArrayTriangle4D< GLdouble > ArrayTriangle4Dd
Definition: ArrayTriangle.h:184
void set(const ge::VBOVertex3< T > *_data)
Definition: ArrayTriangle.h:120
ArrayTriangle2D< GLfloat > ArrayTriangle2Df
Definition: ArrayTriangle.h:93
ArrayTriangle4D< GLubyte > ArrayTriangle4Dub
Definition: ArrayTriangle.h:178
void set(const ge::Vertex2< T > *_data)
Definition: ArrayTriangle.h:78
ArrayTriangle2D< GLuint > ArrayTriangle2Dui
Definition: ArrayTriangle.h:92
T y() const
Definition: VBOVertex.h:80
ArrayTriangle4D< GLfloat > ArrayTriangle4Df
Definition: ArrayTriangle.h:183
ArrayTriangle2D< GLshort > ArrayTriangle2Ds
Definition: ArrayTriangle.h:89
void setRangeArray(int _startIndex, int _pointCount, const T *_data)
Definition: ArrayTriangle.h:212
ArrayTriangle3D(const ge::VBOVertex3< T > _p1, const ge::VBOVertex3< T > _p2, const ge::VBOVertex3< T > _p3)
Definition: ArrayTriangle.h:100
Definition: ArrayTriangle.h:57
ArrayTriangle3D()
Definition: ArrayTriangle.h:99
Definition: ArrayTriangle.h:96
Definition: ArrayTriangle.h:139
ArrayTriangle()
Definition: ArrayTriangle.h:27
ArrayTriangle4D()
Definition: ArrayTriangle.h:142
ArrayTriangle2D< GLbyte > ArrayTriangle2Db
Definition: ArrayTriangle.h:87
T y() const
Definition: VBOVertex.h:132
ArrayTriangle3D< GLint > ArrayTriangle3Di
Definition: ArrayTriangle.h:134
T x() const
Definition: VBOVertex.h:246
T z() const
Definition: VBOVertex.h:133
ArrayTriangle3D(const ge::VBOVertex3< T > *_data)
Definition: ArrayTriangle.h:104
ArrayTriangle2D(const ge::Vertex2< T > *_data)
Definition: ArrayTriangle.h:65
T x() const
Definition: VBOVertex.h:131
ArrayTriangle4D< GLshort > ArrayTriangle4Ds
Definition: ArrayTriangle.h:179
ArrayTriangle3D< GLbyte > ArrayTriangle3Db
Definition: ArrayTriangle.h:130
ArrayTriangle2D< GLubyte > ArrayTriangle2Dub
Definition: ArrayTriangle.h:88
void set(const ge::VBOVertex4< T > *_data)
Definition: ArrayTriangle.h:166
~ArrayTriangle()
Definition: ArrayTriangle.h:33
ArrayTriangle3D< GLushort > ArrayTriangle3Dus
Definition: ArrayTriangle.h:133
ArrayTriangle3D< GLfloat > ArrayTriangle3Df
Definition: ArrayTriangle.h:136
Definition: VBOVertex.h:115
ArrayTriangle(const T *_data)
Definition: ArrayTriangle.h:29
void setAt(int _idx, const T _data)
Definition: ArrayTriangle.h:208
ArrayTriangle3D< GLdouble > ArrayTriangle3Dd
Definition: ArrayTriangle.h:137
int triangleCount
Definition: ArrayTriangle.h:256
T data[3 *D]
Definition: ArrayTriangle.h:54
ArrayTriangle4D< GLuint > ArrayTriangle4Dui
Definition: ArrayTriangle.h:182
T * data
Definition: ArrayTriangle.h:257
void setArray(const T *_data)
Definition: ArrayTriangle.h:35
ArrayTriangle2D< GLdouble > ArrayTriangle2Dd
Definition: ArrayTriangle.h:94
void create(int _triangleCount)
Definition: ArrayTriangle.h:204
const int getTriangleCount()
Definition: ArrayTriangle.h:225
ArrayTriangle4D< GLbyte > ArrayTriangle4Db
Definition: ArrayTriangle.h:177
T w() const
Definition: VBOVertex.h:249
Definition: ArrayTriangle.h:188
TriangleArray(int _triangleCount, const T *_data)
Definition: ArrayTriangle.h:195
ArrayTriangle2D()
Definition: ArrayTriangle.h:60
Definition: VBOVertex.h:51
ArrayTriangle2D< GLushort > ArrayTriangle2Dus
Definition: ArrayTriangle.h:90
TriangleArray()
Definition: ArrayTriangle.h:191
void setArray(int _triangleCount, const T *_data)
Definition: ArrayTriangle.h:216
Definition: VBOVertex.h:228
const T * getArray()
Definition: ArrayTriangle.h:39
ArrayTriangle3D< GLuint > ArrayTriangle3Dui
Definition: ArrayTriangle.h:135
ArrayTriangle2D(const ge::Vertex2< T > _p1, const ge::Vertex2< T > _p2, const ge::Vertex2< T > _p3)
Definition: ArrayTriangle.h:61
T z() const
Definition: VBOVertex.h:248
ArrayTriangle4D(const ge::VBOVertex4< T > _p1, const ge::VBOVertex4< T > _p2, const ge::VBOVertex4< T > _p3)
Definition: ArrayTriangle.h:143