5#ifndef BALL_DATATYPE_REGULARDATA1D_H
6#define BALL_DATATYPE_REGULARDATA1D_H
12#ifndef BALL_SYSTEM_FILE_H
16#ifndef BALL_SYSTEM_BINARYFILEADAPTOR_H
40 template <
typename ValueType>
360 template <
typename ValueType>
369 template <
typename ValueType>
374 template <
typename ValueType>
376 : origin_(data.origin_),
377 dimension_(data.dimension_),
378 spacing_(data.spacing_),
386 catch (std::bad_alloc&)
388 throw Exception::OutOfMemory(__FILE__, __LINE__, data.
size() *
sizeof(ValueType));
392 template <
typename ValueType>
398 dimension_(dimension),
410 catch (std::bad_alloc&)
412 throw Exception::OutOfMemory(__FILE__, __LINE__,
size *
sizeof(ValueType));
416 template <
typename ValueType>
422 dimension_(dimension),
423 spacing_(dimension / ((double)data.size()-1)),
431 catch (std::bad_alloc&)
433 throw Exception::OutOfMemory(__FILE__, __LINE__, data.size() *
sizeof(ValueType));
438 template <
class ValueType>
452 catch (std::bad_alloc&)
455 throw Exception::OutOfMemory(__FILE__, __LINE__,
size *
sizeof(ValueType));
459 template <
typename ValueType>
465 std::fill(
data_.begin(),
data_.end(), default_value);
468 template <
typename ValueType>
479 catch (std::bad_alloc&)
488 template <
typename ValueType>
496 catch (std::bad_alloc&)
505 template <
typename ValueType>
513 template <
class ValueType>
520 template <
typename ValueType>
524 if (index >=
data_.size())
531 template <
typename ValueType>
535 if (index >=
data_.size())
542 template <
typename ValueType>
552 if (lower ==
data_.size() - 1)
555 lower =
data_.size() - 2;
560 template <
typename ValueType>
568 lower =
data_[lower_index];
569 upper =
data_[upper_index];
572 template <
typename ValueType>
580 return operator () (x);
583 template <
typename ValueType>
588 if ((index >=
data_.size()) || (
data_.size() == 0))
596 template <
typename ValueType>
608 template <
typename ValueType>
620 template <
typename ValueType>
634 template <
typename ValueType>
648 template <
typename ValueType>
654 for (
IndexType i = 0; i < data_points; i++)
662 template <
typename ValueType>
669 for (
IndexType i = 0; i < data_points; i++)
671 stddev += (pow(
data_[i]-mean,2));
673 stddev /= (data_points-1);
674 stddev = sqrt(stddev);
678 template <
typename ValueType>
683 if (left_index ==
data_.size() - 1)
691 return data_[left_index] * d + (1.0 - d) *
data_[left_index + 1];
694 template <
typename ValueType>
699 if (
data_.size() > 0)
707 data_.resize(new_size);
709 catch (std::bad_alloc&)
717 template <
typename ValueType>
731 if (
data_.size() == 0)
734 data_.resize(new_size);
740 if ((
data_.size() == 1) && (new_size > 1))
743 data_.resize(new_size);
746 data_[i] = old_value;
758 for (
Size i = 0; i < new_size; i++)
765 if (old_idx >= (
data_.size() - 1))
767 old_idx =
data_.size() - 2;
770 new_data[i] =
data_[old_idx] * (1 - factor3) + factor3 *
data_[old_idx + 1];
776 catch (std::bad_alloc&)
787 template <
typename ValueType>
793 << data.
getSize() - 1 << std::endl;
796 std::copy(data.
begin(), data.
end(), std::ostream_iterator<ValueType>(os,
"\n"));
801 template <
typename ValueType>
819 std::copy(std::istream_iterator<ValueType>(is),
820 std::istream_iterator<ValueType>(),
827 template <
typename ValueType>
830 File outfile(filename, std::ios::out|std::ios::binary);
844 outfile << adapt_size;
847 outfile << adapt_coordinate;
850 outfile << adapt_coordinate;
853 outfile << adapt_coordinate;
856 Index window_pos = 0;
857 while (((
int)
data_.size() - (1024 + window_pos)) >= 0 )
860 outfile << adapt_block;
865 for (
Size i = window_pos; i <
data_.size(); i++)
868 outfile << adapt_single;
875 template <
typename ValueType>
878 File infile(filename, std::ios::in|std::ios::binary);
888 infile >> adapt_size;
891 infile >> adapt_coordinate;
894 infile >> adapt_coordinate;
897 infile >> adapt_coordinate;
900 data_.resize(new_size);
903 Index window_pos = 0;
905 while ( ((
int)
data_.size() - (1024 + window_pos)) >= 0 )
907 infile >> adapt_block;
919 for (
Size i=window_pos; i<
data_.size(); i++)
921 infile >> adapt_single;
922 data_[i] = adapt_single.getData();
const T & getData() const
void setData(const T &data)
CoordinateType dimension_
const ValueType & getClosestValue(const CoordinateType &x) const
BALL_INLINE size_type max_size() const
ValueType getInterpolatedValue(const CoordinateType &x) const
BALL_INLINE size_type size() const
void rescale(const IndexType &new_size)
IndexType getLowerIndex(const CoordinateType &x) const
BALL_INLINE const CoordinateType & getOrigin() const
std::vector< ValueType > VectorType
The type containing an STL vector of the corresponding ValueType.
BALL_INLINE const CoordinateType & getDimension() const
std::vector< ValueType >::pointer pointer
IndexType getClosestIndex(const CoordinateType &x) const
void getEnclosingValues(const CoordinateType &x, ValueType &lower, ValueType &upper) const
BALL_INLINE void setDimension(const CoordinateType &dimension)
std::vector< ValueType >::iterator iterator
void resize(const IndexType &size)
bool operator==(const TRegularData1D &data) const
Equality operator.
const ValueType & getData(const IndexType &index) const
BALL_INLINE void setOrigin(const CoordinateType &origin)
BALL_INLINE IndexType getSize() const
Return the number of points in the data set.
std::vector< ValueType >::iterator Iterator
A mutable iterator.
double CoordinateType
The coordinate type.
ValueType calculateSD() const
std::vector< ValueType >::difference_type difference_type
std::vector< ValueType >::size_type size_type
std::vector< ValueType >::const_iterator const_iterator
BALL_INLINE void swap(TRegularData1D< ValueType > &data)
ValueType calculateMean() const
virtual ~TRegularData1D()
Destructor.
TRegularData1D()
Default constructor.
Position IndexType
The IndexType.
BALL_INLINE Iterator end()
BALL_INLINE const CoordinateType & getSpacing() const
TRegularData1D & operator=(const TRegularData1D< ValueType > &data)
CoordinateType getCoordinates(const IndexType &index) const
std::vector< ValueType >::reference reference
ValueType operator()(const CoordinateType &x) const
BALL_INLINE ConstIterator begin() const
ValueType & getClosestValue(const CoordinateType &x)
BALL_INLINE bool empty() const
Empty predicate.
BALL_INLINE Iterator begin()
std::vector< ValueType >::const_iterator ConstIterator
A constant iterator.
void binaryWrite(const String &filename) const
void binaryRead(const String &filename)
const ValueType & operator[](const IndexType &index) const
ValueType & getData(const IndexType &index)
std::vector< ValueType >::const_reference const_reference
bool isInside(const CoordinateType &x) const
Test whether a point is inside the grid.
void getEnclosingIndices(const CoordinateType &x, Position &lower, Position &upper) const
BALL_INLINE ConstIterator end() const
#define BALL_CREATE(name)
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
TRegularData1D< float > RegularData1D
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
The block data type for reading and writing binary data.