Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
Transformation.h
1 #ifndef TRANSFORMATION_H
2 #define TRANSFORMATION_H
3 
4 #include "CmdMediator.h"
5 #include "DocumentModelCoords.h"
6 #include <QPointF>
7 #include <QString>
8 #include <QTransform>
9 
24 {
25  // For unit testing
26  friend class TestTransformation;
27 
28 public:
31 
34 
36  void identity();
37 
39  bool operator!=(const Transformation &other);
40 
47  static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
48  const QPointF &posFrom1,
49  const QPointF &posFrom2,
50  const QPointF &posTo0,
51  const QPointF &posTo1,
52  const QPointF &posTo2);
53 
56  const QPointF &posGraphIn);
57 
59  static QPointF cartesianOrPolarFromCartesian (const DocumentModelCoords &modelCoords,
60  const QPointF &posGraphIn);
61 
63  void coordTextForStatusBar (QPointF cursorScreen,
64  QString &coordsScreen,
65  QString &coordsGraph,
66  QString &resolutionGraph);
67 
69  static double logToLinearCartesian (double xy);
70 
72  static double logToLinearRadius (double r,
73  double rCenter);
74 
77 
79  void printStream (QString indentation,
80  QTextStream &str) const;
81 
83  void resetOnLoad();
84 
86  bool transformIsDefined() const { return m_transformIsDefined; }
87 
89  void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
90  QPointF &coordScreen) const;
91 
93  void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
94  QPointF &coordScreen) const;
95 
97  QTransform transformMatrix () const;
98 
100  void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
101  QPointF &pointLinearCartesian) const;
102 
104  void transformRawGraphToScreen (const QPointF &pointRaw,
105  QPointF &pointScreen) const;
106 
108  void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
109  QPointF &pointLinearCartesian) const;
110 
112  void transformScreenToRawGraph (const QPointF &coordScreen,
113  QPointF &coordGraph) const;
114 
116  void update (bool fileIsLoaded,
117  const CmdMediator &cmdMediator);
118 
119 private:
120 
121  // No need to display values like 1E-17 when it is insignificant relative to the range
122  double roundOffSmallValues (double value, double range);
123 
124  // Model coords are set upon entry from CmdMediator
125  void setModelCoords (const DocumentModelCoords &modelCoords);
126 
127  // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
128  void updateTransformFromMatrices (const QTransform &matrixScreen,
129  const QTransform &matrixGraph);
130 
131  // State variable
132  bool m_transformIsDefined;
133 
134  // Transform between cartesian screen coordinates and cartesian graph coordinates
135  QTransform m_transform;
136 
137  // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
138  DocumentModelCoords m_modelCoords;
139 };
140 
142 const Transformation &operator<< (std::ostringstream &str,
143  const Transformation &transformation);
144 
145 #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...
void update(bool fileIsLoaded, const CmdMediator &cmdMediator)
Update transform by iterating through the axis points.
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:16
void identity()
Identity transformation.
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...