Engauge Digitizer 2
Loading...
Searching...
No Matches
ExportOrdinalsSmooth.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
8#include "LinearToLog.h"
9#include "Logger.h"
10#include <qdebug.h>
11#include <qmath.h>
12#include <QPointF>
13#include "Spline.h"
14#include "Transformation.h"
15
16using namespace std;
17
21
25{
26 LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::loadSplinePairsWithoutTransformation";
27
28 Points::const_iterator itrP;
29 for (itrP = points.begin(); itrP != points.end(); itrP++) {
30 const Point &point = *itrP;
31 QPointF posScreen = point.posScreen();
32
33 t.push_back (point.ordinal ());
34 xy.push_back (SplinePair (posScreen.x(),
35 posScreen.y()));
36 }
37}
38
40 const Transformation &transformation,
41 bool isLogXTheta,
42 bool isLogYRadius,
45{
46 LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::loadSplinePairsWithTransformation";
47
49
50 Points::const_iterator itrP;
51 for (itrP = points.begin(); itrP != points.end(); itrP++) {
52 const Point &point = *itrP;
53 QPointF posScreen = point.posScreen();
54 QPointF posGraph;
55 transformation.transformScreenToRawGraph (posScreen,
56 posGraph);
57
58 t.push_back (point.ordinal ());
59 xy.push_back (SplinePair (linearToLog.linearize (posGraph.x(), isLogXTheta),
60 linearToLog.linearize (posGraph.y(), isLogYRadius)));
61 }
62}
63
66 double pointsInterval) const
67{
68 LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::ordinalsAtIntervalsGraph";
69
70 const double NUM_SMALLER_INTERVALS = 1000;
71
72 // Results. Initially empty, but at the end it will have tMin, ..., tMax
74
75 // Spline class requires at least one point
76 if (xy.size() > 0) {
77
78 // Fit a spline
79 Spline spline (t,
80 xy);
81
82 // Integrate the distances for the subintervals
83 double integratedSeparation = 0;
84 QPointF posLast (xy [0].x(),
85 xy [0].y());
86
87 // Simplest method to find the intervals is to break up the curve into many smaller intervals, and then aggregate them
88 // into intervals that, as much as possible, have the desired length. Simplicity wins out over accuracy in this
89 // approach - accuracy is sacrificed to achieve simplicity
90 double tMin = t.front();
91 double tMax = t.back();
92
93 double tLast = 0.0;
94 int iTLastInterval = 0;
95 for (int iT = 0; iT < NUM_SMALLER_INTERVALS; iT++) {
96
97 double tIter = tMin + ((tMax - tMin) * iT) / (NUM_SMALLER_INTERVALS - 1.0);
98
99 SplinePair pairNew = spline.interpolateCoeff(tIter);
100
102 pairNew.y());
103
105 double integratedSeparationDelta = qSqrt (posDelta.x() * posDelta.x() + posDelta.y() * posDelta.y());
107
109
110 // End of current interval, and start of next interval. For better accuracy without having to crank up
111 // the number of points by orders of magnitude, we use linear interpolation
112 double sInterp;
113 if (iT == 0) {
114 sInterp = 0.0;
115 } else {
117 }
118 double tInterp = (1.0 - sInterp) * tLast + sInterp * tIter;
119
120 integratedSeparation -= pointsInterval; // Part of delta that was not used gets applied to next interval
121
122 tLast = tInterp;
123 ordinals.push_back (tInterp);
125 }
126
127 tLast = tIter;
128 posLast = posNew;
129 }
130
132
133 // Add last point so we end up at tMax
134 ordinals.push_back (tMax);
135
136 }
137 }
138
139 return ordinals;
140}
const int INNER_RADIUS_MIN
QList< double > ExportValuesOrdinal
log4cpp::Category * mainCat
Definition Logger.cpp:14
QList< Point > Points
Definition Points.h:13
void loadSplinePairsWithTransformation(const Points &points, const Transformation &transformation, bool isLogXTheta, bool isLogYRadius, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, converting screen coordinates to graph coor...
ExportValuesOrdinal ordinalsAtIntervalsGraph(const std::vector< double > &t, const std::vector< SplinePair > &xy, double pointsInterval) const
Perform the interpolation on the arrays loaded by the other methods.
void loadSplinePairsWithoutTransformation(const Points &points, std::vector< double > &t, std::vector< SplinePair > &xy) const
Load t (=ordinal) and xy (=screen position) spline pairs, without any conversion to graph coordinates...
ExportOrdinalsSmooth()
Single constructor.
Warps log coordinates to make them linear before passing them to code that accepts only linear coordi...
Definition LinearToLog.h:14
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition Point.h:26
QPointF posScreen() const
Accessor for screen position.
Definition Point.cpp:404
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
Definition Point.cpp:386
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition SplinePair.h:14
Cubic interpolation given independent and dependent value vectors.
Definition Spline.h:30
Affine transformation between screen and graph coordinates, based on digitized axis points.
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18