Subversion Repositories gelsvn

Rev

Rev 315 | Rev 595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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