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
34 friend class TestExport;
35 friend class TestSplineDrawer;
36 friend class TestTransformation;
37
38public:
41
44
47
49 void identity();
50
52 bool operator!=(const Transformation &other);
53
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
73 const QPointF &posGraphIn);
74
80 bool usingScaleBar);
81
83 static double logToLinearCartesian (double xy);
84
86 static double logToLinearRadius (double r,
87 double rCenter);
88
91
94
97
100 QTextStream &str) const;
101
103 void resetOnLoad();
104
106 bool transformIsDefined() const;
107
110 QPointF &coordScreen) const;
111
114 QPointF &coordScreen) const;
115
118
122
125 QPointF &pointScreen) const;
126
130
133 QPointF &coordGraph) const;
134
136 void update (bool fileIsLoaded,
137 const CmdMediator &cmdMediator,
139
140private:
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,
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
171std::ostringstream &operator<< (std::ostringstream &str,
172 const Transformation &transformation);
173
174#endif // TRANSFORMATION_H
const int INNER_RADIUS_MIN
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.
Unit test of Export classes.
Definition TestExport.h:17
Unit test of spline drawer, which classifies single- versus multi-valued data.
Unit test of transformation class. Checking mostly involves verifying forward/reverse are inverses of...
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.
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.
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.
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.