Engauge Digitizer  2
TestSplineDrawer.cpp
1 #include "DocumentModelCoords.h"
2 #include "DocumentModelGeneral.h"
3 #include "Logger.h"
4 #include "MainWindow.h"
5 #include "MainWindowModel.h"
6 #include <map>
7 #include <qmath.h>
8 #include <QtTest/QtTest>
9 #include "Spline.h"
10 #include "SplineDrawer.h"
11 #include "SplinePair.h"
12 #include <sstream>
13 #include "Test/TestSplineDrawer.h"
14 #include "Transformation.h"
15 
16 QTEST_MAIN (TestSplineDrawer)
17 
18 using namespace std;
19 
21  QObject(parent)
22 {
23 }
24 
25 void TestSplineDrawer::cleanupTestCase ()
26 {
27 
28 }
29 
30 void TestSplineDrawer::initTestCase ()
31 {
32  const bool NO_DROP_REGRESSION = false;
33  const QString NO_ERROR_REPORT_LOG_FILE;
34  const QString NO_REGRESSION_OPEN_FILE;
35  const bool NO_GNUPLOT_LOG_FILES = false;
36  const bool NO_REGRESSION_IMPORT = false;
37  const bool NO_RESET = false;
38  const bool NO_EXPORT_ONLY = false;
39  const bool NO_EXPORT_IMAGE_ONLY = false;
40  const QString NO_EXPORT_IMAGE_EXTENSION;
41  const bool DEBUG_FLAG = false;
42  const QStringList NO_LOAD_STARTUP_FILES;
43  const QStringList NO_COMMAND_LINE;
44 
45  initializeLogging ("engauge_test",
46  "engauge_test.log",
47  DEBUG_FLAG);
48 
49  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
50  NO_REGRESSION_OPEN_FILE,
51  NO_DROP_REGRESSION,
52  NO_REGRESSION_IMPORT,
53  NO_GNUPLOT_LOG_FILES,
54  NO_RESET,
55  NO_EXPORT_ONLY,
56  NO_EXPORT_IMAGE_ONLY,
57  NO_EXPORT_IMAGE_EXTENSION,
58  NO_LOAD_STARTUP_FILES,
59  NO_COMMAND_LINE);
60  w.show ();
61 }
62 
63 bool TestSplineDrawer::testMultiValuedGeneric (const vector<SplinePair> &xy,
64  const vector<bool> &isMultiValued) const
65 {
66  bool success = true;
67  vector<double> t;
68 
69  // Models
70  DocumentModelCoords modelCoords;
71  DocumentModelGeneral modelGeneral;
72  MainWindowModel modelMainWindow;
73 
74  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
75  modelCoords.setCoordScaleYRadius (COORD_SCALE_LINEAR);
76 
77  // Transformation
78  Transformation trans;
79  trans.setModelCoords (modelCoords,
80  modelGeneral,
81  modelMainWindow);
82  QTransform matrixScreen (198.5 , 627.562, 55.625 ,
83  562.562, 562.562, 155.562,
84  1 , 1 , 1 );
85  QTransform matrixGraph (0.001, 1.0, 0.0001,
86  0 , 0 , 30 ,
87  1 , 1 , 1 );
88  trans.updateTransformFromMatrices (matrixScreen,
89  matrixGraph);
90 
91  int counter = 0;
92  vector<SplinePair>::const_iterator itr;
93  for (itr = xy.begin(); itr != xy.end(); itr++) {
94  t.push_back (counter++);
95  }
96 
97  // Generate the spline
98  Spline s (t, xy);
99 
100  SplineDrawer sd (trans);
101  for (unsigned int segment = 0; segment < isMultiValued.size(); segment++) {
102  if (isMultiValued [segment] != sd.segmentIsMultiValued (s,
103  xy.size(),
104  segment)) {
105  success = false;
106  }
107  }
108 
109  return success;
110 }
111 
112 void TestSplineDrawer::testMultiValuedLeadingOverlap ()
113 {
114  vector<SplinePair> xy;
115  vector<bool> isMultiValued;
116 
117  xy.push_back (SplinePair (198.388, 426.423)); isMultiValued.push_back (true);
118  xy.push_back (SplinePair (198.531, 399.463)); isMultiValued.push_back (false);
119  xy.push_back (SplinePair (384.589, 263.384)); isMultiValued.push_back (true);
120  xy.push_back (SplinePair (409.525, 250.684)); isMultiValued.push_back (true);
121  xy.push_back (SplinePair (441.360, 535.685)); isMultiValued.push_back (false);
122  xy.push_back (SplinePair (484.557, 358.601)); isMultiValued.push_back (false);
123  xy.push_back (SplinePair (495.663, 454.633)); isMultiValued.push_back (false);
124  xy.push_back (SplinePair (527.411, 182.426)); isMultiValued.push_back (false);
125  xy.push_back (SplinePair (633.561, 155.353)); isMultiValued.push_back (false);
126  xy.push_back (SplinePair (756.603, 358.646)); // Last point has no corresponding segment
127 
128  bool success = testMultiValuedGeneric (xy,
129  isMultiValued);
130 
131  QVERIFY (success);
132 }
133 
134 void TestSplineDrawer::testMultiValuedTrailingOverlap ()
135 {
136  vector<SplinePair> xy;
137  vector<bool> isMultiValued;
138 
139  // Same data as testMultiValuedLeadingOverlap but horizontally flipped about x=(198+756)/2
140  double maxPlusMin = 756.603 + 198.388;
141  xy.push_back (SplinePair (maxPlusMin - 756.603, 358.646)); isMultiValued.push_back (false);
142  xy.push_back (SplinePair (maxPlusMin - 633.561, 155.353)); isMultiValued.push_back (false);
143  xy.push_back (SplinePair (maxPlusMin - 527.411, 182.426)); isMultiValued.push_back (false);
144  xy.push_back (SplinePair (maxPlusMin - 495.663, 454.633)); isMultiValued.push_back (false);
145  xy.push_back (SplinePair (maxPlusMin - 484.557, 358.601)); isMultiValued.push_back (false);
146  xy.push_back (SplinePair (maxPlusMin - 441.360, 535.685)); isMultiValued.push_back (true);
147  xy.push_back (SplinePair (maxPlusMin - 409.525, 250.684)); isMultiValued.push_back (true);
148  xy.push_back (SplinePair (maxPlusMin - 384.589, 263.384)); isMultiValued.push_back (false);
149  xy.push_back (SplinePair (maxPlusMin - 198.531, 399.463)); isMultiValued.push_back (true);
150  xy.push_back (SplinePair (maxPlusMin - 198.388, 426.423)); // Last point has no corresponding segment
151 
152  bool success = testMultiValuedGeneric (xy,
153  isMultiValued);
154 
155  QVERIFY (success);
156 }
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Cubic interpolation given independent and dependent value vectors.
Definition: Spline.h:29
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
Affine transformation between screen and graph coordinates, based on digitized axis points.
Model for DlgSettingsMainWindow.
Model for DlgSettingsCoords and CmdSettingsCoords.
TestSplineDrawer(QObject *parent=0)
Single constructor.
Unit test of spline drawer, which classifies single- versus multi-valued data.
This class takes the output from Spline and uses that to draw the curve in the graphics window,...
Definition: SplineDrawer.h:35
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:91
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition: SplinePair.h:13
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.