-
Notifications
You must be signed in to change notification settings - Fork 0
/
wu_fillellipse+antialiasing.cpp
207 lines (190 loc) · 5.34 KB
/
wu_fillellipse+antialiasing.cpp
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
/***********************************************************************
This code is generated by the AlgoPascal translator
This code is distributed under the ALGLIB license
(see http://www.alglib.net/copyrules.php for details)
***********************************************************************/
#include "ap.h"
/*-----------------------------------------------
This routines must be defined by the programmer:
void setpixel(int x, int y, double alpha);
-----------------------------------------------*/
void drawwufilledellipse(double x1, double y1, double x2, double y2);
void sethline(int x1, int x2, int y);
void setvline(int x, int y1, int y2);
/*************************************************************************
<<<<<<< HEAD
РиÑование заполненного ÑллипÑа Ñ Ð¸Ñпользованием
метода Ву Ð´Ð»Ñ Ð°Ð½Ñ‚Ð¸Ð°Ð»Ð¸Ð°Ñинга.
Ð’ процеÑÑе Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð¸ÑпользуютÑÑ Ñ„ÑƒÐ½ÐºÑ†Ð¸Ð¸ SetVLine
и SetHLine, риÑующие прÑмые. ПрограммиÑÑ‚ может
переопределить их Ñ Ñ†ÐµÐ»ÑŒÑŽ оптимизации быÑтродейÑтвиÑ
программы.
=======
Ðèñîâàíèå çàïîëíåííîãî ýëëèïñà ñ èñïîëüçîâàíèåì
ìåòîäà Âó äëÿ àíòèàëèàñèíãà.
 ïðîöåññå çàïîëíåíèÿ èñïîëüçóþòñÿ ôóíêöèè SetVLine
è SetHLine, ðèñóþùèå ïðÿìûå. Ïðîãðàììèñò ìîæåò
ïåðåîïðåäåëèòü èõ ñ öåëüþ îïòèìèçàöèè áûñòðîäåéñòâèÿ
ïðîãðàììû.
>>>>>>> 58e3d87... Added Wu's antialiasing algorithms for circle, ellipsis, line
*************************************************************************/
void drawwufilledellipse(double x1, double y1, double x2, double y2)
{
double t;
double a;
double b;
double cx;
double cy;
double x;
double y;
double f;
int ix;
int iy;
int i1;
int i2;
bool exch;
if( x2<x1 )
{
t = x1;
x1 = x2;
x2 = t;
}
if( y2<y1 )
{
t = y1;
y1 = y2;
y2 = t;
}
if( x2-x1<y2-y1 )
{
exch = false;
}
else
{
exch = true;
t = x1;
x1 = y1;
y1 = t;
t = x2;
x2 = y2;
y2 = t;
}
a = (x2-x1)/2;
b = (y2-y1)/2;
cx = (x1+x2)/2;
cy = (y1+y2)/2;
t = a*a/sqrt(a*a+b*b);
i1 = ap::ifloor(cx-t);
i2 = ap::iceil(cx+t);
for(ix = i1; ix <= i2; ix++)
{
if( 1-ap::sqr((ix-cx)/a)<0 )
{
continue;
}
y = b*sqrt(1-ap::sqr((ix-cx)/a));
iy = ap::iceil(cy+y);
f = iy-cy-y;
if( !exch )
{
setpixel(ix, iy, 1-f);
}
else
{
setpixel(iy, ix, 1-f);
}
iy = ap::ifloor(cy-y);
f = cy-y-iy;
if( !exch )
{
setpixel(ix, iy, 1-f);
}
else
{
setpixel(iy, ix, 1-f);
}
}
t = b*b/sqrt(a*a+b*b);
i1 = ap::iceil(cy-t);
i2 = ap::ifloor(cy+t);
for(iy = i1; iy <= i2; iy++)
{
if( 1-ap::sqr((iy-cy)/b)<0 )
{
continue;
}
x = a*sqrt(1-ap::sqr((iy-cy)/b));
ix = ap::ifloor(cx-x);
f = cx-x-ix;
if( !exch )
{
setpixel(ix, iy, 1-f);
}
else
{
setpixel(iy, ix, 1-f);
}
ix = ap::iceil(cx+x);
f = ix-cx-x;
if( !exch )
{
setpixel(ix, iy, 1-f);
}
else
{
setpixel(iy, ix, 1-f);
}
}
i1 = ap::iceil(cx-a);
i2 = ap::ifloor(cx+a);
for(ix = i1; ix <= i2; ix++)
{
if( 1-ap::sqr((ix-cx)/a)<0 )
{
continue;
}
y = b*sqrt(1-ap::sqr((ix-cx)/a));
if( !exch )
{
setvline(ix, ap::iceil(cy-y), ap::ifloor(cy+y));
}
else
{
sethline(ap::iceil(cy-y), ap::ifloor(cy+y), ix);
}
}
}
/*************************************************************************
<<<<<<< HEAD
процедура риÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð³Ð¾Ñ€Ð¸Ð·Ð¾Ð½Ñ‚Ð°Ð»ÑŒÐ½Ð¾Ð¹ линии.
может быть переопределена Ð´Ð»Ñ Ð¾Ð¿Ñ‚Ð¸Ð¼Ð¸Ð·Ð°Ñ†Ð¸Ð¸ по ÑкороÑти
=======
ïðîöåäóðà ðèñîâàíèÿ ãîðèçîíòàëüíîé ëèíèè.
ìîæåò áûòü ïåðåîïðåäåëåíà äëÿ îïòèìèçàöèè ïî ñêîðîñòè
>>>>>>> 58e3d87... Added Wu's antialiasing algorithms for circle, ellipsis, line
*************************************************************************/
void sethline(int x1, int x2, int y)
{
int i;
for(i = x1; i <= x2; i++)
{
setpixel(i, y, double(1));
}
}
/*************************************************************************
<<<<<<< HEAD
процедура риÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð²ÐµÑ€Ñ‚Ð¸ÐºÐ°Ð»ÑŒÐ½Ð¾Ð¹ линии.
может быть переопределена Ð´Ð»Ñ Ð¾Ð¿Ñ‚Ð¸Ð¼Ð¸Ð·Ð°Ñ†Ð¸Ð¸ по ÑкороÑти
=======
ïðîöåäóðà ðèñîâàíèÿ âåðòèêàëüíîé ëèíèè.
ìîæåò áûòü ïåðåîïðåäåëåíà äëÿ îïòèìèçàöèè ïî ñêîðîñòè
>>>>>>> 58e3d87... Added Wu's antialiasing algorithms for circle, ellipsis, line
*************************************************************************/
void setvline(int x, int y1, int y2)
{
int i;
for(i = y1; i <= y2; i++)
{
setpixel(x, i, double(1));
}
}