⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voronoiview.cpp

📁 一个很不错的求Voronoi线与最小凸壳的vc++源程序
💻 CPP
字号:
// VoronoiView.cpp : implementation of the CVoronoiView class
//

#include "stdafx.h"
#include "Voronoi.h"

#include "VoronoiDoc.h"
#include "VoronoiView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CGraphPara *p_GraphPara;
extern void LPtoRP(int x,int y,double *X,double *Y);
/////////////////////////////////////////////////////////////////////////////
// CVoronoiView

IMPLEMENT_DYNCREATE(CVoronoiView, CView)

BEGIN_MESSAGE_MAP(CVoronoiView, CView)
	//{{AFX_MSG_MAP(CVoronoiView)
	ON_WM_SIZE()
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(ID_PROTRUDE, OnProtrude)
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_VORONOI, OnVoronoi)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVoronoiView construction/destruction
CVoronoiView *p_View;
void RPtoLP(double x,double y,int *X,int *Y);
void LPtoRP(int x,int y,double *X,double *Y);
int RLtoLL(double l);
double LLtoRL(int l);
CVoronoiView::CVoronoiView()
{
	// TODO: add construction code here
    m_xStart=0.0;
	m_yStart=0.0;
	blc=1.0;
	m_pColor=1;
	m_Layer=1;
	m_bColor=2;
}

CVoronoiView::~CVoronoiView()
{
}

BOOL CVoronoiView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CVoronoiView drawing

void CVoronoiView::OnDraw(CDC* pDC)
{
	CVoronoiDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	DrawBack(pDC);
	pDoc->Draw(pDC,0,0,m_bColor);

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CVoronoiView printing

BOOL CVoronoiView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CVoronoiView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CVoronoiView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CVoronoiView diagnostics

#ifdef _DEBUG
void CVoronoiView::AssertValid() const
{
	CView::AssertValid();
}

void CVoronoiView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CVoronoiDoc* CVoronoiView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVoronoiDoc)));
	return (CVoronoiDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CVoronoiView message handlers
void CVoronoiView::LPtoRP(int x,int y,double *X,double *Y)
{
	*X=m_xStart+x*blc;
	*Y=m_yStart+blc*(m_hScreen-y);
}
void CVoronoiView::RPtoLP(double x,double y,int *X,int *Y)
{
	*X=(int)((x-m_xStart)/blc);
	*Y=m_hScreen-(int)((y-m_yStart)/blc);
}
double CVoronoiView::LLtoRL(int l)
{
	return blc*l;
}
int CVoronoiView::RLtoLL(double l)
{
	return (int)(l/blc);
}

void CVoronoiView::OnSize(UINT nType, int cx, int cy) 
{
	m_wScreen=cx;
	m_hScreen=cy;
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
}

void CVoronoiView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	p_View=this;
	CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void RPtoLP(double x,double y,int *X,int *Y)
{
	p_View->RPtoLP(x,y,X,Y);
}
void LPtoRP(int x,int y,double *X,double *Y)
{
	p_View->LPtoRP(x,y,X,Y);
}
int RLtoLL(double l)
{
	return p_View->RLtoLL(l);
}
double LLtoRL(int l)
{
	return p_View->LLtoRL(l);
}

void CVoronoiView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CString str;

	CVoronoiDoc* pDoc=GetDocument();
	CClientDC ht(this);
	double x,y;
	int id;
	LPtoRP(point.x,point.y,&x,&y);
	id=pDoc->GetGraphID();
	pDoc->AddNetPoint(x,y,3,m_Layer,id,m_pColor)->Draw(&ht,0,0,1,id);
    ReleaseCapture();
    
}

void CVoronoiView::OnProtrude() 
{
//  CString str;
	static i=0;
//	DWORD i;
	CVoronoiDoc* pDoc=GetDocument(); 
	CClientDC ht(this);
//	i=GetTickCount();
	pDoc->GetProtrude(&ht);
//	i=GetTickCount()-i;
//	str.Format("%d",i);
//	ht.TextOut(0,0,str);
	// TODO: Add your command handler code here
}

void CVoronoiView::DrawBack(CDC *pDC)
{
	CBrush brush(p_GraphPara->GetColor(m_bColor));
	CBrush* pOldBrush=pDC->SelectObject(&brush);
	pDC->PatBlt(0,0,m_wScreen,m_hScreen,PATCOPY);
	pDC->SelectObject(pOldBrush);
}

void CVoronoiView::OnVoronoi() 
{
	CVoronoiDoc* pDoc=GetDocument(); 
	CClientDC ht(this);
	pDoc->GetVoronoi(&ht);
	// TODO: Add your command handler code here
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -