All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Types | Public Member Functions
QGpCoreTools::Curve< pointType > Class Template Reference

Template class for a curve It is a vector of "points" that may eventually contain extra data. The "point" type must at least have the following functions: More...

#include <Curve.h>

Inheritance diagram for QGpCoreTools::Curve< pointType >:
QVector

List of all members.

Public Types

typedef const pointType * const_iterator
typedef pointType * iterator

Public Member Functions

void append (const pointType &p)
void append (const Curve< pointType > &c)
pointType at (double x) const
const pointType & at (int index) const
void average (const Curve< pointType > &o)
double azimuth (const CurvePointOptions *pointOptions=0) const
const_iterator begin () const
iterator begin ()
void clear ()
int closestMax (int index)
int count () const
 Curve ()
 Curve (int n)
 Curve (const Curve< pointType > &o)
 Curve (const QVector< pointType > &o)
void cut (double min, double max, SamplingOptions options)
Curve< pointType > derivative (const CurvePointOptions *pointOptions=0) const
const_iterator end () const
iterator end ()
const pointType & first () const
pointType & first ()
int indexAfter (double valX) const
int indexOf (const pointType &p) const
void insert (int index, const pointType &p)
void insert (const pointType &p)
bool isEmpty () const
const pointType & last () const
pointType & last ()
bool leastSquare (double &a, double &b, const CurvePointOptions *pointOptions=0) const
void line (const pointType &p1, const pointType &p2)
int maximumX (int startIndex=0) const
int maximumY (int startIndex=0, const CurvePointOptions *pointOptions=0) const
int minimumX (int startIndex=0) const
int minimumY (int startIndex=0, const CurvePointOptions *pointOptions=0) const
void operator*= (const Curve< pointType > &o)
void operator+= (const Curve< pointType > &o)
bool operator== (const Curve< pointType > &o) const
pointType & operator[] (int index)
const pointType & operator[] (int index) const
void prepend (const pointType &p)
QVector< double > project (const CurvePointOptions *pointOptions=0) const
void remove (int index)
void removeInvalid ()
void resample (int n, double min, double max, SamplingOptions options, double valX, double valY, const CurvePointOptions *pointOptions=0)
void resample (int n, double min, double max, SamplingOptions options)
void resample (const Curve< pointType > &xModel, SamplingOptions options)
void resample (const QVector< double > &xModel, SamplingOptions options)
void resize (int n)
bool sameSampling (const Curve< pointType > &o) const
void setFunction ()
void setValid (bool v)
void smooth (double min, double max, const SmoothingParameters &param)
void swapXY (const CurvePointOptions *pointOptions=0)
QString toString (int precision=6, char format='g') const
void unique ()
void xExp10 ()
void xInverse (SamplingOptions options=Function)
void xLog10 ()
void xMultiply (double factor, SamplingOptions options=Function)
QVector< double > xVector () const
void yExp10 (const CurvePointOptions *pointOptions=0)
void yInverse (const CurvePointOptions *pointOptions=0)
void yLog10 (const CurvePointOptions *pointOptions=0)
void yMultiply (double factor, const CurvePointOptions *pointOptions=0)
void yMultiply (const Curve< pointType > &o, const CurvePointOptions *pointOptions=0)
void ySetMaximumValue (double value, const CurvePointOptions *pointOptions=0)
void ySetMinimumValue (double value, const CurvePointOptions *pointOptions=0)
void ySetValue (double value, const CurvePointOptions *pointOptions=0)
void ySqrt (const CurvePointOptions *pointOptions=0)
void ySquare (const CurvePointOptions *pointOptions=0)
void ySum (double value, const CurvePointOptions *pointOptions=0)
void ySum (const Curve< pointType > &o, const CurvePointOptions *pointOptions=0)

Detailed Description

template<class pointType>
class QGpCoreTools::Curve< pointType >

Template class for a curve It is a vector of "points" that may eventually contain extra data. The "point" type must at least have the following functions:


Member Typedef Documentation

template<class pointType>
typedef const pointType* QGpCoreTools::Curve< pointType >::const_iterator
template<class pointType>
typedef pointType* QGpCoreTools::Curve< pointType >::iterator

Constructor & Destructor Documentation

template<class pointType>
QGpCoreTools::Curve< pointType >::Curve ( ) [inline]
{}
template<class pointType>
QGpCoreTools::Curve< pointType >::Curve ( int  n) [inline]
template<class pointType>
QGpCoreTools::Curve< pointType >::Curve ( const Curve< pointType > &  o) [inline]
template<class pointType>
QGpCoreTools::Curve< pointType >::Curve ( const QVector< pointType > &  o) [inline]

Member Function Documentation

template<class pointType>
void QGpCoreTools::Curve< pointType >::append ( const pointType &  p) [inline]
template<class pointType>
void QGpCoreTools::Curve< pointType >::append ( const Curve< pointType > &  c) [inline]
template<class pointType >
pointType QGpCoreTools::Curve< pointType >::at ( double  x) const

Referenced by QGpCoreTools::Curve< pointType >::average(), MonoStation::StationResults::comments(), DampingResults::compute(), QGpCoreTools::IrregularGrid2DData::crossSection(), QGpCoreWave::AutocorrCurves::dispersionCurve(), MonoStation::StationResults::highestPeak(), ToolRefra::initStations(), SpacSelector::inverse(), SpacSelector::inverseAt(), MonoStation::StationResults::lowestPeak(), MonoStation::StationResults::maximumAmplitudePeak(), QGpGuiWave::ModalProxy::maximumX(), QGpGuiWave::ModalProxy::maximumY(), SciFigs::ComplexStatisticalProxy::maximumY(), QGpGuiWave::RefractionProxy::maximumY(), QGpGuiWave::ModalProxy::minimumX(), QGpGuiWave::ModalProxy::minimumY(), SciFigs::ComplexStatisticalProxy::minimumY(), QGpGuiWave::RefractionProxy::minimumY(), Spac3CForward::misfit(), MonoStation::StationResults::peak(), SciFigs::ComplexStatisticalLine::point(), SciFigs::RealStatisticalLine::point(), QGpGuiWave::MagnetoTelluricLine::point(), QGpGuiWave::ModalLine::point(), QGpGuiWave::RefractionLine::point(), MonoStation::StationResults::printPeaks(), QGpCoreTools::Curve< pointType >::resample(), Process::run(), QGpCoreTools::Curve< pointType >::sameSampling(), SpacSelector::selectSamples(), MonoStation::StatisticResults::studentTest(), QGpCoreTools::Curve< pointType >::yMultiply(), and QGpCoreTools::Curve< pointType >::ySum().

{
  if(count()<2) {
    if(count()==1) {
      return at(0);
    } else {
      return pointType();
    }
  } else {
    int i=indexAfter(x);
    if(i==0) i++;                // Force interpolation if outside range
    else if(i==count()) i--;
    pointType p;
    p.interpole(x, at(i-1), at(i));
    return p;
  }
}
template<class pointType>
const pointType& QGpCoreTools::Curve< pointType >::at ( int  index) const [inline]
{return QVector<pointType>::at(index);}
template<class pointType>
void QGpCoreTools::Curve< pointType >::average ( const Curve< pointType > &  curve)

Average this function with curve and put the result in this curve.

References QGpCoreTools::Curve< pointType >::at(), QGpCoreTools::Curve< pointType >::count(), QGpCoreTools::Function, QGpCoreTools::Curve< pointType >::resample(), TRACE, QGpCoreTools::unique(), and QGpCoreTools::Curve< pointType >::xVector().

Referenced by QGpGuiWave::ModalProxy::average(), SciFigs::RealStatisticalProxy::average(), SciFigs::ComplexStatisticalProxy::average(), and QGpGuiWave::RefractionProxy::average().

{
  TRACE;
  if(o.count()<2) return;
  if(count()==0) {
    *this=o;
    return;
  }
  // Set the same sampling for both curves
  QVector<double> x=xVector();
  x+=o.xVector();
  qSort(x);
  ::QGpCoreTools::unique(x);
  resample(x, Function);
  Curve<pointType> oResamp=o;
  oResamp.resample(x, Function);
  // Take the average of the two curves
  for(int i=x.count()-1; i>=0; i--) {
    operator[](i).average(oResamp.at(i));
  }
  setFunction();
}
template<class pointType >
double QGpCoreTools::Curve< pointType >::azimuth ( const CurvePointOptions pointOptions = 0) const

Performs a least square regression on all points in the horizontal plane.

Returns the azimuth of the regression line (mathematical sense).

References TRACE.

Referenced by GeopsyCore::SubSignalPool::azimuth().

{
  TRACE;
  int n=count();
  if(n>1) {
    double a, b;
    if(leastSquare(a, b, pointOptions)) {
      return atan(a);
    } else {
      return 0.5*M_PI;
    }
  }
  return 0.0;
}
template<class pointType>
const_iterator QGpCoreTools::Curve< pointType >::begin ( ) const [inline]
template<class pointType>
iterator QGpCoreTools::Curve< pointType >::begin ( ) [inline]
template<class pointType>
void QGpCoreTools::Curve< pointType >::clear ( ) [inline]
template<class pointType >
int QGpCoreTools::Curve< pointType >::closestMax ( int  index)

Return the local maxima close to index either on the left or right side

References TRACE.

Referenced by QGpCoreTools::IrregularGrid2DData::followMaximumX(), and QGpCoreTools::IrregularGrid2DData::followMaximumY().

{
  TRACE;
  int n=count();
  int di;

  if(index==0) {
    di=1;
    index=1;
  }
  else if(index>=n) {
    index=n;
    di=-1;
  } else if(at(index).y()>at(index-1).y()) di=1;
  else if(at(index).y()<at(index-1).y()) di=-1;
  else return index;

  if(di>0) {
    while(index<n) {
      if(at(index).y()<at(index-1).y()) {
        index--;
        break;
      }
      index+=di;
    }
    if(index==n) index--;
  } else {
    while(index>0) {
      if(at(index).y()>at(index-1).y()) break;
      index+=di;
    }
  }
  return index;
}
template<class pointType>
int QGpCoreTools::Curve< pointType >::count ( ) const [inline]
template<class pointType >
void QGpCoreTools::Curve< pointType >::cut ( double  min,
double  max,
SamplingOptions  options 
)

Cut function between min and max considering these limits expressed in a linear or inversed scale.

Accepted options are LinearScale or InversedScale, option Function is mandatory and you must call setFunction() before.

References QGpCoreTools::Function, QGpCoreTools::Interpole, QGpCoreTools::InversedScale, and TRACE.

Referenced by QGpGuiWave::ModalProxy::cut(), SciFigs::ComplexStatisticalProxy::cut(), SciFigs::RealStatisticalProxy::cut(), QGpGuiWave::RefractionProxy::cut(), QGpCoreTools::IrregularGrid2DData::cut(), and ShReader::parse().

{
  TRACE;
  ASSERT(options & Function);
  // Assert that count()>1 is made by indexAfter()
  // Transforms X scale according to options (log and inv)
  if(options & InversedScale) {
    xInverse(options);
  }
  if(min < first().x())
    min=first().x();
  if(max > last().x())
    max=last().x();
  // Find the first point
  int ix=indexAfter(min);
  if(ix>0) {
    if(fabs(min - at(ix-1).x()) < 1e-15) {
      ix--;
    } else if((options & Interpole) && fabs(min - at(ix).x()) > 1e-15) {
      ix--;
      (*this)[ ix ].interpole(min, at(ix), at(ix+1));
    }
  }
  // Remove everything before
  for(int i=0; i<ix; i++) remove(0);
  // Find the last point
  ix=indexAfter(max);
  if(ix < count()) {
    if(fabs(max - at(ix).x()) < 1e-15) {
      ix++;
    } else if((options & Interpole) && fabs(max - at(ix-1).x()) > 1e-15) {
      (*this)[ ix ].interpole(max, at(ix-1), at(ix));
      ix++;
    }
  }
  // Remove everything after
  for(int i=count()-1; i>=ix; i--) remove(i);
  // Re-Transforms axis according options (log and inv)
  if(options & InversedScale)
    xInverse(options);
}
template<class pointType >
Curve< pointType > QGpCoreTools::Curve< pointType >::derivative ( const CurvePointOptions pointOptions = 0) const

References TRACE.

{
  TRACE;
  int n=count()-1;
  ASSERT(n>1);
  Curve<pointType> d(n-1);
  for(int i=1; i<n; i++ ) {
    double v=(at(i).y(pointOptions)-at(i-1).y(pointOptions))
               /(at(i).x()-at(i-1).x());
    v+=(at(i+1).y(pointOptions)-at(i).y(pointOptions))
      /(at(i+1).x()-at(i).x());
    v*=2.0;
    pointType& p=d[i-1];
    p.setX(at(i).x());
    p.setY(v, pointOptions);
  }
  return d;
}
template<class pointType>
const_iterator QGpCoreTools::Curve< pointType >::end ( ) const [inline]
template<class pointType>
iterator QGpCoreTools::Curve< pointType >::end ( ) [inline]
template<class pointType>
const pointType& QGpCoreTools::Curve< pointType >::first ( ) const [inline]
template<class pointType>
pointType& QGpCoreTools::Curve< pointType >::first ( ) [inline]
template<class pointType >
int QGpCoreTools::Curve< pointType >::indexAfter ( double  valX) const

Returns the index for which x() is just greater or equal to valX. Returns indexes from 0 to count(). Uses dichotomy, best for functions with more than 10 values. Assumes that points are sorted (setFunction() called before).

References TRACE.

Referenced by QGpCoreTools::IrregularGrid2DData::followMaximumX(), QGpCoreTools::IrregularGrid2DData::followMaximumY(), and QGpCoreTools::Curve< pointType >::resample().

{
  TRACE;
  ASSERT(count()>1);
  if(valX <= at(0).x()) return 0;
  int lasti=count()-1;
  if(valX > at(lasti).x()) return lasti+1;
  int i=1;
  while(i < count()) i=i << 1;
  int step2=i >> 1;
  while(step2>0) {
    if(i>lasti) i-=step2;
    else if(valX <= at(i).x()) {
      if(valX > at(i-1).x()) break;
      i-=step2;
    } else i+=step2;
    step2=step2 >> 1;
  }
  return i;
}
template<class pointType>
int QGpCoreTools::Curve< pointType >::indexOf ( const pointType &  p) const [inline]
template<class pointType>
void QGpCoreTools::Curve< pointType >::insert ( int  index,
const pointType &  p 
) [inline]
template<class pointType>
void QGpCoreTools::Curve< pointType >::insert ( const pointType &  p)

References TRACE.

{
  TRACE;
  if(count()<2) {
    if(isEmpty()) {
      append(p);
    } else if(p.x() < at(0).x()) {
      prepend(p);
    } else if(p.x() > at(0).x()) {
      append(p);
    } else {
      (*this)[0]=p;
    }
  } else {
    int i=indexAfter(p.x());
    if(i<count() && at(i).x()==p.x()) {
      (*this)[i]=p;
    } else {
      if(at(p.x()).y()!=p.y()) {
        insert(i, p);
      }
    }
  }
}
template<class pointType>
bool QGpCoreTools::Curve< pointType >::isEmpty ( ) const [inline]
template<class pointType>
const pointType& QGpCoreTools::Curve< pointType >::last ( ) const [inline]
template<class pointType>
pointType& QGpCoreTools::Curve< pointType >::last ( ) [inline]
template<class pointType >
bool QGpCoreTools::Curve< pointType >::leastSquare ( double &  a,
double &  b,
const CurvePointOptions pointOptions = 0 
) const

Performs a least square regression on all points in the horizontal plane.

Returns true if there is a sufficient number of points in curve (minimum=2) and if a is not inf. Returns coefficient a and b from expression y=a*x+b passed as reference in arguments.

References TRACE.

Referenced by SciFigs::ImageLayer::scaling().

