Engauge Digitizer  2
Public Member Functions | List of all members
ExportOrdinalsSmooth Class Reference

Utility class to interpolate points spaced evenly along a piecewise defined curve with fitted spline. More...

#include <ExportOrdinalsSmooth.h>

Collaboration diagram for ExportOrdinalsSmooth:
Collaboration graph

Public Member Functions

 ExportOrdinalsSmooth ()
 Single constructor. More...
 
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. More...
 
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 coordinates. More...
 
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. More...
 

Detailed Description

Utility class to interpolate points spaced evenly along a piecewise defined curve with fitted spline.

Definition at line 20 of file ExportOrdinalsSmooth.h.

Constructor & Destructor Documentation

◆ ExportOrdinalsSmooth()

ExportOrdinalsSmooth::ExportOrdinalsSmooth ( )

Single constructor.

Definition at line 18 of file ExportOrdinalsSmooth.cpp.

19 {
20 }

Member Function Documentation

◆ loadSplinePairsWithoutTransformation()

void ExportOrdinalsSmooth::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.

Definition at line 22 of file ExportOrdinalsSmooth.cpp.

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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:25
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
log4cpp::Category * mainCat
Definition: Logger.cpp:14
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition: SplinePair.h:13

◆ loadSplinePairsWithTransformation()

void ExportOrdinalsSmooth::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 coordinates.

Definition at line 39 of file ExportOrdinalsSmooth.cpp.

45 {
46  LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::loadSplinePairsWithTransformation";
47 
48  LinearToLog linearToLog;
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 }
double linearize(double value, bool isLog) const
Convert log coordinates to linear. This is a noop if the input is already linear.
Definition: LinearToLog.cpp:25
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:25
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
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Warps log coordinates to make them linear before passing them to code that accepts only linear coordi...
Definition: LinearToLog.h:13
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition: SplinePair.h:13

◆ ordinalsAtIntervalsGraph()

ExportValuesOrdinal ExportOrdinalsSmooth::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.

Definition at line 64 of file ExportOrdinalsSmooth.cpp.

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
73  ExportValuesOrdinal ordinals;
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 
101  QPointF posNew = QPointF (pairNew.x(),
102  pairNew.y());
103 
104  QPointF posDelta = posNew - posLast;
105  double integratedSeparationDelta = qSqrt (posDelta.x() * posDelta.x() + posDelta.y() * posDelta.y());
106  integratedSeparation += integratedSeparationDelta;
107 
108  while (integratedSeparation >= pointsInterval) {
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 {
116  sInterp = double (pointsInterval) / double (integratedSeparation);
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);
124  iTLastInterval = iT;
125  }
126 
127  tLast = tIter;
128  posLast = posNew;
129  }
130 
131  if (iTLastInterval < NUM_SMALLER_INTERVALS - 1) {
132 
133  // Add last point so we end up at tMax
134  ordinals.push_back (tMax);
135 
136  }
137  }
138 
139  return ordinals;
140 }
Cubic interpolation given independent and dependent value vectors.
Definition: Spline.h:29
double y() const
Get method for y.
Definition: SplinePair.cpp:88
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
double x() const
Get method for x.
Definition: SplinePair.cpp:83
QList< double > ExportValuesOrdinal
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition: SplinePair.h:13

The documentation for this class was generated from the following files: