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 QString NO_ERROR_REPORT_LOG_FILE;
33  const QString NO_REGRESSION_OPEN_FILE;
34  const bool NO_GNUPLOT_LOG_FILES = false;
35  const bool NO_REGRESSION_IMPORT = false;
36  const bool NO_RESET = false;
37  const bool NO_EXPORT_ONLY = false;
38  const bool NO_EXPORT_IMAGE_ONLY = false;
39  const QString NO_EXPORT_IMAGE_EXTENSION;
40  const bool DEBUG_FLAG = false;
41  const QStringList NO_LOAD_STARTUP_FILES;
42  const QStringList NO_COMMAND_LINE;
43 
44  initializeLogging ("engauge_test",
45  "engauge_test.log",
46  DEBUG_FLAG);
47 
48  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
49  NO_REGRESSION_OPEN_FILE,
50  NO_REGRESSION_IMPORT,
51  NO_GNUPLOT_LOG_FILES,
52  NO_RESET,
53  NO_EXPORT_ONLY,
54  NO_EXPORT_IMAGE_ONLY,
55  NO_EXPORT_IMAGE_EXTENSION,
56  NO_LOAD_STARTUP_FILES,
57  NO_COMMAND_LINE);
58  w.show ();
59 }
60 
61 bool TestSplineDrawer::testMultiValuedGeneric (const vector<SplinePair> &xy,
62  const vector<bool> &isMultiValued) const
63 {
64  bool success = true;
65  vector<double> t;
66 
67  // Models
68  DocumentModelCoords modelCoords;
69  DocumentModelGeneral modelGeneral;
70  MainWindowModel modelMainWindow;
71 
72  modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
73  modelCoords.setCoordScaleYRadius (COORD_SCALE_LINEAR);
74 
75  // Transformation
76  Transformation trans;
77  trans.setModelCoords (modelCoords,
78  modelGeneral,
79  modelMainWindow);
80  QTransform matrixScreen (198.5 , 627.562, 55.625 ,
81  562.562, 562.562, 155.562,
82  1 , 1 , 1 );
83  QTransform matrixGraph (0.001, 1.0, 0.0001,
84  0 , 0 , 30 ,
85  1 , 1 , 1 );
86  trans.updateTransformFromMatrices (matrixScreen,
87  matrixGraph);
88 
89  int counter = 0;
90  vector<SplinePair>::const_iterator itr;
91  for (itr = xy.begin(); itr != xy.end(); itr++) {
92  t.push_back (counter++);
93  }
94 
95  // Generate the spline
96  Spline s (t, xy);
97 
98  SplineDrawer sd (trans);
99  for (unsigned int segment = 0; segment < isMultiValued.size(); segment++) {
100  if (isMultiValued [segment] != sd.segmentIsMultiValued (s,
101  xy.size(),
102  segment)) {
103  success = false;
104  }
105  }
106 
107  return success;
108 }
109 
110 void TestSplineDrawer::testMultiValuedLeadingOverlap ()
111 {
112  vector<SplinePair> xy;
113  vector<bool> isMultiValued;
114 
115  xy.push_back (SplinePair (198.388, 426.423)); isMultiValued.push_back (true);
116  xy.push_back (SplinePair (198.531, 399.463)); isMultiValued.push_back (false);
117  xy.push_back (SplinePair (384.589, 263.384)); isMultiValued.push_back (true);
118  xy.push_back (SplinePair (409.525, 250.684)); isMultiValued.push_back (true);
119  xy.push_back (SplinePair (441.360, 535.685)); isMultiValued.push_back (false);
120  xy.push_back (SplinePair (484.557, 358.601)); isMultiValued.push_back (false);
121  xy.push_back (SplinePair (495.663, 454.633)); isMultiValued.push_back (false);
122  xy.push_back (SplinePair (527.411, 182.426)); isMultiValued.push_back (false);
123  xy.push_back (SplinePair (633.561, 155.353)); isMultiValued.push_back (false);
124  xy.push_back (SplinePair (756.603, 358.646)); // Last point has no corresponding segment
125 
126  bool success = testMultiValuedGeneric (xy,
127  isMultiValued);
128 
129  QVERIFY (success);
130 }
131 
132 void TestSplineDrawer::testMultiValuedTrailingOverlap ()
133 {
134  vector<SplinePair> xy;
135  vector<bool> isMultiValued;
136 
137  // Same data as testMultiValuedLeadingOverlap but horizontally flipped about x=(198+756)/2
138  double maxPlusMin = 756.603 + 198.388;
139  xy.push_back (SplinePair (maxPlusMin - 756.603, 358.646)); isMultiValued.push_back (false);
140  xy.push_back (SplinePair (maxPlusMin - 633.561, 155.353)); isMultiValued.push_back (false);
141  xy.push_back (SplinePair (maxPlusMin - 527.411, 182.426)); isMultiValued.push_back (false);
142  xy.push_back (SplinePair (maxPlusMin - 495.663, 454.633)); isMultiValued.push_back (false);
143  xy.push_back (SplinePair (maxPlusMin - 484.557, 358.601)); isMultiValued.push_back (false);
144  xy.push_back (SplinePair (maxPlusMin - 441.360, 535.685)); isMultiValued.push_back (true);
145  xy.push_back (SplinePair (maxPlusMin - 409.525, 250.684)); isMultiValued.push_back (true);
146  xy.push_back (SplinePair (maxPlusMin - 384.589, 263.384)); isMultiValued.push_back (false);
147  xy.push_back (SplinePair (maxPlusMin - 198.531, 399.463)); isMultiValued.push_back (true);
148  xy.push_back (SplinePair (maxPlusMin - 198.388, 426.423)); // Last point has no corresponding segment
149 
150  bool success = testMultiValuedGeneric (xy,
151  isMultiValued);
152 
153  QVERIFY (success);
154 }
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.