BALL  1.5.0
Classes | Public Types | Protected Attributes | List of all members
BALL::TRegularData1D< ValueType > Class Template Reference

#include <BALL/DATATYPE/regularData1D.h>

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. More...
 
typedef std::vector< ValueType > VectorType
 The type containing an STL vector of the corresponding ValueType. More...
 
typedef double CoordinateType
 The coordinate type. More...
 
typedef std::vector< ValueType >::iterator Iterator
 A mutable iterator. More...
 
typedef std::vector< ValueType >::const_iterator ConstIterator
 A constant iterator. More...
 

Public Member Functions

Constructors and Destructors.
 TRegularData1D ()
 Default constructor. More...
 
 TRegularData1D (const TRegularData1D &data)
 
 TRegularData1D (const CoordinateType &origin, const CoordinateType &dimension, const CoordinateType &spacing)
 
 TRegularData1D (const IndexType &size)
 
 TRegularData1D (const VectorType &data, const CoordinateType &origin=0.0, const CoordinateType &dimension=1.0)
 
virtual ~TRegularData1D ()
 Destructor. More...
 
virtual void clear ()
 Clear the contents. More...
 
Assignment
TRegularData1Doperator= (const TRegularData1D< ValueType > &data)
 
TRegularData1Doperator= (const VectorType &data)
 
Predicates
bool operator== (const TRegularData1D &data) const
 Equality operator. More...
 
BALL_INLINE bool operator!= (const TRegularData1D &data) const
 Inequality operator. More...
 
BALL_INLINE bool empty () const
 Empty predicate. More...
 
bool isInside (const CoordinateType &x) const
 Test whether a point is inside the grid. More...
 
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 (TRegularData1D< ValueType > &data)
 
const ValueType & getData (const IndexType &index) const
 
ValueType & getData (const IndexType &index)
 
const ValueType & operator[] (const IndexType &index) const
 
ValueType & operator[] (const IndexType &index)
 
ValueType operator() (const CoordinateType &x) const
 
ValueType getInterpolatedValue (const CoordinateType &x) const
 
void getEnclosingIndices (const CoordinateType &x, Position &lower, Position &upper) const
 
void getEnclosingValues (const CoordinateType &x, ValueType &lower, ValueType &upper) const
 
CoordinateType getCoordinates (const IndexType &index) const
 
IndexType getClosestIndex (const CoordinateType &x) const
 
IndexType getLowerIndex (const CoordinateType &x) const
 
const ValueType & getClosestValue (const CoordinateType &x) const
 
ValueType & getClosestValue (const CoordinateType &x)
 
BALL_INLINE IndexType getSize () const
 Return the number of points in the data set. More...
 
BALL_INLINE const CoordinateTypegetOrigin () const
 
BALL_INLINE const CoordinateTypegetSpacing () const
 
BALL_INLINE void setOrigin (const CoordinateType &origin)
 
BALL_INLINE const CoordinateTypegetDimension () const
 
BALL_INLINE void setDimension (const CoordinateType &dimension)
 
void resize (const IndexType &size)
 
void rescale (const IndexType &new_size)
 
ValueType calculateMean () const
 
ValueType calculateSD () const
 
void binaryWrite (const String &filename) const
 
void binaryRead (const String &filename)
 

Protected Attributes

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

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.

Definition at line 41 of file regularData1D.h.

Member Typedef Documentation

◆ const_iterator

template<typename ValueType>
typedef std::vector<ValueType>::const_iterator BALL::TRegularData1D< ValueType >::const_iterator

Definition at line 67 of file regularData1D.h.

◆ const_reference

template<typename ValueType>
typedef std::vector<ValueType>::const_reference BALL::TRegularData1D< ValueType >::const_reference

Definition at line 69 of file regularData1D.h.

◆ ConstIterator

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

A constant iterator.

Definition at line 60 of file regularData1D.h.

◆ CoordinateType

template<typename ValueType>
typedef double BALL::TRegularData1D< ValueType >::CoordinateType

The coordinate type.

Definition at line 56 of file regularData1D.h.

◆ difference_type

template<typename ValueType>
typedef std::vector<ValueType>::difference_type BALL::TRegularData1D< ValueType >::difference_type

Definition at line 71 of file regularData1D.h.

◆ IndexType

template<typename ValueType>
typedef Position BALL::TRegularData1D< ValueType >::IndexType

