/MycvProject/MycvProjectDoc.cpp

https://bitbucket.org/skyline75489/mycvproject · C++ · 186 lines · 120 code · 42 blank · 24 comment · 11 complexity · 3a0068caedd9582ca763cd6e9fab5625 MD5 · raw file

  1. // MycvProjectDoc.cpp : CMycvProjectDoc ÀàµÄʵÏÖ
  2. //
  3. #include "stdafx.h"
  4. // SHARED_HANDLERS ¿ÉÒÔÔÚʵÏÖÔ¤ÀÀ¡¢ËõÂÔͼºÍËÑË÷ɸѡÆ÷¾ä±úµÄ
  5. // ATL ÏîÄ¿ÖнøÐж¨Ò壬²¢ÔÊÐíÓë¸ÃÏîÄ¿¹²ÏíÎĵµ´úÂë¡£
  6. #ifndef SHARED_HANDLERS
  7. #include "MycvProject.h"
  8. #endif
  9. #include "MycvProjectDoc.h"
  10. #include <propkey.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #endif
  14. // CMycvProjectDoc
  15. IMPLEMENT_DYNCREATE(CMycvProjectDoc, CDocument)
  16. BEGIN_MESSAGE_MAP(CMycvProjectDoc, CDocument)
  17. END_MESSAGE_MAP()
  18. // CMycvProjectDoc ¹¹Ôì/Îö¹¹
  19. CMycvProjectDoc::CMycvProjectDoc()
  20. {
  21. // TODO: ÔÚ´ËÌí¼ÓÒ»´ÎÐÔ¹¹Ôì´úÂë
  22. pImg=NULL;
  23. m_Display=-1;
  24. }
  25. CMycvProjectDoc::~CMycvProjectDoc()
  26. {
  27. if (pImg)
  28. cvReleaseImage(&pImg);
  29. }
  30. BOOL CMycvProjectDoc::OnNewDocument()
  31. {
  32. if (!CDocument::OnNewDocument())
  33. return FALSE;
  34. // TODO: ÔÚ´ËÌí¼ÓÖØÐ³õʼ»¯´úÂë
  35. // (SDI Îĵµ½«ÖØÓøÃÎĵµ)
  36. return TRUE;
  37. }
  38. // CMycvProjectDoc ÐòÁл¯
  39. void CMycvProjectDoc::Serialize(CArchive& ar)
  40. {
  41. if (ar.IsStoring())
  42. {
  43. // TODO: ÔÚ´ËÌí¼Ó´æ´¢´úÂë
  44. }
  45. else
  46. {
  47. // TODO: ÔÚ´ËÌí¼Ó¼ÓÔØ´úÂë
  48. }
  49. }
  50. #ifdef SHARED_HANDLERS
  51. // ËõÂÔͼµÄÖ§³Ö
  52. void CMycvProjectDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
  53. {
  54. // Ð޸Ĵ˴úÂëÒÔ»æÖÆÎĵµÊý¾Ý
  55. dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
  56. CString strText = _T("TODO: implement thumbnail drawing here");
  57. LOGFONT lf;
  58. CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
  59. pDefaultGUIFont->GetLogFont(&lf);
  60. lf.lfHeight = 36;
  61. CFont fontDraw;
  62. fontDraw.CreateFontIndirect(&lf);
  63. CFont* pOldFont = dc.SelectObject(&fontDraw);
  64. dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
  65. dc.SelectObject(pOldFont);
  66. }
  67. // ËÑË÷´¦Àí³ÌÐòµÄÖ§³Ö
  68. void CMycvProjectDoc::InitializeSearchContent()
  69. {
  70. CString strSearchContent;
  71. // ´ÓÎĵµÊý¾ÝÉèÖÃËÑË÷ÄÚÈÝ¡£
  72. // ÄÚÈݲ¿·ÖÓ¦ÓÉ¡°;¡±·Ö¸ô
  73. // ÀýÈç: strSearchContent = _T("point;rectangle;circle;ole object;")£»
  74. SetSearchContent(strSearchContent);
  75. }
  76. void CMycvProjectDoc::SetSearchContent(const CString& value)
  77. {
  78. if (value.IsEmpty())
  79. {
  80. RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
  81. }
  82. else
  83. {
  84. CMFCFilterChunkValueImpl *pChunk = NULL;
  85. ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
  86. if (pChunk != NULL)
  87. {
  88. pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
  89. SetChunkValue(pChunk);
  90. }
  91. }
  92. }
  93. #endif // SHARED_HANDLERS
  94. // CMycvProjectDoc Õï¶Ï
  95. #ifdef _DEBUG
  96. void CMycvProjectDoc::AssertValid() const
  97. {
  98. CDocument::AssertValid();
  99. }
  100. void CMycvProjectDoc::Dump(CDumpContext& dc) const
  101. {
  102. CDocument::Dump(dc);
  103. }
  104. #endif //_DEBUG
  105. // CMycvProjectDoc ÃüÁî
  106. BOOL CMycvProjectDoc::OnOpenDocument(LPCTSTR lpszPathName)
  107. {
  108. if (!CDocument::OnOpenDocument(lpszPathName))
  109. return FALSE;
  110. // TODO: Add your specialized creation code here
  111. BOOL boolean;
  112. Load(&pImg,lpszPathName);
  113. if (pImg!=NULL)
  114. boolean=true;
  115. else
  116. boolean=false;
  117. return(boolean);
  118. }
  119. //---------------------------------------------------------
  120. //---------------------------------------------------------
  121. // ImageIO
  122. BOOL CMycvProjectDoc::Load(IplImage** pp,LPCTSTR csFileName)
  123. {
  124. IplImage* pImg=NULL;
  125. pImg = cvLoadImage(csFileName,-1); // ¶ÁͼÏñÎļþ(DSCV)
  126. if (!pImg){
  127. AfxMessageBox("´ò¿ªÍ¼Ïñʧ°Ü£¬Çë¼ì²éͼÏñ¸ñʽºÍ·¾¶ÊÇ·ñÕýÈ·");
  128. return(false);
  129. }
  130. cvFlip(pImg); // Óë DIB ÏñËØ½á¹¹Ò»ÖÂ
  131. if (*pp) {
  132. cvReleaseImage(pp);
  133. }
  134. (*pp)=pImg;
  135. m_Display=0;
  136. return(true);
  137. }
  138. BOOL CMycvProjectDoc::Save(LPCTSTR csFileName,IplImage* pImg)
  139. {
  140. int bl;
  141. cvFlip(pImg); // »Ö¸´Ô­ OpenCV λͼ½á¹¹
  142. bl=cvSaveImage(csFileName,pImg); // ͼÏñ´æÅÌ
  143. return(bl);
  144. }