LOOS  v2.3.2
loos::DensityTools::DensityGrid< T > Class Template Reference

A simple 3D grid class of arbitrary types. More...

#include <DensityGrid.hpp>

Inheritance diagram for loos::DensityTools::DensityGrid< T >:

Public Types

typedef T value_type
 
typedef DensityGridIterator< T, T > iterator
 
typedef DensityGridIterator< T, const T > const_iterator
 
typedef std::pair< int, int > Range
 

Public Member Functions

 DensityGrid ()
 Empty grid.
 
 DensityGrid (const loos::GCoord &gmin, const loos::GCoord &gmax, const DensityGridpoint &griddims)
 Create a grid with explicit location in realspace and dimensions. More...
 
 DensityGrid (const loos::GCoord &gmin, const loos::GCoord &gmax, const int dim)
 
 DensityGrid (const DensityGrid< T > &g)
 Copies an existing grid.
 
void resize (const loos::GCoord &gmin, const loos::GCoord &gmax, const DensityGridpoint &griddims)
 
const DensityGrid< T > & operator= (const DensityGrid< T > &g)
 This is a "deep" copy of grid.
 
DensityGrid< T > subset (const Range &c, const Range &b, const Range &a)
 
void zero (void)
 Zero out all elements.
 
long gridToIndex (const DensityGridpoint v) const
 
DensityGridpoint gridpoint (const loos::GCoord &x) const
 Converts a real-space coordinate into grid coords.
 
DensityGridpoint gridpoint (const double z, const double y, const double x) const
 Converts a real-space coordinate into grid coords.
 
bool inRange (const DensityGridpoint &g) const
 Checks to make sure the gridpoint lies within the grid boundaries.
 
bool inRange (const int k, const int j, const int i) const
 
T & operator() (const int k, const int j, const int i)
 Access the grid element indexed by k, j, i.
 
T & operator() (const DensityGridpoint &v)
 Access the grid element indexed by the DensityGridPoint.
 
T & operator() (const long i)
 
T & operator() (const loos::GCoord &x)
 Converts x into grid coords, then accesses that element.
 
const T & operator() (const int k, const int j, const int i) const
 
const T & operator() (const DensityGridpoint &v) const
 
const T & operator() (const long i) const
 
const T & operator() (const loos::GCoord &x) const
 
DensityGridPlane< T > operator[] (const int k)
 Returns the kth plane from the grid.
 
loos::GCoord gridToWorld (const DensityGridpoint &v) const
 Converts grid coords to real-space (world) coords.
 
DensityGridpoint indexToGrid (const long idx) const
 Calculates the grid coords from a linear index.
 
double gridDist2 (const DensityGridpoint &u, const DensityGridpoint &v)
 Squared-distance (in real-space) between two grid coords.
 
double gridDist (const DensityGridpoint &u, const DensityGridpoint &v)
 Linear distance (in real-space) between two grid coords.
 
std::vector< DensityGridpointwithinBoxRadius (const double r, const loos::GCoord &u, const int pad=0) const
 
std::vector< DensityGridpointwithinRadius (const double r, const loos::GCoord &u) const
 
template<typename Func >
void applyWithinRadius (const double r, const loos::GCoord &u, const Func &f)
 
void scale (const T val)
 
void clear (const T val=0)
 
DensityGridpoint gridDims (void) const
 
loos::GCoord minCoord (void) const
 
loos::GCoord maxCoord (void) const
 
loos::GCoord gridDelta (void) const
 
long maxGridIndex (void) const
 
long size () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
bool empty () const
 
void setMetadata (const std::string &s)
 
void addMetadata (const std::string &s)
 
SimpleMeta metadata () const
 
void metadata (const SimpleMeta &m)
 

Friends

class DensityGridRow< T >
 
class DensityGridPlane< T >
 
class DensityGridIterator< T, T >
 
class DensityGridIterator< T, const T >
 
std::ostream & operator<< (std::ostream &os, const DensityGrid< T > &grid)
 Write out a grid. More...
 
std::istream & operator>> (std::istream &is, DensityGrid< T > &grid)
 Read in a grid. More...
 

Detailed Description

template<class T>
class loos::DensityTools::DensityGrid< T >

A simple 3D grid class of arbitrary types.

