Engauge Digitizer  2
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 "MainWindowModel.h"
13 #include <QPointF>
14 #include <QString>
15 #include <QTransform>
16 
31 {
32  // For unit testing
33  friend class TestTransformation;
34 
35 public:
38 
41 
43  void identity();
44 
46  bool operator!=(const Transformation &other);
47 
54  static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
55  const QPointF &posFrom1,
56  const QPointF &posFrom2,
57  const QPointF &posTo0,
58  const QPointF &posTo1,
59  const QPointF &posTo2);
60 
63  const QPointF &posGraphIn);
64 
66  static QPointF cartesianOrPolarFromCartesian (const DocumentModelCoords &modelCoords,
67  const QPointF &posGraphIn);
68 
70  void coordTextForStatusBar (QPointF cursorScreen,
71  QString &coordsScreen,
72  QString &coordsGraph,
73  QString &resolutionGraph);
74 
76  static double logToLinearCartesian (double xy);
77 
79  static double logToLinearRadius (double r,
80  double rCenter);
81 
84 
86  void printStream (QString indentation,
87  QTextStream &str) const;
88 
90  void resetOnLoad();
91 
93  bool transformIsDefined() const;
94 
96  void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
97  QPointF &coordScreen) const;
98 
100  void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
101  QPointF &coordScreen) const;
102 
104  QTransform transformMatrix () const;
105 
107  void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
108  QPointF &pointLinearCartesian) const;
109 
111  void transformRawGraphToScreen (const QPointF &pointRaw,
112  QPointF &pointScreen) const;
113 
115  void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
116  QPointF &pointLinearCartesian) const;
117 
119  void transformScreenToRawGraph (const QPointF &coordScreen,
120  QPointF &coordGraph) const;
121 
123  void update (bool fileIsLoaded,
124  const CmdMediator &cmdMediator,
125  const MainWindowModel &modelMainWindow);
126 
127 private:
128 
129  // No need to display values like 1E-17 when it is insignificant relative to the range
130  double roundOffSmallValues (double value, double range);
131 
132  // Model coords are set upon entry from CmdMediator
133  void setModelCoords (const DocumentModelCoords &modelCoords,
134  const MainWindowModel &modelMainWindow);
135 
136  // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
137  void updateTransformFromMatrices (const QTransform &matrixScreen,
138  const QTransform &matrixGraph);
139 
140  // State variable
141  bool m_transformIsDefined;
142 
143  // Transform between cartesian screen coordinates and cartesian graph coordinates
144  QTransform m_transform;
145 
146  // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
147  DocumentModelCoords m_modelCoords;
148 
149  // Formatting information
150  MainWindowModel m_modelMainWindow;
151 };
152 
154 std::ostringstream &operator<< (std::ostringstream &str,
155  const Transformation &transformation);
156 
157 #endif // TRANSFORMATION_H
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
void coordTextForStatusBar(QPointF cursorScreen, QString &coordsScreen, QString &coordsGraph, QString &resolutionGraph)
Return string descriptions of cursor coordinates for status bar.
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...
static double logToLinearCartesian(double xy)
Convert cartesian scaling from log to linear. Calling code is responsible for determining if this is ...
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.
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.
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...