GEL  2
GEL is a library for Geometry and Linear Algebra
Public Types | Public Member Functions
Geometry::AncestorGrid< T, ChildT > Class Template Reference

Class template is used as abstract ancestor of voxel grids. More...

#include <AncestorGrid.h>

List of all members.

Public Types

typedef T DataType

Public Member Functions

 AncestorGrid (int _x_dim, int _y_dim, int _z_dim)
 Construct a grid of specified xyz dimensions.
 AncestorGrid (const CGLA::Vec3i &_dims)
 Construct a grid of specified xyz dimensions.
bool in_domain (const CGLA::Vec3i &p) const
const CGLA::Vec3iget_dims () const
const CGLA::Vec3i get_lo_corner () const
 Get the corner having smallest coordinates.
const CGLA::Vec3iget_hi_corner () const
 Get the corner having greatest coordinates.
const T & operator[] (const CGLA::Vec3i &p) const
void store (const CGLA::Vec3i &p, const T &t)

Detailed Description

template<typename T, class ChildT>
class Geometry::AncestorGrid< T, ChildT >

Class template is used as abstract ancestor of voxel grids.

Strictly speaking, this class is not abstract, since it does not have any virtual functions. However, operator[]() and store() simply call functions in derived classes. To do so, you must pass the derived class as a template argument to this class when you define the derived class. This is called the Barton and Nackman trick. See Todd Veldhuizen, "Techniques for Scientific C++" 1.3.3.


Member Function Documentation

template<typename T, class ChildT>
const CGLA::Vec3i& Geometry::AncestorGrid< T, ChildT >::get_dims ( ) const [inline]

Get dimensions of grid.

This function returns a Vec3i with the dimensions of the grid.

template<typename T, class ChildT>
bool Geometry::AncestorGrid< T, ChildT >::in_domain ( const CGLA::Vec3i p) const [inline]

Check if voxel is within grid bounds. This function is passed a Vec3i, p, and returns true if p is within the voxel grid.

template<typename T, class ChildT>
const T& Geometry::AncestorGrid< T, ChildT >::operator[] ( const CGLA::Vec3i p) const [inline]

Access (read only) a voxel in a grid.

This is the operator[]which is passed a Vec3i and returns a const reference to a voxel. This function is "statically virtual", i.e. it simply calls the store function of a derived class. See below why there is no non-const operator[]

Reimplemented in Geometry::RGrid< T >, and Geometry::HGrid< T, CellT >.

template<typename T, class ChildT>
void Geometry::AncestorGrid< T, ChildT >::store ( const CGLA::Vec3i p,
const T &  t 
) [inline]

Store a voxel in grid.

This function returns nothing but is passed a Vec3i p and T value t and stores t at p in the grid. This function is "statically virtual", i.e. it simply calls the store function of a derived class.

Yes, it would be simpler to provide a non-const operator[], however, a non-const operator[]will often be called even when no writing takes place. (Scott Meyers, "More Effective C++, p. 218) If a grid implementation allocates memory when a voxel is accessed for writing, then it is a problem that we cannot be sure a non-const operator[] is called only if we are writing. We might then allocate memory even if we just want to read.

Reimplemented in Geometry::HGrid< T, CellT >, and Geometry::RGrid< T >.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations