📄 lbtreeview.cpp
字号:
// LBTreeView.cpp : implementation of the CLBTreeView class
//
#include "stdafx.h"
#include "LBTree.h"
#include "LBTreeDoc.h"
#include "LBTreeView.h"
#include "MakeDataDlg.h"
#include "NPoint.h"
#include "stdlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CLBTreeView
IMPLEMENT_DYNCREATE(CLBTreeView, CView)
BEGIN_MESSAGE_MAP(CLBTreeView, CView)
// 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)
ON_COMMAND(ID_ProduceNewData, &CLBTreeView::OnProducenewdata)
ON_COMMAND(ID_TREEBUILD, &CLBTreeView::OnTreebuild)
ON_COMMAND(ID_ZOOMIN, &CLBTreeView::OnZoomIn)
ON_COMMAND(ID_ZOOMOUT, &CLBTreeView::OnZoomOut)
ON_COMMAND(ID_HAAR, &CLBTreeView::OnHaar)
ON_COMMAND(ID_LEFTMOVE, &CLBTreeView::OnLeftMove)
ON_COMMAND(ID_RIGHTMOVE, &CLBTreeView::OnRightMove)
ON_COMMAND(ID_UPMOVE, &CLBTreeView::OnUpMove)
ON_COMMAND(ID_DOWNMOVE, &CLBTreeView::OnDownMove)
ON_COMMAND(ID_HEAP, &CLBTreeView::OnHeap)
ON_COMMAND(ID_QUERYPOINT, &CLBTreeView::OnQueryPoint)
ON_COMMAND(ID_HAARQUERY, &CLBTreeView::OnHaarQuery)
END_MESSAGE_MAP()
// CLBTreeView construction/destruction
CLBTreeView::CLBTreeView()
: Root(NULL)
, Zoom(2)
, CoordinateX(200)
, CoordinateY(10)
, QueryPoint(NULL)
, ShowData(false)
, ShowResult(false)
{
// TODO: add construction code here
}
CLBTreeView::~CLBTreeView()
{
}
BOOL CLBTreeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CLBTreeView drawing
void CLBTreeView::OnDraw(CDC* pDC)
{
CLBTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
if((Root!=NULL)&&(ShowResult==true))
Root->Illustrate(pDC,Zoom,CoordinateX,CoordinateY,0,Root->GetMeanPoint());
if((QueryPoint!=NULL)&&(ShowResult==true))
{
int x=CoordinateX+100*Zoom+(int)(QueryPoint->GetValueAt(0)*100*Zoom);
int y=CoordinateY+100*Zoom+(int)(QueryPoint->GetValueAt(1)*100*Zoom);
pDC->Rectangle(x-5,y-5,x+5,y+5);
}
if((pDoc->PointArray.GetSize()!=0)&&(ShowData==true))
{
pDC->Rectangle(CoordinateX,CoordinateY,CoordinateX+300,CoordinateY+250);
for(int i=0;i<pDoc->DataAmount;i++)
{
int x=CoordinateX+150+(int)(100*((NPoint*)pDoc->PointArray.GetAt(i))->GetValueAt(0));
int y=CoordinateY+130+(int)(100*((NPoint*)pDoc->PointArray.GetAt(i))->GetValueAt(pDoc->DataDim-1));
CPen pen(0,1,RGB(0,0,0));
CPen* Old=pDC->SelectObject(&pen);
pDC->Ellipse(x,y,x+5,y+5);
pDC->SelectObject(Old);
}
}
// TODO: add draw code for native data here
}
// CLBTreeView printing
BOOL CLBTreeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLBTreeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLBTreeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CLBTreeView diagnostics
#ifdef _DEBUG
void CLBTreeView::AssertValid() const
{
CView::AssertValid();
}
void CLBTreeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CLBTreeDoc* CLBTreeView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLBTreeDoc)));
return (CLBTreeDoc*)m_pDocument;
}
#endif //_DEBUG
// CLBTreeView message handlers
void CLBTreeView::OnProducenewdata()
{
// TODO: Add your command handler code here
CLBTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC *pDC=GetDC();
pDoc->PointArray.RemoveAll();
MakeDataDlg dlg;
dlg.m_DataAmount=pDoc->DataAmount;
dlg.m_DataDim=pDoc->DataDim;
dlg.Upper=pDoc->Upper;
dlg.Lower=pDoc->Lower;
dlg.Mean=pDoc->Mean;
dlg.Deviation=pDoc->Deviation;
if(dlg.DoModal()==IDOK)
{
pDoc->DataAmount=dlg.m_DataAmount;
pDoc->DataDim=dlg.m_DataDim;
pDoc->Upper=dlg.Upper;
pDoc->Lower=dlg.Lower;
pDoc->Mean=dlg.Mean;
pDoc->Deviation=dlg.Deviation;
}
pDoc->ProduceNewData();
Invalidate();
ShowResult=false;
ShowData=true;
}
void CLBTreeView::OnTreebuild()
{
// TODO: Add your command handler code here
CLBTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC *pDC=GetDC();
if(pDoc->PointArray.GetSize()!=0)
{
Root=new Cluster(pDoc->DataDim,-1);
for(int i=0;i<pDoc->PointArray.GetSize();i++)
{
Cluster *NewPoint=new Cluster(pDoc->DataDim,0);
NewPoint->InitialMeanPoint((NPoint*)(pDoc->PointArray.GetAt(i)));
NewPoint->SetTag(i);
Root->InsertSubCluster(NewPoint);
}
Root->AggSubCluster(1);
Root->Illustrate(pDC,Zoom,CoordinateX,CoordinateY,0,Root->GetMeanPoint());
Invalidate();
ReleaseDC(pDC);
ShowResult=true;
ShowData=false;
}
}
void CLBTreeView::OnZoomIn()
{
// TODO: Add your command handler code here
if(Zoom<5)
Zoom++;
Invalidate();
}
void CLBTreeView::OnZoomOut()
{
// TODO: Add your command handler code here
if(Zoom>1)
Zoom--;
Invalidate();
}
void CLBTreeView::OnHaar()
{
// TODO: Add your command handler code here
CLBTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int num=(int)pDoc->PointArray.GetSize();
for(int i=0;i<num;i++)
{
((NPoint*)(pDoc->PointArray.GetAt(i)))->Haar();
}
Invalidate();
ShowResult=false;
ShowData=true;
}
void CLBTreeView::OnLeftMove()
{
// TODO: Add your command handler code here
CoordinateX-=10;
Invalidate();
}
void CLBTreeView::OnRightMove()
{
// TODO: Add your command handler code here
CoordinateX+=10;
Invalidate();
}
void CLBTreeView::OnUpMove()
{
// TODO: Add your command handler code here
CoordinateY-=10;
Invalidate();
}
void CLBTreeView::OnDownMove()
{
// TODO: Add your command handler code here
CoordinateY+=10;
Invalidate();
}
void CLBTreeView::OnHeap()
{
// TODO: Add your command handler code here
if(Root!=NULL)
{
HeapSearch Heap(Root,QueryPoint);
Cluster* Result=Heap.NearestNeighbor();
CDC *pDC=GetDC();
int x=CoordinateX+100*Zoom+(int)(QueryPoint->GetValueAt(0)*100*Zoom);
int y=CoordinateY+100*Zoom+(int)(QueryPoint->GetValueAt(1)*100*Zoom);
pDC->Rectangle(x-5,y-5,x+5,y+5);
pDC->MoveTo(x,y);
int x2=CoordinateX+100*Zoom+(int)(Result->GetMeanPoint()->GetValueAt(0)*100*Zoom);
int y2=CoordinateY+100*Zoom+(int)(Result->GetMeanPoint()->GetValueAt(1)*100*Zoom);
pDC->LineTo(x2,y2);
ReleaseDC(pDC);
ShowResult=true;
ShowData=false;
}
}
void CLBTreeView::OnQueryPoint()
{
// TODO: Add your command handler code here
CLBTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
QueryPoint=new NPoint(pDoc->DataDim);
for(int i=0;i<pDoc->DataDim;i++)
{
double x=NewRandon.AverageRandom(pDoc->Lower,pDoc->Upper);
QueryPoint->SetValueAt(i,x);
}
Invalidate();
ShowResult=true;
ShowData=false;
}
void CLBTreeView::OnHaarQuery()
{
// TODO: Add your command handler code here
if(QueryPoint!=NULL)
QueryPoint->Haar();
Invalidate();
ShowResult=true;
ShowData=false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -