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 if (xy.size() > 0) {
00072
00073
00074 Spline spline (t,
00075 xy);
00076
00077
00078 double integratedSeparation = 0;
00079 QPointF posLast (xy [0].x(),
00080 xy [0].y());
00081
00082
00083
00084
00085 double tMin = t.front();
00086 double tMax = t.back();
00087
00088 double tLast = 0.0;
00089 int iTLastInterval = 0;
00090 for (int iT = 0; iT < NUM_SMALLER_INTERVALS; iT++) {
00091
00092 double t = tMin + ((tMax - tMin) * iT) / (NUM_SMALLER_INTERVALS - 1.0);
00093
00094 SplinePair pairNew = spline.interpolateCoeff(t);
00095
00096 QPointF posNew = QPointF (pairNew.x(),
00097 pairNew.y());
00098
00099 QPointF posDelta = posNew - posLast;
00100 double integratedSeparationDelta = qSqrt (posDelta.x() * posDelta.x() + posDelta.y() * posDelta.y());
00101 integratedSeparation += integratedSeparationDelta;
00102
00103 while (integratedSeparation >= pointsInterval) {
00104
00105
00106
00107 double sInterp;
00108 if (iT == 0) {
00109 sInterp = 0.0;
00110 } else {
00111 sInterp = (double) pointsInterval / (double) integratedSeparation;
00112 }
00113 double tInterp = (1.0 - sInterp) * tLast + sInterp * t;
00114
00115 integratedSeparation -= pointsInterval;
00116
00117 tLast = tInterp;
00118 ordinals.push_back (tInterp);
00119 iTLastInterval = iT;
00120 }
00121
00122 tLast = t;
00123 posLast = posNew;
00124 }
00125
00126 if (iTLastInterval < NUM_SMALLER_INTERVALS - 1) {
00127
00128
00129 ordinals.push_back (tMax);
00130
00131 }
00132 }
00133
00134 return ordinals;
00135 }