This class represents a simple 3D grid of elements. The grid is located somewhere in realspace and supports conversion from grid-space to real-space and back. Individual grid elements can be indexed any number of ways. The DensityGridPoint type is really a LOOS Coord, but with integer elements. You can index a grid-point by using a DensityGridPoint, i.e.

DensityGridPoint p(1,2,3);
T value = a_grid(p);

Alternatively, you can pass the indices separately to the grid () operator,

T value = a_grid(3,2,1);

This can be the source of some confusion about how to index the grid. The above example has the form a_grid(z,y,x), which mimics how one would address a multidimensional array in C/C++. When using a DensityGridPoint, however, the components are specified as a regular coordinate, i.e. (x,y,z). As an alternative, you can access the grid as though it was a linear array by passing a long to operator(), i.e.

T value = a_grid(1024);

Finally, you can slice up a grid using operator[], so the first example above could be rewritten as:

T value = a_grid[3][2][1];

This method is not terribly efficient, unless you are going to operate say just a plane.

Storing and loading grids is very easy. Just use the << and >> operators...

Definition at line 53 of file DensityGrid.hpp.

Constructor & Destructor Documentation

template<class T>
loos::DensityTools::DensityGrid< T >::DensityGrid ( const loos::GCoord gmin,
const loos::GCoord gmax,
const DensityGridpoint griddims 
)
inline

Create a grid with explicit location in realspace and dimensions.

The passed GCoords are the corners of the grid in real-space. The DensityGridpoint defines the size of each dimension of the grid.

Definition at line 248 of file DensityGrid.hpp.

template<class T>
loos::DensityTools::DensityGrid< T >::DensityGrid ( const loos::GCoord gmin,
const loos::GCoord gmax,
const int  dim 
)
inline

Creates a grid with an explicit location and uniform size in all dimensions

Definition at line 253 of file DensityGrid.hpp.

Member Function Documentation

template<class T>
template<typename Func >
void loos::DensityTools::DensityGrid< T >::applyWithinRadius ( const double  r,
const loos::GCoord u,
const Func &  f 
)
inline

Applies a functor to all grid points that lie on or within a sphere of radius r about the real-space coords u.

Definition at line 524 of file DensityGrid.hpp.

template<class T>
long loos::DensityTools::DensityGrid< T >::gridToIndex ( const DensityGridpoint  v) const
inline

Takes an DensityGridPoint and returns the "linear" index into the grid

Definition at line 324 of file DensityGrid.hpp.

template<class T>
T& loos::DensityTools::DensityGrid< T >::operator() ( const long  i)
inline

Access the element indexed by i, assuming the grid to be a big linear array

Definition at line 381 of file DensityGrid.hpp.

template<class T>
std::vector<DensityGridpoint> loos::DensityTools::DensityGrid< T >::withinBoxRadius ( const double  r,
const loos::GCoord u,
const int  pad = 0 
) const
inline

Returns a vector of DensityGridPoints that lie within a box containing a sphere of radius r

Definition at line 464 of file DensityGrid.hpp.

template<class T>
std::vector<DensityGridpoint> loos::DensityTools::DensityGrid< T >::withinRadius ( const double  r,
const loos::GCoord u 
) const
inline

Returns a vector of DensityGridPoints that lie within a given radius of a real-space coord This first converts the real-space coords into grid-space, then finds the bounding box for the sphere with radius r. It then checks each grid-point to see if it actually lies on the surface or within the sphere and returns a vector of DensityGridPoints that do.

Definition at line 497 of file DensityGrid.hpp.

Friends And Related Function Documentation

template<class T>
std::ostream& operator<< ( std::ostream &  os,
const DensityGrid< T > &  grid 
)
friend

Write out a grid.

This simply linearizes the grid and writes it out (with associated metadata). This means that if your grid is mostly empty, it will be rather wasteful. On the other handle, it IS a simple grid implementation...

Definition at line 579 of file DensityGrid.hpp.

template<class T>
std::istream& operator>> ( std::istream &  is,
DensityGrid< T > &  grid 
)
friend

Read in a grid.

Any existing grid will get clobbered–replaced by the grid being read in.

Definition at line 596 of file DensityGrid.hpp.


The documentation for this class was generated from the following file: