Loading...
Searching...
No Matches
spectrum.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: spectrum.h,v 1.14.18.6 2007-04-12 13:53:57 anne Exp $
//
#ifndef BALL_NMR_SPECTRUM_H
#define BALL_NMR_SPECTRUM_H
#ifndef BALL_NMR_PEAKLIST_H
# include<BALL/NMR/peakList.h>
#endif
#ifndef BALL_DATATYPE_REGULARDATA1D_H
# include<BALL/DATATYPE/regularData1D.h>
#endif
#ifndef BALL_DATATYPE_REGULARDATA2D_H
# include<BALL/DATATYPE/regularData2D.h>
#endif
#ifndef BALL_DATATYPE_REGULARDATA3D_H
# include<BALL/DATATYPE/regularData3D.h>
#endif
#ifdef BALL_HAS_FFTW
# include <BALL/MATHS/complex.h>
#ifndef BALL_MATHS_FFT1D_H
# include <BALL/MATHS/FFT1D.h>
#endif
#ifndef BALL_MATHS_FFT2D_H
# include <BALL/MATHS/FFT2D.h>
#endif
#endif
namespace BALL
{
template <typename DataT, typename PeakT, typename PositionT = typename PeakT::Position>
class Spectrum
{
public:
typedef DataT DataType;
typedef PositionT PositionType;
typedef PeakT PeakType;
typedef typename DataT::Iterator Iterator;
typedef typename DataT::ConstIterator ConstIterator;
// ?????
Spectrum()
: data_(),
sticks_(),
spacing_(),
min_(),
max_()
{}
Spectrum(const DataType& data)
: data_(data),
sticks_(),
spacing_(),
min_(),
max_()
{}
Spectrum(const std::vector<PeakType>& peaks, const PositionType& origin, const PositionType& dimension, const PositionType& spacing)
{}
virtual ~Spectrum() {}
const DataType& getData() const;
DataType& getData();
const std::vector<float>& getHuInvariants() const;
std::vector<float>& getHuInvariants();
virtual void clear();
virtual void clearSticks();
virtual double difference(const Spectrum<DataT, PeakT, PositionT>& spectrum) const;
virtual Spectrum<DataT, PeakT, PositionT> differenceSpectrum(const Spectrum<DataT, PeakT, PositionT>& spectrum);
virtual double earthMoversDistance(const Spectrum<DataT,PeakT, PositionT>& spectrum) const;
virtual void convertToGaussian();
virtual void convertToLorentzian();
virtual void computeAllMoments(int moment_number);
virtual void setSpacing(const PositionType& spacing);
virtual PositionType getSpacing() const;
virtual void setSticks(std::vector<PeakType> sticks) {sticks_ = sticks;};
virtual std::vector<PeakType> getSticks() const {return sticks_;};
// computes the integral over the fabs() of the spectrum
virtual double getAbsIntegral() const;
virtual void computeHuInvariants();
virtual std::vector<float> computeHuInvariantsDifferences(std::vector<Spectrum<DataT, PeakT, PositionT> >& spectra);
virtual double getFourierDifference(const Spectrum<DataT,PeakT, PositionT>& spectrum, float min_freq = 1e6, float max_freq = -1e6);
virtual double getNormalMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
virtual double getCentralMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
virtual double getStandardizedMomentsDifference(Spectrum<DataT,PeakT, PositionT>& spectrum, int moment_number);
std::vector<float> normal_moments;
std::vector<float> central_moments;
std::vector<float> standardized_moments;
void binaryWrite(const String& filename);
void binaryRead(const String& filename);
protected:
DataType data_;
std::vector<PeakType> sticks_;
PositionType spacing_; // rausschmeissen , wie auch immer
PositionType min_; // rausschmeissen , wie auch immer
PositionType max_; // rausschmeissen , wie auch immer
std::vector<float> Hu_invariants_;
};
template <typename DataT, typename PeakT, typename PositionT>
void Spectrum<DataT, PeakT, PositionT>::clear()
{
data_.clear();
sticks_.clear();
}
template <typename DataT, typename PeakT, typename PositionT>
void Spectrum<DataT, PeakT, PositionT>::clearSticks()
{
sticks_.clear();
}
// TODO: muss die hier stehen???
template <typename DataT, typename PeakT, typename PositionT>
double Spectrum<DataT, PeakT, PositionT>::difference(const Spectrum<DataT, PeakT, PositionT>& /* spectrum */) const
{
// ?????
return 0.0;
}
template <typename DataT, typename PeakT, typename PositionT>
typename Spectrum<DataT, PeakT, PositionT>::PositionType Spectrum<DataT, PeakT, PositionT>::getSpacing() const
{
return spacing_;
}
template <typename DataT, typename PeakT, typename PositionT>
void Spectrum<DataT, PeakT, PositionT>::setSpacing(const typename Spectrum<DataT, PeakT, PositionT>::PositionType& spacing)
{
spacing_ = spacing;
}
template <typename DataT, typename PeakT, typename PositionT>
double operator - (const Spectrum<DataT, PeakT, PositionT>& s1, const Spectrum<DataT, PeakT, PositionT>& s2)
{
return s1.difference(s2);
}
template <typename DataT, typename PeakT, typename PositionT>
double Spectrum<DataT, PeakT, PositionT>::getNormalMomentsDifference(Spectrum<DataT, PeakT, PositionT>& spectrum, int moment_number)
{
if (normal_moments.size() != (Size)moment_number)
computeAllMoments(moment_number);
if (spectrum.normal_moments.size() != (Size)moment_number)
spectrum.computeAllMoments(moment_number);
double diff = 0.;
for (int current_moment=0; current_moment<moment_number; current_moment++)
diff += fabs(normal_moments[current_moment] - spectrum.normal_moments[current_moment]);
return diff;
}
template <typename DataT, typename PeakT, typename PositionT>
double Spectrum<DataT, PeakT, PositionT>::getCentralMomentsDifference(Spectrum<DataT, PeakT, PositionT>& spectrum, int moment_number)
{
if (central_moments.size() != (Size)moment_number)
computeAllMoments(moment_number);
if (spectrum.central_moments.size() != (Size)moment_number)
spectrum.computeAllMoments(moment_number);
double diff = 0.;
for (int current_moment=0; current_moment<moment_number; current_moment++)
diff += fabs(central_moments[current_moment] - spectrum.central_moments[current_moment]);
return diff;
}
template <typename DataT, typename PeakT, typename PositionT>
double Spectrum<DataT, PeakT, PositionT>::getStandardizedMomentsDifference(Spectrum<DataT, PeakT, PositionT>& spectrum, int moment_number)
{
if (standardized_moments.size() != (Size)moment_number)
computeAllMoments(moment_number);
if (spectrum.standardized_moments.size() != (Size)moment_number)
spectrum.computeAllMoments(moment_number);
double diff = 0.;
for (int current_moment=0; current_moment<moment_number; current_moment++)
diff += fabs(standardized_moments[current_moment] - spectrum.standardized_moments[current_moment]);
return diff;
}
template <typename DataT, typename PeakT, typename PositionT>
const DataT& Spectrum<DataT, PeakT, PositionT>::getData() const
{
return data_;
}
template <typename DataT, typename PeakT, typename PositionT>
DataT& Spectrum<DataT, PeakT, PositionT>::getData()
{
return data_;
}
/*
const vector<float>& getHuInvariants();
*/
template <typename DataT, typename PeakT, typename PositionT>
const std::vector<float>& Spectrum<DataT, PeakT, PositionT>::getHuInvariants() const
{
return Hu_invariants_;
}
template <typename DataT, typename PeakT, typename PositionT>
std::vector<float>& Spectrum<DataT, PeakT, PositionT>::getHuInvariants()
{
return Hu_invariants_;
}
template <typename DataT, typename PeakT, typename PositionT>
void Spectrum<DataT, PeakT, PositionT>::computeHuInvariants()
{
Log.error()<< "computeHuInvariants() only implemented in 2D" << std::endl;
return;
}
template <typename DataT, typename PeakT, typename PositionT>
std::vector<float> Spectrum<DataT, PeakT, PositionT>::computeHuInvariantsDifferences(std::vector<Spectrum<DataT, PeakT, PositionT> >& /*spectra*/)
{
Log.error()<< "computeHuInvariantsDifferences() only implemented in 2D" << std::endl;
std::vector<float> result;
return result;
}
template <typename DataT, typename PeakT, typename PositionT>
double Spectrum<DataT, PeakT, PositionT>::getFourierDifference(const Spectrum<DataT, PeakT, PositionT>& spectrum, float min_freq, float max_freq)
{
Log.error() << "getFourierDifference only implemented in 1D and 2D" << std::endl;
return 0.;
}
typedef Spectrum<RegularData1D, Peak1D> Spectrum1D;
typedef Spectrum<RegularData2D, Peak2D> Spectrum2D;
typedef Spectrum<RegularData3D, Peak3D> Spectrum3D;
template <typename DataT, typename PeakT, typename PositionT>
std::ostream& operator << (std::ostream& os, const Spectrum<DataT, PeakT, PositionT>& spectrum);
template <typename DataT, typename PeakT, typename PositionT>
std::istream& operator >> (std::istream& is, Spectrum<DataT, PeakT, PositionT>& spectrum);
# ifndef BALL_NO_INLINE_FUNCTIONS
# include <BALL/NMR/spectrum.iC>
# endif
} // namespace BALL
#endif // BALL_NMR_SPECTRUM_H
FFT1D.h
FFT2D.h
BALL::Spectrum
Definition spectrum.h:47
BALL::Spectrum::binaryRead
void binaryRead(const String &filename)
This function requires that DataT has a binaryRead method.
BALL::Spectrum::DataType
DataT DataType
The datatype used to store the spectrum.
Definition spectrum.h:54
BALL::Spectrum::convertToLorentzian
virtual void convertToLorentzian()
BALL::Spectrum< RegularData1D, Peak1D >::central_moments
std::vector< float > central_moments
Definition spectrum.h:147
BALL::Spectrum::Iterator
DataT::Iterator Iterator
An iterator.
Definition spectrum.h:60
BALL::Spectrum::getData
DataType & getData()
Definition spectrum.h:270
BALL::Spectrum::getHuInvariants
std::vector< float > & getHuInvariants()
Definition spectrum.h:285
BALL::Spectrum::getSpacing
virtual PositionType getSpacing() const
Definition spectrum.h:196
BALL::Spectrum::difference
virtual double difference(const Spectrum< DataT, PeakT, PositionT > &spectrum) const
Definition spectrum.h:187
BALL::Spectrum::getSticks
virtual std::vector< PeakType > getSticks() const
Definition spectrum.h:121
BALL::Spectrum::earthMoversDistance
virtual double earthMoversDistance(const Spectrum< DataT, PeakT, PositionT > &spectrum) const
BALL::Spectrum::PeakType
PeakT PeakType
The peak type.
Definition spectrum.h:58
BALL::Spectrum::Spectrum
Spectrum(const std::vector< PeakType > &peaks, const PositionType &origin, const PositionType &dimension, const PositionType &spacing)
Definition spectrum.h:85
BALL::Spectrum::setSpacing
virtual void setSpacing(const PositionType &spacing)
Definition spectrum.h:204
BALL::Spectrum::getAbsIntegral
virtual double getAbsIntegral() const
BALL::Spectrum< RegularData1D, Peak1D >::spacing_
PositionType spacing_
Definition spectrum.h:160
BALL::Spectrum::getHuInvariants
const std::vector< float > & getHuInvariants() const
Definition spectrum.h:279
BALL::Spectrum< RegularData1D, Peak1D >::min_
PositionType min_
Definition spectrum.h:161
BALL::Spectrum::getStandardizedMomentsDifference
virtual double getStandardizedMomentsDifference(Spectrum< DataT, PeakT, PositionT > &spectrum, int moment_number)
Definition spectrum.h:249
BALL::Spectrum::convertToGaussian
virtual void convertToGaussian()
BALL::Spectrum::clearSticks
virtual void clearSticks()
Definition spectrum.h:177
BALL::Spectrum< RegularData1D, Peak1D >::sticks_
std::vector< PeakType > sticks_
Definition spectrum.h:159
BALL::Spectrum::Spectrum
Spectrum(const DataType &data)
Definition spectrum.h:77
BALL::Spectrum::PositionType
PositionT PositionType
the data type used to store a position (for peaks and data)
Definition spectrum.h:56
BALL::Spectrum::computeHuInvariants
virtual void computeHuInvariants()
Definition spectrum.h:293
BALL::Spectrum::clear
virtual void clear()
Definition spectrum.h:170
BALL::Spectrum::getNormalMomentsDifference
virtual double getNormalMomentsDifference(Spectrum< DataT, PeakT, PositionT > &spectrum, int moment_number)
Definition spectrum.h:219
BALL::Spectrum< RegularData1D, Peak1D >::normal_moments
std::vector< float > normal_moments
Definition spectrum.h:145
BALL::Spectrum< RegularData1D, Peak1D >::Hu_invariants_
std::vector< float > Hu_invariants_
Definition spectrum.h:163
BALL::Spectrum::ConstIterator
DataT::ConstIterator ConstIterator
A constant iterator.
Definition spectrum.h:62
BALL::Spectrum::~Spectrum
virtual ~Spectrum()
Definition spectrum.h:90
BALL::Spectrum::Spectrum
Spectrum()
Definition spectrum.h:69
BALL::Spectrum< RegularData1D, Peak1D >::data_
DataType data_
Definition spectrum.h:158
BALL::Spectrum::computeHuInvariantsDifferences
virtual std::vector< float > computeHuInvariantsDifferences(std::vector< Spectrum< DataT, PeakT, PositionT > > &spectra)
Definition spectrum.h:300
BALL::Spectrum::differenceSpectrum
virtual Spectrum< DataT, PeakT, PositionT > differenceSpectrum(const Spectrum< DataT, PeakT, PositionT > &spectrum)
BALL::Spectrum::getCentralMomentsDifference
virtual double getCentralMomentsDifference(Spectrum< DataT, PeakT, PositionT > &spectrum, int moment_number)
Definition spectrum.h:234
BALL::Spectrum< RegularData1D, Peak1D >::max_
PositionType max_
Definition spectrum.h:162
BALL::Spectrum::computeAllMoments
virtual void computeAllMoments(int moment_number)
BALL::Spectrum::binaryWrite
void binaryWrite(const String &filename)
This function requires that DataT has a binaryWrite method.
BALL::Spectrum::setSticks
virtual void setSticks(std::vector< PeakType > sticks)
Definition spectrum.h:120
BALL::Spectrum< RegularData1D, Peak1D >::standardized_moments
std::vector< float > standardized_moments
Definition spectrum.h:149
BALL::Spectrum::getData
const DataType & getData() const
Definition spectrum.h:264
BALL::Spectrum::getFourierDifference
virtual double getFourierDifference(const Spectrum< DataT, PeakT, PositionT > &spectrum, float min_freq=1e6, float max_freq=-1e6)
Definition spectrum.h:308
BALL::String
Definition string.h:57
complex.h
BALL::operator<<
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
BALL::Spectrum1D
Spectrum< RegularData1D, Peak1D > Spectrum1D
One-dimensional spectrum.
Definition spectrum.h:319
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Spectrum3D
Spectrum< RegularData3D, Peak3D > Spectrum3D
Three-dimensional spectrum.
Definition spectrum.h:325
BALL::Log
BALL_EXPORT LogStream Log
BALL::operator>>
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
Definition regularData1D.h:802
BALL::Spectrum2D
Spectrum< RegularData2D, Peak2D > Spectrum2D
Two-dimensional spectrum.
Definition spectrum.h:322
BALL::operator-
BALL_INLINE TAngle< T > operator-(const T &val, const TAngle< T > &angle)
Definition angle.h:724
peakList.h
regularData1D.h
regularData2D.h
regularData3D.h