边标志填充算法程序(国外英文资料).docVIP

  • 3
  • 0
  • 约9千字
  • 约 26页
  • 2017-07-05 发布于河南
  • 举报

边标志填充算法程序(国外英文资料).doc

边标志填充算法程序(国外英文资料)

边标志填充算法程序 边标志填充算法程序 EdgeMarkFill(int p [ ] [ 2 ],int n,int boundarycolor,int纽卡) { int i,x,y,国旗,xmin,Xmax,Ymin,YMAX; 设置颜色(boundarycolor);/ * * /设置画笔色 为(i = 0;i ;;+(+)) 线(P [我]的[ 0 ],P [我]的[ 1 ],P [(i + 1)% ] [ 0 ],P [(i + 1)% ])[ 1 ]);/*画出多边形的N条边*/ 用求极值的算法,从多边形顶点数组P中,求出xmin,Xmax,Ymin,YMAX; 为(y = Ymin;Y = YMAX;Y + +) { 标志= 1; 对(X = Xmin;x = Xmax;X + +) { 如果(GetPixel(x,y)= = boundarycolor) 标志=标志; 如果(标志= 1) putpixel(x,y,纽卡); } } } int = i 0,j,k; int,e; 浮点数; 为(i = 0;i 民;i++){ //对各条边进行处理 我的[我]; e =我的[(i + 1)%数字]; d =浮点数(我[ MX(i + 1)% ])/(我的[我] -我的[ [(i + 1)% ]); 浮点(MX); 如果(b = e){ J = B; b = e; e = j; 浮点(MX [(i + 1)% ]; } 为(J = B;J<E;j++){ //处理一条边上各个点 /如果 //; / } // { / / K = int(float((j-my [我])*(我的[(i + 1)%民]我的[我]))/浮(MX [(i + 1)%民] - MX [我])+浮动(MX [我])+ 0.5f); / } K = int(FD +(新山)* D + 0.5f); 用于((k<518;k ++){) 如果(PIC。GetPixel(k,j)= = COL){ 的照片。SetPixel(K,J,RGB(255255255)); } 别的{ 的照片。SetPixel(K,J,COL); } } } } 作废(假); } 此程序是对科恩萨瑟兰编码裁剪算法的演示。在图形学中,图形裁剪是其一项重要的内容裁剪的目的就是把落在用户定义的窗口外的部分图形裁剪掉,从而为图像识别和图像处理提供清晰的对象。 图形裁剪的关键技术是对直线段和平面多边形的裁剪,因为任何图形都可以用多面体逼近,每一个面可视为一个多边形,而多边形的裁剪归结于直线的裁剪。因此直线段的裁剪算法的优劣对图形的裁剪速度的影响较大。科恩萨瑟兰编码裁剪算法的优点在于用区域检查的办法有效地识别可直接接受或直接舍弃的线段,只有不属于这两种情况的线段才算线段与窗口边线的交点,并作相应的取舍处理。 科恩萨瑟兰算法是将一平面区域分成九个子区域,每个子区域给一个4位二进制编码,如图所示,其意义是:XL,XR,Yb,YT为窗口的四边界线。规定YT上方的第1位为1,YB下方的第2位为1,XL左边的第4位为1,XR右边的第3位为1,其余为0, Obviously, when the encoding of both ends of the line segment is 0, the line segments are all in the window and are accepted directly. If the 4 bit code on both ends of the line carries out bit operations logic and the result is not 0, then the segment is all out of the window and is discarded. Otherwise, we can find the intersection of the line segment and the boundary line of the window, and also make the four bit encoding of the intersection point, and check or accept the segment of the line separately, or discard, or re segment. Repeat this process until completion of [2]. As shown in the figure, line AB, only accept the CD segment, and the rest are abandoned. Figure 2-1 Firs

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档