资源描述:
《图形学多边形区域填充》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验二:多边形的区域填充一、实验目的与要求1.通过实验,进一步理解和掌握几种常用多边形填充算法的基本原理2.掌握多边形区域填充算法的基本过程3.掌握在C/C++环境下用多边形填充算法编程实现指定多边形的填充。二、实验内容#include#include#include"stdio.h"#includetypedeffloatColor[3];rgbColorEqual(Colorc1,Colorc2){if(abs(c1[1]-c2[1])<0.001&&abs(c1[2]-c
2、2[2])<0.001&&abs(c1[0]-c2[0])<0.001)returntrue;elsereturnfalse;}voidsetPixel(GLintx,GLinty){glBegin(GL_POINTS);glVertex2i(x,y);glEnd();}voidgetPixel(GLintx,GLinty,Colorc){glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,c);}voidBoundaryFill(intx,inty,ColorfillColor,ColorborderCol
3、or){ColorcurrentColor;getPixel(x,y,currentColor);if((!rgbColorEqual(currentColor,fillColor))&&(!rgbColorEqual(currentColor,borderColor))){//setColor(fillColor);GLintx1;GLintx2;setPixel(x,y);getPixel(x,y+1,currentColor);if((!rgbColorEqual(currentColor,fillColor))&&(!rg
4、bColorEqual(currentColor,borderColor))){getPixel(x+1,y+1,currentColor);if(rgbColorEqual(currentColor,borderColor)){BoundaryFill(x,(y+1),fillColor,borderColor);}}getPixel(x,y-1,currentColor);if((!rgbColorEqual(currentColor,fillColor))&&(!rgbColorEqual(currentColor,bord
5、erColor))){getPixel(x+1,y-1,currentColor);if(rgbColorEqual(currentColor,borderColor)){BoundaryFill(x,y-1,fillColor,borderColor);}}x1=x+1;getPixel(x1,y+1,currentColor);if((!rgbColorEqual(currentColor,fillColor))&&(!rgbColorEqual(currentColor,borderColor)))//x的上面那个点是内点,
6、且未被填充{getPixel(x1+1,y+1,currentColor);if(rgbColorEqual(currentColor,borderColor))//x的上面那个点的右边是边界点,那么说明这个点是需要填充的最右边的点{BoundaryFill(x1,y+1,fillColor,borderColor);//对这个最右边的点调用函数,进行扫描线种子填充(下面的同上)}}getPixel(x1,y-1,currentColor);if((!rgbColorEqual(currentColor,fillColor))&&
7、(!rgbColorEqual(currentColor,borderColor))){getPixel(x1+1,y-1,currentColor);if(rgbColorEqual(currentColor,borderColor)){BoundaryFill(x1,y-1,fillColor,borderColor);}}getPixel(x1,y,currentColor);while((!rgbColorEqual(currentColor,fillColor))&&(!rgbColorEqual(currentColo
8、r,borderColor))){setPixel(x1,y);x1++;getPixel(x1,y+1,currentColor);if((!rgbColorEqual(currentColor,fillColor))&&(!rgbColorEq