Subversion Repositories gelsvn

Rev

Rev 61 | Rev 595 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61 Rev 89
Line 4... Line 4...
4
#include "CGLA/Vec3i.h"
4
#include "CGLA/Vec3i.h"
5
 
5
 
6
namespace Geometry 
6
namespace Geometry 
7
{
7
{
8
 
8
 
9
	/** This class template is used as abstract ancestor of 
9
	/** \brief Class template is used as abstract ancestor of 
-
 
10
			voxel grids. 
-
 
11
 
10
			voxel grids. Strictly speaking, this class is not 
12
			Strictly speaking, this class is not 
11
			abstract, since it does not have any virtual functions.
13
			abstract, since it does not have any virtual functions.
12
			However, operator[]() and store() simply call 
14
			However, operator[]() and store() simply call 
13
			functions in derived classes. To do so, you must pass
15
			functions in derived classes. To do so, you must pass
14
			the derived class as a template argument to this class
16
			the derived class as a template argument to this class
15
			when you define the derived class. This is called the
17
			when you define the derived class. This is called the
16
			Barton and Nackman trick. See Todd Veldhuizen, 
18
			Barton and Nackman trick. See Todd Veldhuizen, 
17
			"Techniques for Scientific C++" 1.3.3.
19
			"Techniques for Scientific C++" 1.3.3.
18
	*/
20
	*/
19
 
-
 
20
 	template<typename T, class ChildT>
21
 	template<typename T, class ChildT>
21
	class AncestorGrid
22
	class AncestorGrid
22
	{
23
	{
23
	public:
24
	public:
24
		typedef T DataType;
25
		typedef T DataType;
Line 46... Line 47...
46
					return false;
47
					return false;
47
			return true;
48
			return true;
48
		}
49
		}
49
  
50
  
50
		/** Get dimensions of grid.
51
		/** Get dimensions of grid.
-
 
52
 
51
				This function returns a Vec3i with the dimensions
53
				This function returns a Vec3i with the dimensions
52
				of the grid. */
54
				of the grid. */
53
 		const CGLA::Vec3i& get_dims() const {return dims;}
55
 		const CGLA::Vec3i& get_dims() const {return dims;}
54
 
56
 
55
		/** Get the corner having smallest coordinates */
57
		/// Get the corner having smallest coordinates.
56
 		const CGLA::Vec3i get_lo_corner() const {return CGLA::Vec3i(0);}
58
 		const CGLA::Vec3i get_lo_corner() const {return CGLA::Vec3i(0);}
57
 
59
 
58
		/** Get the corner having greatest coordinates. */
60
		/// Get the corner having greatest coordinates. 
59
 		const CGLA::Vec3i& get_hi_corner() const {return dims;}
61
 		const CGLA::Vec3i& get_hi_corner() const {return dims;}
60
 
62
 
61
		/** Access (read only) a voxel in a grid. 
63
		/** Access (read only) a voxel in a grid. 
-
 
64
 
62
				This is the operator[] which is passed a Vec3i 
65
				This is the operator[] which is passed a Vec3i 
63
				and returns a const reference to a voxel.
66
				and returns a const reference to a voxel.
64
				This function is "statically virtual", i.e.
67
				This function is "statically virtual", i.e.
65
				it simply calls the store function of a derived 
68
				it simply calls the store function of a derived 
66
				class.
69
				class.
Line 71... Line 74...
71
			return static_cast<const ChildT&>(*this)[p];
74
			return static_cast<const ChildT&>(*this)[p];
72
		}
75
		}
73
 
76
 
74
 
77
 
75
		/** Store a voxel in grid. 
78
		/** Store a voxel in grid. 
-
 
79
 
76
				This function returns nothing but is passed a 
80
				This function returns nothing but is passed a 
77
				Vec3i p and T value t and stores t at p in the 
81
				Vec3i p and T value t and stores t at p in the 
78
				grid. This function is "statically virtual", i.e.
82
				grid. This function is "statically virtual", i.e.
79
				it simply calls the store function of a derived 
83
				it simply calls the store function of a derived 
80
				class. 
84
				class. 
Line 91... Line 95...
91
		*/
95
		*/
92
 		void store(const CGLA::Vec3i& p, const T& t)
96
 		void store(const CGLA::Vec3i& p, const T& t)
93
		{
97
		{
94
			return static_cast<ChildT&>(*this).store(p,t);
98
			return static_cast<ChildT&>(*this).store(p,t);
95
		}
99
		}
96
 
-
 
97
 		void clear()
-
 
98
		{
-
 
99
			return static_cast<ChildT&>(*this).clear();
-
 
100
		}
-
 
101
	};
100
	};
102
}
101
}
103
 
102
 
104
#endif
103
#endif