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>
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 ¶m) |
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) |
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:
typedef const pointType* QGpCoreTools::Curve< pointType >::const_iterator |
typedef pointType* QGpCoreTools::Curve< pointType >::iterator |
QGpCoreTools::Curve< pointType >::Curve | ( | ) | [inline] |
{}
QGpCoreTools::Curve< pointType >::Curve | ( | int | n | ) | [inline] |
: QVector<pointType>(n) {}
QGpCoreTools::Curve< pointType >::Curve | ( | const Curve< pointType > & | o | ) | [inline] |
: QVector<pointType>(o) {}
QGpCoreTools::Curve< pointType >::Curve | ( | const QVector< pointType > & | o | ) | [inline] |
: QVector<pointType>(o) {}
void QGpCoreTools::Curve< pointType >::append | ( | const pointType & | p | ) | [inline] |
Referenced by GeopsyCore::SubSignalPool::azimuth(), createCurve(), createCurveName(), SpacSelector::createObjects(), ArrayGui::ArrayResponse::createObjects(), QGpCoreTools::IrregularGrid2DData::crossSection(), QGpCoreWave::Profile::curve(), QGpCoreWave::ModalStorage::curve(), QGpCoreWave::AutocorrCurves::dispersionCurve(), MonoStation::AbstractSummary::distance2Station(), QGpCoreTools::IrregularGrid2DData::integralCrossSection(), DinverCore::VoronoiNavigator::intersections(), SpacSelector::inverseAt(), main(), Group2PhaseReader::parse(), ShReader::parse(), CurveReader::parse(), QGpGuiWave::DispersionProxy::parse(), QGpGuiWave::AutocorrProxy::parse(), QGpGuiWave::EllipticityProxy::parse(), SciFigs::RealStatisticalProxy::parse(), SciFigs::ComplexStatisticalProxy::parse(), QGpGuiWave::RefractionProxy::parse(), GeopsyCore::SubSignalPool::receivers(), QGpCoreTools::Curve< pointType >::resample(), QGpCoreWave::AutocorrCurves::ringCurves(), TapePositioningSystem::Node::robustQuads(), SpacSelector::selectSamples(), ArrayGui::ArrayResponse::setAzimuth(), QGpGuiWave::DispersionLimitLayer::setFrequencySampling(), QGpCoreTools::Curve< pointType >::setFunction(), sortCurve(), GeopsyCore::SubSignalPool::sources(), ProcessStatus::updateMisfitCurve(), Acquisition::varVoltageCurve(), and DinverDCCore::TargetList::xml_polishChild().
void QGpCoreTools::Curve< pointType >::append | ( | const Curve< pointType > & | c | ) | [inline] |
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().
const pointType& QGpCoreTools::Curve< pointType >::at | ( | int | index | ) | const [inline] |
{return QVector<pointType>::at(index);}
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(); }
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; }
const_iterator QGpCoreTools::Curve< pointType >::begin | ( | ) | const [inline] |
iterator QGpCoreTools::Curve< pointType >::begin | ( | ) | [inline] |
{return QVector<pointType>::begin();}
void QGpCoreTools::Curve< pointType >::clear | ( | ) | [inline] |
Reimplemented in QGpCoreWave::ModalCurve, QGpCoreWave::MagnetoTelluricCurve, QGpCoreWave::RefractionCurve, and QGpCoreTools::Histogram.
Referenced by DampingResults::compute(), SpacSelector::inverseAt(), CurveReader::parse(), SciFigs::ComplexStatisticalProxy::parse(), SciFigs::RealStatisticalProxy::parse(), ArrayGui::ArrayResponse::setAzimuth(), and QGpGuiWave::DispersionLimitLayer::setFrequencySampling().
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; }
int QGpCoreTools::Curve< pointType >::count | ( | ) | const [inline] |
Referenced by QGpCoreTools::Curve< pointType >::average(), GeopsyCore::SubSignalPool::azimuth(), QGpCoreTools::IrregularGrid2DData::crossSection(), QGpCoreTools::IrregularGrid2DData::cut(), QGpCoreWave::AutocorrCurves::dispersionCurve(), ToolRefra::initStations(), StatGridAnalyser::on_freqScroll_valueChanged(), QGpCoreWave::ModalCurve::operator=(), QGpCoreTools::Curve< pointType >::resample(), QGpCoreTools::Curve< pointType >::sameSampling(), QGpGuiWave::RefractionProxy::sampleCount(), QGpGuiWave::DispersionLimitLayer::setConstantWaveNumber(), QGpCoreTools::Curve< pointType >::setFunction(), SpacSelector::setK(), MonoStation::AbstractSummary::setSpectrumGridValues(), QGpCoreWave::MagnetoTelluricFactory::setX(), QGpCoreWave::ModalFactory::setX(), MonoStation::StatisticResults::studentTest(), QGpCoreTools::Curve< pointType >::yMultiply(), and QGpCoreTools::Curve< pointType >::ySum().
{return QVector<pointType>::count();}
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); }
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; }
const_iterator QGpCoreTools::Curve< pointType >::end | ( | ) | const [inline] |
iterator QGpCoreTools::Curve< pointType >::end | ( | ) | [inline] |
{return QVector<pointType>::end();}
const pointType& QGpCoreTools::Curve< pointType >::first | ( | ) | const [inline] |
Referenced by ToolRefra::initStations(), SpacSelector::inverse(), SpacSelector::inverseAt(), SpacSelector::selectSamples(), and MapWindow::signalsUpdate().
{return QVector<pointType>::first();}
pointType& QGpCoreTools::Curve< pointType >::first | ( | ) | [inline] |
{return QVector<pointType>::first();}
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; }
int QGpCoreTools::Curve< pointType >::indexOf | ( | const pointType & | p | ) | const [inline] |
{return QVector<pointType>::indexOf(p);}
void QGpCoreTools::Curve< pointType >::insert | ( | int | index, |
const pointType & | p | ||
) | [inline] |
{QVector<pointType>::insert(index, p);}
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); } } } }
bool QGpCoreTools::Curve< pointType >::isEmpty | ( | ) | const [inline] |
Referenced by createCurve(), createCurveName(), QGpGuiWave::DispersionProxy::parse(), QGpGuiWave::AutocorrProxy::parse(), QGpGuiWave::EllipticityProxy::parse(), SciFigs::RealStatisticalProxy::parse(), SciFigs::ComplexStatisticalProxy::parse(), QGpGuiWave::RefractionProxy::parse(), and sortCurve().
{return QVector<pointType>::isEmpty();}
const pointType& QGpCoreTools::Curve< pointType >::last | ( | ) | const [inline] |
pointType& QGpCoreTools::Curve< pointType >::last | ( | ) | [inline] |
{return QVector<pointType>::last();}
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; }
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().
int QGpCoreTools::Curve< pointType >::maximumX | ( | int | startIndex = 0 | ) | const |
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 QGpCoreTools::Curve< pointType >::minimumX | ( | int | startIndex = 0 | ) | const |
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().
void QGpCoreTools::Curve< pointType >::operator*= | ( | const Curve< pointType > & | o | ) |
void QGpCoreTools::Curve< pointType >::operator+= | ( | const Curve< pointType > & | o | ) |
bool QGpCoreTools::Curve< pointType >::operator== | ( | const Curve< pointType > & | o | ) | const [inline] |
{return QVector<pointType>::operator==(o);}
pointType& QGpCoreTools::Curve< pointType >::operator[] | ( | int | index | ) | [inline] |
{return QVector<pointType>::operator[](index);}
const pointType& QGpCoreTools::Curve< pointType >::operator[] | ( | int | index | ) | const [inline] |
{return QVector<pointType>::at(index);}
void QGpCoreTools::Curve< pointType >::prepend | ( | const pointType & | p | ) | [inline] |
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; }
void QGpCoreTools::Curve< pointType >::remove | ( | int | index | ) | [inline] |
Referenced by NewNoiseModel::curve().
{QVector<pointType>::remove(index);}
void QGpCoreTools::Curve< pointType >::removeInvalid | ( | ) |
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); }
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); }
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); }
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; }
void QGpCoreTools::Curve< pointType >::resize | ( | int | n | ) | [inline] |
Referenced by DampingResults::compute(), QGpCoreWave::MagnetoTelluricFactory::curve(), main(), DinverDCGui::GroundModelViewer::minMaxProfiles(), QGpCoreWave::RefractionDippingModel::ray(), ToolSPAC::setArrayMap(), MonoStation::StationResults::setAverageLayer(), ToolSPAC::setCoArrayMap(), SciFigs::PlotLine2D::setCurve(), ProfileReader::setOptions(), MapWindow::signalsUpdate(), and MonoStation::StatisticResults::studentTest().
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().
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; } }
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().
void QGpCoreTools::Curve< pointType >::smooth | ( | double | min, |
double | max, | ||
const SmoothingParameters & | param | ||
) |
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().
QString QGpCoreTools::Curve< pointType >::toString | ( | int | precision = 6 , |
char | format = 'g' |
||
) | const |
References TRACE.
Referenced by TargetExtract::execute(), main(), RefraReader::parse(), ShReader::parse(), MonoStation::StationResults::printAverage(), ProfileReader::terminate(), CurveReader::terminate(), and HistogramWidget::toStream().
{ TRACE; QString s; for(const_iterator it=begin(); it!=end(); ++it) { s+=it->toString(precision, format); s+="\n"; } return s; }
void QGpCoreTools::Curve< pointType >::unique | ( | ) |
References QGpCoreTools::unique().
Referenced by ToolRefra::initStations().
{ ::QGpCoreTools::unique(*this); }
void QGpCoreTools::Curve< pointType >::xExp10 | ( | ) |
void QGpCoreTools::Curve< pointType >::xInverse | ( | SamplingOptions | options = Function | ) |
References QGpCoreTools::Function, and TRACE.
Referenced by LinearFKActiveResults::adjust().
void QGpCoreTools::Curve< pointType >::xLog10 | ( | ) |
void QGpCoreTools::Curve< pointType >::xMultiply | ( | double | factor, |
SamplingOptions | options = Function |
||
) |
References QGpCoreTools::Function, and TRACE.
Referenced by EllipticityReader::setOptions(), DispersionReader::setOptions(), and CurvesThread::setParameters().
QVector< double > QGpCoreTools::Curve< pointType >::xVector | ( | ) | const |
Referenced by QGpCoreTools::Curve< pointType >::average(), MagnetoTelluricReader::parse(), ShReader::setOptions(), EllipticityReader::setOptions(), DispersionReader::setOptions(), CurvesThread::setParameters(), Histogram2D::setXSampling(), and Histogram2D::setYSampling().
{ int n=count(); QVector<double> x(n); for(int i=0; i<n; i++ ) { x[i]=at(i).x(); } return x; }
void QGpCoreTools::Curve< pointType >::yExp10 | ( | const CurvePointOptions * | pointOptions = 0 | ) |
void QGpCoreTools::Curve< pointType >::yInverse | ( | const CurvePointOptions * | pointOptions = 0 | ) |
void QGpCoreTools::Curve< pointType >::yLog10 | ( | const CurvePointOptions * | pointOptions = 0 | ) |
void QGpCoreTools::Curve< pointType >::yMultiply | ( | double | factor, |
const CurvePointOptions * | pointOptions = 0 |
||
) |
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); } }
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); } } }
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); } } }
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); } }
void QGpCoreTools::Curve< pointType >::ySqrt | ( | const CurvePointOptions * | pointOptions = 0 | ) |
References QGpCoreTools::sqrt().
Referenced by MonoStation::AbstractSummary::setAverageValues().
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); } }
void QGpCoreTools::Curve< pointType >::ySum | ( | double | value, |
const CurvePointOptions * | pointOptions = 0 |
||
) |
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); } }