-
Notifications
You must be signed in to change notification settings - Fork 1
/
array3d.h
112 lines (91 loc) · 2.34 KB
/
array3d.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef TAK__ARRAY3D_H__
#define TAK__ARRAY3D_H__
#include "define.h"
#include <cassert>
template <class T>
class Array3d
{
public:
Array3d(unsigned int x, unsigned int y, unsigned int z);
~Array3d();
Array3d(const Array3d<T>& array);
void Set(unsigned int x, unsigned int y, unsigned int z, T type);
T Get(unsigned int x, unsigned int y, unsigned int z) const;
void Reset(T type);
unsigned int SizeX() const;
unsigned int SizeY() const;
unsigned int SizeZ() const;
private:
unsigned int m_x, m_y, m_z;
T* m_array;
T& GetElement(unsigned int x, unsigned int y, unsigned int z);
const T& GetElement(unsigned int x, unsigned int y, unsigned int z) const;
};
template <class T>
Array3d<T>::Array3d(unsigned int x, unsigned int y, unsigned int z) : m_x(x), m_y(y), m_z(z)
{
m_array = new T[m_x * m_y * m_z];
}
template <class T>
Array3d<T>::~Array3d()
{
delete [] m_array;
}
template <class T>
Array3d<T>::Array3d(const Array3d& array)
{
m_x = array.m_x;
m_y = array.m_y;
m_z = array.m_z;
m_array = new T[m_x * m_y * m_z];
for(unsigned int i = 0; i < m_x * m_y * m_z; ++i)
m_array[i] = array.m_blocs[i];
}
template <class T>
void Array3d<T>::Set(unsigned int x, unsigned int y, unsigned int z, T type)
{
GetElement(x, y, z) = type;
}
template <class T>
T Array3d<T>::Get(unsigned int x, unsigned int y, unsigned int z) const
{
return GetElement(x, y, z);
}
template <class T>
void Array3d<T>::Reset(T type)
{
for(unsigned int i = 0; i < m_x * m_y * m_z; ++i)
m_array[i] = type;
}
template <class T>
unsigned int Array3d<T>::SizeX() const
{
return m_x;
}
template <class T>
unsigned int Array3d<T>::SizeY() const
{
return m_y;
}
template <class T>
unsigned int Array3d<T>::SizeZ() const
{
return m_z;
}
template <class T>
T& Array3d<T>::GetElement(unsigned int x, unsigned int y, unsigned int z)
{
assert(x < m_x);
assert(y < m_y);
assert(z < m_z);
return m_array[x + (z * m_x) + (y * m_z * m_x)];
}
template <class T>
const T& Array3d<T>::GetElement(unsigned int x, unsigned int y, unsigned int z) const
{
assert(x < m_x);
assert(y < m_y);
assert(z < m_z);
return m_array[x + (z * m_x) + (y * m_z * m_x)];
}
#endif // ARRAY3D_H__