1 | #ifndef MXBLOCK3_INCLUDED // -*- C++ -*-
|
---|
2 | #define MXBLOCK3_INCLUDED
|
---|
3 | #if !defined(__GNUC__)
|
---|
4 | # pragma once
|
---|
5 | #endif
|
---|
6 |
|
---|
7 | /************************************************************************
|
---|
8 |
|
---|
9 | MxBlock3 provides typed access to 3D data blocks.
|
---|
10 |
|
---|
11 | Copyright (C) 1998 Michael Garland. See "COPYING.txt" for details.
|
---|
12 |
|
---|
13 | $Id: MxBlock3.h,v 1.1 2002/09/24 16:53:54 wimmer Exp $
|
---|
14 |
|
---|
15 | ************************************************************************/
|
---|
16 |
|
---|
17 | #include "MxBlock.h"
|
---|
18 |
|
---|
19 | template<class T>
|
---|
20 | class MxBlock3 : public MxBlock<T>
|
---|
21 | {
|
---|
22 | private:
|
---|
23 | uint W, H, D;
|
---|
24 |
|
---|
25 | protected:
|
---|
26 | MxBlock3() { }
|
---|
27 |
|
---|
28 | void init_block(uint w, uint h, uint d)
|
---|
29 | { W=w; H=h; D=d; MxBlock<T>::init_block(w*h*d); }
|
---|
30 | void resize_block(uint w, uint h, uint d)
|
---|
31 | { W=w; H=h; D=d; MxBlock<T>::resize_block(w*h*d); }
|
---|
32 | void free_block() { MxBlock<T>::free_block(); }
|
---|
33 |
|
---|
34 | T& raw(uint i, uint j, uint k) { return MxBlock<T>::raw(k*W*H + j*W + i); }
|
---|
35 | const T& raw(uint i, uint j, uint k) const
|
---|
36 | { return MxBlock<T>::raw(k*W*H + j*W + i); }
|
---|
37 |
|
---|
38 | #define __MXCK(i,j,k) AssertBound(i<W); AssertBound(j<H); AssertBound(k<D)
|
---|
39 |
|
---|
40 | public:
|
---|
41 | MxBlock3(uint w, uint h, uint d) { init_block(w, h, d); }
|
---|
42 | ~MxBlock3() { free_block(); }
|
---|
43 |
|
---|
44 | T& ref(uint i,uint j,uint k) {__MXCK(i,j,k);return raw(i,j,k);}
|
---|
45 | const T& ref(uint i,uint j,uint k) const {__MXCK(i,j,k);return raw(i,j,k);}
|
---|
46 | T& operator()(uint i,uint j,uint k) { return ref(i,j,k); }
|
---|
47 | const T& operator()(uint i,uint j,uint k) const { return ref(i,j,k); }
|
---|
48 |
|
---|
49 | uint width() const { return W; }
|
---|
50 | uint height() const { return H; }
|
---|
51 | uint depth() const { return D; }
|
---|
52 |
|
---|
53 | void resize(uint w, uint h, uint d) { resize_block(w,h,d); }
|
---|
54 |
|
---|
55 | #undef __MXCK
|
---|
56 | };
|
---|
57 |
|
---|
58 | // MXBLOCK3_INCLUDED
|
---|
59 | #endif
|
---|