BALL::TRegularData2D< ValueType > Class Template Reference
[Generic Datastructures for Regularly Spaced Data]

#include <BALL/DATATYPE/regularData2D.h>

List of all members.


Classes

struct  BlockValueType
 

The block data type for reading and writing binary data.

More...
class  IndexType
 

The index type used to refer to a specific element in the grid (x-, and y-index).

More...

Public Types

typedef ValueType value_type
typedef std::vector< ValueType >
::iterator 
iterator
typedef std::vector< ValueType >
::const_iterator 
const_iterator
typedef std::vector< ValueType >
::reference 
reference
typedef std::vector< ValueType >
::const_reference 
const_reference
typedef std::vector< ValueType >
::pointer 
pointer
typedef std::vector< ValueType >
::difference_type 
difference_type
typedef std::vector< ValueType >
::size_type 
size_type
Type Definitions
typedef std::vector< ValueType > VectorType
 

The type containing an STL vector of the appropriate type.


typedef TVector2< floatCoordinateType
 

The coordinate type.


typedef std::vector< ValueType >
::iterator 
Iterator
 

A mutable iterator.


typedef std::vector< ValueType >
::const_iterator 
ConstIterator
 

A nonmutable iterator.



Public Member Functions

Constructors and Destructors
 TRegularData2D ()
 TRegularData2D (const TRegularData2D< ValueType > &data) throw (Exception::OutOfMemory)
 

Copy constructor.


 TRegularData2D (const CoordinateType &origin, const CoordinateType &dimension, const CoordinateType &spacing) throw (Exception::OutOfMemory)
 TRegularData2D (const IndexType &size, const CoordinateType &origin=CoordinateType(0.0), const CoordinateType &dimension=CoordinateType(1.0)) throw (Exception::OutOfMemory)
virtual ~TRegularData2D ()
virtual void clear ()
Assignment
TRegularData2Doperator= (const TRegularData2D< ValueType > &data) throw (Exception::OutOfMemory)
Predicates
bool operator== (const TRegularData2D< ValueType > &data) const
BALL_INLINE bool operator!= (const TRegularData2D< ValueType > &data) const
 

Inequality operator.


BALL_INLINE bool empty () const
 

Empty predicate.


bool isInside (const CoordinateType &x) const
 

Test if a given point is inside the grid.


Iterators
BALL_INLINE ConstIterator begin () const
BALL_INLINE ConstIterator end () const
BALL_INLINE Iterator begin ()
BALL_INLINE Iterator end ()
Accessors
BALL_INLINE size_type size () const
BALL_INLINE size_type max_size () const
BALL_INLINE void swap (TRegularData2D< ValueType > &data)
const ValueType & getData (const IndexType &index) const throw (Exception::OutOfGrid)
ValueType & getData (const IndexType &index) throw (Exception::OutOfGrid)
const ValueType & getData (Position index) const throw (Exception::OutOfGrid)
ValueType & getData (Position index) throw (Exception::OutOfGrid)
const ValueType & operator[] (const IndexType &index) const
ValueType & operator[] (const IndexType &index)
const ValueType & operator[] (Position index) const
ValueType & operator[] (Position index)
ValueType operator() (const CoordinateType &x) const
ValueType getInterpolatedValue (const CoordinateType &x) const throw (Exception::OutOfGrid)
const ValueType & getClosestValue (const CoordinateType &x) const throw (Exception::OutOfGrid)
ValueType & getClosestValue (const CoordinateType &x) throw (Exception::OutOfGrid)
IndexType getLowerIndex (const CoordinateType &v) const throw (Exception::OutOfGrid)
IndexType getClosestIndex (const CoordinateType &v) const throw (Exception::OutOfGrid)
const IndexTypegetSize () const
const CoordinateTypegetOrigin () const
const CoordinateTypegetSpacing () const
void setOrigin (const CoordinateType &origin)
const CoordinateTypegetDimension () const
void setDimension (const CoordinateType &dimension)
void resize (const IndexType &new_size) throw (Exception::OutOfMemory)
void rescale (const IndexType &new_size) throw (Exception::OutOfMemory)
CoordinateType getCoordinates (const IndexType &index) const throw (Exception::OutOfGrid)
CoordinateType getCoordinates (Position index) const throw (Exception::OutOfGrid)
void getEnclosingIndices (const CoordinateType &r, Position &ll, Position &lr, Position &ul, Position &ur) const throw (Exception::OutOfGrid)
void getEnclosingValues (const CoordinateType &r, ValueType &ll, ValueType &lr, ValueType &ul, ValueType &ur) const throw (Exception::OutOfGrid)
void binaryWrite (const String &filename) const throw (Exception::FileNotFound)
void binaryRead (const String &filename) throw (Exception::FileNotFound)

Protected Attributes

VectorType data_
 

The grid data.


CoordinateType origin_
 

Origin of the grid (offset).


CoordinateType dimension_
 

Dimension of the grid.


CoordinateType spacing_
 

Grid spacing.


IndexType size_
 

The dimensions in grid points.



Detailed Description

template<typename ValueType>
class BALL::TRegularData2D< ValueType >

Two-dimensional grid class. This class represents a two-dimensional array. An instance of ValueType will be created for each point of the grid upon instantiation of TRegularData2D.

This class fulfills the STL Container and Unary Function requirements. Iteration is along the x-axis first, then along the y-axis.

Member Typedef Documentation

template<typename ValueType>
typedef std::vector<ValueType>::const_iterator BALL::TRegularData2D< ValueType >::const_iterator
template<typename ValueType>
typedef std::vector<ValueType>::const_reference BALL::TRegularData2D< ValueType >::const_reference
template<typename ValueType>
typedef std::vector<ValueType>::const_iterator BALL::TRegularData2D< ValueType >::ConstIterator

A nonmutable iterator.

template<typename ValueType>
typedef TVector2<float> BALL::TRegularData2D< ValueType >::CoordinateType

The coordinate type.

template<typename ValueType>
typedef std::vector<ValueType>::difference_type BALL::TRegularData2D< ValueType >::difference_type
template<typename ValueType>
typedef std::vector<ValueType>::iterator BALL::TRegularData2D< ValueType >::iterator
template<typename ValueType>
typedef std::vector<ValueType>::iterator BALL::TRegularData2D< ValueType >::Iterator

A mutable iterator.

template<typename ValueType>
typedef std::vector<ValueType>::pointer BALL::TRegularData2D< ValueType >::pointer
template<typename ValueType>
typedef std::vector<ValueType>::reference BALL::TRegularData2D< ValueType >::reference
template<typename ValueType>
typedef std::vector<ValueType>::size_type BALL::TRegularData2D< ValueType >::size_type
template<typename ValueType>
typedef ValueType BALL::TRegularData2D< ValueType >::value_type
template<typename ValueType>
typedef std::vector<ValueType> BALL::TRegularData2D< ValueType >::VectorType

The type containing an STL vector of the appropriate type.


Constructor & Destructor Documentation

template<class ValueType >
BALL::TRegularData2D< ValueType >::TRegularData2D (  )  [inline]

Default constructor. Creates an empty TRegularData2D object.

template<class ValueType>
BALL::TRegularData2D< ValueType >::TRegularData2D ( const TRegularData2D< ValueType > &  data  )  throw (Exception::OutOfMemory) [inline]

Copy constructor.

template<typename ValueType>
BALL::TRegularData2D< ValueType >::TRegularData2D ( const CoordinateType origin,
const CoordinateType dimension,
const CoordinateType spacing 
) throw (Exception::OutOfMemory)

Constructor.

Parameters:
origin the origin of the grid
dimension the dimension of the grid (extension in x- and y-direction)
spacing the grid spacing along the x- and y-axis
Exceptions:
OutOfMemory if insufficient memory is available to allocate the grid
template<typename ValueType>
BALL::TRegularData2D< ValueType >::TRegularData2D ( const IndexType size,
const CoordinateType origin = CoordinateType(0.0),
const CoordinateType dimension = CoordinateType(1.0) 
) throw (Exception::OutOfMemory)
template<class ValueType >
BALL::TRegularData2D< ValueType >::~TRegularData2D (  )  [inline, virtual]

Destructor.


Member Function Documentation

template<typename ValueType>
BALL_INLINE Iterator BALL::TRegularData2D< ValueType >::begin (  )  [inline]
template<typename ValueType>
BALL_INLINE ConstIterator BALL::TRegularData2D< ValueType >::begin (  )  const [inline]

Referenced by BALL::operator>>().

template<typename ValueType >
void BALL::TRegularData2D< ValueType >::binaryRead ( const String filename  )  throw (Exception::FileNotFound) [inline]

Read the grid contents from a file written with binaryWrite

Exceptions:
FileNotFound thrown if file doesnt exists or could not be read

References BALL::File::close(), BALL::BinaryFileAdaptor< T >::getData(), and BALL::File::isValid().

template<typename ValueType >
void BALL::TRegularData2D< ValueType >::binaryWrite ( const String filename  )  const throw (Exception::FileNotFound) [inline]

Write the grid contents in a (non-portable) binary format.

Exceptions:
FileNotFound thrown if file could not be written

References BALL::BinaryFileAdaptor< T >::setData().

template<typename ValueType>
BALL_INLINE bool BALL::TRegularData2D< ValueType >::empty (  )  const [inline]

Empty predicate.

