Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | List of all members
GeometryStrategyAbstractBase Class Referenceabstract

Base class for all geometry strategies. More...

#include <GeometryStrategyAbstractBase.h>

Inheritance diagram for GeometryStrategyAbstractBase:
Inheritance graph
Collaboration diagram for GeometryStrategyAbstractBase:
Collaboration graph

Public Member Functions

 GeometryStrategyAbstractBase ()
 Single constructor. More...
 
virtual ~GeometryStrategyAbstractBase ()
 
virtual void calculateGeometry (const Points &points, const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, const MainWindowModel &modelMainWindow, const Transformation &transformation, QString &funcArea, QString &polyArea, QVector< QString > &x, QVector< QString > &y, QVector< bool > &isPotentialExportAmbiguity, QVector< QString > &distanceGraphForward, QVector< QString > &distancePercentForward, QVector< QString > &distanceGraphBackward, QVector< QString > &distancePercentBackward) const =0
 Calculate geometry parameters. More...
 

Protected Member Functions

void calculatePositionsGraph (const Points &points, const Transformation &transformation, QVector< QPointF > &positionsGraph) const
 Convert screen positions to graph positions. More...
 
double functionArea (const QVector< QPointF > &positionsGraph) const
 Use trapezoidal approximation to compute area under the function. Does not apply to relation. More...
 
void insertSubintervalsAndLoadDistances (int subintervalsPerInterval, const QVector< QPointF > &positionsGraph, QVector< QPointF > &positionsGraphWithSubintervals, QVector< QString > &distanceGraphForward, QVector< QString > &distancePercentForward, QVector< QString > &distanceGraphBackward, QVector< QString > &distancePercentBackward) const
 Insert the specified number of subintervals into each interval. More...
 
virtual void loadPotentialExportVector (QVector< QString > &x, QVector< QString > &y, const Transformation &transformation, QVector< bool > &isPotentialExportAmbiguity) const
 Load isPotentialExportAmbiguity vector. Default in base class is to load false values since there are no ambiguities. More...
 
void loadXY (const QVector< QPointF > &positionsGraph, const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, const MainWindowModel &modelMainWindow, const Transformation &transformation, QVector< QString > &x, QVector< QString > &y) const
 Load x and y coordinate vectors. More...
 
double polygonAreaForSimplyConnected (const QVector< QPointF > &points) const
 Area in polygon using Shoelace formula, which only works if polygon is simply connected. More...
 

Detailed Description

Base class for all geometry strategies.

Each strategy computes geometry parameters according to the curve's settings.

The numbering for the strategies is specified as the CurveConnectAs enumeration

Definition at line 24 of file GeometryStrategyAbstractBase.h.

Constructor & Destructor Documentation

GeometryStrategyAbstractBase::GeometryStrategyAbstractBase ( )

Single constructor.

Definition at line 19 of file GeometryStrategyAbstractBase.cpp.

20 {
21 }
GeometryStrategyAbstractBase::~GeometryStrategyAbstractBase ( )
virtual

Definition at line 23 of file GeometryStrategyAbstractBase.cpp.

24 {
25 }

Member Function Documentation

virtual void GeometryStrategyAbstractBase::calculateGeometry ( const Points points,
const DocumentModelCoords modelCoords,
const DocumentModelGeneral modelGeneral,
const MainWindowModel modelMainWindow,
const Transformation transformation,
QString &  funcArea,
QString &  polyArea,
QVector< QString > &  x,
QVector< QString > &  y,
QVector< bool > &  isPotentialExportAmbiguity,
QVector< QString > &  distanceGraphForward,
QVector< QString > &  distancePercentForward,
QVector< QString > &  distanceGraphBackward,
QVector< QString > &  distancePercentBackward 
) const
pure virtual
void GeometryStrategyAbstractBase::calculatePositionsGraph ( const Points points,
const Transformation transformation,
QVector< QPointF > &  positionsGraph 
) const
protected

Convert screen positions to graph positions.

Definition at line 27 of file GeometryStrategyAbstractBase.cpp.

30 {
31  positionsGraph.clear();
32 
33  for (int i = 0; i < points.size(); i++) {
34  const Point &pointScreen = points [i];
35  QPointF posScreen = pointScreen.posScreen ();
36  QPointF posGraph;
37 
38  transformation.transformScreenToRawGraph (posScreen,
39  posGraph);
40 
41  positionsGraph.push_back (posGraph);
42  }
43 }
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
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 GeometryStrategyAbstractBase::functionArea ( const QVector< QPointF > &  positionsGraph) const
protected

Use trapezoidal approximation to compute area under the function. Does not apply to relation.

Definition at line 45 of file GeometryStrategyAbstractBase.cpp.

46 {
47  // Integrate using trapezoidal approximation to get the area under the function
48  double sum = 0, xLast = 0, yLast = 0;
49  for (int i = 1; i < positionsGraph.size (); i++) {
50  double x = positionsGraph [i].x();
51  double y = positionsGraph [i].y();
52  double area = 0.5 * (y + yLast) * (x - xLast);
53  sum += area;
54  xLast = x;
55  yLast = y;
56  }
57 
58  return sum;
59 }
void GeometryStrategyAbstractBase::insertSubintervalsAndLoadDistances ( int  subintervalsPerInterval,
const QVector< QPointF > &  positionsGraph,
QVector< QPointF > &  positionsGraphWithSubintervals,
QVector< QString > &  distanceGraphForward,
QVector< QString > &  distancePercentForward,
QVector< QString > &  distanceGraphBackward,
QVector< QString > &  distancePercentBackward 
) const
protected

Insert the specified number of subintervals into each interval.