The IndexType.

Definition at line 52 of file regularData1D.h.

◆ Iterator

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

A mutable iterator.

Definition at line 58 of file regularData1D.h.

◆ iterator

template<typename ValueType>
typedef std::vector<ValueType>::iterator BALL::TRegularData1D< ValueType >::iterator

Definition at line 66 of file regularData1D.h.

◆ pointer

template<typename ValueType>
typedef std::vector<ValueType>::pointer BALL::TRegularData1D< ValueType >::pointer

Definition at line 70 of file regularData1D.h.

◆ reference

template<typename ValueType>
typedef std::vector<ValueType>::reference BALL::TRegularData1D< ValueType >::reference

Definition at line 68 of file regularData1D.h.

◆ size_type

template<typename ValueType>
typedef std::vector<ValueType>::size_type BALL::TRegularData1D< ValueType >::size_type

Definition at line 72 of file regularData1D.h.

◆ value_type

template<typename ValueType>
typedef ValueType BALL::TRegularData1D< ValueType >::value_type

Definition at line 65 of file regularData1D.h.

◆ VectorType

template<typename ValueType>
typedef std::vector<ValueType> BALL::TRegularData1D< ValueType >::VectorType

The type containing an STL vector of the corresponding ValueType.

Definition at line 54 of file regularData1D.h.

Constructor & Destructor Documentation

◆ TRegularData1D() [1/5]

template<typename ValueType >
BALL::TRegularData1D< ValueType >::TRegularData1D ( )

Default constructor.

Definition at line 361 of file regularData1D.h.

◆ TRegularData1D() [2/5]

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

Copy constructor

Exceptions
Exception::OutOfMemoryif the memory for the copy could not be allocated.

Definition at line 375 of file regularData1D.h.

◆ TRegularData1D() [3/5]

template<typename ValueType>
BALL::TRegularData1D< ValueType >::TRegularData1D ( const CoordinateType origin,
const CoordinateType dimension,
const CoordinateType spacing 
)

Detailed constructor.

Exceptions
Exception::OutOfMemoryif the memory for the grid could not be allocated.

◆ TRegularData1D() [4/5]

template<typename ValueType>
BALL::TRegularData1D< ValueType >::TRegularData1D ( const IndexType size)

This constructor sets origin to 0.0 and dimension to 1.0

Exceptions
Exception::OutOfMemoryif the memory for the grid could not be allocated.

◆ TRegularData1D() [5/5]

template<typename ValueType>
BALL::TRegularData1D< ValueType >::TRegularData1D ( const VectorType data,
const CoordinateType origin = 0.0,
const CoordinateType dimension = 1.0 
)

This constructor sets origin to 0.0 and dimension to 1.0

Exceptions
Exception::OutOfMemoryif the memory for the grid could not be allocated.

◆ ~TRegularData1D()

template<typename ValueType >
BALL::TRegularData1D< ValueType >::~TRegularData1D ( )
virtual

Destructor.

Definition at line 370 of file regularData1D.h.

Member Function Documentation

◆ begin() [1/2]

template<typename ValueType>
BALL_INLINE ConstIterator BALL::TRegularData1D< ValueType >::begin ( ) const
inline

Definition at line 147 of file regularData1D.h.

◆ begin() [2/2]

template<typename ValueType>
BALL_INLINE Iterator BALL::TRegularData1D< ValueType >::begin ( )
inline

Definition at line 151 of file regularData1D.h.

◆ binaryRead()

template<typename ValueType >
void BALL::TRegularData1D< ValueType >::binaryRead ( const String filename)

Read the grid contents from a file written with binaryWrite

Exceptions
FileNotFoundthrown if file doesnt exists or could not be read

Definition at line 876 of file regularData1D.h.

◆ binaryWrite()

template<typename ValueType >
void BALL::TRegularData1D< ValueType >::binaryWrite ( const String filename) const

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

Exceptions
FileNotFoundthrown if the file could not be written

Definition at line 828 of file regularData1D.h.

◆ calculateMean()

template<typename ValueType >
BALL_INLINE ValueType BALL::TRegularData1D< ValueType >::calculateMean ( ) const

Calculate the mean of the dataset

Returns
ValueType

Definition at line 650 of file regularData1D.h.

◆ calculateSD()

