5 #ifndef BALL_MATHS_TFFT1D_H 6 #define BALL_MATHS_TFFT1D_H 8 #ifndef BALL_COMMON_EXCEPTION_H 12 #ifndef BALL_DATATYPE_REGULARDATA1D_H 35 template <
typename ComplexTraits>
37 :
public TRegularData1D<std::complex<typename ComplexTraits::ComplexPrecision> >
41 typedef std::complex<typename ComplexTraits::ComplexPrecision>
Complex;
66 TFFT1D(
Size ldn,
double stepPhys = 1.,
double origin = 0.,
bool inFourierSpace =
false);
168 Complex
getData(
const double pos)
const;
185 void setData(
double pos, Complex val);
199 const Complex&
operator [] (
const double pos)
const;
239 Complex
phase(
const double pos)
const;
283 template <
typename ComplexTraits>
294 template <
typename ComplexTraits>
314 for (
double pos=min; pos<=
max; pos+=step)
328 template <
typename ComplexTraits>
349 template <
typename ComplexTraits>
370 template <
typename ComplexTraits>
376 template <
typename ComplexTraits>
382 template <
typename ComplexTraits>
388 template <
typename ComplexTraits>
394 template <
typename ComplexTraits>
400 template <
typename ComplexTraits>
406 template <
typename ComplexTraits>
412 template <
typename ComplexTraits>
419 template <
typename ComplexTraits>
458 template <
typename ComplexTraits>
462 double normalization=1.;
466 result = (*this)[pos];
471 result = (*this)[pos]*
phase(pos);
476 result *= normalization;
481 template <
typename ComplexTraits>
490 if ((pos < min) || (pos > max))
495 double h = pos -
min;
496 double mod = fmod(h,step);
503 double before =
floor(h/step)*step+
min;
504 double after = ceil(h/step)*step+
min;
506 double t = (pos - before)/step;
508 result =
getData(before)*(
typename ComplexTraits::ComplexPrecision)(1.-t);
509 result +=
getData(after)*(
typename ComplexTraits::ComplexPrecision)t;
514 template <
typename ComplexTraits>
520 dummy =
Complex(val.real()*((
typename ComplexTraits::ComplexPrecision)pow((
typename ComplexTraits::ComplexPrecision)(
length_),(
int)
numFourierToPhys_)),
521 val.imag()*((
typename ComplexTraits::ComplexPrecision)pow((
typename ComplexTraits::ComplexPrecision)(
length_),(
int)
numFourierToPhys_)));
527 val*=
phase(pos)*(
typename ComplexTraits::ComplexPrecision)((sqrt(2*M_PI)/
stepPhys_))
528 *(
typename ComplexTraits::ComplexPrecision)pow((
typename ComplexTraits::ComplexPrecision)
length_,(
int)
numFourierToPhys_);
536 template <
typename ComplexTraits>
555 if ((internalPos < 0) || (internalPos>=(
Index)
length_))
563 template <
typename ComplexTraits>
582 if ((internalPos < 0) || (internalPos>=(
Index)
length_))
590 template <
typename ComplexTraits>
601 template <
typename ComplexTraits>
672 template <
typename ComplexTraits>
673 const RegularData1D& operator << (RegularData1D& to, const TFFT1D<ComplexTraits>& from)
676 if (!from.isInFourierSpace())
679 Size lengthX = from.getMaxIndex()+1;
682 newGrid.
setOrigin(from.getPhysSpaceMin());
683 newGrid.
setDimension(from.getPhysSpaceMax()-from.getPhysSpaceMin());
686 double normalization = 1./(pow((
float)(lengthX),from.getNumberOfInverseTransforms()));
688 for (
Position i = 0; i < from.size(); i++)
690 newGrid[i] = from[i].real()*normalization;
702 Size lengthX = from.getMaxIndex()+1;
704 float stepFourierX = from.getFourierStepWidth();
707 newGrid.
setOrigin(from.getFourierSpaceMin());
708 newGrid.
setDimension(from.getFourierSpaceMax()-from.getFourierSpaceMin());
712 double normalization=1./sqrt(2.*M_PI)/(pow((
float)(lengthX),from.getNumberOfInverseTransforms()));
718 for (
Position i = 0; i < from.size(); i++)
731 x-=(int)(lengthX/2.);
735 x+=(int)(lengthX/2.);
739 r = ((
float)xp * stepFourierX);
741 newGrid[i] = (from[i]*(
typename ComplexTraits::ComplexPrecision)normalization*from.phase(r)).real();
750 #endif // BALL_MATHS_TFFT1D_H double getFourierSpaceMax() const
Complex & operator[](const Position &pos)
#define BALL_CREATE(name)
double getGridCoordinates(Position position) const
bool setPhysStepWidth(double new_width)
TFFT1D< BALL_FFTW_DEFAULT_TRAITS > FFT1D
double getFourierSpaceMin() const
bool operator==(const TFFT1D &fft1d) const
void setNumberOfiFFTTransforms(Size num)
double getPhysStepWidth() const
TFFT1D()
Default constructor.
BALL_EXTERN_VARIABLE const double h
ComplexTraits::FftwPlan planForward_
Complex & operator[](const double pos)
double rint(double x)
round to integral value in floating-point format
Size getNumberOfInverseTransforms() const
const Complex & operator[](const Position &pos) const
double getPhysSpaceMax() const
BALL_INLINE size_type size() const
T max(const T &a, const T &b)
void setNumberOfFFTTransforms(Size num)
BALL_INLINE void setDimension(const CoordinateType &dimension)
Complex getData(const double pos) const
bool isInFourierSpace() const
-*- Mode: C++; tab-width: 2; -*-
const ValueType & operator[](const IndexType &index) const
const TFFT1D & operator=(const TFFT1D &fft1d)
Assignment operator.
double getFourierStepWidth() const
Complex getInterpolatedValue(const double pos) const
bool translate(double trans_origin)
std::complex< typename ComplexTraits::ComplexPrecision > Complex
virtual ~TFFT1D()
Destructor.
ComplexTraits::FftwPlan planBackward_
double getPhysSpaceMin() const
BALL_INLINE void setOrigin(const CoordinateType &origin)
Complex phase(const double pos) const
T min(const T &a, const T &b)
void setData(double pos, Complex val)
TRegularData1D< std::complex< typename ComplexTraits::ComplexPrecision > > ComplexVector