Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator 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 "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 
40  Transformation (const Transformation &other);
41 
44 
46  void identity();
47 
49  bool operator!=(const Transformation &other);
50 
57  static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
58  const QPointF &posFrom1,
59  const QPointF &posFrom2,
60  const QPointF &posTo0,
61  const QPointF &posTo1,
62  const QPointF &posTo2);
63 
66  const QPointF &posGraphIn);
67 
69  static QPointF cartesianOrPolarFromCartesian (const DocumentModelCoords &modelCoords,
70  const QPointF &posGraphIn);
71 
73  void coordTextForStatusBar (QPointF cursorScreen,
74  QString &coordsScreen,
75  QString &coordsGraph,
76  QString &resolutionGraph);
77 
79  static double logToLinearCartesian (double xy);
80 
82  static double logToLinearRadius (double r,
83  double rCenter);
84 
87 
90 
92  void printStream (QString indentation,
93  QTextStream &str) const;
94 
96  void resetOnLoad();
97 
99  bool transformIsDefined() const;
100 
102  void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
103  QPointF &coordScreen) const;
104 
106  void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
107  QPointF &coordScreen) const;
108 
110  QTransform transformMatrix () const;
111 
113  void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
114  QPointF &pointLinearCartesian) const;
115 
117  void transformRawGraphToScreen (const QPointF &pointRaw,
118  QPointF &pointScreen) const;
119 
121  void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
122  QPointF &pointLinearCartesian) const;
123 
125  void transformScreenToRawGraph (const QPointF &coordScreen,
126  QPointF &coordGraph) const;
127 
129  void update (bool fileIsLoaded,
130  const CmdMediator &cmdMediator,
131  const MainWindowModel &modelMainWindow);
132 
133 private:
134 
135  // No need to display values like 1E-17 when it is insignificant relative to the range
136  double roundOffSmallValues (double value, double range);
137 
138  // Model coords are set upon entry from CmdMediator
139  void setModelCoords (const DocumentModelCoords &modelCoords,
140  const MainWindowModel &modelMainWindow);
141 
142  // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
143  void updateTransformFromMatrices (const QTransform &matrixScreen,
144  const QTransform &matrixGraph);
145 
146  // State variable
147  bool m_transformIsDefined;
148 
149  // Transform between cartesian screen coordinates and cartesian graph coordinates
150  QTransform m_transform;
151 
152  // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
153  DocumentModelCoords m_modelCoords;
154 
155  // Formatting information
156  MainWindowModel m_modelMainWindow;
157 };
158 
160 std::ostringstream &operator<< (std::ostringstream &str,
161  const Transformation &transformation);
162 
163 #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 ...
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.
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...