{
  TRACE;
  int n=count();
  if(n>1) {
    double invn=1.0/(double)n;
    double sx=sumX();
    double sy=sumY(pointOptions);
    double sxy=sumXY(pointOptions);
    double sx2=sumX2();
    printf("sum x=%lg sum x*sum x=%lg nsum2 x=%lg\n", sx, sx*sx, n*sx2);
    double denom=sx2-invn*sx*sx;
    if(denom!=0.0) {
      a=(sxy-invn*sy*sx)/denom;
      b=(invn*sy*sx2-invn*sxy*sx)/denom;
      return true;
    } else {
      a=0.0;
      b=sx*invn;
    }
  }
  return false;
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::line ( const pointType &  p1,
const pointType &  p2 
)

Construct a basic line curve between (x1 , y1) and ( x2 , y2)

The resulting curve is not necessarely a function.

References TRACE.

Referenced by NewNoiseModel::curve(), MagnetoTelluricReader::parse(), EllipticityReader::setOptions(), ShReader::setOptions(), DispersionReader::setOptions(), SpacReader::setOptions(), CurvesThread::setParameters(), Histogram2D::setXSampling(), Histogram2D::setYSampling(), and DinverDCCore::TargetList::validateTargets().

{
  TRACE;
  resize(2);
  (*this)[0]=p1;
  (*this)[1]=p2;
}
template<class pointType >
int QGpCoreTools::Curve< pointType >::maximumX ( int  startIndex = 0) const

Referenced by QGpGuiWave::ModalProxy::maximumX(), SciFigs::RealStatisticalProxy::maximumX(), SciFigs::ComplexStatisticalProxy::maximumX(), and QGpGuiWave::RefractionProxy::maximumX().

{
  int n=count();
  ASSERT(n>0 && startIndex<n);
  if(startIndex<0) startIndex=0;
  const pointType * p=&at(startIndex);
  int iMax=startIndex;
  for(int i=startIndex+1; i<n; i++ ) {
    if(at(i).x() > p->x()) {
      p=&at(i);
      iMax=i;
    }
  }
  return iMax;
}
template<class pointType >
int QGpCoreTools::Curve< pointType >::maximumY ( int  startIndex = 0,
const CurvePointOptions pointOptions = 0 
) const

Return the point at maximum Y value

Referenced by QGpGuiWave::ModalProxy::maximumY(), SciFigs::RealStatisticalProxy::maximumY(), SciFigs::ComplexStatisticalProxy::maximumY(), and QGpGuiWave::RefractionProxy::maximumY().

{
  int n=count();
  ASSERT(n>0 && startIndex<n);
  if(startIndex<0) startIndex=0;
  const pointType * p=&at(startIndex);
  int iMax=startIndex;
  for(int i=startIndex+1; i<n; i++ ) {
    if(at(i).y(pointOptions) > p->y(pointOptions)) {
      p=&at(i);
      iMax=i;
    }
  }
  return iMax;
}
template<class pointType >
int QGpCoreTools::Curve< pointType >::minimumX ( int  startIndex = 0) const

Referenced by QGpGuiWave::ModalProxy::minimumX(), SciFigs::RealStatisticalProxy::minimumX(), SciFigs::ComplexStatisticalProxy::minimumX(), and QGpGuiWave::RefractionProxy::minimumX().

{
  int n=count();
  ASSERT(n>0 && startIndex<n);
  if(startIndex<0) startIndex=0;
  const pointType * p=&at(startIndex);
  int iMin=startIndex;
  for(int i=startIndex+1; i<n; i++ ) {
    if(at(i).x() < p->x()) {
      p=&at(i);
      iMin=i;
    }
  }
  return iMin;
}
template<class pointType >
int QGpCoreTools::Curve< pointType >::minimumY ( int  startIndex = 0,
const CurvePointOptions pointOptions = 0 
) const

Return the point at minimum Y value

Referenced by QGpGuiWave::ModalProxy::minimumY(), SciFigs::RealStatisticalProxy::minimumY(), SciFigs::ComplexStatisticalProxy::minimumY(), and QGpGuiWave::RefractionProxy::minimumY().

{
  int n=count();
  ASSERT(n>0 && startIndex<n);
  if(startIndex<0) startIndex=0;
  const pointType * p=&at(startIndex);
  int iMin=startIndex;
  for(int i=startIndex+1; i<n; i++ ) {
    if(at(i).y(pointOptions) < p->y(pointOptions)) {
      p=&at(i);
      iMin=i;
    }
  }
  return iMin;
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::operator*= ( const Curve< pointType > &  o)
template<class pointType>
void QGpCoreTools::Curve< pointType >::operator+= ( const Curve< pointType > &  o)
template<class pointType>
bool QGpCoreTools::Curve< pointType >::operator== ( const Curve< pointType > &  o) const [inline]
template<class pointType>
pointType& QGpCoreTools::Curve< pointType >::operator[] ( int  index) [inline]
template<class pointType>
const pointType& QGpCoreTools::Curve< pointType >::operator[] ( int  index) const [inline]
{return QVector<pointType>::at(index);}
template<class pointType>
void QGpCoreTools::Curve< pointType >::prepend ( const pointType &  p) [inline]
template<class pointType >
QVector< double > QGpCoreTools::Curve< pointType >::project ( const CurvePointOptions pointOptions = 0) const

Performs a least square regression on all points in the horizontal plane.

Returns the distances along the profile

References QGpCoreTools::sqrt(), and TRACE.

Referenced by MonoStation::AbstractSummary::distance2Station(), and GeopsyGui::SignalLayer::subPoolUpdate().

{
  TRACE;
  int n=count();
  if(!n) return QVector<double>();
  QVector<double> projections(n);
  if(n>1) {
    double a, b;
    double min=1e99;
    if(leastSquare(a, b, pointOptions)) {
      for(int i=0; i<n; i++) {
        const pointType& p=at(i);
        double denom=a*a+1.0;
        double cp=-p.x()-a*p.y(pointOptions);
        double xp=(-cp-a*b)/denom;
        double yp=(-a*cp+b)/denom-b;
        double d=::sqrt(xp*xp+yp*yp);
        projections[i]=(xp>=0)? d : -d;
        if(projections[i]<min) min=projections[i];
      }
    } else {
      for(int i=0; i<n; i++) {
        const pointType& p=at(i);
        projections[i]=p.y(pointOptions);
        if(projections[i]<min) min=projections[i];
      }
    }
    // set min to abcsisse=0
    for(int i=0; i<n;i++) projections[i]-=min;
  } else {
    projections[0]=0;
  }
  return projections;
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::remove ( int  index) [inline]
template<class pointType >
void QGpCoreTools::Curve< pointType >::removeInvalid ( )

Remove invalid points

References TRACE.

{
  TRACE;
  for(int i=count() - 1; i>=0; i-- ) {
    if( !at(i).isValid()) {
      remove(i);
    }
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::resample ( int  n,
double  min,
double  max,
SamplingOptions  options,
double  valX,
double  valY,
const CurvePointOptions pointOptions = 0 
)

References QGpCoreTools::Curve< pointType >::at(), QGpCoreTools::Function, QGpCoreTools::Curve< pointType >::indexAfter(), QGpCoreTools::Point2D::interpole(), QGpCoreTools::InversedScale, QGpCoreTools::LogScale, QGpCoreTools::Curve< pointType >::setFunction(), QGpCoreTools::sqrt(), QGpCoreTools::Curve< pointType >::swapXY(), TRACE, and QGpCoreTools::Point2D::y().

Referenced by QGpCoreTools::Curve< pointType >::average(), NewNoiseModel::curve(), MagnetoTelluricReader::parse(), ShReader::parse(), SciFigs::ComplexStatisticalProxy::resample(), SciFigs::RealStatisticalProxy::resample(), QGpGuiWave::ModalProxy::resample(), QGpGuiWave::RefractionProxy::resample(), QGpCoreTools::IrregularGrid2DData::resample(), SpacSelector::selectSamples(), EllipticityReader::setOptions(), ShReader::setOptions(), DispersionReader::setOptions(), SpacReader::setOptions(), CurvesThread::setParameters(), Histogram2D::setXSampling(), Histogram2D::setYSampling(), MonoStation::StatisticResults::studentTest(), and DinverDCCore::TargetList::validateTargets().

{
  TRACE;
  // Transforms X scale according to options (log and inv)
  if(options & InversedScale) {
    xInverse(options);
    valX=1.0/valX;
  }
  if(options & LogScale) {
    xLog10();
    valX=::log10(valX);
    if(options & Function) {
      min=::log10(min);
      max=::log10(max);
    }
  }
  if(options & Function) {
    if(min < first().x())
      min=first().x();
    if(max > last().x())
      max=last().x();
  }
  int currentN=count();

  // Calculate the total "distance" curve
  Curve<Point2D> distances(currentN);
  distances[ 0 ].setX(at(0).x());
  distances[ 0 ].setY(0.0);
  for(int i=1; i < currentN; i++ ) {
    const pointType& p1=at(i - 1);
    const pointType& p2=at(i);
    distances[ i ].setX(p2.x());
    double deltaX=(p2.x() - p1.x())/valX;
    double deltaY=(p2.y(pointOptions) - p1.y(pointOptions))/valY;
    distances[ i ].setY(distances[ i - 1 ].y() + ::sqrt(deltaX * deltaX + deltaY * deltaY));
  }
  distances.setFunction();

  // Calculate the distance of min and max, and constant step
  double distMin, distMax;
  if(options & Function) {
    Point2D p;
    int i;
    i=distances.indexAfter(min);
    p.interpole(min, distances.at(i-1), distances.at(i));
    distMin=p.y();
    i=distances.indexAfter(max);
    p.interpole(max, distances.at(i-1), distances.at(i));
    distMax=p.y();
  } else {
    distMin=0;
    distMax=distances[ currentN - 1 ].y();
  }
  double cstStep=(distMax - distMin)/(currentN - 1);

  // Map x as a function of distance, function monotoneous, then no need to setFunction()
  distances.swapXY();

  // Intepolate x for constant step distance
  QVector<double> x(n);
  double dist=distMin;
  Point2D p;
  for(int i=0; i < n; i++, dist += cstStep) {
    int iDist=distances.indexAfter(dist  );
    p.interpole(dist, distances.at(iDist-1), distances.at(iDist));
    x[ i ]=p.y();
  }
  resample(x, options);

  // Re-Transforms axis according options (log and inv)
  if(options & LogScale)
    xExp10();
  if(options & InversedScale)
    xInverse(options);
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::resample ( int  n,
double  min,
double  max,
SamplingOptions  options 
)

References QGpCoreTools::Function, QGpCoreTools::InversedScale, QGpCoreTools::LogScale, and TRACE.

{
  TRACE;
  ASSERT(options & Function);
  // Transforms X scale according to options (log and inv)
  if(options & InversedScale) {
    xInverse(options);
  }
  if(options & LogScale) {
    xLog10();
    min=::log10(min);
    max=::log10(max);
  }
  // Calculate the constant step
  double cstStep=(max - min)/(n - 1);
  QVector<double> x(n);
  for(int i=0;i < n;i++ )
    x[ i ]=min + (double)i*cstStep;
  resample(x, options);

  // Re-Transforms axis according options (log and inv)
  if(options & LogScale)
    xExp10();
  if(options & InversedScale)
    xInverse(options);
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::resample ( const Curve< pointType > &  xModel,
SamplingOptions  options 
)

References QGpCoreTools::Curve< pointType >::at(), QGpCoreTools::Curve< pointType >::count(), QGpCoreTools::Function, and TRACE.

{
  TRACE;
  ASSERT(options & Function);
  QVector<double> x(xModel.count());
  for(int i=0;i < xModel.count();i++ )
    x[ i ]=xModel.at(i).x();
  resample(x, options);
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::resample ( const QVector< double > &  xModel,
SamplingOptions  options 
)

References QGpCoreTools::Curve< pointType >::append(), QGpCoreTools::Function, QGpCoreTools::Curve< pointType >::setFunction(), QGpCoreTools::Curve< pointType >::setValid(), and TRACE.

{
  TRACE;
  ASSERT(options & Function);
  setFunction(); // Make sure values are sorted
  int nCurve=count();
  int nModel=xModel.count();
  if(nCurve<2 || nModel<2) return;
  Curve<pointType> interpolated(nModel);
  // Insert values inside xModel
  int iCurve=1;
  double min=at(0).x()*(1+(at(0).x()<0 ? 1e-15 : -1e-15));
  double max=at(nCurve-1).x()*(1+(at(nCurve-1).x()<0 ? -1e-15 : 1e-15));
  for(int i =0; i<nModel;i++) {
    double x=xModel.at(i);
    while(iCurve<nCurve-1 && at(iCurve).x()<x) iCurve++;
    interpolated[i].interpole(x, at(iCurve-1), at(iCurve));
    if(x<min || x>max || !at(iCurve-1).isValid() || !at(iCurve).isValid()) interpolated[i].setValid(false);
  }
  // Insert all values outside xModel
  if(nModel>1) {
    min=xModel.at(0)*(1+(xModel.at(0)<0 ? 1e-15 : -1e-15));
    max=xModel.at(nModel-1)*(1+(xModel.at(nModel-1)<0 ? -1e-15 : 1e-15));
    for(int i=0;i<nCurve;i++) {
      const pointType& p=at(i);
      if(p.x()<min || max<p.x()) {
        interpolated.append(p);
      }
    }
  }
  interpolated.setFunction();
  *this=interpolated;
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::resize ( int  n) [inline]
template<class pointType>
bool QGpCoreTools::Curve< pointType >::sameSampling ( const Curve< pointType > &  o) const

References QGpCoreTools::Curve< pointType >::at(), QGpCoreTools::Curve< pointType >::count(), and TRACE.

Referenced by MonoStation::WinResults::studentTest().

{
  TRACE;
  int n=count();
  if(n!=o.count()) {
    return false;
  }
  for(int i=0; i<n; i++) {
    if(at(i).x()!=o.at(i).x()) {
      return false;
    }
  }
  return true;
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::setFunction ( )

Sort points by increasing x and remove duplicates if any, so that only one Y corresponds to each X.

References QGpCoreTools::Curve< pointType >::append(), and QGpCoreTools::Curve< pointType >::count().

Referenced by QGpCoreTools::IrregularGrid2DData::crossSection(), QGpCoreTools::IrregularGrid2DData::integralCrossSection(), DinverCore::VoronoiNavigator::intersections(), QGpCoreTools::Curve< pointType >::resample(), SpacSelector::selectSamples(), QGpGuiWave::ModalProxy::setFunction(), SciFigs::ComplexStatisticalProxy::setFunction(), SciFigs::RealStatisticalProxy::setFunction(), and QGpGuiWave::RefractionProxy::setFunction().

{
  if(!isEmpty()) {
    qSort(begin(), end(), lessThan);
    // In case of lot of double entries, this is function was quite long with a remove()
    Curve<pointType> f;
    f.reserve(f.count());
    f.append(at(0));
    for(int i=1; i<count(); i++) {
      if(at(i-1).x()!=at(i).x()) {
        f.append(at(i));
      }
    }
    f.squeeze();
    // This is quite fast with implicit sharing
    *this=f;
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::setValid ( bool  v)

Set all point as valid or not valid according to v.

References TRACE.

Referenced by SpacSelector::createObjects(), QGpCoreTools::Curve< pointType >::resample(), SpacSelector::selectSamples(), and QGpGuiWave::RefractionProxy::setValid().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    it->setValid(v);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::smooth ( double  min,
double  max,
const SmoothingParameters param 
)

Smooth function between two x values

References TRACE.

{
  TRACE;
  
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::swapXY ( const CurvePointOptions pointOptions = 0)

Swap x() and y(), if the curve is a function, mandatory to call setFunction() again, except if monotoneous.

References TRACE.

Referenced by QGpCoreTools::Curve< pointType >::resample().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    double tmp=it->x();
    it->setX(it->y(pointOptions));
    it->setY(tmp, pointOptions);
  }
}
template<class pointType >
QString QGpCoreTools::Curve< pointType >::toString ( int  precision = 6,
char  format = 'g' 
) const
template<class pointType >
void QGpCoreTools::Curve< pointType >::unique ( )
template<class pointType >
void QGpCoreTools::Curve< pointType >::xExp10 ( )

References TRACE.

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    p.setX(pow(10, p.x()));
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::xInverse ( SamplingOptions  options = Function)

References QGpCoreTools::Function, and TRACE.

Referenced by LinearFKActiveResults::adjust().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    p.setX(1.0/p.x());
  }
  if(options & Function) setFunction();
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::xLog10 ( )

References TRACE.

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    if(p.x()>0.0) p.setX(::log10(p.x()));
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::xMultiply ( double  factor,
SamplingOptions  options = Function 
)

References QGpCoreTools::Function, and TRACE.

Referenced by EllipticityReader::setOptions(), DispersionReader::setOptions(), and CurvesThread::setParameters().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    p.setX(p.x()*factor);
  }
  if(factor<0.0 && options & Function) setFunction();
}
template<class pointType >
QVector< double > QGpCoreTools::Curve< pointType >::xVector ( ) const
template<class pointType >
void QGpCoreTools::Curve< pointType >::yExp10 ( const CurvePointOptions pointOptions = 0)

References TRACE.

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    p.setY(pow(10, p.y(pointOptions)), pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::yInverse ( const CurvePointOptions pointOptions = 0)

References TRACE.

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    double v=p.y(pointOptions);
    if(v!=0.0) p.setY(1.0/v, pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::yLog10 ( const CurvePointOptions pointOptions = 0)

References TRACE.

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    double v=p.y(pointOptions);
    if(v>0.0) p.setY(::log10(v), pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::yMultiply ( double  factor,
const CurvePointOptions pointOptions = 0 
)

References TRACE.

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    p.setY(p.y(pointOptions)*factor, pointOptions);
  }
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::yMultiply ( const Curve< pointType > &  o,
const CurvePointOptions pointOptions = 0 
)

References QGpCoreTools::Curve< pointType >::at(), QGpCoreTools::Curve< pointType >::count(), QGpCoreTools::endl(), QGpCoreTools::App::stream(), and QGpCoreTools::tr().

{
  if(isEmpty()) {
    *this=o;
    return;
  }
  int n=count();
  if(n!=o.count()) {
    App::stream() << tr("Curve::yMultiply(): uncompatible sampling.") << endl;
    return;
  }
  for(int i=0; i<n; i++) {
    pointType& p=(*this)[i];
    p.setY(p.y(pointOptions)*o.at(i).y(pointOptions), pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::ySetMaximumValue ( double  value,
const CurvePointOptions pointOptions = 0 
)
{
  int n=count();
  for(int i=0; i<n; i++) {
    pointType& p=(*this)[i];
    if(p.y(pointOptions)>v) {
      p.setY(v, pointOptions);
    }
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::ySetMinimumValue ( double  value,
const CurvePointOptions pointOptions = 0 
)

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  int n=count();
  for(int i=0; i<n; i++) {
    pointType& p=(*this)[i];
    if(p.y(pointOptions)<v) {
      p.setY(v, pointOptions);
    }
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::ySetValue ( double  value,
const CurvePointOptions pointOptions = 0 
)

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  int n=count();
  for(int i=0; i<n; i++) {
    (*this)[i].setY(v, pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::ySqrt ( const CurvePointOptions pointOptions = 0)

References QGpCoreTools::sqrt().

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  int n=count();
  for(int i=0; i<n; i++) {
    pointType& p=(*this)[i];
    double v=p.y(pointOptions);
    if(v>=0.0) p.setY(::sqrt(v), pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::ySquare ( const CurvePointOptions pointOptions = 0)

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  int n=count();
  for(int i=0; i<n; i++) {
    pointType& p=(*this)[i];
    double v=p.y(pointOptions);
    p.setY(v*v, pointOptions);
  }
}
template<class pointType >
void QGpCoreTools::Curve< pointType >::ySum ( double  value,
const CurvePointOptions pointOptions = 0 
)

References TRACE.

Referenced by MonoStation::AbstractSummary::setAverageValues().

{
  TRACE;
  iterator it;
  for(it=begin(); it!=end(); ++it) {
    pointType& p=*it;
    p.setY(p.y(pointOptions)+value, pointOptions);
  }
}
template<class pointType>
void QGpCoreTools::Curve< pointType >::ySum ( const Curve< pointType > &  o,
const CurvePointOptions pointOptions = 0 
)

References QGpCoreTools::Curve< pointType >::at(), QGpCoreTools::Curve< pointType >::count(), QGpCoreTools::endl(), QGpCoreTools::App::stream(), and QGpCoreTools::tr().

{
  if(isEmpty()) {
    *this=o;
    return;
  }
  int n=count();
  if(n!=o.count()) {
    App::stream() << tr("Curve::ySum(): uncompatible sampling.") << endl;
    return;
  }
  for(int i=0; i<n; i++) {
    pointType& p=(*this)[i];
    p.setY(p.y(pointOptions)+o.at(i).y(pointOptions), pointOptions);
  }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines