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 “outc[r]
Trang 1(c) SE/FIT/HUT 2002 1
B ài 3:
Các giải thuật cơ sở
Le Tan Hung hunglt@it-hut.edu.vn 0913030731
Trang 2Nộ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
Trang 3(c) SE/FIT/HUT 2002 3
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
Việc loại từng điểm ảnh của đối tượng
thường chậm nhất là khi đối tượng mà
phần lớn nằm ngoài cửa sổ hiển thị.
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ụ
Định nghĩa Clipping điểm
xmin ≤ x ≤ xmax
ymin ≤ y ≤ ymax
Trang 4Clipping đ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
Trang 5(c) SE/FIT/HUT 2002 5
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
Trang 7(c) SE/FIT/HUT 2002 7
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
Trang 8
=
−
=
=
−
=
Dy P
Dy P
Dx P
Dx P
4 3 2 1
−
=
−
=
−
=
−
=
1 4
1 3
1 2
1 1
y y
q
y y
q
x x
q
x x
q
M
m M
m
Trang 9(c) SE/FIT/HUT 2002 9
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.
Trang 10 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