-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageTransform.h
126 lines (104 loc) · 3.28 KB
/
ImageTransform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/** @file ImageTransform.h
*
* @author marco corvi
* @date dec 2009
*
* @brief tranforms for the background sketches
* --------------------------------------------------------
* Copyright This sowftare is distributed under GPL-3.0 or later
* See the file COPYING.
*/
#ifndef IMAGE_TRANSFORM_H
#define IMAGE_TRANSFORM_H
#ifdef HAS_BACKIMAGE
#include <string>
#include <vector>
#include <qpixmap.h>
#include "BackgroundImageStation.h"
class PlotPoint; // forward
/** point correspondence between sketch image and plot
*/
struct BackgroundImagePoint
{
double x; //!< sketch coordinates (pixel in the image)
double y;
double x0; //!< plot coordinates (point on the canvas)
double y0;
PlotPoint * point; //!< pointer to the corresponding canvas point
BackgroundImagePoint( PlotPoint * pt, const BackgroundImageStation * st )
: x( st->x )
, y( st->y )
, point(pt )
{ }
};
/** interface that uses a sketch to make the background image
*/
class BackgroundImageCallback
{
public:
virtual ~BackgroundImageCallback() { }
/** warp the input sketch using the stations correspondences
* @param stations stations correspondences
* @param sketch background sketch
*/
virtual void evalBackground( const std::vector< BackgroundImageStation *> & stations,
QPixmap * sketch ) = 0;
};
class Transform
{
protected:
bool init; //!< whether the transform has been properly initialized
public:
/** cstr
*/
Transform()
: init( false )
{ }
/** dstr
*/
virtual ~Transform() {}
/** check if this transform is initialized
* @return true if this transform is initialized
*/
bool isInitialized() const { return init; }
/** map a background image point (xs,ys) to a sketch point (xt,yt)
* @param xs X coord of the point in the background image
* @param ys Y coord
* @param xt X coord in the sketch image
* @param yt Y coord
* @return the "distance" of the point in the background image
*/
virtual double map( double xs, double ys, double & xt, double & yt ) = 0;
/** compute the "distance" of a point (in the background image)
* @param xs X coord of the point in the background image
* @param ys Y coord
* @return the "distance" of the point in the background image
*/
virtual double distance( double xs, double ys ) = 0;
};
/** transform based on two points
* x' = g x + s y + a
* y' = -s x + g y + b
*/
class TransformTwoPt : public Transform
{
private:
double x1s0, y1s0;
double x1t0, y1t0;
double ds0, dt0;
double scale; //!< scales
double n1sx, n1sy; //!< unit vector in source space
double n1tx, n1ty; //!< unit vector in target space
// double t1x = n1y, t1y = -n1x //!< normal vector;
public:
TransformTwoPt( double x1s, double y1s, double x1t, double y1t,
double x2s, double y2s, double x2t, double y2t );
double map( double xs, double ys, double & xt, double & yt );
double distance( double xs, double ys );
};
bool
imageWarp( std::vector< BackgroundImagePoint > & stations,
unsigned char * dst, int w1, int h1,
const unsigned char * src, int w2, int h2 );
#endif // HAS_BACKIMAGE
#endif