Bài giảng đồ họa và hiện thực ảo bài 3 các giải thuật cơ sở

7 80 0
Bài giảng đồ họa và hiện thực ảo   bài 3  các giải thuật cơ sở

Đang tải... (xem toàn văn)

Thông tin tài liệu

Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Nội dung Các giải thuật sở Bài Các giải thuật xén tỉa - Clipping z Các thuật tốn tơ miền kín z Phép xử lý Antialiasing z Le Tan Hung hunglt@it-hut.edu.vn 0913030731 Xén tỉa - Clipping Clipping đoạn thẳng Khái niệm Xén tỉa tiến trình tự động xác định điểm đối tượng nằm hay cửa sổ hiển thị Tiết kiệm thời gian tiến trình rasterize bỏ qua phần nằm ngồi cửa sổ hiển thị ymax Clipping điểm xmin ≤ x ≤ xmax ymin ≤ y ≤ ymax z Tiến trình, giải thuật kiểm tra chấp nhận đoạn thẳng nằm loại bỏ đoạn thẳng nằm dựa điểm đầu cuối Lý do: Không kiểm tra điểm đoạn thẳng Hầu hết đoạn thẳng với hình hiển thị chấp nhận loại bỏ Rất đợn thẳng cắt cửa sổ hiển thị Giải thuật Cohen-Sutherland thực nhanh với trương hợp đoạn thẳng nằm hay cửa sổ thị z If P1.code OR P2.code == 0000 z If P1.code AND P2.code != 0000 z Mỗi điểm đầu cuối gán mã code phụ thuộc vào vị trí mặt phẳng mã z z p.code = 0000 If p.x > P.code or 0001 If p.y > P.code or 0100 If p.x >= xmax >> P.code or 0010 If p.y >= ymax >> P.code or 1000 z z z z xmin z xmax z z ymin Giải thuật Cohen Sutherland Outcode z z z z z – Chấp nhận toàn đoạn thẳng – Loại Với truờng hợp cắt, giải thuật xác định lại điểm đầu cuối giao đoạn thẳng khung bao cửa sổ hiển thị Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Liabarsky z x = x1 + (x2 - x1)u = x1 + uDx y = y1 + (y2 - y1)u = y1 + uDy xmin ≤ x1 + Dx.u ≤ xmax ⇔ x ∈ [xm, xM] ymin ≤ y1 + Dy.u ≤ ymax ⇔ y ∈ [ym, yM] z Pk u ≤ qk z z z z k = 1, 2, 3, ⎧q1 = x1 − xm ⎪q = x − x ⎪ M ⎨ ⎪q3 = y1 − ym ⎪⎩q4 = y M − y1 z ⎧ ⎪ ⎪ ⎨ ⎪ ⎪⎩ P1 = − Dx z P = Dx Nếu Pk = : điều tương đương với việc đoạn thẳng xét song song với cạnh thứ k hình chữ nhật clipping a) Nếu qk < ⇒ Đường thẳng nằm cửa sổ (hệ bất phương trình vơ nghiệm) b)Nếu qk >= đoạn thẳng nằm nằm cạnh cửa sổ clipping Hệ bất phương trình ln thoả mãn P = − Dy P = Dy z z Nếu Pk ≠ : đoạn thẳng xét cắt cạnh k tương ứng cửa sổ clipping vị trí đoạn thẳng uk = qk/Pk – Pk < đoạn thẳng có dạng từ ngồi vào z bất phương trình có dạng u ≥ qk/Pk Ù u ≥ uk – Pk > z u ≥ uk thuộc cửa sổ hiển thị z bất phương trình có dạng u ≤ qk/Pk z u ≤ uk với uk = qk/Pk giao đoạn thẳng với cạnh k cửa sổ clipping z đoạn thẳng có dạng từ so với cạnh k z Pk < uk < – – – cạnh k cửa sổ clipping cắt đoạn thẳng phần mở rộng nằm đoạn thẳng uk ≤ u< thoả mãn bất phương trình khơng nằm đoạn thẳng cần xét => uk nhận uk uk > z điểm nằm cửa sổ clipping có dạng sau: – – => uk tương ứng nhận giá trị U ≤ u ≤ U2 10 Sutherland-Hodgman Clipping z – ⎛ ⎧ ⎫⎞ q U = min⎜ {1}∪ ⎨u k : u k = k , Pk > ⎬ ⎟ ⎜ ⎟ Pk ⎩ ⎭⎠ ⎝ ⎛ ⎧ ⎫⎞ q U = max ⎜ {0}∪ ⎨u k : u k = k , Pk < ⎬ ⎟ ⎜ ⎟ Pk ⎩ ⎭⎠ ⎝ 11 Basic idea: – – Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all planes, the polygon is fully clipped 12 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Sutherland-Hodgman Clipping z Input/output for algorithm: – – z Sutherland-Hodgman Clipping z Input: list of polygon vertices in order Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) Sutherland-Hodgman basic routine: – – – Note: this is exactly what we expect from the clipping operation against each edge 13 Go around polygon one vertex at a time Current vertex has position p Previous vertex had position s, and it has been added to the output if appropriate 14 Sutherland-Hodgman Clipping z Sutherland-Hodgman Clipping Edge from s to p takes one of four cases: z (Purple line can be a line or a plane) inside outside inside outside inside Four cases: – outside p s inside p s inside plane and p inside plane z outside z s – s inside plane and p outside plane z z p s p output i output no output – s outside plane and p inside plane z i output p output z Add nothing Find intersection point i Add i to output, followed by p 16 Giải thuật Cyrus-Beck Liang Barsky z z z z 17 s outside plane and p outside plane z 15 Find intersection point i Add i to output – s p Add p to output Note: s has already been added 3-D Clipping Giải Cohen-Sutherland yêu cầu cửa sổ hình chữ nhật, cạnh cạnh hình Vấn đề nảy sinh cửa sổ clip đa giác hình chữ nhật quay góc Giải thuật Liang-Barsky tối ưu tìm giao điểm đoạn thẳng với cử sổ hiển thị Nicholl-Lee-Nicholl reducing redundant boundary clipping by identifying edge and corner regions z z Before actually drawing on the screen, we have to clip (Why?) Can we transform to screen coordinates first, then clip in 2D? – Correctness: shouldn’t draw objects behind viewer (what will an object with negative z coordinates in our perspective matrix?) (draw it…) 18 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Giải thuật đường biên (Boundary - File Algorithm) Edge Walking z z 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 chạm biên chạm phần tô Else Putcolor(x,y, mauto) 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 lại giải thuật với điểm lân cận End 19 – – – – Draw edges vertically Fill in horizontal spans for each scanline Interpolate colors down edges At each scanline, interpolate edge colors across span 20 Edge Walking: Notes z z – z z Fractional offsets: z Be careful when interpolating color values! Also: beware gaps between adjacent edges cases: break left, break right, no break Walk down left and right edges – z Edge Walking: Notes Order vertices in x and y – Fill each span Until breakpoint or bottom vertex is reached Advantage: can be made very fast Disadvantages: – – – Lots of finicky special cases Tough to get right Need to pay attention to fractional offsets z 21 22 Giải thuật đường quét Scan-Line Algorithm z The scan-line algorithm uses edge-coherence and incremental integer calculations for maximum efficiency: – – z z z 23 Basic idea: Edge Table (ET) (0,0) Tạo bảng edge table (ET) tập cạnh đa giác theo thứ tự giá trị ymin chúng Tạo bảng active edge table (AET) tập cạnh giao vớI đoạn thẳng quét scan-line Trong tiến trình quét cạnh chuyển từ ET AET Các cạnh AET giá trị ymax cạnh đạt tới = scanline Lúc cạnh bị loại khỏi AET ymax xmin numerator −3 ⇒ = denominator m (15,15) scan-line Note: line (8,6) → (13,6) has been deleted according to the scan rules 24 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Active Edge Table (AET) Giải thuật dòng quét-Scanline cho việc tô mầu vùng round down round down round up round up AET = AET = 25 yma current x denominator current numerator ymax 26 current numerator current x denominator x Scan-Line Algorithm Rasterizing Triangles z y = y of first non empty entry in ET AET = null repeat move all ET entries in slot y to AET sort AET entries according to xmin fill spans using pairs of AET entries for all AET members if ymax = y then remove from AET y = y+1 for all AET members update numerator if numerator>denominator numerator=numerator-denominator x = x+1 until AET and ET empty 27 z Interactive graphics hardware commonly uses edge walking or edge equation techniques for rasterizing triangles Two techniques we won’t talk about much: – – Recursive subdivision of primitive into micropolygons (REYES, Renderman) Recursive subdivision of screen (Warnock) 28 Recursive Triangle Subdivision Edge Equations z An edge equation is simply the equation of the line containing that edge – – – – Q: What is the equation of a 2D line? A: Ax + By + C = Q: Given a point (x,y), what does plugging x & y into this equation tell us? A: Whether the point is: z z z 29 On the line: Ax + By + C = “Above” the line: Ax + By + C > “Below” the line: Ax + By + C < 30 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Edge Equations z Edge equations thus define two half-spaces: And a triangle can be defined as the intersection of three positive half-spaces: Ax + By Ax + + C By 0 z Edge Equations z - + ++- Ax + By Ax + + C By 0 C >0 B y+ A 1x + C 0: Signal Processing Aliasing: signal processing term with very specific meaning Aliasing: computer graphics term for any unwanted visual artifact Antialiasing: computer graphics term for avoiding unwanted artifacts z z Raster display: regular sampling of a continuous function (Really?) Think about sampling a 1-D function: 36 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 0913030731 Signal Processing z Signal Processing Sampling a 1-D function: 37 z Sampling a 1-D function: 38 Signal Processing z Signal Processing Sampling a 1-D function: – z What you notice? 39 Sampling a 1-D function: what you notice? – Jagged, not smooth 40 Signal Processing z Antialiasing Sampling a 1-D function: what you notice? – – z Jagged, not smooth Loses information! Méo thông tin trình lấy mẫu tần số thấp sampling frequency z z 41 In raster images – leads to jagged edges with hiệu ứng bậc thang – staircase effect Việc làm giảm hiệu ứng méo thông tin phương pháp bù trừ 42 ... Putcolor(x,y, mauto) 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 lại giải thuật với điểm lân... 18 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 09 130 30 731 Giải thuật đường biên (Boundary - File Algorithm) Edge Walking z z Giải_ thuật_ đường_biên ( x, y ) Color : biến mầu Begin Color =... a 1-D function: 36 Khoa CNTT-DDHBK Hà nội Email: hunglt@it-hut.edu.vn 09 130 30 731 Signal Processing z Signal Processing Sampling a 1-D function: 37 z Sampling a 1-D function: 38 Signal Processing

Ngày đăng: 19/06/2019, 10:10

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan