Subversion Repositories gelsvn

Rev

Rev 90 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
77 jab 1
#ifndef __GRID2D_H
2
#define __GRID2D_H
3
 
4
#include <vector>
5
#include "CGLA/Vec2i.h"
6
 
7
namespace Util
8
{
9
 
10
	template<class T>
11
	class Grid2D
12
	{
13
		int XDIM, YDIM;
14
		std::vector<T> pixels;
15
 
16
	public:
17
 
18
		~Grid2D() {}
19
 
20
		Grid2D(int i, int j, const T& val): XDIM(i), YDIM(j), pixels(i*j, val) {}
21
		Grid2D(int i, int j): XDIM(i), YDIM(j), pixels(i*j) {}
22
 
23
		const T& operator()(int i, int j) const 
24
		{
25
		  assert(i>=0 && i< XDIM);
26
		  assert(j>=0 && j< YDIM);
27
		  return pixels[j*XDIM+i];
28
		}
29
 
30
		T& operator()(int i, int j) 
31
		{
32
		  assert(i>=0 && i< XDIM);
33
		  assert(j>=0 && j< YDIM);
34
		  return pixels[j*XDIM+i];
35
		}
36
 
37
		const T& operator()(const CGLA::Vec2i& p) const 
38
		{
39
		  assert(p[0]>=0 && p[0]< XDIM);
40
		  assert(p[1]>=0 && p[1]< YDIM);
41
		  return pixels[p[1]*XDIM+p[0]];
42
		}
43
 
44
		T& operator()(const CGLA::Vec2i& p) 
45
		{
46
		  assert(p[0]>=0 && p[0]< XDIM);
47
		  assert(p[1]>=0 && p[1]< YDIM);
48
		  return pixels[p[1]*XDIM+p[0]];
49
		}
50
 
51
		int get_xdim() const {return XDIM;}
52
		int get_ydim() const {return YDIM;}
53
 
54
	};
55
}
56
 
57
#endif