Subversion Repositories gelsvn

Rev

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

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