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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4 (Public License)
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
// Pascal Port By: Milan Marusinec alias Milano
// milan@marusinec.sk
// http://www.aggpas.org
// Copyright (c) 2005-2006
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//
//----------------------------------------------------------------------------
//
// Bilinear 2D transformations
//
// [Pascal Port History] -----------------------------------------------------
//
// 23.06.2006-Milano: ptrcomp adjustments
// 07.02.2006-Milano: Unit port establishment
//
{ agg_trans_bilinear.pas }
unit
agg_trans_bilinear ;
INTERFACE
{$I agg_mode.inc }
uses
agg_basics ,
agg_trans_affine ,
agg_simul_eq ;
{ TYPES DEFINITION }
type
iterator_x = object
inc_x ,inc_y ,x ,y : double;
constructor Construct; overload;
constructor Construct(tx ,ty ,step : double; m : double_42_ptr ); overload;
procedure inc_operator;
end;
trans_bilinear_ptr = ^trans_bilinear;
trans_bilinear = object(trans_affine )
m_valid : boolean;
m_mtx : array[0..3 ,0..1 ] of double;
constructor Construct; overload;
// Arbitrary quadrangle transformations
constructor Construct(src ,dst : double_ptr ); overload;
// Direct transformations
constructor Construct(x1 ,y1 ,x2 ,y2 : double; quad : double_ptr ); overload;
// Reverse transformations
constructor Construct(quad : double_ptr; x1 ,y1 ,x2 ,y2 : double ); overload;
// Set the transformations using two arbitrary quadrangles.
procedure quad_to_quad(src ,dst : double_ptr );
// Set the direct transformations, i.e., rectangle -> quadrangle
procedure rect_to_quad(x1 ,y1 ,x2 ,y2 : double; quad : double_ptr );
// Set the reverse transformations, i.e., quadrangle -> rectangle
procedure quad_to_rect(quad : double_ptr; x1 ,y1 ,x2 ,y2 : double );
// Check if the equations were solved successfully
function is_valid : boolean;
function begin_(x ,y ,step : double ) : iterator_x;
end;
{ GLOBAL PROCEDURES }
IMPLEMENTATION
{ LOCAL VARIABLES & CONSTANTS }
{ UNIT IMPLEMENTATION }
{ CONSTRUCT }
constructor iterator_x.Construct;
begin
end;
{ CONSTRUCT }
constructor iterator_x.Construct(tx ,ty ,step : double; m : double_42_ptr );
begin
inc_x:=m^[1 ,0 ] * step * ty + m^[2 ,0 ] * step;
inc_y:=m^[1 ,1 ] * step * ty + m^[2 ,1 ] * step;
x:=m^[0 ,0 ] + m^[1 ,0 ] * tx * ty + m^[2 ,0 ] * tx + m^[3 ,0 ] * ty;
y:=m^[0 ,1 ] + m^[1 ,1 ] * tx * ty + m^[2 ,1 ] * tx + m^[3 ,1 ] * ty;
end;
{ INC_OPERATOR }
procedure iterator_x.inc_operator;
begin
x:=x + inc_x;
y:=y + inc_y;
end;
{ _transform }
procedure _transform(this : trans_bilinear_ptr; x ,y : double_ptr );
var
tx ,ty ,xy : double;
begin
tx:=x^;
ty:=y^;
xy:=tx * ty;
x^:=this.m_mtx[0 ,0 ] + this.m_mtx[1 ,0 ] * xy + this.m_mtx[2 ,0 ] * tx + this.m_mtx[3 ,0 ] * ty;
y^:=this.m_mtx[0 ,1 ] + this.m_mtx[1 ,1 ] * xy + this.m_mtx[2 ,1 ] * tx + this.m_mtx[3 ,1 ] * ty;
end;
{ CONSTRUCT }
constructor trans_bilinear.Construct;
begin
inherited Construct;
m_valid:=false;
transform:=@_transform;
end;
{ CONSTRUCT }
constructor trans_bilinear.Construct(src ,dst : double_ptr );
begin
inherited Construct;
quad_to_quad(src ,dst );
transform:=@_transform;
end;
{ CONSTRUCT }
constructor trans_bilinear.Construct(x1 ,y1 ,x2 ,y2 : double; quad : double_ptr );
begin
inherited Construct;
rect_to_quad(x1 ,y1 ,x2 ,y2 ,quad );
transform:=@_transform;
end;
{ CONSTRUCT }
constructor trans_bilinear.Construct(quad : double_ptr; x1 ,y1 ,x2 ,y2 : double );
begin
inherited Construct;
quad_to_rect(quad ,x1 ,y1 ,x2 ,y2 );
transform:=@_transform;
end;
{ QUAD_TO_QUAD }
procedure trans_bilinear.quad_to_quad;
var
left : double_44;
right : double_42;
i ,ix ,iy : unsigned;
begin
for i:=0 to 3 do
begin
ix:=i * 2;
iy:=ix + 1;
left[i ,0 ]:=1.0;
left[i ,1 ]:=double_ptr(ptrcomp(src ) + ix * sizeof(double ) )^ * double_ptr(ptrcomp(src ) + iy * sizeof(double ) )^;
left[i ,2 ]:=double_ptr(ptrcomp(src ) + ix * sizeof(double ) )^;
left[i ,3 ]:=double_ptr(ptrcomp(src ) + iy * sizeof(double ) )^;
right[i ,0 ]:=double_ptr(ptrcomp(dst ) + ix * sizeof(double ) )^;
right[i ,1 ]:=double_ptr(ptrcomp(dst ) + iy * sizeof(double ) )^;
end;
m_valid:=simul_eq_solve(@left ,@right ,@m_mtx ,4 ,2 );
end;
{ RECT_TO_QUAD }
procedure trans_bilinear.rect_to_quad;
var
src : double_8;
begin
src[0 ]:=x1;
src[6 ]:=x1;
src[2 ]:=x2;
src[4 ]:=x2;
src[1 ]:=y1;
src[3 ]:=y1;
src[5 ]:=y2;
src[7 ]:=y2;
quad_to_quad(@src ,quad );
end;
{ QUAD_TO_RECT }
procedure trans_bilinear.quad_to_rect;
var
dst : double_8;
begin
dst[0 ]:=x1;
dst[6 ]:=x1;
dst[2 ]:=x2;
dst[4 ]:=x2;
dst[1 ]:=y1;
dst[3 ]:=y1;
dst[5 ]:=y2;
dst[7 ]:=y2;
quad_to_quad(quad ,@dst );
end;
{ IS_VALID }
function trans_bilinear.is_valid;
begin
result:=m_valid;
end;
{ BEGIN_ }
function trans_bilinear.begin_;
begin
result.Construct(x ,y ,step ,@m_mtx );
end;
END.
|