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