Các giải thuật cơ sở

5 518 1
Tài liệu đã được kiểm tra trùng lặp
Các giải thuật cơ sở

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

Thông tin tài liệu

Các giải thuật cơ sở

Khoa CNTT-DDHBK Hà nộiEmail: hunglt@it-hut.edu.vn09130307311(c) SE/FIT/HUT 20021Bài 3:Các giảithuậtcơ sởLe Tan Hunghunglt@it-hut.edu.vn0913030731(c) SE/FIT/HUT 20022Nội dung Các giảithuậtxéntỉa - ClippingCác thuậttoántômiềnkínPhép tô mầuPhép xử lý Antialiasing(c) SE/FIT/HUT 20023Xén tỉa - ClippingA fundamental task in graphics is to keep those parts of an object that lie outside a selected view from being drawnClipping is the removal of all objects or part of objects in a modelled scene that are outside the real-world window.Việcloạitừng điểm ảnh của đốitượngthường chậmnhấtlàkhiđốitượng màphầnlớnnằm ngoài cửasổ hiểnthị.More practical techniques are necessary to speed up the task Khái niệmXén tỉalàtiếntrìnhxácđịnh các điểmcủa1 đốitượng nằm trong hay ngoài cửasổ hiểnthịClipping điểmxmin ≤ x ≤ xmaxymin ≤ y ≤ ymax(c) SE/FIT/HUT 20024Clipping đoạnthẳ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 20025GiảithuậtCohen 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 20026NếumãcủaP1và P2đều = 0000 thì toàn bộđoạnthẳng thuộcphầnhiểnthị.If P1.Mã OR P2.Mã == 0000 then “ cảđoạnthẳng thuộccửasổ hiểnthị”NếumãcủaP1và P2có cùng mộtvị trí mà ởđó ≠ 0 thì P1và P2=> cùngphíaIf P1.Mã AND P2.Mã != 0000 then “ 2 điểmnằmvề 1 phía củacửasổ” Khoa CNTT-DDHBK Hà nộiEmail: hunglt@it-hut.edu.vn09130307312(c) SE/FIT/HUT 20027Giảithuật Cyrus-BeckLyang 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 20028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]Pk u ≤ qk k = 1, 2, 3, 4⎪⎪⎩⎪⎪⎨⎧=−==−=DyPDyPDxPDxP4321⎪⎪⎩⎪⎪⎨⎧−=−=−=−=14131211yyqyyqxxqxxqMmMm(c) SE/FIT/HUT 20029NếuPk= 0 : điều đótương đương vớiviệc đoạnthẳng đangxét song song vớicạnh thứ kcủahìnhchữ nhật clipping.a) Nếuqk< 0 ⇒ Đường thẳng nằm ngoài cửasổ (hệ bấtphươngtrìnhtrênvônghiệm)b)Nếuqk>= 0 thì đoạnthẳng nằm trong hoặcnằmtrêncạnhcủacửasổ clipping.Hệ bấtphương trình luôn thoả mãn.(c) SE/FIT/HUT 200210NếuPk≠ 0 : đoạnthẳng đang xét sẽ cắtcạnh k tương ứng củacửasổ clipping tạivị trí trên đoạnthẳng uk = qk/Pk. Pk < 0 đoạnthẳng dạng đitừ ngoài vào trong• bấtphương trình sẽ dạng u ≥ qk/Pk Ù u ≥ uk. Pk > 0 • u ≥ uk sẽ thuộccửasổ hiểnthị.• bấtphương trình sẽ dạng u ≤ qk/Pk• u ≤ uk vớiuk= qk/Pk là giao của đoạnthẳng vớicạnhkcủacửasổ clipping• đoạnthẳng dạng đitừ trong ra ngoài so vớicạnh k.(c) SE/FIT/HUT 200211Pk < 0 và uk < 0 cạnhkcủacửasổ clipping cắt đoạnthẳng tạiphầnmở rộng nằmngoài đoạnthẳng. uk ≤ u< 0 thoả mãn bấtphương trình sẽ không nằmtrênđoạnthẳng cầnxét. => uk sẽ nhậnlà0 khi uk<0 Pk > 0 và uk > 1=> uk tương ứng sẽ nhận giá trị 1. điểmnằm trong cửasổ clipping sẽ dạng như sau:U1≤ u ≤ U2(c) SE/FIT/HUT 200212{}⎟⎟⎠⎞⎜⎜⎝⎛⎭⎬⎫⎩⎨⎧<=∪= 0,:0max1 kkkkkPPquuU{}⎟⎟⎠⎞⎜⎜⎝⎛⎭⎬⎫⎩⎨⎧>=∪= 0,:1min2 kkkkkPPquuU Khoa CNTT-DDHBK Hà nộiEmail: hunglt@it-hut.edu.vn09130307313(c) SE/FIT/HUT 200213Nicholl-Lee-Nicholl clippingSome edges are irrelevant to clipping, particularly if one vertex lies inside region.Cases: x1inx1in corner regionx1in edge regionFor each case, we generate specialized test regions for x2, which use simple tests (slope, >, <), and tell which edges to clip against. aaa(c) SE/FIT/HUT 200214Nicholl-Lee-Nicholl (2)Special cases for each endpoint location and slopeNumber of cases explodes in 3D, making it unsuitable1234RejectTopTop, RightTop, BottomLeftLeft, bottom(c) SE/FIT/HUT 200215Giảithuật đường biên (Boundary - File Algorithm)Giải_thuật_đường_biên ( x, y )Color : biếnmầuBegin Color = Readpixel ( x, y );If ( Color = mầutô) or ( Color = mầu đường biên ) Kết thúc vì chạmbiênhoặcchạmphầ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ựchiệnlạigiảithuậtvới các điểmlâncậnEnd. (c) SE/FIT/HUT 200216Giảithuật dòng quét-Scanline cho việctômầu vùngAET =ymaxcurrent x denominator current numeratorround upround down(c) SE/FIT/HUT 200217Giảithuậttôvùngkíntheomẫu(Pattern Filling)Phương pháp 1Phương pháp 2(c) SE/FIT/HUT 200218Hiệu ứng răng cưaAliasing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 Khoa CNTT-DDHBK Hà nộiEmail: hunglt@it-hut.edu.vn09130307314(c) SE/FIT/HUT 200219When 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 pixelss>1: called upsampling or interpolationcan lead to blocky appearance if point sampling is useds<1: called downsampling or decimationcan lead to moire patterns and jaggies(c) SE/FIT/HUT 200220Phương pháp khử hiệu ứng răng cưaAntialiasing Methods1. Cốđịnh tín hiệubằng phương pháp lọc-prefiltering:Giảm độ rộng dảitầntínhiệubỏibộ lọcthấphơntrướckhilấymẫu.Highest quality method, but often impractical.2. Cốđịnh mẫubằng siêu mẫu supersampling:Use more samples to raise the Nyquist frequency.Simple and widely used.3. Cốđịnh mẫubằng phương pháp mẫubấtkỳ- stochastic sampling:Sample randomly, not uniformly.Relatively simple, usually used in combination with supersampling.(c) SE/FIT/HUT 200221AntialiasingMéo thông tin trong quá trình lấymẫutầnsố thấp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 undersamplingsampling frequency(c) SE/FIT/HUT 200222Antialiasing by supersampling(c) SE/FIT/HUT 200223(c) SE/FIT/HUT 200224anti aliasing (1) Khoa CNTT-DDHBK Hà nộiEmail: hunglt@it-hut.edu.vn09130307315(c) SE/FIT/HUT 200225Antialiasing (2) . SE/FIT/HUT 20021Bài 3 :Các giảithuậtcơ sởLe Tan Hunghunglt@it-hut.edu.vn0913030731(c) SE/FIT/HUT 20022Nội dung Các giảithuậtxéntỉa - Clipping Các thuậttoántômiềnkínPhép. 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ựchiệnlạigiảithuậtvới

Ngày đăng: 27/08/2012, 13:54

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

Tài liệu liên quan