For straight curves subintervalsPerInterval=1 so the linearity is maintained, and for smooth curves subintervalsPerInterval>1 so the geometry calculations take into account the curvature(s) of the line

Definition at line 61 of file GeometryStrategyAbstractBase.cpp.

68 {
69  if (positionsGraph.size () > 0) {
70 
71  int i;
72 
73  // Fit splines to the points
74  vector<double> t;
75  vector<SplinePair> xy;
76  for (int i = 0; i < positionsGraph.size (); i++) {
77  t.push_back (double (i));
78  xy.push_back (SplinePair (positionsGraph [i].x(),
79  positionsGraph [i].y()));
80  }
81 
82  Spline spline (t,
83  xy);
84 
85  // Loop over the original points, with one original point per original interval
86  QVector<double> distanceGraphDouble;
87  double xLast = 0, yLast = 0, distance = 0;
88  for (i = 0; i < positionsGraph.size(); i++) {
89 
90  // In the interval i-1 to i we insert points to create smaller subintervals
91  for (int subinterval = 0; subinterval < subintervalsPerInterval; subinterval++) {
92 
93  // Go from i-1 (exclusive) to i (inclusive)
94  double t = double (i - 1.0) + double (subinterval + 1) / double (subintervalsPerInterval);
95 
96  SplinePair splinePair = spline.interpolateCoeff (t);
97 
98  double x = splinePair.x ();
99  double y = splinePair.y ();
100 
101  // All points from intervals where i>0, and last point from interval i=0
102  if (i > 0 || subinterval == subintervalsPerInterval - 1) {
103 
104  // Insert one of several new points for each original point
105  positionsGraphWithSubintervals.push_back (QPointF (x, y));
106 
107  }
108 
109  if (i > 0) {
110 
111  // Add to cumulative distance
112  distance += qSqrt ((x - xLast) * (x - xLast) + (y - yLast) * (y - yLast));
113 
114  }
115 
116  xLast = x;
117  yLast = y;
118  }
119 
120  // Insert one distance entry for each original point
121  distanceGraphDouble.push_back (distance);
122  }
123 
124  // Compute distance columns
125  double dTotal = qMax (1.0, distanceGraphDouble [distanceGraphDouble.size() - 1]); // qMax prevents divide by zero
126  for (i = 0; i < distanceGraphDouble.size (); i++) {
127  double d = distanceGraphDouble [i];
128  distanceGraphForward.push_back (QString::number (d));
129  distancePercentForward.push_back (QString::number (100.0 * d / dTotal));
130  distanceGraphBackward.push_back (QString::number (dTotal - d));
131  distancePercentBackward.push_back (QString::number (100.0 * (dTotal - d) / dTotal));
132  }
133  }
134 }
Cubic interpolation given independent and dependent value vectors.
Definition: Spline.h:29
double y() const
Get method for y.
Definition: SplinePair.cpp:88
double x() const
Get method for x.
Definition: SplinePair.cpp:83
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition: SplinePair.h:13
void GeometryStrategyAbstractBase::loadPotentialExportVector ( QVector< QString > &  x,
QVector< QString > &  y,
const Transformation transformation,
QVector< bool > &  isPotentialExportAmbiguity 
) const
protectedvirtual

Load isPotentialExportAmbiguity vector. Default in base class is to load false values since there are no ambiguities.

Definition at line 136 of file GeometryStrategyAbstractBase.cpp.

140 {
141  for (int i = 0; i < x.size(); i++) {
142  isPotentialExportAmbiguity.append (false);
143  }
144 }
void GeometryStrategyAbstractBase::loadXY ( const QVector< QPointF > &  positionsGraph,
const DocumentModelCoords modelCoords,
const DocumentModelGeneral modelGeneral,
const MainWindowModel modelMainWindow,
const Transformation transformation,
QVector< QString > &  x,
QVector< QString > &  y 
) const
protected

Load x and y coordinate vectors.

Definition at line 146 of file GeometryStrategyAbstractBase.cpp.

153 {
154  FormatCoordsUnits formatCoordsUnits;
155 
156  for (int i = 0; i < positionsGraph.size(); i++) {
157 
158  double xI = positionsGraph [i].x();
159  double yI = positionsGraph [i].y();
160 
161  QString xFormatted, yFormatted;
162  formatCoordsUnits.unformattedToFormatted (xI,
163  yI,
164  modelCoords,
165  modelGeneral,
166  modelMainWindow,
167  xFormatted,
168  yFormatted,
169  transformation);
170  x.push_back (xFormatted);
171  y.push_back (yFormatted);
172 
173  }
174 }
void unformattedToFormatted(double xThetaUnformatted, double yRadiusUnformatted, const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, const MainWindowModel &mainWindowModel, QString &xThetaFormatted, QString &yRadiusFormatted, const Transformation &transformation) const
Convert unformatted numeric value to formatted string. Transformation is used to determine best resol...
Highest-level wrapper around other Formats classes.
double GeometryStrategyAbstractBase::polygonAreaForSimplyConnected ( const QVector< QPointF > &  points) const
protected

Area in polygon using Shoelace formula, which only works if polygon is simply connected.

We do not check to see if the polygon is simply connected since that would be (1) slow and (2) much work

Definition at line 176 of file GeometryStrategyAbstractBase.cpp.

177 {
178  // Shoelace formula
179  int N = points.size ();
180 
181  double sum = 0.0;
182  if (N > 0) {
183 
184 
185  for (int i = 0; i < N - 1; i++) {
186  sum += points [i].x() * points [i + 1].y() - points [i + 1].x() * points [i].y();
187  }
188 
189  sum += points [N - 1].x() * points [0].y() - points [0].x() * points [N - 1].y ();
190  }
191 
192  return qAbs (sum) / 2.0;
193 }

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