📄 waveletdlg.cpp
字号:
// WaveletDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Wavelet.h"
#include "WaveletDlg.h"
#include "Splash.h"
#include "Process.h"
#include "DlgIDWT.h"
#include <math.h>
#include <iostream.h>
#include <fstream.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define pi (double)3.14159265359
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWaveletDlg dialog
CWaveletDlg::CWaveletDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWaveletDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWaveletDlg)
m_DataLength = 512;
m_J = 3;
m_Jtmp = 1;
m_mean = 0.0;
m_sigma = 0.01;
lMaxCount=0;
lMaxCount2=0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
INPUTDATA=false;
PAINTAFTERDWT=false;
PAINTCHONGGOU=false;
AFTERDWT=false;
}
void CWaveletDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWaveletDlg)
DDX_Control(pDX, IDC_BUTTON1, m_see1);
DDX_Control(pDX, IDC_BUTTON2, m_see2);
DDX_Control(pDX, IDC_BUTTON3, m_see3);
DDX_Control(pDX, IDC_BUTTON4, m_see4);
DDX_Control(pDX, IDC_BUTTON5, m_see5);
DDX_Control(pDX, IDOK, m_OK);
DDX_Text(pDX, IDC_EDIT4, m_DataLength);
DDX_Text(pDX, IDC_EDIT5, m_J);
DDX_Text(pDX, IDC_EDIT6, m_Jtmp);
DDX_Text(pDX, IDC_EDIT7, m_mean);
DDX_Text(pDX, IDC_EDIT8, m_sigma);
DDX_CBString(pDX, IDC_COMBO1, m_combo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWaveletDlg, CDialog)
//{{AFX_MSG_MAP(CWaveletDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnInputData)
ON_BN_CLICKED(IDC_BUTTON2, OnDWT)
ON_BN_CLICKED(IDC_BUTTON3, OnPaintAfterDWT)
ON_BN_CLICKED(IDC_BUTTON4, OnIDWT)
ON_BN_CLICKED(IDC_BUTTON5, OnInputNoise)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWaveletDlg message handlers
BOOL CWaveletDlg::OnInitDialog()
{
// TODO: Add extra initialization here
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_see1.LoadBitmaps(IDB_BITMAP,5, 5, 5, 5, 4 );
m_see1.SetFontColor( RGB(2,0,0) );
m_see2.LoadBitmaps(IDB_BITMAP,5, 5, 5, 5, 4 );
m_see2.SetFontColor( RGB(2,0,0) );
m_see3.LoadBitmaps(IDB_BITMAP,5, 5, 5, 5, 4 );
m_see3.SetFontColor( RGB(2,0,0) );
m_see4.LoadBitmaps(IDB_BITMAP,5, 5, 5, 5, 4 );
m_see4.SetFontColor( RGB(2,0,0) );
m_see5.LoadBitmaps(IDB_BITMAP,5, 5, 5, 5, 4 );
m_see5.SetFontColor( RGB(2,0,0) );
m_OK.LoadBitmaps(IDB_BITMAP,5, 5, 5, 5, 4 );
m_OK.SetFontColor( RGB(2,0,0) );
m_combo="DAUBECHIES小波" ;
UpdateData(false);
CSplashWnd::EnableSplashScreen();
CSplashWnd::ShowSplashScreen(this);
// ::PlaySound("SplashWindow.wav", NULL, SND_ASYNC | SND_FILENAME);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWaveletDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWaveletDlg::OnPaint()
{
CString str;
// 循环变量
LONG i;
// 最大计数
int lMaxCount = 0;
// 设备上下文
CPaintDC dc(this);
// 获取绘制坐标的文本框
CWnd* pWnd = GetDlgItem(IDC_EDIT1);
// 指针
CDC* pDC = pWnd->GetDC();
pWnd->Invalidate();
pWnd->UpdateWindow();
// 绘制坐标轴
pDC->MoveTo(20,10);
// 垂直轴
pDC->LineTo(20,180);
// 水平轴
pDC->LineTo(580,180);
str.Format("n");
pDC->TextOut(590, 183, str);
str.Format("y");
pDC->TextOut(10, 5, str);
// 绘制X轴箭头
pDC->MoveTo(575,175);
pDC->LineTo(580,180);
pDC->LineTo(575,185);
// 绘制y轴箭头
pDC->MoveTo(20,10);
pDC->LineTo(15,15);
pDC->MoveTo(20,10);
pDC->LineTo(25,15);
if(INPUTDATA==true) PaintInputData(pDC);
//////////////////////////////////////////
// 获取绘制坐标的文本框
CWnd* pWnd2 = GetDlgItem(IDC_EDIT2);
// 指针
CDC* pDC2 = pWnd2->GetDC();
pWnd2->Invalidate();
pWnd2->UpdateWindow();
// 绘制坐标轴
pDC2->MoveTo(20,10);
// 垂直轴
pDC2->LineTo(20,180);
// 水平轴
pDC2->LineTo(580,180);
str.Format("n");
pDC2->TextOut(590, 183, str);
str.Format("y");
pDC2->TextOut(10, 5, str);
// 绘制X轴箭头
pDC2->MoveTo(575,175);
pDC2->LineTo(580,180);
pDC2->LineTo(575,185);
// 绘制y轴箭头
pDC2->MoveTo(20,10);
pDC2->LineTo(15,15);
pDC2->MoveTo(20,10);
pDC2->LineTo(25,15);
//////////////////////////////////////
// 获取绘制坐标的文本框
CWnd* pWnd3 = GetDlgItem(IDC_EDIT3);
// 指针
CDC* pDC3 = pWnd3->GetDC();
pWnd3->Invalidate();
pWnd3->UpdateWindow();
// 绘制坐标轴
pDC3->MoveTo(20,10);
// 3垂直轴
pDC3->LineTo(20,180);
// 水平轴
pDC3->LineTo(580,180);
str.Format("n");
pDC3->TextOut(590, 183, str);
str.Format("y");
pDC3->TextOut(10, 5, str);
// 绘制X轴箭头
pDC3->MoveTo(575,175);
pDC3->LineTo(580,180);
pDC3->LineTo(575,185);
// 绘制y轴箭头
pDC3->MoveTo(20,10);
pDC3->LineTo(15,15);
pDC3->MoveTo(20,10);
pDC3->LineTo(25,15);
if(PAINTAFTERDWT==true) PaintAfterDWT(pDC2, pDC3);
if(PAINTCHONGGOU==true) PaintChonggou(pDC2);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWaveletDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWaveletDlg::OnInputData()
{
UpdateData(true);
DataLength=m_DataLength;
J=m_J;
int i,j,temp,Jtemp;
double f1,f2,fs,freq;
f1=5.0;
f2=10.0;
fs=320.0;
memset(d,0.0,sizeof(double)*SHUZU);
memset(c,0.0,sizeof(double)*SHUZU);
memset(dxianshi,0.0,sizeof(double)*SHUZU);
memset(cxianshi,0.0,sizeof(double)*SHUZU);
/*
for(i=0;i<DataLength/4;i++)
{
c[i]=0.0;
}
for(i=DataLength/4;i<DataLength/2;i++)
{
c[i]=sin(2*pi*i*f2/fs);
}
for(i=DataLength/2;i<DataLength;i++)
{
c[i]=0.0;
}*/
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file to load the data
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal () == IDOK)
{
inputdatafile = dlg.GetPathName ();
}
else
{
return;
}
ifstream istrm;
istrm.open(inputdatafile);
for(i=0;i<DataLength;i++)
{
istrm>>c[i];
}
istrm.close();
for (i=0; i<DataLength; i++)
{
// 判断是否大于当前最大值
if (c[i] > lMaxCount)
{
// 更新最大值
lMaxCount = c[i];
}
}
memcpy(cxianshi,c,sizeof(double)*SHUZU);
memcpy(dxianshi,d,sizeof(double)*SHUZU);
INPUTDATA=true;
PAINTAFTERDWT=false;
PAINTCHONGGOU=false;
OnPaint();
}
void CWaveletDlg::PaintInputData(CDC *pDC)
{
int i,j,k;
int lengthX,lengthY;
int jiangeX,jiangeY;
CString str;
int DataLengthtmp;
//绘制x轴刻度
if(DataLength<100)
{
DataLengthtmp=DataLength-DataLength%10;
lengthX=int( (DataLengthtmp)/10 );
jiangeX=int(540/lengthX);
for (i = 0; i <= lengthX; i ++)
{
pDC->MoveTo(20+i*jiangeX, 180);
pDC->LineTo(20+i*jiangeX, 186);
str.Format("%d",10*i);
pDC->TextOut(20+i*jiangeX, 183, str);
}
}
else
{
DataLengthtmp=DataLength-DataLength%10;
lengthX=int( (DataLengthtmp)/10 );
jiangeX=int(540/lengthX);
for (i = 0; i <= lengthX; i+=5)
{
pDC->MoveTo(20+i*jiangeX, 180);
pDC->LineTo(20+i*jiangeX, 186);
str.Format("%d",10*i);
pDC->TextOut(20+i*jiangeX, 183, str);
}
}
//绘制y轴刻度
lengthY=lMaxCount-(int)lMaxCount%10;
lengthY=int(lMaxCount+10)/10;
jiangeY=(int)(180/lengthY);
for (i = 1; i < lengthY; i+=1)
{
pDC->MoveTo(20, 180-i*jiangeY);
pDC->LineTo(16, 180-i*jiangeY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -