WaveletCoi.cpp
上传用户:aqingfeng
上传日期:2014-03-25
资源大小:1839k
文件大小:6k
源码类别:

波变换

开发平台:

Visual C++

  1. // WaveletCoi.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "小波变换.h"
  5. #include "WaveletCoi.h"
  6. #include "math.h"
  7. #include "Daubechiesdlg.h"
  8. #include "Symletsdlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. const double pi=3.1415926535;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CWaveletCoi dialog
  17. CWaveletCoi::CWaveletCoi(CWnd* pParent /*=NULL*/)
  18. : CDialog(CWaveletCoi::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(CWaveletCoi)
  21. m_waveletfunction = -1;
  22. m_waveletlength = 0;
  23. //}}AFX_DATA_INIT
  24. }
  25. void CWaveletCoi::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CWaveletCoi)
  29. DDX_Radio(pDX, IDC_SHANNON, m_waveletfunction);
  30. DDX_Text(pDX, IDC_WAVELETLENGTH, m_waveletlength);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CWaveletCoi, CDialog)
  34. //{{AFX_MSG_MAP(CWaveletCoi)
  35. ON_WM_PAINT()
  36. ON_BN_CLICKED(IDC_DAUBECHIES, OnDaubechies)
  37. ON_BN_CLICKED(IDC_MORLET, OnMorlet)
  38. ON_BN_CLICKED(IDC_MEXICANHAT, OnMexicanhat)
  39. ON_BN_CLICKED(IDC_MEYER, OnMeyer)
  40. ON_BN_CLICKED(IDC_BSPLINE, OnBspline)
  41. ON_BN_CLICKED(IDC_SYMLETS, OnSymlets)
  42. ON_BN_CLICKED(IDC_COIFLETS, OnCoiflets)
  43. ON_BN_CLICKED(IDC_SHANNON, OnShannon)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CWaveletCoi message handlers
  48. BOOL CWaveletCoi::OnInitDialog() 
  49. {
  50. CDialog::OnInitDialog();
  51. // TODO: Add extra initialization here
  52. GetDlgItem(IDC_FUNCTIONIMAGE)->GetWindowRect(&m_prectfunction);
  53. ScreenToClient(&m_prectfunction);
  54. return TRUE;  // return TRUE unless you set the focus to a control
  55.               // EXCEPTION: OCX Property Pages should return FALSE
  56. }
  57. void CWaveletCoi::OnShannon() 
  58. {
  59. // TODO: Add your control notification handler code here
  60. if(IsDlgButtonChecked(IDC_SHANNON))
  61. {
  62. m_bitmap.LoadBitmap(IDB_SHANNON);
  63. m_strlength="0000";
  64. InvalidateRect(&m_prectfunction);
  65. UpdateWindow();
  66. }
  67. }
  68. void CWaveletCoi::OnDaubechies() 
  69. {
  70. // TODO: Add your control notification handler code here
  71. if(IsDlgButtonChecked(IDC_DAUBECHIES))
  72. {
  73. CDaubechiesdlg daudlg;
  74. if(daudlg.DoModal()==IDOK)
  75. {
  76. int i;
  77. i=daudlg.m_nlength;
  78. switch(i)
  79. {
  80. case 1:
  81. m_bitmap.LoadBitmap(IDB_DAUBECHIES1);
  82. break;
  83. case 4:
  84. m_bitmap.LoadBitmap(IDB_DAUBECHIES4);
  85. break;
  86. case 6:
  87. m_bitmap.LoadBitmap(IDB_DAUBECHIES6);
  88. break;
  89. case 8:
  90. m_bitmap.LoadBitmap(IDB_DAUBECHIES8);
  91. break;
  92. default:
  93. m_bitmap.LoadBitmap(IDB_DAUBECHIES);
  94. break;
  95. }
  96. m_strlength.Format("%d",2*i);
  97. InvalidateRect(&m_prectfunction);
  98. UpdateWindow();
  99. }
  100. }
  101. }
  102. void CWaveletCoi::OnMorlet() 
  103. {
  104. // TODO: Add your control notification handler code here
  105. if(IsDlgButtonChecked(IDC_MORLET))
  106. {
  107. m_bitmap.LoadBitmap(IDB_MORLET);
  108. m_strlength="0000";
  109. InvalidateRect(&m_prectfunction);
  110. UpdateWindow();
  111. }
  112. }
  113. void CWaveletCoi::OnMexicanhat() 
  114. {
  115. // TODO: Add your control notification handler code here
  116. if(IsDlgButtonChecked(IDC_MEXICANHAT))
  117. {
  118. m_bitmap.LoadBitmap(IDB_MEXICANHAT);
  119. m_strlength="0000";
  120. InvalidateRect(&m_prectfunction);
  121. UpdateWindow();
  122. }
  123. }
  124. void CWaveletCoi::OnMeyer() 
  125. {
  126. // TODO: Add your control notification handler code here
  127. if(IsDlgButtonChecked(IDC_MEYER))
  128. {
  129. m_bitmap.LoadBitmap(IDB_MEYER);
  130. m_strlength="0000";
  131. InvalidateRect(&m_prectfunction);
  132. UpdateWindow();
  133. }
  134. }
  135. void CWaveletCoi::OnBspline() 
  136. {
  137. // TODO: Add your control notification handler code here
  138. if(IsDlgButtonChecked(IDC_BSPLINE))
  139. {
  140. m_bitmap.LoadBitmap(IDB_BSPLINE);
  141. m_strlength="0000";
  142. InvalidateRect(&m_prectfunction);
  143. UpdateWindow();
  144. }
  145. }
  146. void CWaveletCoi::OnSymlets() 
  147. {
  148. // TODO: Add your control notification handler code here
  149. if(IsDlgButtonChecked(IDC_SYMLETS))
  150. {
  151. CSymletsdlg symdlg;
  152. if(symdlg.DoModal()==IDOK)
  153. {
  154. int i;
  155. i=symdlg.m_symlength;
  156. switch(i)
  157. {
  158. case 4:
  159. m_bitmap.LoadBitmap(IDB_SYMLETS4);
  160. break;
  161. case 6:
  162. m_bitmap.LoadBitmap(IDB_SYMLETS6);
  163. break;
  164. case 8:
  165. m_bitmap.LoadBitmap(IDB_SYMLETS8);
  166. break;
  167. default:
  168. m_bitmap.LoadBitmap(IDB_SYMLETS);
  169. break;
  170. }
  171. m_strlength.Format("%d",i*2);
  172. InvalidateRect(&m_prectfunction);
  173. UpdateWindow();
  174. }
  175. }
  176. }
  177. void CWaveletCoi::OnCoiflets() 
  178. {
  179. // TODO: Add your control notification handler code here
  180. if(IsDlgButtonChecked(IDC_COIFLETS))
  181. {
  182. m_bitmap.LoadBitmap(IDB_COIFLETS);
  183. m_strlength="8";
  184. InvalidateRect(&m_prectfunction);
  185. UpdateWindow();
  186. }
  187. }
  188. void CWaveletCoi::OnPaint() 
  189. {
  190. CPaintDC dc(this); // device context for painting
  191. // TODO: Add your message handler code here
  192. UpdateData(TRUE);
  193. if((m_waveletfunction>=0)&&(m_waveletfunction<=7))
  194. {
  195. CDC dcmem;
  196. dcmem.CreateCompatibleDC(&dc);
  197. BITMAP bmp;
  198. m_bitmap.GetBitmap(&bmp);
  199. dcmem.SelectObject(m_bitmap);
  200. double h,v;
  201. h=double(bmp.bmWidth)/double(m_prectfunction.Width());
  202. v=double(bmp.bmHeight)/double(m_prectfunction.Height());
  203. if((h<=1)&&(v<=1))
  204. {
  205. dc.BitBlt(m_prectfunction.left+(m_prectfunction.Width()-bmp.bmWidth)/2,
  206. m_prectfunction.top+(m_prectfunction.Height()-bmp.bmHeight)/2,
  207. bmp.bmWidth,bmp.bmHeight,&dcmem,0,0,SRCCOPY);
  208. }
  209. else 
  210. {
  211. if(h>v)
  212. dc.StretchBlt(m_prectfunction.left,
  213. m_prectfunction.top+int(m_prectfunction.Height()-bmp.bmHeight/h)/2,
  214. m_prectfunction.Width(),int(bmp.bmHeight/h),
  215. &dcmem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
  216. else
  217. dc.StretchBlt(m_prectfunction.left+int(m_prectfunction.Width()-bmp.bmWidth/v)/2,
  218. m_prectfunction.top,
  219. int(bmp.bmWidth/v),m_prectfunction.Height(),
  220. &dcmem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
  221. }
  222. GetDlgItem(IDC_WAVELETLENGTH)->SetWindowText(m_strlength);
  223. GetDlgItem(IDOK)->EnableWindow(TRUE);
  224. m_bitmap.DeleteObject();
  225. }
  226. // Do not call CDialog::OnPaint() for painting messages
  227. }