template<typename ValueType >
BALL_INLINE ValueType BALL::TRegularData1D< ValueType >::calculateSD ( ) const

Calculate the standard deviation of the dataset

Returns
ValueType

Definition at line 664 of file regularData1D.h.

◆ clear()

template<typename ValueType >
void BALL::TRegularData1D< ValueType >::clear ( )
virtual

Clear the contents.

Reimplemented in BALL::TFFT1D< ComplexTraits >.

Definition at line 460 of file regularData1D.h.

◆ empty()

template<typename ValueType>
BALL_INLINE bool BALL::TRegularData1D< ValueType >::empty ( ) const
inline

Empty predicate.

Definition at line 137 of file regularData1D.h.

◆ end() [1/2]

template<typename ValueType>
BALL_INLINE ConstIterator BALL::TRegularData1D< ValueType >::end ( ) const
inline

Definition at line 149 of file regularData1D.h.

◆ end() [2/2]

template<typename ValueType>
BALL_INLINE Iterator BALL::TRegularData1D< ValueType >::end ( )
inline

Definition at line 153 of file regularData1D.h.

◆ getClosestIndex()

template<typename ValueType >
BALL_INLINE TRegularData1D< ValueType >::IndexType BALL::TRegularData1D< ValueType >::getClosestIndex ( const CoordinateType x) const

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.

Exceptions
Exception::OutOfGridif the point is outside the grid boundaries

Definition at line 598 of file regularData1D.h.

◆ getClosestValue() [1/2]

template<typename ValueType >
BALL_INLINE const ValueType & BALL::TRegularData1D< ValueType >::getClosestValue ( const CoordinateType x) const

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.

Exceptions
Exception::OutOfGridif the point is outside the grid boundaries

Definition at line 622 of file regularData1D.h.

◆ getClosestValue() [2/2]

template<typename ValueType >
BALL_INLINE ValueType & BALL::TRegularData1D< ValueType >::getClosestValue ( const CoordinateType x)

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.

Exceptions
Exception::OutOfGridif the point is outside the grid boundaries

Definition at line 636 of file regularData1D.h.

◆ getCoordinates()

template<typename ValueType>
BALL_INLINE TRegularData1D< ValueType >::CoordinateType BALL::TRegularData1D< ValueType >::getCoordinates ( const IndexType index) const

Return the exact coordinates of a grid point.

Returns
CoordinateType
Exceptions
Exception::OutOfGridif the point is outside the grid boundaries

Definition at line 586 of file regularData1D.h.

◆ getData() [1/2]

template<typename ValueType >
BALL_INLINE const ValueType & BALL::TRegularData1D< ValueType >::getData ( const IndexType index) const

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

Exceptions
Exception::OutOfGridif index is outside the grid boundaries

Definition at line 522 of file regularData1D.h.

◆ getData() [2/2]

template<typename ValueType >
BALL_INLINE ValueType & BALL::TRegularData1D< ValueType >::getData ( const IndexType index)

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

Exceptions
Exception::OutOfGridif index is outside the grid boundaries

Definition at line 533 of file regularData1D.h.

◆ getDimension()

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

Definition at line 283 of file regularData1D.h.

◆ getEnclosingIndices()

template<typename ValueType>
void BALL::TRegularData1D< ValueType >::getEnclosingIndices ( const CoordinateType x,
Position lower,
Position upper 
) const

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

Parameters
xa point inside the grid
lowerindex of the grid point to the left
upperindex of the grid point to the right
Exceptions
Exception::OutOfGridif the point is outside the grid boundaries

Definition at line 544 of file regularData1D.h.

◆ getEnclosingValues()

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

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

Exceptions
Exception::OutOfGridif the point is outside the grid boundaries
See also
getEnclosingIndices

Definition at line 562 of file regularData1D.h.

◆ getInterpolatedValue()

template<typename ValueType >
BALL_INLINE ValueType BALL::TRegularData1D< ValueType >::getInterpolatedValue ( const CoordinateType x) const

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.

Exceptions
Exception::OutOfGridif x is outside the grid boundaries

Definition at line 574 of file regularData1D.h.

◆ getLowerIndex()

template<typename ValueType >
BALL_INLINE TRegularData1D< ValueType >::IndexType BALL::TRegularData1D< ValueType >::getLowerIndex ( const CoordinateType x) const

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.

