实验1Bresenham算法文档格式.docx
《实验1Bresenham算法文档格式.docx》由会员分享,可在线阅读,更多相关《实验1Bresenham算法文档格式.docx(8页珍藏版)》请在冰豆网上搜索。
//CEView
IMPLEMENT_DYNCREATE(CEView,CView)
BEGIN_MESSAGE_MAP(CEView,CView)
//{{AFX_MSG_MAP(CEView)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG_MAP
//Standardprintingcommands
ON_COMMAND(ID_FILE_PRINT,CView:
:
OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT,CView:
ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView:
OnFilePrintPreview)
END_MESSAGE_MAP()
//CEViewconstruction/destruction
CEView:
CEView()
{
//TODO:
addconstructioncodehere
}
~CEView()
BOOLCEView:
PreCreateWindow(CREATESTRUCT&
cs)
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
PreCreateWindow(cs);
//CEViewdrawing
voidBresenhamline(intx1,inty1,intx2,inty2,CDC*pDC)
{//对于所有直线均按照从左至右的方向绘制
intx,y,dy,dx,right,rightleft,d;
if(x1>
x2){
inttempx,tempy;
tempx=x1;
x1=x2;
x2=tempx;
tempy=y1;
y1=y2;
y2=tempy;
}
//根据斜率的情况不同而绘制
if(y1==y2){//斜率为0的情况
for(x=x1;
x<
=x2;
x++)
pDC->
SetPixel(x,y1,2);
elseif(x1==x2){//直线为垂直的情况
if(y1>
y2){//使直线按从下往上画
inttempy=y1;
y1=y2;
}
for(y=y1;
y<
=y2;
y++)
SetPixel(x1,y,2);
else{
dy=y2-y1;
dx=x2-x1;
if(abs(dy)==abs(dx)){////斜率为1或-1时
x=x1;
y=y1;
if(dy<
0){//斜率为1
for(;
y>
y--){
x++;
pDC->
SetPixel(x,y,2);
}
}//斜率为1
else{//斜率为-1
y++){
}//斜率为-1
elseif(abs(dy)<
abs(dx)){//斜率的绝对值小于1时
if(dy>
0&
&
dx>
0){//斜率为正时
right=-2*dy;
rightleft=2*dx-2*dy;
d=dx-2*dy;
x=x1;
while(x<
=x2){
if(d<
0){
y++;
d=d+rightleft;
}else{
d=d+right;
}
}//斜率为正时
else{//斜率为负时
right=2*dy;
rightleft=2*dy-2*dx;
d=2*dy-dx;
}//斜率为负时
}//斜率的绝对值小于1时
else{////斜率的绝对值大于1时
right=2*dx;
d=2*dx-dy;
while(y<
=y2){
y++;
if(d>
=0){
x++;
else{//斜率为负时
right=-2*dx;
rightleft=-2*dx-2*dy;
d=-2*dx-dy;
while(y>
y--;
}//斜率的绝对值大于1时
}//斜率的所有情况
voidCEView:
OnDraw(CDC*pDC)
CEDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
adddrawcodefornativedatahere
Bresenhamline(10,10,1000,1000,pDC);
//CEViewprinting
OnPreparePrinting(CPrintInfo*pInfo)
//defaultpreparation
returnDoPreparePrinting(pInfo);
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addextrainitializationbeforeprinting
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
addcleanupafterprinting
//CEViewdiagnostics
AssertValid()const
CView:
AssertValid();
Dump(CDumpContext&
dc)const
Dump(dc);
CEDoc*CEView:
GetDocument()//non-debugversionisinline
ASSERT(m_pDocument->
IsKindOf(RUNTIME_CLASS(CEDoc)));
return(CEDoc*)m_pDocument;
#endif//_DEBUG
//CEViewmessagehandlers