📄 onedim_norm_cloudview.cpp
字号:
// OneDim_Norm_CloudView.cpp : implementation of the COneDim_Norm_CloudView class
//
#include "stdafx.h"
#include "OneDim_Norm_Cloud.h"
#include "OneDim_Norm_CloudDoc.h"
#include "OneDim_Norm_CloudView.h"
#include <math.h>
#define Pi 3.1415926
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COneDim_Norm_CloudView
IMPLEMENT_DYNCREATE(COneDim_Norm_CloudView, CView)
BEGIN_MESSAGE_MAP(COneDim_Norm_CloudView, CView)
//{{AFX_MSG_MAP(COneDim_Norm_CloudView)
ON_COMMAND(ID_1NORMALCLOUD, On1normalcloud)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// COneDim_Norm_CloudView construction/destruction
COneDim_Norm_CloudView::COneDim_Norm_CloudView()
{
// TODO: add construction code here
}
COneDim_Norm_CloudView::~COneDim_Norm_CloudView()
{
}
BOOL COneDim_Norm_CloudView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// COneDim_Norm_CloudView drawing
void COneDim_Norm_CloudView::OnDraw(CDC* pDC)
{
COneDim_Norm_CloudDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rc;
GetClientRect(rc);
float ex,en,len;
float xunit;
if(m_normal)
{
ex = OneDimGenDlgN.m_expectation;
en = OneDimGenDlgN.m_entropy;
}
if(m_right)
{
ex = OneDimGenDlgR.m_expectation;
en = OneDimGenDlgR.m_entropy;
}
if(m_left)
{
ex = OneDimGenDlgL.m_expectation;
en = OneDimGenDlgL.m_entropy;
}
len =( 3 * en )/(0.9974/2);
xunit = len / 3.0;
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetViewportOrg(0,0);
BeginWaitCursor(); //显示执行状态鼠标
//绘制云图
if(m_FCloud == true) //表示执行了绘制云图的命令,进行云图的绘制
{
CBrush brush(RGB(0,0,255));
CBrush* pOldBrush=pDC->SelectObject(&brush);
pDC->SetWindowExt(500,500);
pDC->SetViewportExt(rc.right,-rc.bottom);
pDC->SetViewportOrg(rc.right/2,rc.bottom/2+200);
BeginWaitCursor();
for (int i=0;i<CloudPoints.GetSize();i++)
{
float x= (float) CloudPoints[i].x;
float y=(float) CloudPoints[i].y;
float ab = x - ex*10;
pDC->SelectStockObject(BLACK_BRUSH);
pDC->Ellipse((int)(ab-1), (int)(y-1), (int)(ab+1), (int)(y+1));
}
pDC->SelectObject(pOldBrush); //恢复画笔
CPen pen(PS_SOLID,1,RGB(255,0,0));//定义红色画笔
CPen* pOldPen=pDC->SelectObject(&pen);
pDC->MoveTo(-15*10,0*300);
pDC->LineTo(15*10,0*300);
pDC->MoveTo(-15*10,0*300);
pDC->LineTo(-15*10,1*300);
for(int m = -10; m <=16; m = m+5)
{
pDC->MoveTo(m*10,0*300);
pDC->LineTo(m*10,10);
}
for(int n = 1; n <=10; n++)
{
pDC->MoveTo(-15*10,0.1*n*300);
pDC->LineTo(-14*10,0.1*n*300);
}
//pDC->MoveTo(-15*10,0*300);
CString str,str2;
// 绘制y轴的坐标标注
str = "0.1";
pDC->TextOut(-17*10,0.1*300,str);
str = "0.2";
pDC->TextOut(-17*10,0.2*300,str);
str = "0.3";
pDC->TextOut(-17*10,0.3*300,str);
str = "0.4";
pDC->TextOut(-17*10,0.4*300,str);
str = "0.5";
pDC->TextOut(-17*10,0.5*300,str);
str = "0.6";
pDC->TextOut(-17*10,0.6*300,str);
str = "0.7";
pDC->TextOut(-17*10,0.7*300,str);
str = "0.8";
pDC->TextOut(-17*10,0.8*300,str);
str = "0.9";
pDC->TextOut(-17*10,0.9*300,str);
str = "1.0";
pDC->TextOut(-17*10,1.0*300,str);
str = "u(x)";
pDC->TextOut(-19*10,0.5*300,str);
//绘制x轴的坐标标注
str2.Format("%.2f",ex + len);
pDC->TextOut(15*10,-0.01*300,str2);
str2.Format("%.2f",ex+2*xunit);
pDC->TextOut(10*10,-0.01*300,str2);
str2.Format("%.2f",ex+xunit);
pDC->TextOut(5*10,-0.01*300,str2);
str2.Format("%.2f",ex);
pDC->TextOut(0,-0.01*300,str2);
str2.Format("%.2f",ex-xunit);
pDC->TextOut(-5*10,-0.01*300,str2);
str2.Format("%.2f",ex-2*xunit);
pDC->TextOut(-10*10,-0.01*300,str2);
str2.Format("%.2f",ex-len);
pDC->TextOut(-15*10,-0.01*300,str2);
str = "x";
pDC->TextOut(10,-0.05*300,str);
pDC->SelectObject(pOldPen); //恢复画笔
}
UpdateData(FALSE);// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// COneDim_Norm_CloudView printing
BOOL COneDim_Norm_CloudView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void COneDim_Norm_CloudView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void COneDim_Norm_CloudView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// COneDim_Norm_CloudView diagnostics
#ifdef _DEBUG
void COneDim_Norm_CloudView::AssertValid() const
{
CView::AssertValid();
}
void COneDim_Norm_CloudView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
COneDim_Norm_CloudDoc* COneDim_Norm_CloudView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COneDim_Norm_CloudDoc)));
return (COneDim_Norm_CloudDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COneDim_Norm_CloudView message handlers
void COneDim_Norm_CloudView::On1normalcloud()
{
// TODO: Add your command handler code here
m_left = false;
m_normal = true;
m_right = false;
m_FCloud = true;
float Ex,En,He;
long CloudNumber;
OneDimGenDlgN.m_title = "一维正态云模型";
OneDimGenDlgN.m_sgroup = "一维正态云模型参数设置";
OneDimGenDlgN.DoModal();
Ex=OneDimGenDlgN.m_expectation;
En=OneDimGenDlgN.m_entropy;
He=OneDimGenDlgN.m_hentropy;
CloudNumber=OneDimGenDlgN.m_cloudnumber;
BeginWaitCursor();
FCloudGenerator1D(Ex,En,He,CloudNumber);
Invalidate(true);
EndWaitCursor();
}
void COneDim_Norm_CloudView::FCloudGenerator1D(float Ex, float En, float He, long CloudNumber)
{
float Enn,x,y;
srand((unsigned)time(NULL));
CloudPoints.RemoveAll(); //清空Carry类型的点集合
Tempdrop = new _drop[CloudNumber];
for (int i=0;i<CloudNumber;i++)
{
Enn=(float) (sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*He+En;//生成以En为均值,He*He为方差的正态随机数
x=(float)(sqrt(-2*log(rand()*1./RAND_MAX))*cos(2*Pi*rand()*1./RAND_MAX))*Enn+Ex;//生成以Ex为均值,Enn*Enn为方差的正态随机数
y=(float)exp(-(x-Ex)*(x-Ex)/(2*Enn*Enn));//生成随机数x所对应的根据云的数字特征(Ex,En,He)所确定的概念的确定度。
Tempdrop[i].x = x;
Tempdrop[i].y = y;
if(m_normal && x*y!=0)
{
pt.x=(long) (10*x);
pt.y=(long) (300*y);
CloudPoints.Add(pt);
}
if(m_left&&x<OneDimGenDlgL.m_expectation)
{
pt.x=(long) (10*x);
pt.y=(long) (300*y);
CloudPoints.Add(pt);
}
if(m_right&&x>OneDimGenDlgR.m_expectation)
{
pt.x=(long) (10*x);
pt.y=(long) (300*y);
CloudPoints.Add(pt);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -