Subversion Repositories gelsvn

Rev

Rev 77 | Rev 448 | Go to most recent revision | 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) {}
315 jab 22
		Grid2D(): XDIM(0), YDIM(0) {}
23
 
24
		void resize(int i, int j) 
25
				{
26
						XDIM = i;
27
						YDIM = j;
28
						pixels.resize(i*j);
29
				}
30
 
77 jab 31
 
32
		const T& operator()(int i, int j) const 
33
		{
34
		  assert(i>=0 && i< XDIM);
35
		  assert(j>=0 && j< YDIM);
36
		  return pixels[j*XDIM+i];
37
		}
38
 
39
		T& operator()(int i, int j) 
40
		{
41
		  assert(i>=0 && i< XDIM);
42
		  assert(j>=0 && j< YDIM);
43
		  return pixels[j*XDIM+i];
44
		}
45
 
46
		const T& operator()(const CGLA::Vec2i& p) const 
47
		{
48
		  assert(p[0]>=0 && p[0]< XDIM);
49
		  assert(p[1]>=0 && p[1]< YDIM);
50
		  return pixels[p[1]*XDIM+p[0]];
51
		}
52
 
53
		T& operator()(const CGLA::Vec2i& p) 
54
		{
55
		  assert(p[0]>=0 && p[0]< XDIM);
56
		  assert(p[1]>=0 && p[1]< YDIM);
57
		  return pixels[p[1]*XDIM+p[0]];
58
		}
59
 
60
		int get_xdim() const {return XDIM;}
61
		int get_ydim() const {return YDIM;}
62
 
63
	};
64
}
65
 
66
#endif