#include #include #include #include #include //////////////////////////////////////////////////////////////functions///////////////////////////////////////////////// void swap(float &m,float &n) { float temp=n; n=m; m=temp; } int sign(float a,float b)//sign() { int t; if(a>b) { t=1;} else if(adx) { swap(dx,dy); Flag=1; } else Flag=0; float Nerror=2*dy-dx; for(int i=1;i=0) { if(Flag) { x=x+sx;} else y=y+sy; Nerror=Nerror-2*dx; } if(Flag) { y=y+sy;} else x=x+sx; Nerror=Nerror+2*dy; } } ///////////////////////////////////四连通种子填充/////////////////////////////////////////////////// void BoundaryFill4(HDC hdc,int x,int y,int FilledColor,int BoundaryColor) { int CurrentColor; CurrentColor=GetPixel(hdc,x,y); if(CurrentColor!=BoundaryColor&&CurrentColor!=FilledColor) { SetPixel(hdc,x,y,FilledColor); BoundaryFill4(hdc,x+1,y,FilledColor,BoundaryColor); BoundaryFill4(hdc,x-1,y,FilledColor,BoundaryColor); BoundaryFill4(hdc,x,y+1,FilledColor,BoundaryColor); BoundaryFill4(hdc,x,y-1,FilledColor,BoundaryColor); } } ////////////////////////////////////////扫描线填充/////////////////////////////////////////////////// //DrawLine()函数:在(x1,y)和(x2,y)两点之间画一条颜色为FilledColor的横线(用来扫描填充) void drawline(HDC hdc, int x1, int x2,int y0, int FilledColor) { for(int n=x1+1;n扫描线函数,将扫描线与图形的交点坐标存在数组中 //数组中同行的点即为该行扫描线与图形的交点(一般为2个) //数组中的行代表扫描线的纵坐标 void scan(HDC hdc, int boundarycolor) { int currentcolor; int a[300][2]={0}; for (int j=0;j<300;j++) { for(int i=300;i<700;i++) { currentcolor=GetPixel(hdc,i,j); if((currentcolor==boundarycolor)&&(GetPixel(hdc,i+1,j)!=boundarycolor)&&(i<500)) {a[j][0]=i;} if((currentcolor==boundarycolor)&&(GetPixel(hdc,i-1,j)!=boundarycolor)&&(i>500)) {a[j][1]=i;} } } //利用循环调用DrawLine函数逐行填充两交点之间的点 for(int k=0;k<300;k++) { if((a[k][0]!=0)&&(a[k][1]!=0)) drawline(hdc,a[k][0],a[k][1],k,RGB(255,0,0));} } ///////////////////////////////////////////////边界填充////////////////////////////////////// //Contrary()取反函数:如果点的颜色为白,则将点置为填充色;如果点的颜色为填充色,则将点置为白色 //忽略了边界色,即不对边界点作颜色处理 void contrary(HDC hdc, int x, int y,int FilledColor) { for(int h=x;h<280;h++) { if(GetPixel(hdc,h,y)==RGB(255,255,255)) { SetPixel(hdc,h,y,FilledColor); } else if(GetPixel(hdc,h,y)==FilledColor) { SetPixel(hdc,h,y,RGB(255,255,255)); } } } //borderline()边线函数: 先找出图形的边界 左边和右边,从右到左的顺序调用contrary()函数进行填充 void borderline(HDC hdc, int boundarycolor) { for(int j=280;j<499;j++) { for(int i=80;i<280;i++) { int currentcolor=GetPixel(hdc,i,j); //排除了边界水平的情况,即(x-1,y)、(x,y)和(x+1,y)连续三点都是边界点的点不参与填充 if((currentcolor==boundarycolor)&&(GetPixel(hdc,i+1,j)!=boundarycolor)&&(GetPixel(hdc,i-1,j)!=boundarycolor)&&(i>100)) { contrary(hdc,i,j,RGB(0,0,255)); } } } for(int m=280;m<499;m++) { for(int n=80;n<280;n++) { int currentcolor=GetPixel(hdc,n,m); if((currentcolor==boundarycolor)&&(GetPixel(hdc,n+1,m)!=boundarycolor)&&(GetPixel(hdc,n-1,m)!=boundarycolor)&&(n<101)) { contrary(hdc,n,m,RGB(0,0,255)); } } } }
1
用C语言实现的扫描线填充算法,可快速填充任意多边形
2022-05-05 21:30:08 3KB 扫描线填充算法
1
图形学六个实验作业程序及实验报告 纯js实现 直线裁剪 扫描线算法 B样条 bezier phong 光线跟踪
2022-04-19 23:13:12 337KB 扫描线 B样条 bezier phone
1
题目:用种子填充算法(或扫描线填充算法)填充任一多边形域 基本要求: (1)数据输入项为:多边形的顶点数、各顶点x,y坐标。 对于种子填充算法要输入种子象素的x,y坐标。 对于扫描线填充算法要输入扫描线间距。 (2)填充区域输出在PictureBox控件中。 附加要求: (1)填充区中可内嵌多个多边形。 (2)对于扫描线填充算法使用一定距离的字符填充。
2022-04-04 18:06:02 12.16MB 种子填充 扫描线填充
1
本实验的目的在于使用VC++6.0为背景,实现扫描线多边形填充的功能,基于前面实验的坐标,运用结构体实现任意给定多边形的扫描线多边形填充算法
2022-03-28 18:11:32 1.85MB 扫描线
1
vs2008下 opengl实现,多边形扫描线填充算法。 用到glut库 鼠标左右键实现选点和填充
2022-03-17 22:29:36 878KB 计算机图形学 扫描线 填充 算法
1
扫描线Zbuffer算法的实现,读取obj模型文件,实现绘制。 软件加速: 1。算出模型的包围盒。 2.每条扫描线打点时并不是包围盒内整条线打点,而是先搜索需要刷新的范围, 只是该范围内打点。
2022-01-11 22:06:09 73KB Zbuffer
1
扫描线Z-buffer算法() { 建多边形y表;对每一个多边形根据顶点最小的y值,将多边形置入多边形y表。 活化多边形表APT,活化边表AET初始化为空。 For(每条扫描线i,i从小到大) { 1. 帧缓存CB置为背景色。 2. 深度缓存ZB (一维数组) 置为无穷大。 3. 将对应扫描线i的,多边形y表中的多边形加入到活化多边形表APT中。 4. 对新加入的多边形,生成其相应的边Y表。 5. 对APT中每一个多边形,若其边Y表中对应扫描线I增加了新的边,
2022-01-11 22:04:24 11.17MB 计算机
1
Delaunay三角形构网的分治扫描线算法借鉴.pdf
2022-01-07 14:17:19 273KB 网络文档
fortune算法 扫描线算法生成voronoi图
2022-01-05 16:26:52 28KB voronoi图
1