Subversion Repositories gelsvn

Rev

Rev 77 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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