生活随笔
收集整理的這篇文章主要介紹了
边表法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
邊表法是用來繪制填充一個(gè)面的,邊表法的關(guān)鍵是邊表和連接邊表的掃描線。
對(duì)于邊的描述利用邊表數(shù)據(jù)結(jié)構(gòu),包含邊與掃描線的交點(diǎn)x坐標(biāo),邊的最大y坐標(biāo),這樣可以知道邊加入到哪些掃描線上,便還有一個(gè)指針來記錄掃描線上其它邊。
#pragma once
#ifndef __CAETZ__
#define __CAETZ__
#include "pch.h"
#include "CPoint3D.h"
#include "RGB.h"
class CAETZ
{
public:CAETZ() = default;CAETZ(const CPoint3D
&start
,const CPoint3D
&end
);~CAETZ() {}
public:CPoint3D start3D
; CPoint3D end3D
; int x
; int y
; int ymax
; double k
; int z
; CRGB rgb
; CAETZ
* pNext
;
};
#pragma once
#ifndef __CBUCKETZ__
#define __CBUCKETZ__#include "CAETZ.h"
#include "pch.h"
#include "CPoint3D.h"
#include "RGB.h"
class CBucketZ
{
public:CBucketZ() = default;CBucketZ(CPoint3D
*pointList
,int pointNum
);~CBucketZ() {CAETZ
*tempPET
= NULL;while (pET
!= NULL){tempPET
= pET
->pNext
;delete pET
;pET
= tempPET
;}};int getScanLine() const { return this->ScanLine
; };
public:CAETZ
* pET
;CBucketZ
* pNext
;CPoint3D
* point3DList
;int pointNum
;int ScanLine
;
private:void creatCBucketZ();void creatCAETZ();void pETaddNext(CBucketZ
* currentCBucket
,CAETZ
*nextCAET
);};
void CBucketZ
::creatCBucketZ()
{int yMin
= (int) point3DList
[0].y
;int yMax
= (int) point3DList
[0].y
;for (int i
= 1; i
< this->pointNum
; i
++){if (yMin
> (int)point3DList
[i
].y
)yMin
= (int)point3DList
[i
].y
;if(yMax
< (int)point3DList
[i
].y
)yMax
= (int)point3DList
[i
].y
;}this->ScanLine
= yMin
;this->pET
= NULL;this->pNext
= NULL;CBucketZ
* currentCBucket
= this;for (int j
= yMin
+ 1; j
<= yMax
; j
++){CBucketZ
* tempNext
= new CBucketZ();tempNext
->ScanLine
= j
;tempNext
->pET
= NULL;tempNext
->pNext
= NULL;currentCBucket
->pNext
= tempNext
;currentCBucket
= tempNext
;}
}void CBucketZ
::creatCAETZ()
{for (int i
= 0; i
< this->pointNum
; i
++){int j
= (i
+ 1) % this->pointNum
;if ((int) point3DList
[i
].y
!= (int)point3DList
[j
].y
){CAETZ
* pETCAETZ
= new CAETZ(point3DList
[i
], point3DList
[j
]);CAETZ
* pETCAETZ2
= pETCAETZ
;CBucketZ
* currentCBucket
= this;while (currentCBucket
->getScanLine() != (int) pETCAETZ
->y
)currentCBucket
= currentCBucket
->pNext
;currentCBucket
->pETaddNext(currentCBucket
, pETCAETZ
);for (int k
= pETCAETZ2
->y
+ 1; k
< pETCAETZ2
->ymax
; k
++){int x
= (int) pETCAETZ2
->start3D
.x
+ (k
- pETCAETZ2
->start3D
.y
) * pETCAETZ2
->k
;int z
= (int)(pETCAETZ2
->end3D
.z
- pETCAETZ2
->start3D
.z
) * (k
- pETCAETZ2
->start3D
.y
) / (pETCAETZ2
->end3D
.y
- pETCAETZ2
->start3D
.y
) + pETCAETZ2
->start3D
.z
;double r
= (k
- pETCAETZ2
->start3D
.y
) / (pETCAETZ2
->end3D
.y
- pETCAETZ2
->start3D
.y
);CRGB newRgb
= (pETCAETZ2
->end3D
.rgb
* r
+ (1 - r
) * pETCAETZ2
->start3D
.rgb
);CPoint3D
newStart3D(x
, k
, z
,newRgb
);CAETZ
* newpETCAETZ
= new CAETZ(newStart3D
, pETCAETZ2
->end3D
);currentCBucket
= currentCBucket
->pNext
;this->pETaddNext(currentCBucket
, newpETCAETZ
);}}}}void CBucketZ
::pETaddNext(CBucketZ
* currentCBucket
, CAETZ
* nextCAET
)
{int a
= 0; CAETZ
* currentpET
= currentCBucket
->pET
;if (currentpET
== NULL){currentCBucket
->pET
= nextCAET
;a
= 1;}else {CAETZ
* tempAET
= NULL;while ((currentpET
!= NULL) && (currentpET
->x
) < (nextCAET
->x
)){tempAET
= currentpET
;currentpET
= currentpET
->pNext
;}if (tempAET
== NULL){CAETZ
* headpET
= currentCBucket
->pET
;nextCAET
->pNext
= headpET
;currentCBucket
->pET
= nextCAET
;a
= 1;}else if (currentpET
== NULL){tempAET
->pNext
= nextCAET
;a
= 1;}else{nextCAET
->pNext
= currentpET
;tempAET
->pNext
= nextCAET
;a
= 1;}}
}
#endif
#endif
總結(jié)
以上是生活随笔為你收集整理的边表法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。