Engauge Digitizer  2
ExportOrdinalsStraight.cpp
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 
7 #include "ExportOrdinalsStraight.h"
8 #include "Logger.h"
9 #include <qdebug.h>
10 #include <qmath.h>
11 #include <QPointF>
12 #include "Transformation.h"
13 
14 using namespace std;
15 
17 {
18 }
19 
21  double pointsInterval) const
22 {
23  LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsStraight::ordinalsAtIntervalsGraph";
24 
25  // Results
26  ExportValuesOrdinal ordinals;
27 
28  // Integrate the distances for the subintervals
29  double distanceAlongSegment = 0;
30  QPointF posLast (points [0].posScreen().x(),
31  points [0].posScreen().y());
32  double ordinalLast = 0;
33 
34  // Simplest method to find the intervals is to break up the curve into many smaller intervals, and then aggregate them
35  // into intervals that, as much as possible, have the desired length. Simplicity wins out over accuracy in this
36  // approach - accuracy is sacrificed to achieve simplicity
37  for (int iP = 0; iP < points.count(); iP++) {
38 
39  const Point &pointNew = points.at (iP);
40  QPointF posNew = pointNew.posScreen();
41 
42  QPointF posDelta = posNew - posLast;
43  double segmentLength = qSqrt (posDelta.x() * posDelta.x() + posDelta.y() * posDelta.y());
44 
45  while (distanceAlongSegment < segmentLength) {
46 
47  double sLocal = distanceAlongSegment / segmentLength;
48 
49  ordinals.push_back (ordinalLast + sLocal);
50 
51  distanceAlongSegment += pointsInterval;
52  }
53 
54  distanceAlongSegment -= segmentLength;
55  ordinalLast = pointNew.ordinal();
56  posLast = posNew;
57  }
58 
59  return ordinals;
60 }
61 
63  const Transformation &transformation,
64  double pointsInterval) const
65 {
66  LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsStraight::ordinalsAtIntervalsGraph";
67 
68  // Results
69  ExportValuesOrdinal ordinals;
70 
71  // Integrate the distances for the subintervals
72  double distanceAlongSegment = 0;
73  QPointF posLast;
74  transformation.transformScreenToRawGraph (points [0].posScreen(),
75  posLast);
76  double ordinalLast = 0;
77 
78  // Simplest method to find the intervals is to break up the curve into many smaller intervals, and then aggregate them
79  // into intervals that, as much as possible, have the desired length. Simplicity wins out over accuracy in this
80  // approach - accuracy is sacrificed to achieve simplicity
81  for (int iP = 0; iP < points.count(); iP++) {
82 
83  const Point &pointNew = points.at (iP);
84  QPointF posNew;
85  transformation.transformScreenToRawGraph (pointNew.posScreen(),
86  posNew);
87 
88  QPointF posDelta = posNew - posLast;
89  double segmentLength = qSqrt (posDelta.x() * posDelta.x() + posDelta.y() * posDelta.y());
90 
91  while (distanceAlongSegment < segmentLength) {
92 
93  double sLocal = distanceAlongSegment / segmentLength;
94 
95  ordinals.push_back (ordinalLast + sLocal);
96 
97  distanceAlongSegment += pointsInterval;
98  }
99 
100  ordinalLast = pointNew.ordinal();
101  posLast = posNew;
102  }
103 
104  return ordinals;
105 }
ExportValuesOrdinal ordinalsAtIntervalsGraphWithTransformation(const Points &points, const Transformation &transformation, double pointsInterval) const
Compute ordinals, converting screen coordinates to graph coordinates.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:23
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:392
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
Definition: Point.cpp:374
ExportOrdinalsStraight()
Single constructor.
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.
ExportValuesOrdinal ordinalsAtIntervalsGraphWithoutTransformation(const Points &points, double pointsInterval) const
Compute ordinals, without any conversion to graph coordinates.