Exceptions
Exception::OutOfGridif the point is outside the grid boundaries

Definition at line 610 of file regularData1D.h.

◆ getOrigin()

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

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

Definition at line 266 of file regularData1D.h.

◆ getSize()

template<typename ValueType>
BALL_INLINE IndexType BALL::TRegularData1D< ValueType >::getSize ( ) const
inline

Return the number of points in the data set.

Definition at line 260 of file regularData1D.h.

◆ getSpacing()

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

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

Definition at line 272 of file regularData1D.h.

◆ isInside()

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

Test whether a point is inside the grid.

Definition at line 515 of file regularData1D.h.

◆ max_size()

template<typename ValueType>
BALL_INLINE size_type BALL::TRegularData1D< ValueType >::max_size ( ) const
inline

Definition at line 162 of file regularData1D.h.

◆ operator!=()

template<typename ValueType>
BALL_INLINE bool BALL::TRegularData1D< ValueType >::operator!= ( const TRegularData1D< ValueType > &  data) const
inline

Inequality operator.

Definition at line 134 of file regularData1D.h.

◆ operator()()

template<typename ValueType >
BALL_INLINE 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 .

Definition at line 680 of file regularData1D.h.

◆ operator=() [1/2]

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

Assignment operator. Copy the data and the boundaries.

Exceptions
Exception::OutOfMemoryif the memory for the copy could not be allocated.

Definition at line 469 of file regularData1D.h.

◆ operator=() [2/2]

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

Assignment from a vector of ValueType. Copy the contents of the data without changing the boundaries.

Exceptions
Exception::OutOfMemoryif the memory for the copy could not be allocated.

Definition at line 489 of file regularData1D.h.

◆ operator==()

template<typename ValueType >
bool BALL::TRegularData1D< ValueType >::operator== ( const TRegularData1D< ValueType > &  data) const

Equality operator.

Definition at line 506 of file regularData1D.h.

◆ operator[]() [1/2]

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

Constant random access operator.

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

Definition at line 181 of file regularData1D.h.

◆ operator[]() [2/2]

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

Mutable random access operator.

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

Definition at line 187 of file regularData1D.h.

◆ rescale()

template<typename ValueType>
void BALL::TRegularData1D< ValueType >::rescale ( const IndexType new_size)

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_sizethe new data set size
Exceptions
Exception::OutOfMemoryif the memory for the resized grid could not be allocated

Definition at line 719 of file regularData1D.h.

◆ resize()

template<typename ValueType>
void BALL::TRegularData1D< ValueType >::resize ( const IndexType size)

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_sizethe new size
Exceptions
Exception::OutOfMemoryif the memory for the resized grid could not be allocated

Definition at line 696 of file regularData1D.h.

◆ setDimension()

template<typename ValueType>
BALL_INLINE void BALL::TRegularData1D< 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 scaling factor and affect the spacing.

Definition at line 290 of file regularData1D.h.

◆ setOrigin()

template<typename ValueType>
BALL_INLINE void BALL::TRegularData1D< ValueType >::setOrigin ( const CoordinateType origin)
inline

Set the origin of the data.

Definition at line 276 of file regularData1D.h.

◆ size()

template<typename ValueType>
BALL_INLINE size_type BALL::TRegularData1D< ValueType >::size ( ) const
inline

Definition at line 161 of file regularData1D.h.

◆ swap()

template<typename ValueType>
BALL_INLINE void BALL::TRegularData1D< ValueType >::swap ( TRegularData1D< ValueType > &  data)
inline

Definition at line 163 of file regularData1D.h.

Member Data Documentation

◆ data_

template<typename ValueType>
VectorType BALL::TRegularData1D< ValueType >::data_
protected

The data.

Definition at line 350 of file regularData1D.h.

◆ dimension_

template<typename ValueType>
CoordinateType BALL::TRegularData1D< ValueType >::dimension_
protected

The dimension (length)

Definition at line 344 of file regularData1D.h.

◆ origin_

template<typename ValueType>
CoordinateType BALL::TRegularData1D< ValueType >::origin_
protected

The origin of the data set.

Definition at line 341 of file regularData1D.h.

◆ spacing_

template<typename ValueType>
CoordinateType BALL::TRegularData1D< ValueType >::spacing_
protected

The spacing.

Definition at line 347 of file regularData1D.h.