source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Array3.h @ 774

Revision 774, 1.2 KB checked in by gumbau, 18 years ago (diff)

GTGeometry and GeoTool? initial imports

Line 
1#ifndef GFXTOOLS_ARRAY3_INCLUDED // -*- C++ -*-
2#define GFXTOOLS_ARRAY3_INCLUDED
3
4template<class T>
5class array3
6{
7protected:
8    T *data;
9    int w, h, d;
10
11public:
12    array3() { data=NULL; w=h=d=0; }
13    array3(int w, int h, int d) { init(w,h,d); }
14    ~array3() { free(); }
15
16    inline void init(int w, int h, int d);
17    inline void free();
18
19
20    inline T& ref(int i, int j, int k);
21    inline T& operator()(int i,int j, int k) { return ref(i,j, k); }
22
23    inline int width() const { return w; }
24    inline int height() const { return h; }
25    inline int depth() const { return d; }
26};
27
28template<class T>
29inline void array3<T>::init(int width, int height, int depth)
30{
31    w = width;
32    h = height;
33    d = depth;
34    data = new T[w*h*d];
35}
36
37template<class T>
38inline void array3<T>::free()
39{
40    if( data )
41    {
42        delete[] data;
43        data = NULL;
44        w = h = d = 0;
45    }
46
47}
48
49template<class T>
50inline T& array3<T>::ref(int i, int j, int k)
51{
52#ifdef SAFETY
53    assert( data );
54    assert( i>=0 && i<w );
55    assert( j>=0 && j<h );
56    assert( k>=0 && k<d );
57#endif
58    return data[k*w*h + j*w + i];
59}
60
61// GFXTOOLS_ARRAY3_INCLUDED
62#endif
Note: See TracBrowser for help on using the repository browser.