Engauge Digitizer  2
 All Classes Functions Variables Typedefs Enumerations Friends Pages
Transformation.h
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 #ifndef TRANSFORMATION_H
8 #define TRANSFORMATION_H
9 
10 #include "CmdMediator.h"
11 #include "DocumentModelCoords.h"
12 #include "DocumentModelGeneral.h"
13 #include "MainWindowModel.h"
14 #include <QPointF>
15 #include <QString>
16 #include <QTransform>
17 
32 {
33  // For unit testing
34  friend class TestExport;
35  friend class TestSplineDrawer;
36  friend class TestTransformation;
37 
38 public:
41 
43  Transformation (const Transformation &other);
44 
47 
49  void identity();
50 
52  bool operator!=(const Transformation &other);
53 
60  static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
61  const QPointF &posFrom1,
62  const QPointF &posFrom2,
63  const QPointF &posTo0,
64  const QPointF &posTo1,
65  const QPointF &posTo2);
66 
69  const QPointF &posGraphIn);
70 
72  static QPointF cartesianOrPolarFromCartesian (const DocumentModelCoords &modelCoords,
73  const QPointF &posGraphIn);
74 
76  void coordTextForStatusBar (QPointF cursorScreen,
77  QString &coordsScreen,
78  QString &coordsGraph,
79  QString &resolutionGraph,
80  bool usingScaleBar);
81 
83  static double logToLinearCartesian (double xy);
84 
86  static double logToLinearRadius (double r,
87  double rCenter);
88 
91 
94 
97 
99  void printStream (QString indentation,
100  QTextStream &str) const;
101 
103  void resetOnLoad();
104 
106  bool transformIsDefined() const;
107 
109  void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
110  QPointF &coordScreen) const;
111 
113  void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
114  QPointF &coordScreen) const;
115 
117  QTransform transformMatrix () const;
118 
120  void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
121  QPointF &pointLinearCartesian) const;
122 
124  void transformRawGraphToScreen (const QPointF &pointRaw,
125  QPointF &pointScreen) const;
126 
128  void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
129  QPointF &pointLinearCartesian) const;
130 
132  void transformScreenToRawGraph (const QPointF &coordScreen,
133  QPointF &coordGraph) const;
134 
136  void update (bool fileIsLoaded,
137  const CmdMediator &cmdMediator,
138  const MainWindowModel &modelMainWindow);
139 
140 private:
141 
142  // No need to display values like 1E-17 when it is insignificant relative to the range
143  double roundOffSmallValues (double value, double range);
144 
145  // Model coords are set upon entry from CmdMediator
146  void setModelCoords (const DocumentModelCoords &modelCoords,
147  const DocumentModelGeneral &modelGeneral,
148  const MainWindowModel &modelMainWindow);
149 
150  // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
151  void updateTransformFromMatrices (const QTransform &matrixScreen,
152  const QTransform &matrixGraph);
153 
154  // State variable
155  bool m_transformIsDefined;
156 
157  // Transform between cartesian screen coordinates and cartesian graph coordinates
158  QTransform m_transform;
159 
160  // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
161  DocumentModelCoords m_modelCoords;
162 
163  // General settings
164  DocumentModelGeneral m_modelGeneral;
165 
166  // Formatting information
167  MainWindowModel m_modelMainWindow;
168 };
169 
171 std::ostringstream &operator<< (std::ostringstream &str,
172  const Transformation &transformation);
173 
174 #endif // TRANSFORMATION_H
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
static QPointF cartesianFromCartesianOrPolar(const DocumentModelCoords &modelCoords, const QPointF &posGraphIn)
Output cartesian coordinates from input cartesian or polar coordinates. This is static for easier use...
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...
static QTransform calculateTransformFromLinearCartesianPoints(const QPointF &posFrom0, const QPointF &posFrom1, const QPointF &posFrom2, const QPointF &posTo0, const QPointF &posTo1, const QPointF &posTo2)
Calculate QTransform using from/to points that have already been adjusted for, when applicable...
void transformScreenToLinearCartesianGraph(const QPointF &pointScreen, QPointF &pointLinearCartesian) const
Transform screen coordinates to linear cartesian coordinates.
QTransform transformMatrix() const
Get method for copying only, for the transform matrix.
void transformLinearCartesianGraphToScreen(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian pixel screen coordinates.
bool operator!=(const Transformation &other)
Inequality operator. This is marked as defined.
static QPointF cartesianOrPolarFromCartesian(const DocumentModelCoords &modelCoords, const QPointF &posGraphIn)
Output cartesian or polar coordinates from input cartesian coordinates. This is static for easier use...
static double logToLinearRadius(double r, double rCenter)
Convert radius scaling from log to linear. Calling code is responsible for determining if this is nec...
Transformation()
Default constructor. This is marked as undefined until the proper number of axis points are added...
Unit test of Export classes.
Definition: TestExport.h:16
static double logToLinearCartesian(double xy)
Convert cartesian scaling from log to linear. Calling code is responsible for determining if this is ...
MainWindowModel modelMainWindow() const
Get method for MainWindowModel.
Unit test of transformation class. Checking mostly involves verifying forward/reverse are inverses of...
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Transformation & operator=(const Transformation &other)
Assignment operator.
Affine transformation between screen and graph coordinates, based on digitized axis points...
Model for DlgSettingsMainWindow.
void coordTextForStatusBar(QPointF cursorScreen, QString &coordsScreen, QString &coordsGraph, QString &resolutionGraph, bool usingScaleBar)
Return string descriptions of cursor coordinates for status bar.
Model for DlgSettingsCoords and CmdSettingsCoords.
void transformLinearCartesianGraphToRawGraph(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian, polar, linear, log coordinates...
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
Command queue stack.
Definition: CmdMediator.h:23
void identity()
Identity transformation.
void update(bool fileIsLoaded, const CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow)
Update transform by iterating through the axis points.
Unit test of spline drawer, which classifies single- versus multi-valued data.
void transformRawGraphToLinearCartesianGraph(const QPointF &pointRaw, QPointF &pointLinearCartesian) const
Convert graph coordinates (linear or log, cartesian or polar) to linear cartesian coordinates...
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.