www.pudn.com > CGMEC013395.rar > ChildView.cpp
// ChildView.cpp : implementation of the CChildView class // #include "stdafx.h" #include "MEC.h" #include "ChildView.h" #include "PointDlg.h" #include#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CChildView CChildView::CChildView() { int i; for(i=0;i<6;i++) if(i==m_MEC||i==m_CH) m_nGraphs[i] = true; else m_nGraphs[i] = false; m_nPoints = 1; //Add Points m_iAlgorithm = 0; //O(N^3); m_lButtonDown = false; //GetDC()->CreateCompatibleDC(&m_dcMem); m_delta = 4; m_sIndex = -1; m_nstIndex = -1; m_isSelected = -1; m_MECircle = NULL; m_NearLine.clear(); } CChildView::~CChildView() { } BEGIN_MESSAGE_MAP(CChildView,CWnd ) //{{AFX_MSG_MAP(CChildView) ON_WM_PAINT() ON_COMMAND(ID_POINTS_ADD, OnPointsAdd) ON_UPDATE_COMMAND_UI(ID_POINTS_ADD, OnUpdatePointsAdd) ON_UPDATE_COMMAND_UI(ID_POINTS_SELECT, OnUpdatePointsSelect) ON_COMMAND(ID_POINTS_SELECT, OnPointsSelect) ON_UPDATE_COMMAND_UI(ID_GRAPHS_CH, OnUpdateGraphsCh) ON_COMMAND(ID_GRAPHS_CH, OnGraphsCh) ON_COMMAND(ID_GRAPHS_LA, OnGraphsLa) ON_UPDATE_COMMAND_UI(ID_GRAPHS_LA, OnUpdateGraphsLa) ON_COMMAND(ID_GRAPHS_MEC, OnGraphsMec) ON_UPDATE_COMMAND_UI(ID_GRAPHS_MEC, OnUpdateGraphsMec) ON_COMMAND(ID_GRAPHS_NN, OnGraphsNn) ON_UPDATE_COMMAND_UI(ID_GRAPHS_NN, OnUpdateGraphsNn) ON_UPDATE_COMMAND_UI(ID_GRAPHS_SC, OnUpdateGraphsSc) ON_COMMAND(ID_GRAPHS_SC, OnGraphsSc) ON_COMMAND(ID_GRAPHS_SI, OnGraphsSi) ON_UPDATE_COMMAND_UI(ID_GRAPHS_SI, OnUpdateGraphsSi) ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() ON_WM_LBUTTONUP() ON_COMMAND(ID_POINTS_DEL, OnPointsDel) ON_COMMAND(ID_POINTS_DAP, OnPointsDap) ON_WM_CHAR() ON_WM_KEYDOWN() ON_COMMAND(ID_ALGORITHM_ON2, OnAlgorithmOn2) ON_UPDATE_COMMAND_UI(ID_ALGORITHM_ON2, OnUpdateAlgorithmOn2) ON_COMMAND(ID_ALGORITHM_ON3, OnAlgorithmOn3) ON_UPDATE_COMMAND_UI(ID_ALGORITHM_ON3, OnUpdateAlgorithmOn3) ON_COMMAND(ID_POINTS_RANDOMADD, OnPointsRandomadd) ON_UPDATE_COMMAND_UI(ID_POINTS_RANDOMADD, OnUpdatePointsRandomadd) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CChildView message handlers BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE; cs.style &= ~WS_BORDER; cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE; } void CChildView::OnPointsDel() { // TODO: Add your command handler code here if(!m_lButtonDown&&m_isSelected != -1 && (m_isSelected>=0&&m_isSelected SetRadio(m_nPoints == 1); } void CChildView::OnUpdatePointsSelect(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetRadio(m_nPoints == 0); } void CChildView::OnPointsSelect() { // TODO: Add your command handler code here m_nPoints = 0; Invalidate(); } void CChildView::OnUpdateGraphsCh(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_nGraphs[m_CH] == true); } void CChildView::OnGraphsCh() { // TODO: Add your command handler code here m_nGraphs[m_CH] = !m_nGraphs[m_CH]; Invalidate(); } void CChildView::OnGraphsLa() { // TODO: Add your command handler code here m_nGraphs[m_LA] = !m_nGraphs[m_LA]; Invalidate(); } void CChildView::OnUpdateGraphsLa(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_nGraphs[m_LA] == true); } void CChildView::OnGraphsMec() { // TODO: Add your command handler code here m_nGraphs[m_MEC] = !m_nGraphs[m_MEC]; Invalidate(); } void CChildView::OnUpdateGraphsMec(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_nGraphs[m_MEC] == true); } void CChildView::OnGraphsNn() { // TODO: Add your command handler code here m_nGraphs[m_NN] = !m_nGraphs[m_NN]; Invalidate(); } void CChildView::OnUpdateGraphsNn(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_nGraphs[m_NN] == true); } void CChildView::OnUpdateGraphsSc(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_nGraphs[m_SC] == true); } void CChildView::OnGraphsSc() { // TODO: Add your command handler code here m_nGraphs[m_SC] = !m_nGraphs[m_SC]; Invalidate(); } void CChildView::OnGraphsSi() { // TODO: Add your command handler code here m_nGraphs[m_SI] = !m_nGraphs[m_SI]; Invalidate(); } void CChildView::OnUpdateGraphsSi(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_nGraphs[m_SI] == true); } vector CChildView:: SearchConvexHull(vector vecPoints) { vector vCH; if(vecPoints.size()==0) return vCH; else if(vecPoints.size()>=1 && vecPoints.size()<=3) return vecPoints; int i,minIndex=-1; for(i=0;i & v = vecPoints; if(v[i].x == v[0].x&&v[i].y == v[0].y) { Point temp; temp = v[i]; v[i] = v[v.size()-1]; v[v.size()-1] = temp; v.pop_back(); i = i-1; continue; } for(j=i+1;j v[0].y) slope1 = DBL_MAX/2.0; else if(v[i].x == v[0].x&&v[i].y < v[0].y) slope1 = -DBL_MAX/2.0; else slope1 = (v[i].y-v[0].y)/(v[i].x-v[0].x); a1 = atan(slope1); if(v[j].x == v[0].x&&v[j].y == v[0].y) { Point temp; temp = v[j]; v[j] = v[v.size()-1]; v[v.size()-1] = temp; v.pop_back(); j = j-1; continue; } else if(v[j].x == v[0].x&&v[j].y > v[0].y) slope2 = DBL_MAX/2.0; else if(v[j].x == v[0].x&&v[j].y < v[0].y) slope2 = -DBL_MAX/2.0; else slope2 = (v[j].y-v[0].y)/(v[j].x-v[0].x); a1 = atan(slope1); a2 = atan(slope2); if(a1>a2) { Point temp; temp = v[i]; v[i] = v[j]; v[j] = temp; } else if(a1==a2) { bool flag; ((v[i].x-v[0].x)*(v[i].x-v[0].x)+(v[i].y-v[0].y)*(v[i].y-v[0].y) < (v[j].x-v[0].x)*(v[j].x-v[0].x)+(v[j].y-v[0].y)*(v[j].y-v[0].y)) ? flag=true : flag = false; if(flag==true) { Point temp; temp = v[j]; v[j] = v[i]; v[i] = temp; //... temp = v[j]; v[j] = v[v.size()-1]; v[v.size()-1] = temp; v.pop_back(); j = j-1; continue; } else { Point temp; temp = v[j]; v[j] = v[v.size()-1]; v[v.size()-1] = temp; v.pop_back(); j = j-1; continue; }; } } } // end of sort by angle... int iSize; Point* ptrWatch = new Point[iSize = vecPoints.size()]; Point* q; for(i=0,q=ptrWatch;i =1 && iSize<=3) return vecPoints; stack stkPoints; stkPoints.push(vecPoints[0]); stkPoints.push(vecPoints[1]); stkPoints.push(vecPoints[2]); for(i=3;i 0) { vCH.push_back(stkPoints.top()); stkPoints.pop(); } return vCH; } void CChildView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here int i; int delta = 2; for(i=0;i vSI; //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(23,25,200)); dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } } if(m_nGraphs[m_NN] == true) { //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex 1) { char testLine[100]; sprintf(testLine,"%d-%d,%d", ptrMEC->GetCenterPoint().x,ptrMEC->GetCenterPoint().y, ptrMEC->GetR()); //MessageBox(testLine); //for test dc.SelectStockObject(NULL_BRUSH); dc.Ellipse(ptrMEC->GetCenterPoint().x-ptrMEC->GetR(), ptrMEC->GetCenterPoint().y-ptrMEC->GetR(), ptrMEC->GetCenterPoint().x+ptrMEC->GetR(), ptrMEC->GetCenterPoint().y+ptrMEC->GetR()); m_MECircle = ptrMEC; } } RECT rect; GetClientRect(&rect); char test[1000]; sprintf(test,"%d %d %d %d",rect.left,rect.top,rect.right,rect.bottom); //MessageBox(test); //GetDC()->BitBlt(0,0,rect.right,rect.bottom,&m_dcMem,0,0,SRCCOPY); // Do not call CWnd::OnPaint() for painting messages } void CChildView::OnLButtonDown(UINT nFlags, CPoint point) { m_lButtonDown = true; // TODO: Add your message handler code here and/or call default CWnd ::OnLButtonDown(nFlags, point); switch (CChildView::m_nPoints) { case 0: //Select Points { if(m_nstIndex ==-1) { m_isSelected = -1; } else if(m_nstIndex>=0 && m_nstIndex 0) { //MessageBox(0); //Invert the old selected point... CBrush brush(RGB(255,255,255)); dc.SelectObject(&brush); CPen pen(PS_SOLID,0,RGB(255,255,255)); dc.SelectObject(&pen); dc.Rectangle(oldPoint.x-m_delta,oldPoint.y-m_delta, oldPoint.x+m_delta,oldPoint.y+m_delta); dc.Rectangle(m_arrPoints[m_isSelected].x-m_delta, m_arrPoints[m_isSelected].y-m_delta, m_arrPoints[m_isSelected].x+m_delta, m_arrPoints[m_isSelected].y+m_delta); //Draw all the Points... for(i=0;i 1) { //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex 1) { //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex vSI; //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(255,255,255)); dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } } //Invert the Convex Hull... if(m_nGraphs[m_CH] == true) { DrawConvexHull(&dc,RGB(255,255,255)); } //MessageBox(0); CBrush brush1(RGB(0,0,0)); dc.SelectObject(&brush1); CPen pen1(PS_SOLID,0,RGB(0,0,0)); dc.SelectObject(&pen1); dc.Rectangle(point.x-m_delta,point.y-m_delta, point.x+m_delta,point.y+m_delta); m_arrPoints[m_isSelected] = point; //******* //enum {m_NN,m_LA,m_SC,m_SI,m_CH,m_MEC}; if(m_nGraphs[m_SI] == true) { vector vSI; //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(23,25,200)); //influence color dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } } if(m_nGraphs[m_NN] == true) { //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex GetCenterPoint().x-m_MECircle->GetR(), m_MECircle->GetCenterPoint().y-m_MECircle->GetR(), m_MECircle->GetCenterPoint().x+m_MECircle->GetR(), m_MECircle->GetCenterPoint().y+m_MECircle->GetR()); //Find and Draw the MEC dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,2,RGB(125,125,125)); dc.SelectObject(&pen); CCircle* ptrMEC = FindMEC(m_arrPoints); if(ptrMEC != NULL && m_arrPoints.GetSize()>1) { char testLine[100]; sprintf(testLine,"%d-%d,%d", ptrMEC->GetCenterPoint().x,ptrMEC->GetCenterPoint().y, ptrMEC->GetR()); //MessageBox(testLine); dc.Ellipse(ptrMEC->GetCenterPoint().x-ptrMEC->GetR(), ptrMEC->GetCenterPoint().y-ptrMEC->GetR(), ptrMEC->GetCenterPoint().x+ptrMEC->GetR(), ptrMEC->GetCenterPoint().y+ptrMEC->GetR()); m_MECircle = ptrMEC; } } } } break; case 1: //Add Points { int i; for(i=0;i vSI; //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(23,25,200)); //influence color dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } } if(m_nGraphs[m_NN] == true) { //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex 1) { char testLine[100]; sprintf(testLine,"%d-%d,%d", ptrMEC->GetCenterPoint().x,ptrMEC->GetCenterPoint().y, ptrMEC->GetR()); //MessageBox(testLine); //for test dc.Ellipse(ptrMEC->GetCenterPoint().x-ptrMEC->GetR(), ptrMEC->GetCenterPoint().y-ptrMEC->GetR(), ptrMEC->GetCenterPoint().x+ptrMEC->GetR(), ptrMEC->GetCenterPoint().y+ptrMEC->GetR()); m_MECircle = ptrMEC; } } } } else if(m_lButtonDown == true) { //MessageBox(0); //Invert the Old Point CBrush brush(RGB(255,255,255)); dc.SelectObject(&brush); CPen pen(PS_SOLID,0,RGB(255,255,255)); dc.SelectObject(&pen); dc.Rectangle(oldPoint.x-m_delta,oldPoint.y-m_delta, oldPoint.x+m_delta,oldPoint.y+m_delta); //Draw All Points for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex vSI; //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(225,255,255)); dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } } if(m_nGraphs[m_SI] == true) { m_arrPoints.Add(oldPoint); //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); vector vSI; //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(255,255,255)); dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } m_arrPoints.RemoveAt(m_arrPoints.GetSize()-1); } //Invert the Old Convex Hull... if(m_nGraphs[m_CH] == true) { DrawConvexHull(&dc,RGB(255,255,255)); m_arrPoints.Add(oldPoint); DrawConvexHull(&dc,RGB(255,255,255)); m_arrPoints.RemoveAt(m_arrPoints.GetSize()-1); } //enum {m_NN,m_LA,m_SC,m_SI,m_CH,m_MEC}; if(m_nGraphs[m_CH] == true) { m_arrPoints.Add(point); DrawConvexHull(&dc,RGB(255,125,25)); m_arrPoints.RemoveAt(m_arrPoints.GetSize()-1); } if(m_nGraphs[m_SI] == true) { m_arrPoints.Add(point); //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); vector vSI; //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } } if(!(mIndex>=0&&mIndex ::iterator it1,it2; for(it1=vSI.begin();it1!=vSI.end();it1++) { for(it2=it1+1;it2!=vSI.end();it2++) { CCircle* q1 = *it1; CCircle* q2 = *it2; if( fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) <=q1->GetR()+q2->GetR() && fabs(GetDistance(q1->GetCenterPoint(),q2->GetCenterPoint())) >fabs((q1->GetR()-q2->GetR()))) { dc.SelectStockObject(NULL_BRUSH); CPen SCPen(PS_SOLID,1,RGB(23,25,200)); //Sphere Influence Color dc.SelectObject(&SCPen); //MessageBox(0); dc.MoveTo(q1->GetCenterPoint()); dc.LineTo(q2->GetCenterPoint()); } } } m_arrPoints.RemoveAt(m_arrPoints.GetSize()-1); } if(m_nGraphs[m_NN] == true) { m_arrPoints.Add(point); //CBrush brush(NULL_BRUSH); dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,0,RGB(0,0,0)); dc.SelectObject(&pen); //dc.Rectangle(0,0,10,10); //MessageBox(0); int i; m_arrNearPoints.RemoveAll(); for(i=0;i ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex ((m_arrPoints[i].x-m_arrPoints[j].x)*(m_arrPoints[i].x-m_arrPoints[j].x) +(m_arrPoints[i].y-m_arrPoints[j].y)*(m_arrPoints[i].y-m_arrPoints[j].y))) { mIndex = j; } } if(!(mIndex>=0&&mIndex GetCenterPoint().x-m_MECircle->GetR(), m_MECircle->GetCenterPoint().y-m_MECircle->GetR(), m_MECircle->GetCenterPoint().x+m_MECircle->GetR(), m_MECircle->GetCenterPoint().y+m_MECircle->GetR()); //Find and Draw the MEC dc.SelectStockObject(NULL_BRUSH); CPen pen(NULL,2,RGB(125,125,125)); dc.SelectObject(&pen); CCircle* ptrMEC = FindMEC(m_arrPoints); if(ptrMEC != NULL && m_arrPoints.GetSize()>1) { char testLine[100]; sprintf(testLine,"%d-%d,%d", ptrMEC->GetCenterPoint().x,ptrMEC->GetCenterPoint().y, ptrMEC->GetR()); //MessageBox(testLine); dc.Ellipse(ptrMEC->GetCenterPoint().x-ptrMEC->GetR(), ptrMEC->GetCenterPoint().y-ptrMEC->GetR(), ptrMEC->GetCenterPoint().x+ptrMEC->GetR(), ptrMEC->GetCenterPoint().y+ptrMEC->GetR()); m_MECircle = ptrMEC; } m_arrPoints.RemoveAt(m_arrPoints.GetSize()-1); } } if(m_isSelected != -1 && m_isSelected!=m_nstIndex) { CBrush brush(RGB(0,0,0)); dc.SelectObject(&brush); CPen pen(PS_SOLID,0,RGB(0,0,0)); dc.SelectObject(&pen); dc.Rectangle(m_arrPoints[m_isSelected].x-m_delta, m_arrPoints[m_isSelected].y-m_delta, m_arrPoints[m_isSelected].x+m_delta, m_arrPoints[m_isSelected].y+m_delta); } } break; }; oldPoint = point; } inline double CChildView::GetDistance(CPoint &p1, CPoint &p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } void CChildView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CWnd ::OnLButtonUp(nFlags, point); if (GetCapture () == this) { m_lButtonDown = false; //MessageBox(0); ::ReleaseCapture (); /// ***~!!! //MessageBox(0); switch (CChildView::m_nPoints) { case 0: //Select Points { } break; case 1: //Add Points { int i; //MessageBox(0); bool tag = true; for(i=0;i =0&&m_isSelected tmpR) break; } if(k==N && tmpR < R) { Px = tempX; Py = tempY; R = tmpR; } for(k=j+1;k tmpR) break; } if(l==N && tmpR < R) { Px = tempX; Py = tempY; R = tmpR; } } } } // printf("%.2lf %.2lf %.2lf\n",P.x,P.y,sqrt(R)); P.x = (long)Px; P.y = (long)Py; R = sqrt(ceil(R)); ptrC = new CCircle(P,(int)ceil(R)); } else { vector v1,v2; Point temp; int i; for(i=0;i v1,v2; Point temp; int i; for(i=0;i SelectObject(&CHPen); pdc->SelectStockObject(NULL_BRUSH); for(i=0;i MoveTo(v2[i].x,v2[i].y); pdc->LineTo(v2[(i+1)%v2.size()].x,v2[(i+1)%v2.size()].y); } } void CChildView::OnAlgorithmOn2() { // TODO: Add your command handler code here m_iAlgorithm = 1; Invalidate(); } void CChildView::OnUpdateAlgorithmOn2(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetRadio(m_iAlgorithm == 1); } void CChildView::OnAlgorithmOn3() { // TODO: Add your command handler code here m_iAlgorithm = 0; Invalidate(); } void CChildView::OnUpdateAlgorithmOn3(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetRadio(m_iAlgorithm == 0); } void CChildView::OnPointsRandomadd() { // TODO: Add your command handler code here CPointDlg dlg; dlg.m_pNumber = 0; if (dlg.DoModal () == IDOK && dlg.m_pNumber>0 && dlg.m_pNumber<=300) { CPoint point; RECT rect; GetClientRect(&rect); srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */ int i; for( i = 0; i < dlg.m_pNumber;i++ ) { point.x = rect.right/6+rand()%(rect.right*2/3); point.y = rect.bottom/6+rand()%(rect.bottom*2/3); m_arrPoints.Add(point); } Invalidate (); } } void CChildView::OnUpdatePointsRandomadd(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here }