📄 fill.h
字号:
#include "stdafx.h"
#include "math.h"
#include<iostream.h>
#include "graphicView.h"
#include "graphicDoc.h"
#include "graphic.h"
#include<stdlib.h>
#if !defined(fill_all_of_myfunction_in_cjp)
#define fill_all_of_myfunction_in_cjp
int m_k,m_ky;
int m_fillMask[16];
int m_fillStyle =1;
int m_MaskWidth=16;
/*
typedef struct tEdge{
int yUpper;
float xIntersect,dxPerScan;
struct tEdge *next;
}Edge;//
/**/
//////////////////////////////
void insertEdge(Edge *list,Edge * edge) {
Edge *p,*q=list;
p=q->next;
while(p!=NULL){
if(edge->xIntersect<p->xIntersect)p=NULL;
else{q=p;
p=p->next;
}//else
}//while
edge->next=q->next;
q->next=edge;
}//insertEdge
//////////////////////////////
int yNext(int k,int cnt,CPoint *pts){
int j;
if((k+1)>(cnt-1)) j=0;
else
j=k+1;
while(pts[k].y==pts[j].y)
if((j+1)>(cnt-1)) j=0;
else
j++;
return (pts[j].y);
}//yNext
//////////////////////////////
void makeEdgeRec(CPoint lower,CPoint upper,int yComp,Edge *edge,Edge *edges[]){
edge->dxPerScan=(float)(upper.x-lower.x)/(upper.y-lower.y);
edge->xIntersect=float(lower.x);
if(upper.y<yComp)
edge->yUpper=upper.y-1;
else
edge->yUpper=upper.y;
insertEdge(edges[lower.y],edge);
}//makeEdgeRec
//////////////////////////////
void buildEdgeList(int cnt,CPoint *pts,Edge *edges[]){
Edge *edge;
CPoint v1,v2;
int i,yPrev=pts[cnt-2].y;
v1.x=pts[cnt-1].x;
v1.y=pts[cnt-1].y;
for(i=0;i<cnt;i++){
v2=pts[i];
if(v1.y!=v2.y){
edge=(Edge *)malloc(sizeof(Edge));
if(v1.y<v2.y) makeEdgeRec(v1,v2,yNext(i,cnt,pts),edge,edges);
else makeEdgeRec(v2,v1,yPrev,edge,edges);
}//if
yPrev=v1.y;
v1 =v2;
}//for
}//buildEdgeList
//////////////////////////////
void buildActiveList (int scan,Edge *active,Edge *edges[]){
Edge *p,*q;
p=edges[scan]->next;
while(p){
q=p->next;
insertEdge(active,p);
p=q;
}//while
}//buildActiveList
//////////////////////////////
void CGraphicView::fillScan(int scan,Edge *active){
Edge *p1,*p2;
int i;
p1=active->next;
while(p1){
m_k=int(p1->xIntersect);
p2=p1->next;
for(i=int(p1->xIntersect);i<p2->xIntersect;i++)
setPixmask((int )i,scan);
p1=p2->next;
}//while
}//fillScan
//////////////////////////////
void deleteAfter(Edge *q){
Edge *p=q->next;
q->next=p->next;
free(p);
}// deleteAfer
//////////////////////////////
void updateActiveList(int scan,Edge *active){
Edge *q=active,*p=active->next;
while(p)
if(scan>=p->yUpper){
p=p->next;
deleteAfter(q);
}//if
else{
p->xIntersect=p->xIntersect+p->dxPerScan;
q=p;
p=p->next;
}//else
}//updateActiveList
//////////////////////////////
void resortActiveList (Edge *active){
Edge *q,*p=active->next;
active->next=NULL;
while(p){
q=p->next;
insertEdge(active,p);
p=q;
}//while
}// resortActiveList
//////////////////////////////
void CGraphicView::scanFill(int cnt,CPoint *pts){
Edge *edges[WINDOW_HEIGHT],*active;
int i,scan;
for(i=0;i<WINDOW_HEIGHT;i++)
{edges[i]=(Edge *)malloc(sizeof(Edge));
edges[i]->next=NULL;
}//for
buildEdgeList(cnt,pts,edges);
active=(Edge *)malloc(sizeof(Edge));
active->next=NULL;
for(scan=0;scan<WINDOW_HEIGHT;scan++){
m_ky=scan%16;
buildActiveList(scan,active,edges);
if(active->next){
fillScan(scan,active);
updateActiveList(scan,active);
resortActiveList(active);
}//if
}//for..
}//scanFill
///////////////////////////////////////////////////////////////
//
void insertEdge2(Edge *list,Edge * edge,coloor color1,coloor color2) {
Edge *p,*q=list;
p=q->next;
while(p!=NULL){
if(edge->xIntersect<p->xIntersect)p=NULL;
else{q=p;
p=p->next;
}//else
}//while
edge->next=q->next;
edge->color1.B=color1.B;
edge->color1.G=color1.G;
edge->color1.R=color1.R;
edge->color2.B=color2.B;
edge->color2.G=color2.G;
edge->color2.R=color2.R;
q->next=edge;
}//insertEdge2
void CGraphicView::scanFill4(CPoint *pts,int iii,int jjj){
int cnt=4;
int i,scan;
Edge *edges[WINDOW_HEIGHT],*active;
for(i=0;i<WINDOW_HEIGHT;i++)
{edges[i]=(Edge *)malloc(sizeof(Edge));
edges[i]->next=NULL;
}//for
buildEdgeList(cnt,pts,edges);
active=(Edge *)malloc(sizeof(Edge));
active->next=NULL;
CPoint v1,v2;
for(scan=0;scan<WINDOW_HEIGHT;scan++){
m_ky=scan%16;
//----------------------------------------------------
Edge *edge;
int yPrev=pts[cnt-2].y;
v1.x=pts[3].x;
v1.y=pts[3].y;
for(i=0;i<4;i++){
v2=pts[i];
if(v1.y!=v2.y){
edge=(Edge *)malloc(sizeof(Edge));
if(v1.y<v2.y){
edge->dxPerScan=(float)(v2.x-v1.x)/(v2.y-v1.y);
edge->xIntersect=float(v1.x);
if(v2.y<yNext(i,cnt,pts))
edge->yUpper =v2.y-1;
else
edge->yUpper =v2.y;
switch(i){
case 0:insertEdge2(edges[v1.y],edge,zp[iii].rgb[jjj],zp[iii-1].rgb[jjj]); break;
case 1:insertEdge2(edges[v1.y],edge,zp[iii-1].rgb[jjj],zp[iii-1].rgb[jjj+1]); break;
case 2:insertEdge2(edges[v1.y],edge,zp[iii-1].rgb[jjj+1],zp[iii].rgb[jjj+1]); break;
case 3:insertEdge2(edges[v1.y],edge,zp[iii].rgb[jjj+1],zp[iii].rgb[jjj]); break;
}//switch
// makeEdgeRec(v1,v2,yNext(i,cnt,pts),edge,edges);
}//if..
else {
edge->dxPerScan=(float)(v1.x-v2.x)/(v1.y-v2.y);
edge->xIntersect=float(v2.x);
if(v1.y<yPrev)
edge->yUpper =v1.y-1;
else
edge->yUpper =v1.y;
switch(i){
case 0:insertEdge2(edges[v1.y],edge,zp[iii-1].rgb[jjj],zp[iii].rgb[jjj]); break;
case 1:insertEdge2(edges[v1.y],edge,zp[iii-1].rgb[jjj+1],zp[iii-1].rgb[jjj]); break;
case 2:insertEdge2(edges[v1.y],edge,zp[iii].rgb[jjj+1],zp[iii-1].rgb[jjj+1]); break;
case 3:insertEdge2(edges[v1.y],edge,zp[iii].rgb[jjj],zp[iii].rgb[jjj+1]); break;
}//switch
}//else..
}//if
yPrev=v1.y;
v1 =v2;
}//for
//----------------------------------------------------
if(active->next){
fillScan(scan,active);
updateActiveList(scan,active);
resortActiveList(active);
}//if
}//for..
}//scanFill4
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -