《精》计算机图形学--区域填充算法的实现.docVIP

  • 6
  • 0
  • 约5.26千字
  • 约 7页
  • 2017-01-16 发布于北京
  • 举报

《精》计算机图形学--区域填充算法的实现.doc

实验 一、实验目的和要求: 1、理解区域的表示和类型,能正确区分四连通和八连通的区域 2、了解区域填充的实现原理 3、利用TurboC实现区域填充的递归算法 二、实验内容: 当给定种子点(x,y)时,首先填充种子点所在的扫描线上的位于给定区域的 一个区段,然后确定与这一区段连通的上下两条扫描线上位于给定区域的区段 依次保存下来。反复这个过程,直到填充结束. 、#include Conio.h #include graphics.h?? /*for initgr()*/ #include stdio.h????? /*for NULL??? */ #define closegr closegraph void initgr(void) /* BGI初始化 */ { int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */ registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */ initgraph(gd, gm, ); } enum BOOL{FALSE = 0, TRUE = 1}; typedef struct{ ??? int y; ??? int xLeft; ??? int xRight; }Span;/*区段*/ typedef struct stacknode { Span span; struct stacknode *next; }stacknode; typedef struct { stacknode *top; }linkstack; /*-----------------进栈操作----------------------------------------*/ void PushStack(linkstack *s, Span *span) { stacknode *p=(stacknode*)malloc(sizeof(stacknode)); p-span.y = span-y; p-span.xLeft = span-xLeft; p-span.xRight = span-xRight; p-next=s-top; s-top=p; } /*-----------------出栈操作------------------------------------------*/ void PopStack(linkstack *s,Span *span) { int x; stacknode *p=s-top; span-y = p-span.y; span-xLeft = p-span.xLeft; span-xRight = p-span.xRight; s-top=p-next; free(p); } /*-----------------将栈清空------------------------------------------*/ void SetStackEmpty(linkstack *s) { ??? stacknode *p=s-top; ??? while( s-top != NULL) ??? { ??????? free(p); ??????? s-top=p-next; ??? } } /*--------------判断栈是否为空----------------------------------------*/ int IsStackEmpty(linkstack *s) { ??? if(s-top == NULL) ??????? return 1; ??? else ??????? return 0; } /*----------------核心程序开始----------------------------------------*/ void ScanLineFill4(int x,int y,int oldColor,int newColor) { ??? int xLeft,xRight; ??? int i; ??? enum BOOL isLeftEndSet, spanNeedFill; ??? Span span; ??? linkstack *s=(linkstack*)malloc(sizeof(linkstack)); ??? s-top = NULL; ??? /*填充并确定种子点(x,y)所在的区段*/ ??? i = x; ??? while(getpixel(i,y) == oldColor)/*向右填充*/ ??? { ??????? putpixel(i,y,

文档评论(0)

1亿VIP精品文档

相关文档