template<typename ValueType>
BALL_INLINE Iterator BALL::TRegularData2D< ValueType >::end (  )  [inline]
template<typename ValueType>
BALL_INLINE ConstIterator BALL::TRegularData2D< ValueType >::end (  )  const [inline]
template<typename ValueType>
IndexType BALL::TRegularData2D< ValueType >::getClosestIndex ( const CoordinateType v  )  const throw (Exception::OutOfGrid)

Return the position of the grid point closest to the given vector. If there are multiple grid points with equal distance, the grid point with the lowest indices in x, y direction is returned.

Exceptions:
OutOfGrid if the point is outside the grid
template<typename ValueType>
ValueType& BALL::TRegularData2D< ValueType >::getClosestValue ( const CoordinateType x  )  throw (Exception::OutOfGrid)

Return a mutable reference to the closest non-interpolated value. This method first performs a range check for the argument x and then returns the value of the closest data point to the left or right of x.

template<typename ValueType>
const ValueType& BALL::TRegularData2D< ValueType >::getClosestValue ( const CoordinateType x  )  const throw (Exception::OutOfGrid)

Return a nonmutable reference to the closest non-interpolated value. This method first performs a range check for the argument x and then returns the value of the closest data point to the left or right of x.

template<class ValueType >
BALL_INLINE TRegularData2D< ValueType >::CoordinateType BALL::TRegularData2D< ValueType >::getCoordinates ( Position  index  )  const throw (Exception::OutOfGrid) [inline]

Return the exact coordinates of a grid point.

Returns:
CoordinateType
Exceptions:
OutOfGrid if the point is outside the grid
template<typename ValueType>
CoordinateType BALL::TRegularData2D< ValueType >::getCoordinates ( const IndexType index  )  const throw (Exception::OutOfGrid)

Return the exact coordinates of a grid point.

Returns:
CoordinateType
Exceptions:
OutOfGrid if the point is outside the grid
template<class ValueType >
BALL_INLINE ValueType & BALL::TRegularData2D< ValueType >::getData ( Position  index  )  throw (Exception::OutOfGrid) [inline]

Return a mutable reference to a specific data element. This is the range chacking version of operator [].

template<class ValueType >
BALL_INLINE const ValueType & BALL::TRegularData2D< ValueType >::getData ( Position  index  )  const throw (Exception::OutOfGrid) [inline]

Return a nonmutable reference to a specific data element. This is the range chacking version of operator [].

template<typename ValueType>
ValueType& BALL::TRegularData2D< ValueType >::getData ( const IndexType index  )  throw (Exception::OutOfGrid)

Return a mutable reference to a specific data element. This is the range chacking version of operator [].

template<typename ValueType>
const ValueType& BALL::TRegularData2D< ValueType >::getData ( const IndexType index  )  const throw (Exception::OutOfGrid)

Return a nonmutable reference to a specific data element. This is the range chacking version of operator [].

template<typename ValueType>
const CoordinateType& BALL::TRegularData2D< ValueType >::getDimension (  )  const [inline]

Return the dimension of the data. The dimension represents the length of the data vector. Hence, the coordinate of the rightmost element, data_[getSize() - 1] is the origin plus the dimension (getOrigin() + getDimension()).

template<typename ValueType>
void BALL::TRegularData2D< ValueType >::getEnclosingIndices ( const CoordinateType r,
Position ll,
Position lr,
Position ul,
Position ur 
) const throw (Exception::OutOfGrid)

Return the indices of the grid points of the enclosing rectangle. This method calculates the grid rectangle that contains the given vector and returns the indices of the grid points forming this rectangle. The given point lies either in the rectangle or is the lower left front edge of the rectangle.

Returns:
bool true if the vector is inside the grid
Exceptions:
OutOfGrid if the point is outside the grid
Parameters:
r a point inside the grid
ll left lower corner of the rectangle
lr right lower corner of the rectangle
ul left upper corner of the rectangle
ur right upper corner of the rectangle
template<typename ValueType>
void BALL::TRegularData2D< ValueType >::getEnclosingValues ( const CoordinateType r,
ValueType &  ll,
ValueType &  lr,
ValueType &  ul,
ValueType &  ur 
) const throw (Exception::OutOfGrid)

Return the values at the grid points of the enclosing the spcified position.

See also:
getEnclosingIndices
template<typename ValueType>
ValueType BALL::TRegularData2D< ValueType >::getInterpolatedValue ( const CoordinateType x  )  const throw (Exception::OutOfGrid)

Return the linearly interpolated value of the surrounding two grid points. This method first performs a range check for the argument x and then calls operator () (x) to determine an interpolated value at that position.

Reimplemented in BALL::TFFT2D< ComplexTraits >.

template<typename ValueType>
IndexType BALL::TRegularData2D< ValueType >::getLowerIndex ( const CoordinateType v  )  const throw (Exception::OutOfGrid)

Return the position of the grid point with coordinates lesser than the given vector.

