00001
00002
00003
00004
00005
00006
00007 #include "ExportOrdinalsSmooth.h"
00008 #include "Logger.h"
00009 #include <qdebug.h>
00010 #include <qmath.h>
00011 #include <QPointF>
00012 #include "Spline.h"
00013 #include "Transformation.h"
00014
00015 using namespace std;
00016
00017 ExportOrdinalsSmooth::ExportOrdinalsSmooth ()
00018 {
00019 }
00020
00021 void ExportOrdinalsSmooth::loadSplinePairsWithoutTransformation (const Points &points,
00022 vector<double> &t,
00023 vector<SplinePair> &xy) const
00024 {
00025 LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::loadSplinePairsWithoutTransformation";
00026
00027 Points::const_iterator itrP;
00028 for (itrP = points.begin(); itrP != points.end(); itrP++) {
00029 const Point &point = *itrP;
00030 QPointF posScreen = point.posScreen();
00031
00032 t.push_back (point.ordinal ());
00033 xy.push_back (SplinePair (posScreen.x(),
00034 posScreen.y()));
00035 }
00036 }
00037
00038 void ExportOrdinalsSmooth::loadSplinePairsWithTransformation (const Points &points,
00039 const Transformation &transformation,
00040 vector<double> &t,
00041 vector<SplinePair> &xy) const
00042 {
00043 LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::loadSplinePairsWithTransformation";
00044
00045 Points::const_iterator itrP;
00046 for (itrP = points.begin(); itrP != points.end(); itrP++) {
00047 const Point &point = *itrP;
00048 QPointF posScreen = point.posScreen();
00049 QPointF posGraph;
00050 transformation.transformScreenToRawGraph (posScreen,
00051 posGraph);
00052
00053 t.push_back (point.ordinal ());
00054 xy.push_back (SplinePair (posGraph.x(),
00055 posGraph.y()));
00056 }
00057 }
00058
00059 ExportValuesOrdinal ExportOrdinalsSmooth::ordinalsAtIntervalsGraph (const vector<double> &t,
00060 const vector<SplinePair> &xy,
00061 double pointsInterval) const
00062 {
00063 LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::ordinalsAtIntervalsGraph";
00064
00065 const double NUM_SMALLER_INTERVALS = 1000;
00066
00067
00068 ExportValuesOrdinal ordinals;
00069
00070
00071 Spline spline (t,
00072 xy);
00073
00074
00075 double integratedSeparation = 0;
00076 QPointF posLast (xy [0].x(),
00077 xy [0].y());
00078
00079
00080
00081
00082 double tMin = t.front();
00083 double tMax = t.back();
00084
00085 double tLast = 0.0;
00086 int iTLastInterval = 0;
00087 for (int iT = 0; iT < NUM_SMALLER_INTERVALS; iT++) {
00088
00089 double t = tMin + ((tMax - tMin) * iT) / (NUM_SMALLER_INTERVALS - 1.0);
00090
00091 SplinePair pairNew = spline.interpolateCoeff(t);
00092
00093 QPointF posNew = QPointF (pairNew.x(),
00094 pairNew.y());
00095
00096 QPointF posDelta = posNew - posLast;
00097 double integratedSeparationDelta = qSqrt (posDelta.x() * posDelta.x() + posDelta.y() * posDelta.y());
00098 integratedSeparation += integratedSeparationDelta;
00099
00100 while (integratedSeparation >= pointsInterval) {
00101
00102
00103
00104 double sInterp;
00105 if (iT == 0) {
00106 sInterp = 0.0;
00107 } else {
00108 sInterp = (double) pointsInterval / (double) integratedSeparation;
00109 }
00110 double tInterp = (1.0 - sInterp) * tLast + sInterp * t;
00111
00112 integratedSeparation -= pointsInterval;
00113
00114 tLast = tInterp;
00115 ordinals.push_back (tInterp);
00116 iTLastInterval = iT;
00117 }
00118
00119 tLast = t;
00120 posLast = posNew;
00121 }
00122
00123 if (iTLastInterval < NUM_SMALLER_INTERVALS - 1) {
00124
00125
00126 ordinals.push_back (tMax);
00127
00128 }
00129
00130 return ordinals;
00131 }