Engauge Digitizer 2
Loading...
Searching...
No Matches
Transformation.h
Go to the documentation of this file.
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"
13#include "MainWindowModel.h"
14#include <QPointF>
15#include <QString>
16#include <QTransform>
17
32{
33 // For unit testing
35 friend class TestExport;
36 friend class TestSplineDrawer;
37 friend class TestTransformation;
38
39public:
42
44 Transformation (const Transformation &other);
45
48
50 void identity();
51
53 bool operator!=(const Transformation &other);
54
61 static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
62 const QPointF &posFrom1,
63 const QPointF &posFrom2,
64 const QPointF &posTo0,
65 const QPointF &posTo1,
66 const QPointF &posTo2);
67
70 const QPointF &posGraphIn);
71
74 const QPointF &posGraphIn);
75
77 void coordTextForStatusBar (QPointF cursorScreen,
78 QString &coordsScreen,
79 QString &coordsGraph,
80 QString &resolutionGraph,
81 bool usingScaleBar);
82
84 static double logToLinearCartesian (double xy);
85
87 static double logToLinearRadius (double r,
88 double rCenter);
89
92
95
98
100 void printStream (QString indentation,
101 QTextStream &str) const;
102
104 void resetOnLoad();
105
107 bool transformIsDefined() const;
108
110 void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
111 QPointF &coordScreen) const;
112
114 void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
115 QPointF &coordScreen) const;
116
118 QTransform transformMatrix () const;
119
121 void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
122 QPointF &pointLinearCartesian) const;
123
125 void transformRawGraphToScreen (const QPointF &pointRaw,
126 QPointF &pointScreen) const;
127
129 void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
130 QPointF &pointLinearCartesian) const;
131
133 void transformScreenToRawGraph (const QPointF &coordScreen,
134 QPointF &coordGraph) const;
135
137 void update (bool fileIsLoaded,
138 const CmdMediator &cmdMediator,
140
141private:
142
143 // No need to display values like 1E-17 when it is insignificant relative to the range
144 double roundOffSmallValues (double value, double range);
145
146 // Model coords are set upon entry from CmdMediator
147 void setModelCoords (const DocumentModelCoords &modelCoords,
150
151 // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
152 void updateTransformFromMatrices (const QTransform &matrixScreen,
153 const QTransform &matrixGraph);
154
155 // State variable
156 bool m_transformIsDefined;
157
158 // Transform between cartesian screen coordinates and cartesian graph coordinates
159 QTransform m_transform;
160
161 // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
162 DocumentModelCoords m_modelCoords;
163
164 // General settings
165 DocumentModelGeneral m_modelGeneral;
166
167 // Formatting information
168 MainWindowModel m_modelMainWindow;
169};
170
172std::ostringstream &operator<< (std::ostringstream &str,
173 const Transformation &transformation);
174
175#endif // TRANSFORMATION_H
std::ostringstream & operator<<(std::ostringstream &str, const Transformation &transformation)
Stream operator.
Command queue stack.
Definition CmdMediator.h:24
Model for DlgSettingsCoords and CmdSettingsCoords.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
Model for DlgSettingsMainWindow.
Affine transformation between screen and graph coordinates, based on digitized axis points.
void identity()
Identity transformation.
bool operator!=(const Transformation &other)
Inequality operator. This is marked as defined.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
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 coordTextForStatusBar(QPointF cursorScreen, QString &coordsScreen, QString &coordsGraph, QString &resolutionGraph, bool usingScaleBar)
Return string descriptions of cursor coordinates for status bar.
Transformation()
Default constructor. This is marked as undefined until the proper number of axis points are added.
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
void transformLinearCartesianGraphToRawGraph(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian, polar, linear, log coordinates.
static double logToLinearCartesian(double xy)
Convert cartesian scaling from log to linear. Calling code is responsible for determining if this is ...
static QPointF cartesianOrPolarFromCartesian(const DocumentModelCoords &modelCoords, const QPointF &posGraphIn)
Output cartesian or polar coordinates from input cartesian coordinates. This is static for easier use...
Transformation & operator=(const Transformation &other)
Assignment operator.
friend class TestExport
static QPointF cartesianFromCartesianOrPolar(const DocumentModelCoords &modelCoords, const QPointF &posGraphIn)
Output cartesian coordinates from input cartesian or polar coordinates. This is static for easier use...
friend class TestCentipedeEndpoints
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
QTransform transformMatrix() const
Get method for copying only, for the transform matrix.
static double logToLinearRadius(double r, double rCenter)
Convert radius scaling from log to linear. Calling code is responsible for determining if this is nec...
void transformRawGraphToLinearCartesianGraph(const QPointF &pointRaw, QPointF &pointLinearCartesian) const
Convert graph coordinates (linear or log, cartesian or polar) to linear cartesian coordinates.
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
void update(bool fileIsLoaded, const CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow)
Update transform by iterating through the axis points.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
friend class TestTransformation
friend class TestSplineDrawer
MainWindowModel modelMainWindow() const
Get method for MainWindowModel.
void transformScreenToLinearCartesianGraph(const QPointF &pointScreen, QPointF &pointLinearCartesian) const
Transform screen coordinates to linear cartesian coordinates.
void transformLinearCartesianGraphToScreen(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian pixel screen coordinates.