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

A class to store regularaly spaced data. More...

#include <regularData1D.h>

Inheritance diagram for BALL::TRegularData1D< ValueType >:
Inheritance graph
[legend]

List of all members.


Classes

struct BlockValueType
The block data type for reading and writing binary data. 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 Position IndexType
The IndexType.
typedef std::vector< ValueType > VectorType
The type containing an STL vector of the corresponding ValueType.
typedef double CoordinateType
The coordinate type.
typedef std::vector< ValueType >
::iterator
Iterator
A mutable iterator.
typedef std::vector< ValueType >
::const_iterator
ConstIterator
A constant iterator.

Public Member Functions

Constructors and Destructors.
TRegularData1D ()
Default constructor.
TRegularData1D (const TRegularData1D &data) throw (Exception::OutOfMemory)
Copy constructor.
TRegularData1D (const CoordinateType &origin, const CoordinateType &dimension, const CoordinateType &spacing) throw (Exception::OutOfMemory)
TRegularData1D (const IndexType &size) throw (Exception::OutOfMemory)
This constructor sets origin to 0.0 and dimension to 1.0.
TRegularData1D (const VectorType &data, const CoordinateType &origin=0.0, const CoordinateType &dimension=1.0) throw (Exception::OutOfMemory)
virtual ~TRegularData1D ()
Destructor.
virtual void clear ()
Clear the contents.
Assignment
TRegularData1D & operator= (const TRegularData1D< ValueType > &data) throw (Exception::OutOfMemory)
Assignment operator.
TRegularData1D & operator= (const VectorType &data) throw (Exception::OutOfMemory)
Assignment from a vector of ValueType.
Predicates
bool operator== (const TRegularData1D &data) const
Equality operator.
bool operator!= (const TRegularData1D &data) const
Inequality operator.
bool empty () const
Empty predicate.
bool isInside (const CoordinateType &x) const
Test whether a point is inside the grid.
Iterators
ConstIterator begin () const
ConstIterator end () const
Iterator begin ()
Iterator end ()
Accessors
size_type size () const
size_type max_size () const
void swap (TRegularData1D< ValueType > &data)
const ValueType & getData (const IndexType &index) const throw (Exception::OutOfGrid)
Return a nonmutable reference to a specific data element.
ValueType & getData (const IndexType &index) throw (Exception::OutOfGrid)
Return a mutable reference to a specific data element.
const ValueType & operator[] (const IndexType &index) const
Constant random access operator.
ValueType & operator[] (const IndexType &index)
Mutable random access operator.
ValueType operator() (const CoordinateType &x) const
Function operator.
ValueType getInterpolatedValue (const CoordinateType &x) const throw (Exception::OutOfGrid)
Return the linearly interpolated value of the surrounding two grid points.
void getEnclosingIndices (const CoordinateType &x, Position &lower, Position &upper) const throw (Exception::OutOfGrid)
Return the indices of the grid points to the left and to the right of a point.
void getEnclosingValues (const CoordinateType &x, ValueType &lower, ValueType &upper) const throw (Exception::OutOfGrid)
Return the data at the grid points to the left and to the right of a point.
CoordinateType getCoordinates (const IndexType &index) const throw (Exception::OutOfGrid)
Return the exact coordinates of a grid point.
IndexType getClosestIndex (const CoordinateType &x) const throw (Exception::OutOfGrid)
Return the index of the closest grid point.
IndexType getLowerIndex (const CoordinateType &x) const throw (Exception::OutOfGrid)
Return the index of the grid point with the next lowest coordinate.
const ValueType & getClosestValue (const CoordinateType &x) const throw (Exception::OutOfGrid)
Return a nonmutable reference to the closest non-interpolated value.
ValueType & getClosestValue (const CoordinateType &x) throw (Exception::OutOfGrid)
Return a mutable reference to the closest non-interpolated value.
IndexType getSize () const
Return the number of points in the data set.
const CoordinateType & getOrigin () const
Return the origin of the data.
const CoordinateType & getSpacing () const
Return the spacing of the data.
void setOrigin (const CoordinateType &origin)
Set the origin of the data.
const CoordinateType & getDimension () const
Return the dimension of the data.
void setDimension (const CoordinateType &dimension)
Set the dimension of the data.
void resize (const IndexType &size) throw (Exception::OutOfMemory)
Resize the data.
void rescale (const IndexType &new_size) throw (Exception::OutOfMemory)
Rescale the data.
void binaryWrite (const String &filename) const throw (Exception::FileNotFound)
Write the grid contents in a (non-portable) binary format.
void binaryRead (const String &filename) throw (Exception::FileNotFound)
Read the grid contents from a file written with binaryWrite
Exceptions:
FileNotFound thrown if file doesnt exists or could not be read.


Protected Attributes

CoordinateType origin_
The origin of the data set.
CoordinateType dimension_
The dimension (length).
CoordinateType spacing_
The spacing.
VectorType data_
The data.

