y-x有效边表填充算法

上传人:第*** 文档编号:32819503 上传时间:2018-02-12 格式:DOC 页数:8 大小:91.50KB
返回 下载 相关 举报
y-x有效边表填充算法_第1页
第1页 / 共8页
y-x有效边表填充算法_第2页
第2页 / 共8页
y-x有效边表填充算法_第3页
第3页 / 共8页
y-x有效边表填充算法_第4页
第4页 / 共8页
y-x有效边表填充算法_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《y-x有效边表填充算法》由会员分享,可在线阅读,更多相关《y-x有效边表填充算法(8页珍藏版)》请在金锄头文库上搜索。

1、第 1 页 共 8 页 有效边表填充算法一、实验目的与要求:设计有效边表节点和边表节点数据结构二、实验描述:使用有效边算法填充示例多边形三、实验结果:四、算法设计:创建菜单栏,添加函数。在 VC+的 class view 界面,新建两个类,VET 和 Bucket。其中 AET 类用于建立有效边表和边表节点,Bucket 类用来建立桶节点。AET.h 文件。class AET public:AET();virtual AET();double x;int yMax;double k;AET *next;Bucket.h 文件第 2 页 共 8 页 #include AET.hclass Buc

2、ket public:Bucket();virtual Bucket();int ScanLine;AET *p;Bucket *next;CExp2View.h 文件。其中添加了成员变量和函数的声明,以及库的导入。#include AET.h#include Bucket.h#define Number 7添加的成员变量和函数声明如下:public:void PolygonFill();void CreatBucket();void Et();void AddEdge(AET *);void EdgeOrder();protected:COLORREF GetColor;CPoint Poi

3、nt7;Bucket *HeadB,*CurrentB;AET ENumber,*HeadE,*CurrentE,*T1,*T2;CExp2View.cpp 文件。包含构造方法、 OnDraw 方法和其他成员方法的描述#define ROUND(a) int(a+0.5)CExp2View:CExp2View()/ TODO: add construction code herePoint0 = CPoint(500,400);Point1 = CPoint(350,600);Point2 = CPoint(250,350);Point3 = CPoint(350,50);Point4 = C

4、Point(500,250);Point5 = CPoint(600,50);Point6 = CPoint(800,450);第 3 页 共 8 页 void CExp2View:OnDraw(CDC* pDC)CExp2Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data herepDC-TextOut(505,410,P0);pDC-TextOut(340,600,P1);pDC-TextOut(230,350,P2);pDC-TextOut(360,50,P3);pDC-Te

5、xtOut(490,225,P4);pDC-TextOut(610,50,P5);pDC-TextOut(800,450,P6);void CExp2View:OnMenuAET() / TODO: Add your command handler code hereAfxGetMainWnd()-SetWindowText();CColorDialog ccd(GetColor);if(ccd.DoModal() = IDOK)GetColor = ccd.GetColor();RedrawWindow();CreatBucket();Et();PolygonFill();void CExp

6、2View:CreatBucket()int ScanMin,ScanMax;ScanMax = ScanMin = Point0.y;for(int i=1;iScanMax)ScanMax = Pointi.y;for(i=ScanMin;iScanLine = ScanMin;CurrentB-p = NULL;CurrentB-next = NULL;elseCurrentB-next = new Bucket;CurrentB = CurrentB-next;CurrentB-ScanLine = i;CurrentB-p = NULL;CurrentB-next = NULL;vo

7、id CExp2View:Et()for(int i=0;iPointi.y)while(CurrentB-ScanLine != Pointi.y)CurrentB = CurrentB-next;Ei.x = Pointi.x;Ei.yMax = Pointj.y;Ei.k = double(Pointj.x-Pointi.x)/(Pointj.y-Pointi.y);Ei.next = NULL;CurrentE = CurrentB-p;if(CurrentB-p = NULL)CurrentE = CurrentB-p = CurrentE;elsewhile(CurrentE-ne

8、xt != NULL)第 5 页 共 8 页 CurrentE = CurrentE-next;CurrentE-next = if(Pointj.y ScanLine != Pointj.y)CurrentB = CurrentB-next;Ei.x = Pointj.x;Ei.yMax = Pointi.y;Ei.k = double(Pointi.x-Pointj.x)/(Pointi.y-Pointj.y);Ei.next = NULL;CurrentE = CurrentB-p;if(CurrentE = NULL)CurrentE = CurrentB-p = CurrentE;e

9、lsewhile(CurrentE-next != NULL)CurrentE = CurrentE-next;CurrentE-next = CurrentB = NULL;CurrentE = NULL;void CExp2View:AddEdge(AET *NewEdge)T1 = HeadE;if(T1 = NULL)T1 = NewEdge;HeadE = T1;第 6 页 共 8 页 elsewhile(T1-next != NULL)T1 = T1-next;T1-next = NewEdge;void CExp2View:EdgeOrder()T1 = HeadE;if(T1

10、=NULL)return;if(T1-next = NULL)return;elseif(T1-next-x x)T2 = T1-next;T1-next = T2-next;T2-next = T1;HeadE = T2;T2 = HeadE;T1 = HeadE-next;while(T1-next != NULL)if(T1-next-x x)T2-next = T1-next;T1-next = T1-next-next;T2-next-next = T1;T2 = T2-next;elseT2 = T1;T1 = T1-next;第 7 页 共 8 页 void CExp2View:

11、PolygonFill()HeadE = NULL;for(CurrentB=HeadB; CurrentB!=NULL; CurrentB=CurrentB-next)for(CurrentE=CurrentB-p; CurrentE != NULL;CurrentE = CurrentE-next)AET *TempEdge = new AET;TempEdge-x = CurrentE-x;TempEdge-yMax = CurrentE-yMax;TempEdge-k = CurrentE-k;TempEdge-next = NULL;AddEdge(TempEdge);EdgeOrd

12、er();T1 = HeadE;if(T1 = NULL)return;while(CurrentB-ScanLine = T1-yMax)T1 = T1-next;HeadE = T1;if(HeadE = NULL)return;if(T1-next != NULL)T2 = T1;T1 = T2-next;while(T1 != NULL)if(CurrentB-ScanLine = T1-yMax)T2-next = T1-next;T1-next = NULL;T1 = T2-next;elseT2 = T1;T1 = T2-next;第 8 页 共 8 页 BOOL In = fa

13、lse;double xb,xe;for(T1=HeadE; T1!=NULL; T1=T1-next)if(In = false)xb = T1-x;In = true;elsexe = T1-x-1;CClientDC dc(this);for(double x=xb; xScanLine,GetColor);Sleep(1);In = FALSE;for(T1=HeadE; T1!=NULL; T1=T1-next)T1-x = T1-x+T1-k;delete HeadB;delete CurrentB;delete CurrentE;delete HeadE;五、实验小结对于有效边填充算法还有一些地方不是很了解们,最后在同学的帮助下新建了一个适合的类才解决了问题

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 工程造价

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号