Xem mẫu
- Bài 3:
Các giải thuật cơ sở
Le Tan Hung
hunglt@it-hut.edu.vn
0913030731
(c) SE/FIT/HUT 2002 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Nội dung
Các giải thuật xén tỉa - Clipping
Các thuật toán tô miền kín
Phép tô mầu
Phép xử lý Antialiasing
(c) SE/FIT/HUT 2002 2
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Xén tỉa - Clipping
Nhiệm vụ cơ bản trong đồ họa là giữ các
phần của đối tượng lựa chọn nằm bên
ngoài đồ hoạ.
Xén tỉa là việc di chuyển tất cả các đối
tượng hoặc các phần của đối tượng thuộc
mô hình ngữ cảnh ra bên ngoài của sổ thế
giới thực Định nghĩa
Việc loại từng điểm ảnh của đối tượng Clipping điểm
thường chậm nhất là khi đối tượng mà xmin ≤ x ≤ xmax
phần lớn nằm ngoài cửa sổ hiển thị.
ymin ≤ y ≤ ymax
Kỹ thuật thực hành là cần thiết để nâng
cao tốc độ trong thực hiện nhiệm vụ
(c) SE/FIT/HUT 2002 3
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Clipping đoạn thẳng
Lines are defined by their endpoints, so it should be
possible just to examine these (in a similar way to points) and
determine whether or not to clip without considering every
pixel on the line
We often have windows that are either very large, i.e. nearly
the whole scene fits inside, or very small, i.e. most of the
scene lies inside the window
Hence, most lines may be either trivially accepted or rejected
(c) SE/FIT/HUT 2002 4
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Giải thuật Cohen Sutherland
Outcode
The Cohen-Sutherland line-clipping algorithm is particularly
fast for “trivial” cases, i.e. lines completely inside or outside
the window.
Non-trivial lines, i.e. ones that cross a boundary of the
window, are clipped by computing the coordinates of the new
boundary endpoint of the line where it crosses the edge of the
window
Each point on all lines are first assigned an “outcode”
defining their position relative to the clipping rectangle
(c) SE/FIT/HUT 2002 5
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- (c) SE/FIT/HUT 2002 6
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Giải thuật Cyrus-Beck
Lyang Barsky
The Cohen-Sutherland algorithm requires the window
to be a rectangle, with edges aligned with the co-
ordinate axes
It is sometimes necessary to clip to any convex
polygonal window, e.g. triangular, hexagonal, or
rotated.
The, and Liang-Barsky line clippers better optimise the
intersection calculations for clipping to window
boundary
Nicholl-Lee-Nicholl reducing redundant boundary
clipping by identifying edge and corner regions
(c) SE/FIT/HUT 2002 7
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- P1 = − Dx
q1 = x1 − xm
q = x − x P 2 = Dx
2 M 1
P 3 = − Dy
q3 = y1 − ym
q4 = y M − y1 P 4 = Dy
(c) SE/FIT/HUT 2002 8
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Nếu Pk = 0 : điều đó tương đương với việc
đoạn thẳng đang xét song song với cạnh
thứ k của hình chữ nhật clipping.
a) Nếu qk < 0 ⇒ vô nghiệm)
b)Nếu qk >= 0 thì bất phương trình luôn
thoả mãn.
(c) SE/FIT/HUT 2002 9
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Nếu Pk ≠ 0 :
uk = qk/Pk.
Pk < 0
• u ≥ qk/Pk Ù u ≥ uk.
Pk > 0
• u ≥ uk u ≤ qk/Pk
• u ≤ uk với uk = qk/Pk
• đoạn thẳng có dạng đi từ trong ra ngoài so với
cạnh k.
(c) SE/FIT/HUT 2002 10
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Pk < 0 và uk < 0
uk ≤ u< 0 thoả mãn bất phương trình sẽ không nằm
trên đoạn thẳng cần xét.
=> uk sẽ nhận là 0 khi uk 0 và uk > 1
=> uk tương ứng sẽ nhận giá trị 1.
điểm nằm trong cửa sổ clipping sẽ có dạng như
sau:
U1 ≤ u ≤ U2
(c) SE/FIT/HUT 2002 11
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- qk
U 2 = min {1}∪ u k : u k = , Pk > 0
P
k
qk
U 1 = max {0}∪ u k : u k = , Pk < 0
P
k
(c) SE/FIT/HUT 2002 12
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Nicholl-Lee-Nicholl clipping
Some edges are irrelevant to
clipping, particularly if one vertex a
lies inside region.
Cases:
x1 in
x1 in corner region a
x1 in edge region
For each case, we generate
specialized test regions for x2, which a
use simple tests (slope, >,
- Nicholl-Lee-Nicholl (2)
Special cases for each endpoint location and slope
Number of cases explodes in 3D, making it
unsuitable 1 2
Reject
3
Top
Left Top, Right
4
Left, bottom
Top, Bottom
(c) SE/FIT/HUT 2002 14
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Giải thuật đường biên (Boundary - File
Algorithm)
Giải_thuật_đường_biên ( x, y )
Color : biến mầu
Begin
Color = Readpixel ( x, y );
If ( Color = mầu tô ) or ( Color = mầu đường biên )
Kết thúc vì chạm biên
hoặc chạm phần đã tô
Else
Giải_thuật_đường_biên ( x+1, y );
Giải_thuật_đường_biên ( x-1, y );
Giải_thuật_đường_biên ( x, y+1 );
Giải_thuật_đường_biên ( x, y-1 );
// Thực hiện lại giải thuật với các điểm lân cận
End.
(c) SE/FIT/HUT 2002 15
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Giải thuật dòng quét-Scanline cho việc tô
mầu vùng
round down
round up
AET =
yma current x denominator current numerator
(c) SE/FIT/HUT 2002 16
x
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Giải thuật tô vùng kín theo mẫu
(Pattern Filling)
Phương pháp 1
Phương pháp 2
(c) SE/FIT/HUT 2002 17
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Hiệu ứng răng cưa
Aliasing
SPATIAL ALIASING, IN PICTURES
moire patterns arise in
image warping & texture mapping
jaggies arise in rendering
TEMPORAL ALIASING, IN AUDIO
when resampling an audio signal at a lower
sampling frequency,
e.g. 50KHz (50,000 samples per second) to
10KHz
TEMPORAL ALIASING, IN
FILM/VIDEO
strobing and the “wagon wheel effect”
jaggies in foreground.
jaggies
(c) SE/FIT/HUT 2002 18
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Antialiasing
Méo thông tin trong quá trình lấy mẫu tần số thấp
sampling frequency
In raster images – leads to jagged edges with hiệu
ứng bậc thang – staircase effect
We can reduce effects by antialiasing methods to
compensate for undersampling
(c) SE/FIT/HUT 2002 19
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- When Does Spatial Aliasing
Occur?
During image synthesis:
when sampling a continuous (geometric) model to create a raster
image,
e.g. scan converting a line or polygon.
Sampling: converting a continuous signal to a discrete signal.
During image processing and image synthesis:
when resampling a picture, as in image warping or texture mapping.
Resampling: sampling a discrete signal at a different
sampling rate.
Example: “zooming” a picture from nx by ny pixels to snx by sny pixels
s>1: called upsampling or interpolation
can lead to blocky appearance if point sampling is used
s
nguon tai.lieu . vn