Exceptions:
OutOfGrid if the point is outside the grid
template<typename ValueType>
const CoordinateType& BALL::TRegularData2D< ValueType >::getOrigin (  )  const [inline]

Return the origin of the data. The origin represents the coordinate of the very first (lower left) element, i.e. data_[0].

template<typename ValueType>
const IndexType& BALL::TRegularData2D< ValueType >::getSize (  )  const [inline]

Return the size of the grid. This method yields the number of grid points in x- and y-direction. Use size to obtain the total number of points in the grid.

Referenced by BALL::TContourLine< T >::createContourLine().

template<typename ValueType>
const CoordinateType& BALL::TRegularData2D< ValueType >::getSpacing (  )  const [inline]

Return the spacing of the data. The spacing corresponds to the distance between two adjacent data elements.

template<typename ValueType>
bool BALL::TRegularData2D< ValueType >::isInside ( const CoordinateType x  )  const

Test if a given point is inside the grid.

template<typename ValueType>
BALL_INLINE size_type BALL::TRegularData2D< ValueType >::max_size (  )  const [inline]
template<typename ValueType>
BALL_INLINE bool BALL::TRegularData2D< ValueType >::operator!= ( const TRegularData2D< ValueType > &  data  )  const [inline]

Inequality operator.

template<typename ValueType>
ValueType BALL::TRegularData2D< ValueType >::operator() ( const CoordinateType x  )  const

Function operator. This operator allows the use of a TRegularData1D instance as a unary function. As required by the STL Unary Function concept, the argument x is required to be within the correct range. A more robust (range-checking) version of this operator is implemented as getInterpolatedValue .

template<typename ValueType>
BALL_INLINE TRegularData2D< ValueType > & BALL::TRegularData2D< ValueType >::operator= ( const TRegularData2D< ValueType > &  data  )  throw (Exception::OutOfMemory) [inline]

Assignment operator. Copy the data, the origin, and the dimension (spacing is copied implicitly as well).

template<typename ValueType>
bool BALL::TRegularData2D< ValueType >::operator== ( const TRegularData2D< ValueType > &  data  )  const [inline]
template<typename ValueType>
ValueType& BALL::TRegularData2D< ValueType >::operator[] ( Position  index  )  [inline]

Mutable random access operator.

Note:
No range checking is done. For a more robust version, please use getData.
template<typename ValueType>
const ValueType& BALL::TRegularData2D< ValueType >::operator[] ( Position  index  )  const [inline]

Nonmutable random access operator.

Note:
No range checking is done. For a more robust version, please use getData.
template<typename ValueType>
ValueType& BALL::TRegularData2D< ValueType >::operator[] ( const IndexType index  )  [inline]

Mutable random access operator.

Note:
No range checking is done. For a more robust version, please use getData.
template<typename ValueType>
const ValueType& BALL::TRegularData2D< ValueType >::operator[] ( const IndexType index  )  const [inline]

Nonmutable random access operator.

Note:
No range checking is done. For a more robust version, please use getData.
template<typename ValueType>
void BALL::TRegularData2D< ValueType >::rescale ( const IndexType new_size  )  throw (Exception::OutOfMemory)

Rescale the data. Keep the current boundaries of the data and reinterpolate the data to reflect the new size. To create a data set of new_size data points, the data is interpolated linearly at the new data points from the closest points in the old data set.

Parameters:
new_size the new data set size
template<typename ValueType>
void BALL::TRegularData2D< ValueType >::resize ( const IndexType new_size  )  throw (Exception::OutOfMemory)

Resize the data. If new_size is larger than the current size, the data vector is extended to the new size and filled with default constructed items of type ValueType. Resizing to a value lesser than the current size truncates the vector.

The boundaries are adapted and the positions of the retained items fixed, i.e. the dimension is increased or decreased proportionally while the origin remains unchanged.
Parameters:
new_size the new size

Referenced by BALL::operator>>().

template<typename ValueType>
void BALL::TRegularData2D< ValueType >::setDimension ( const CoordinateType dimension  )  [inline]

Set the dimension of the data. This will affect neither the origin of the data, nor the number of elements stored (in contrast to resize() ). It will just store the appropriate scling factor and affect the spacing.

Referenced by BALL::operator>>().

template<typename ValueType>
void BALL::TRegularData2D< ValueType >::setOrigin ( const CoordinateType origin  ) 

Set the origin of the data.

Referenced by BALL::operator>>().

template<typename ValueType>
BALL_INLINE size_type BALL::TRegularData2D< ValueType >::size (  )  const [inline]
template<typename ValueType>
BALL_INLINE void BALL::TRegularData2D< ValueType >::swap ( TRegularData2D< ValueType > &  data  )  [inline]

Member Data Documentation

template<typename ValueType>
CoordinateType BALL::TRegularData2D< ValueType >::spacing_ [protected]