Detailed Description

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

A class to store regularaly spaced data.

This class can is intended to hold regularly spaced, one-dimensional data sets. It might be useful to hold data sets like spectra, or precomputed function values.

The two bounds (set with setBoundaries ) designate an X-range with getSize equally spaced values. The data can be accessed in the same way as data of an STL vector (i.e., using operator [] and iterators).
This class fulfills the STL Container and Unary Function requirements.

Member Function Documentation

template<typename ValueType >
void BALL::TRegularData1D< ValueType >::binaryWrite ( const String & filename ) const throw (Exception::FileNotFound)

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

Exceptions:
FileNotFound thrown if file could not be written

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

template<typename ValueType >
TRegularData1D< ValueType >::IndexType BALL::TRegularData1D< ValueType >::getClosestIndex ( const CoordinateType & x ) const throw (Exception::OutOfGrid)

Return the index of the closest grid point.

This method first performs a range check for the argument x and then returns the index of the closest grid point to the left or right of x.

References BALL::Maths::floor().

template<typename ValueType >
ValueType & BALL::TRegularData1D< 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.

References BALL::Maths::floor().

template<typename ValueType >
const ValueType & BALL::TRegularData1D< 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.

References BALL::Maths::floor().

template<typename ValueType>
CoordinateType BALL::TRegularData1D< 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<typename ValueType >
ValueType & BALL::TRegularData1D< 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::TRegularData1D< 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::TRegularData1D< ValueType >::getDimension ( ) const

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::TRegularData1D< ValueType >::getEnclosingIndices ( const CoordinateType & x,
Position & lower,
Position & upper
) const throw (Exception::OutOfGrid)

Return the indices of the grid points to the left and to the right of a point.

Exceptions:
OutOfGrid if the point is outside the grid
Parameters:
x a point inside the grid
lower index of the grid point to the left
upper index of the grid point to the right

template<typename ValueType>
void BALL::TRegularData1D< ValueType >::getEnclosingValues ( const CoordinateType & x,
ValueType & lower,
ValueType & upper
) const throw (Exception::OutOfGrid)

Return the data at the grid points to the left and to the right of a point.

getEnclosingIndices

template<typename ValueType >
ValueType BALL::TRegularData1D< 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.

template<typename ValueType >
TRegularData1D< ValueType >::IndexType BALL::TRegularData1D< ValueType >::getLowerIndex ( const CoordinateType & x ) const throw (Exception::OutOfGrid)

Return the index of the grid point with the next lowest coordinate.

This method first performs a range check for the argument x and then returns the index of the closest grid point to the left (i.e. with a lesser coordinate) of x.

References BALL::Maths::floor().

template<typename ValueType>
const CoordinateType& BALL::TRegularData1D< ValueType >::getOrigin ( ) const

Return the origin of the data.

The origin represents the coordinate of the very first (leftmost) element, i.e. data_[0].

template<typename ValueType>
const CoordinateType& BALL::TRegularData1D< ValueType >::getSpacing ( ) const

Return the spacing of the data.

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

template<typename ValueType >
ValueType BALL::TRegularData1D< 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 .

References BALL::TRegularData1D< ValueType >::data_, BALL::Maths::floor(), BALL::TRegularData1D< ValueType >::origin_, and BALL::TRegularData1D< ValueType >::spacing_.

template<typename ValueType>
TRegularData1D< ValueType > & BALL::TRegularData1D< ValueType >::operator= ( const VectorType & data ) throw (Exception::OutOfMemory)

Assignment from a vector of ValueType.

Copy the contents of the data without changing the boundaries.

References BALL::TRegularData1D< ValueType >::resize().

template<typename ValueType>
TRegularData1D< ValueType > & BALL::TRegularData1D< ValueType >::operator= ( const TRegularData1D< ValueType > & data ) throw (Exception::OutOfMemory)

Assignment operator.

Copy the data and the boundaries.

References BALL::TRegularData1D< ValueType >::origin_.

template<typename ValueType>
ValueType& BALL::TRegularData1D< ValueType >::operator[] ( const IndexType & index )

Mutable random access operator.

Note:
No range checking is done. For a more robust version, please use getData.

template<typename ValueType>
const ValueType& BALL::TRegularData1D< ValueType >::operator[] ( const IndexType & index ) const

Constant random access operator.

Note:
No range checking is done. For a more robust version, please use getData.

template<typename ValueType>
void BALL::TRegularData1D< 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::TRegularData1D< ValueType >::resize ( const IndexType & 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::TRegularData1D< ValueType >::operator=().

template<typename ValueType>
void BALL::TRegularData1D< ValueType >::setDimension ( const CoordinateType & dimension )

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 scaling factor and affect the spacing.


Generated on Thu Aug 6 18:30:28 2009 for BALL by doxygen 1.5.8