?? 小波變換view.cpp
字號:
// 小波變換View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "小波變換.h"
#include "小波變換Doc.h"
#include "小波變換View.h"
#include "dibapi.h"
#include "math.h"
#include "waveletlevel.h"
#include "WaveletCoi.h"
#include "QuantizationDlg.h"
#include "QuantizeColorDlg.h"
#include "HaffmanDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(ID_COMPRESSION, OnCompression)
ON_COMMAND(ID_DISCOMPRESSION, OnDiscompression)
ON_COMMAND(ID_QUANTIZATION, OnQuantization)
ON_COMMAND(ID_DECODING, OnDecoding)
ON_COMMAND(ID_ENCODING, OnEncoding)
ON_COMMAND(ID_WAVELETCONSTRUCTION, OnWaveletconstruction)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
m_nLevel=1;
FWidth=0;
wavefunction=-1;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
BeginWaitCursor();
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// 獲取DIB
HDIB hDIB = pDoc->GetHDIB();
// 判斷DIB是否為空
if (hDIB != NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
// 獲取DIB寬度
int cxDIB = (int) ::DIBWidth(lpDIB);
// 獲取DIB高度
int cyDIB = (int) ::DIBHeight(lpDIB);
::GlobalUnlock((HGLOBAL) hDIB);
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
// 輸出DIB
::PaintDIB(pDC->m_hDC, &rcDIB, pDoc->GetHDIB(),
&rcDIB, pDoc->GetDocPalette());
}
// 恢復正常光標
CRect rect;
GetClientRect(&rect);
int x,y;
y=rect.bottom;
x=rect.right;
pDC->TextOut(x-100,y-100,"低低");
pDC->TextOut(x-100,y-50,"低高");
pDC->MoveTo(x-60,y-100);
pDC->LineTo(x-60,y-35);
pDC->MoveTo(x-100,y-68);
pDC->LineTo(x-20,y-68);
pDC->TextOut(x-50,y-100,"高低");
pDC->TextOut(x-50,y-50,"高高");
CString str;
switch(wavefunction)
{
case 0:
str="Shannon";
break;
case 1:
str="Daubechies";
break;
case 2:
str="Morlet";
break;
case 3:
str="Mexican Hat";
break;
case 4:
str="Meyer";
break;
case 5:
str="B_Spline";
break;
case 6:
str="Symlets";
break;
case 7:
str="Coiflets";
break;
}
CString str2;
str2.Format("選擇的小波是:%s小波",str);
pDC->TextOut(rect.left,y-50,str2);
str.Format("小波支撐集長度是:%d",FWidth);
pDC->TextOut(rect.left,y-25,str);
EndWaitCursor();
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnWaveletconstruction()
{
// TODO: Add your command handler code here
//所謂的構建,其實是已經將數據存入了數組里。
BeginWaitCursor();
CMyDoc* pDoc = GetDocument();
Ld = new double[20]; //分解尺度函數
Hd = new double[20]; //分解母函數
Lr = new double[20]; //重建尺度函數
Hr = new double[20]; //重建母函數
CWaveletCoi waveletcoi;
if(waveletcoi.DoModal()==IDOK)
{
FWidth=waveletcoi.m_waveletlength;
wavefunction=waveletcoi.m_waveletfunction;
switch(wavefunction)
{
case 0://IDC_SHANNON
{
Ld[0]=1/(double)sqrt((double)(2));
Ld[1]=1/(double)sqrt((double)(2));
break;
}
case 1://IDC_DAUBECHIES
{
switch(FWidth)
{
case 2:
Ld[0]=1/(double)sqrt((double)(2)); Ld[1]=1/(double)sqrt((double)(2));
m_wavetransform.m_preoffset=0;
m_wavetransform.m_aftoffset=1;
break;
case 4:
Ld[0]=0.4829629131445341; Ld[1]=0.8365163037378077; Ld[2]=0.2241438680420134;
Ld[3]=-0.1294095225512603;
m_wavetransform.m_preoffset=0;
m_wavetransform.m_aftoffset=3;
break;
case 6:
Ld[0]=0.3326705529500825; Ld[1]=0.8068915093110924; Ld[2]=0.4598775021184914;
Ld[3]=-0.1350110200102546; Ld[4]=-0.0854412738820267; Ld[5]=0.035226218857095;
m_wavetransform.m_preoffset=1;
m_wavetransform.m_aftoffset=4;
break;
case 8:
Ld[0]=0.230377813309; Ld[1]=0.714846570553; Ld[2]=0.630880767930;
Ld[3]=-0.027983769417; Ld[4]=-0.187034811719; Ld[5]=0.030841381836;
Ld[6]=0.032883011667; Ld[7]=-0.010597401785;
m_wavetransform.m_preoffset=1;
m_wavetransform.m_aftoffset=6;
break;
case 10:
Ld[0]=0.160102397974; Ld[1]=0.603829269797; Ld[2]=0.724308528438;
Ld[3]=0.138428145901; Ld[4]=-0.242294887066; Ld[5]=-0.032244869585;
Ld[6]=0.077571493840; Ld[7]=-0.006241490213; Ld[8]=-0.012580751999;
Ld[9]=0.003335725285;
m_wavetransform.m_preoffset=1;
m_wavetransform.m_aftoffset=8;
break;
case 12:
Ld[0]=0.111540743350; Ld[1]=0.494623890398; Ld[2]=0.751133908021;
Ld[3]=0.315250351709; Ld[4]=-0.226264693965; Ld[5]=-0.129766867567;
Ld[6]=0.097501605587; Ld[7]=0.027522865530; Ld[8]=-0.031582039318;
Ld[9]=0.000553842201; Ld[10]=0.004777257511; Ld[11]=-0.001077301085;
m_wavetransform.m_preoffset=1;
m_wavetransform.m_aftoffset=10;
break;
case 14:
Ld[0]=0.077852054085; Ld[1]=0.396539319482; Ld[2]=0.729132090846;
Ld[3]=0.469782287405; Ld[4]=-0.143906003929; Ld[5]=-0.224036184994;
Ld[6]=0.071309219267; Ld[7]=0.080612609151; Ld[8]=-0.038029936935;
Ld[9]=-0.016574541631; Ld[10]=0.012550998556; Ld[11]=0.000429577973;
Ld[12]=-0.001801640704; Ld[13]=0.000353713800;
m_wavetransform.m_preoffset=1;
m_wavetransform.m_aftoffset=12;
break;
case 16:
Ld[0]=0.054415842243; Ld[1]=0.312871590914; Ld[2]=0.675630736297;
Ld[3]=0.585354683654; Ld[4]=-0.015829105256; Ld[5]=-0.284015542962;
Ld[6]=0.000472484574; Ld[7]=0.128747426620; Ld[8]=-0.017369301002;
Ld[9]=-0.044088253931; Ld[10]=0.013981027917; Ld[11]=0.008746094047;
Ld[12]=-0.004870352993; Ld[13]=-0.000391740373; Ld[14]=0.000675449406;
Ld[15]=-0.000117476784;
m_wavetransform.m_preoffset=1;
m_wavetransform.m_aftoffset=14;
break;
case 18:
Ld[0]=0.038077947364; Ld[1]=0.243834674613; Ld[2]=0.604823123690;
Ld[3]=0.657288078051; Ld[4]=0.133197385825; Ld[5]=-0.293273783279;
Ld[6]=-0.096840783223; Ld[7]=0.148540749338; Ld[8]=0.030725681479;
Ld[9]=-0.067632829061; Ld[10]=0.000250947115; Ld[11]=0.022361662124;
Ld[12]=-0.004723204758; Ld[13]=-0.004281503682; Ld[14]=0.001847646883;
Ld[15]=0.000230385764; Ld[16]=-0.000251963189; Ld[17]=0.000039347320;
m_wavetransform.m_preoffset=2;
m_wavetransform.m_aftoffset=15;
break;
case 20:
Ld[0]=0.026670057901; Ld[1]=0.188176800078; Ld[2]=0.527201188932;
Ld[3]=0.688459039454; Ld[4]=0.281172343661; Ld[5]=-0.249846424327;
Ld[6]=-0.195946274377; Ld[7]=0.127369340336; Ld[8]=0.093057364604;
Ld[9]=-0.071394147166; Ld[10]=-0.029457536822; Ld[11]=0.033212674059;
Ld[12]=0.003606553567; Ld[13]=-0.010733175483; Ld[14]=0.001395351747;
Ld[15]=0.001992405295; Ld[16]=-0.000685856695; Ld[17]=-0.000116466855;
Ld[18]=0.000093588670; Ld[19]=-0.000013264203;
m_wavetransform.m_preoffset=2;
m_wavetransform.m_aftoffset=17;
break;
}
}
break;
case 2://IDC_MORLET
break;
case 3://IDC_MEXICANHAT
break;
case 4://IDC_MEYER
break;
case 5://IDC_BSPLINE
break;
case 6://IDC_SYMLETS
{
switch(FWidth)
{
case 8:
Ld[0]=-0.107148901418/(double)sqrt((double)(2)); Ld[1]=-0.041910965126/(double)sqrt((double)(2)); Ld[2]=0.703739068656/(double)sqrt((double)(2));
Ld[3]=1.136658243409/(double)sqrt((double)(2)); Ld[4]=0.421234534204/(double)sqrt((double)(2)); Ld[5]=-0.140317624179/(double)sqrt((double)(2));
Ld[6]=-0.017824701442/(double)sqrt((double)(2)); Ld[7]=0.045570345896/(double)sqrt((double)(2));
m_wavetransform.m_preoffset=3;
m_wavetransform.m_aftoffset=4;
break;
case 10:
Ld[0]=0.038654795955/(double)sqrt((double)(2)); Ld[1]=0.041746864422/(double)sqrt((double)(2)); Ld[2]=-0.055344186117/(double)sqrt((double)(2));
Ld[3]=0.281990696854/(double)sqrt((double)(2)); Ld[4]=1.023052966894/(double)sqrt((double)(2)); Ld[5]=0.896581648380/(double)sqrt((double)(2));
Ld[6]=0.023478923136/(double)sqrt((double)(2)); Ld[7]=-0.247951362613/(double)sqrt((double)(2)); Ld[8]=-0.029842499869/(double)sqrt((double)(2));
Ld[9]=0.027632152958/(double)sqrt((double)(2));
m_wavetransform.m_preoffset=4;
m_wavetransform.m_aftoffset=5;
break;
case 12:
Ld[0]=0.021784700327/(double)sqrt((double)(2)); Ld[1]=0.004936612372/(double)sqrt((double)(2)); Ld[2]=-0.166863215412/(double)sqrt((double)(2));
Ld[3]=-0.068323121587/(double)sqrt((double)(2)); Ld[4]=0.0694457972958/(double)sqrt((double)(2)); Ld[5]=1.113892783926/(double)sqrt((double)(2));
Ld[6]=0.477904371333/(double)sqrt((double)(2)); Ld[7]=-0.102724969862/(double)sqrt((double)(2)); Ld[8]=-0.029783751299/(double)sqrt((double)(2));
Ld[9]=0.063250562660/(double)sqrt((double)(2)); Ld[10]=0.002499922093/(double)sqrt((double)(2)); Ld[11]=-0.011031867509/(double)sqrt((double)(2));
m_wavetransform.m_preoffset=5;
m_wavetransform.m_aftoffset=6;
break;
case 14:
Ld[0]=0.003792658534/(double)sqrt((double)(2)); Ld[1]=-0.001481225915/(double)sqrt((double)(2)); Ld[2]=-0.017870431651/(double)sqrt((double)(2));
Ld[3]=0.043155452582/(double)sqrt((double)(2)); Ld[4]=0.096014767936/(double)sqrt((double)(2)); Ld[5]=-0.070078291222/(double)sqrt((double)(2));
Ld[6]=0.024665659489/(double)sqrt((double)(2)); Ld[7]=0.758162601964/(double)sqrt((double)(2)); Ld[8]=1.085782709814/(double)sqrt((double)(2));
Ld[9]=0.408183939725/(double)sqrt((double)(2)); Ld[10]=-0.198056706807/(double)sqrt((double)(2)); Ld[11]=-0.152463872896/(double)sqrt((double)(2));
Ld[12]=0.005671342686/(double)sqrt((double)(2)); Ld[13]=0.014521394762/(double)sqrt((double)(2));
m_wavetransform.m_preoffset=7;
m_wavetransform.m_aftoffset=6;
break;
case 16:
Ld[0]=0.002672793393/(double)sqrt((double)(2)); Ld[1]=-0.000428394300/(double)sqrt((double)(2)); Ld[2]=-0.021145686528/(double)sqrt((double)(2));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -