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

📄 gcluserview.cpp

📁 分级聚类算法:包括k-mean max-dist min-dist 程序使用方法: 程序中打开文件“.dat”-》选择聚类方法-》显示数据 .dat文件格式: 分成几类 输入样本维数 样本
💻 CPP
字号:
// GCluserView.cpp : implementation of the CGCluserView class
//

#include "stdafx.h"
#include "GCluser.h"

#include "GCluserDoc.h"
#include "GCluserView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGCluserView

IMPLEMENT_DYNCREATE(CGCluserView, CView)

BEGIN_MESSAGE_MAP(CGCluserView, CView)
	//{{AFX_MSG_MAP(CGCluserView)
	ON_COMMAND(ID_DRAW_DATA, OnDrawData)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CGCluserView construction/destruction

CGCluserView::CGCluserView()
{
	// TODO: add construction code here

}

CGCluserView::~CGCluserView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGCluserView drawing

void CGCluserView::OnDraw(CDC* pDC)
{
	CGCluserDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CGCluserView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGCluserView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CGCluserView message handlers

void CGCluserView::OnDrawData() 
{
	CGCluserDoc* pDoc = GetDocument();
	int * pSample = pDoc->GetSamples();
	int i, j;
	int k = 5;
	SHAPE shape;
	COLORREF rgb;
	for (i = 0; i < pDoc->GetNumSample(); i++)
	{
		shape = (SHAPE)(pSample[i * pDoc->GetNumDimension() + 2] % 4);
		j = pSample[i * pDoc->GetNumDimension() + 2] % 5;
		switch (j)
		{
		case 0: rgb = RGB(255,0,0);
			break;
		case 1: rgb = RGB(0,0,255);
			break;
		case 2: rgb = RGB(160,32,240);
			break;
		case 3: rgb = RGB(0,201,87);
			break;
		case 4: rgb = RGB(128,42,42);
			break;
		default: rgb = RGB(0,0,0);
			break;
		}
		DrawPoint(pSample[i * pDoc->GetNumDimension()
			+ 0] * k + 120, pSample[i * pDoc->GetNumDimension()
			+ 1] * k + 120, shape, rgb);
	}
}

void CGCluserView::DrawPoint(int i, int j, SHAPE shape, COLORREF rgb)
{
	CDC *pDC=GetDC();
	CPen pen(PS_SOLID, 1, rgb);
	CPen *pOldPen=pDC->SelectObject(&pen);
	int w = 3;
	switch (shape)
	{
	case 0: pDC->MoveTo(i-w, j); pDC->LineTo(i+w+1, j);
		pDC->MoveTo(i, j-w); pDC->LineTo(i, j+w+1);
		break;
	case 1: pDC->Ellipse(i-w, j+w, i+w, j-w);
		break;
	case 2: pDC->MoveTo(i-w, j-w); pDC->LineTo(i+w, j-w);
		pDC->MoveTo(i-w, j+w); pDC->LineTo(i+w, j+w);
		pDC->MoveTo(i-w, j-w); pDC->LineTo(i-w, j+w);
		pDC->MoveTo(i+w, j-w); pDC->LineTo(i+w, j+w+1);
		break;
	case 3: pDC->MoveTo(i-1, j-1); pDC->LineTo(i+2, j-1);
		pDC->MoveTo(i-1, j); pDC->LineTo(i+2, j);
		pDC->MoveTo(i-1, j+1); pDC->LineTo(i+2, j+1);
		break;
	default: break;
	}
	pDC->SelectObject(pOldPen);
	ReleaseDC(pDC);
}

⌨️ 快捷键说明

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