⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagefeaturesview.cpp

📁 A tutorial and open source code for finding edges and corners based on the filters used in primary v
💻 CPP
字号:
// Partially wizard generated code
// ImageFeaturesView.cpp : implementation of the CImageFeaturesView class
//

#include "stdafx.h"
#include "ImageFeatures.h"

#include "ImageFeaturesDoc.h"
#include "ImageFeaturesView.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CImageFeaturesView

IMPLEMENT_DYNCREATE(CImageFeaturesView, CView)

BEGIN_MESSAGE_MAP(CImageFeaturesView, CView)
	//{{AFX_MSG_MAP(CImageFeaturesView)
	ON_WM_ERASEBKGND()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
//	ON_MESSAGE((WM_USER+1), OnBackgroundNotify)
	// 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()

/////////////////////////////////////////////////////////////////////////////
// CImageFeaturesView construction/destruction

CImageFeaturesView::CImageFeaturesView()
{
	// TODO: add construction code here

}

CImageFeaturesView::~CImageFeaturesView()
{
}


/////////////////////////////////////////////////////////////////////////////
// CImageFeaturesView drawing

void CImageFeaturesView::OnDraw(CDC* pDC)
{
	CImageFeaturesDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CVisImageBase& refimage = pDoc->Image();
	
	// UNDONE:  Need an IsValid() test on CVisImageBase.
	assert(refimage.Width() > 0);

	refimage.DisplayInHdc(*pDC);

    // TODO: add draw code for native data here
//	CDefaultImage image = pDoc->GetImage();
//	if ((image.Width() > 0) && (image.Height() > 0))
//	{
//		CRect rectInvalid;
//		pDC->GetClipBox(&rectInvalid);
//		CPoint pt(rectInvalid.left, rectInvalid.top);
//		image.DisplayInHdc(pDC->m_hDC, rectInvalid, pt);
//	}
}

/////////////////////////////////////////////////////////////////////////////
// CImageFeaturesView printing

BOOL CImageFeaturesView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CImageFeaturesView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CImageFeaturesView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CImageFeaturesView diagnostics

#ifdef _DEBUG
void CImageFeaturesView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CImageFeaturesView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CImageFeaturesDoc* CImageFeaturesView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageFeaturesDoc)));
	return (CImageFeaturesDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CImageFeaturesView message handlers
//LONG CImageFeaturesView::OnBackgroundNotify(UINT, LONG )
//{
//	GetDocument()->OnNewImage();
//	return 0;
//}
void CImageFeaturesView::OnInitialUpdate() 
{
	// Need to set the document size.
	// MFC Example says that MM_LOENGLISH is better than MM_TEXT for
	// printing.
	// Note:  We could also add page and line sizes to SetScrollSize.
	CImageFeaturesDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CVisImageBase& refimage = pDoc->Image();
	
	// UNDONE:  Need an IsValid() test on CVisImageBase.
	if (refimage.Width() != 0)
	{
		CSize size(refimage.Size());
		SetScrollSizes(MM_TEXT, size);
		ResizeParentToFit(false);

		// May need to reduce the view's frame window size to make
		// it fit in its parent's client area.
		CFrameWnd* pFrame = GetParentFrame();
		if (pFrame != NULL)
		{
			CRect rectSized;
			pFrame->GetWindowRect(&rectSized);

			CWnd *pParent = pFrame->GetParent();
			if (pParent != 0)
			{
				// May need to adjust rect so that it fits in parent.
				bool fResized = false;

				pParent->ScreenToClient(rectSized);

				CRect rectParent;
				pParent->GetClientRect(&rectParent);

				assert(rectParent.left <= rectSized.left);
				assert(rectParent.top <= rectSized.top);

				if (rectParent.right < rectSized.right)
				{
					rectSized.right = rectParent.right;
					rectSized.bottom += GetSystemMetrics(SM_CYVSCROLL) + 1;
					fResized = true;
				}

				if (rectParent.bottom < rectSized.bottom)
				{
					rectSized.bottom = rectParent.bottom;
					rectSized.right += GetSystemMetrics(SM_CXHSCROLL) + 1;
					if (rectParent.right < rectSized.right)
						rectSized.right = rectParent.right;
					fResized = true;
				}

				if (fResized)
					pFrame->MoveWindow(&rectSized);
			}
		}
	}

	CScrollView::OnInitialUpdate();
	
}


BOOL CImageFeaturesView::OnEraseBkgnd(CDC* pDC) 
{
    // This probably isn't needed if the windows are sized correctly,
	// but it might improve performance a little.
	CBrush br( GetSysColor( COLOR_WINDOW ) ); 
    FillOutsideRect( pDC, &br );
	
	return CScrollView::OnEraseBkgnd(pDC);
}

void CImageFeaturesView::OnMouseMove(UINT nFlags, CPoint point) 
{
	CRect rect;
	GetClientRect(&rect);
	if (rect.PtInRect(point))
	{
		CImageFeaturesDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		CVisImageBase& refimage = pDoc->Image();

		CPoint pointImage = point + GetDeviceScrollPosition();

		if (refimage.Rect().PtInRect(pointImage))
		{
			CMainFrame *pMainFrame = ((CMainFrame *) AfxGetApp()->m_pMainWnd);

			char szValue[256];
			refimage.GetPixelValueString(pointImage, szValue, sizeof(szValue));
	
			CString text;
			text.Format("(%3d, %3d)  -> [%s]",
					pointImage.x, pointImage.y, szValue);

			pMainFrame->SetMessageText(text);
		}
	}
	
	CScrollView::OnMouseMove(nFlags, point);

}


void CImageFeaturesView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	CImageFeaturesApp *pApp = (CImageFeaturesApp *) AfxGetApp();
	ASSERT_VALID(pApp);
	CImageFeaturesDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	CVisImageBase& refimage = pDoc->Image();
	
	// UNDONE:  Need an IsValid() test on CVisImageBase.
	if (refimage.Width() > 0)
	{
		assert(pDC != 0);
		assert(pInfo != 0);

		int w = GetDeviceCaps(*pDC, RASTERCAPS);
		if (((RC_STRETCHDIB & w) != 0)
				&& (pApp->FScaleWhenPrinting()))
		{
			// Scale the image when printing.
			CSize sizeImage(refimage.Size());
			CSize sizePage(pInfo->m_rectDraw.Size());
			CRect rectDest(pInfo->m_rectDraw);

			if (sizeImage.cy * sizePage.cx < sizeImage.cx * sizePage.cy)
			{
				// X-dimensions determine scale
				rectDest.bottom = rectDest.top
						+ sizeImage.cy * sizePage.cx / sizeImage.cx;
			}
			else
			{
				// Y-dimensions determine scale
				rectDest.right = rectDest.left
						+ sizeImage.cx * sizePage.cy / sizeImage.cy;
			}

			rectDest.right = rectDest.left + rectDest.Width()
					* pApp->PercentPrintPage() / 100;
			rectDest.bottom = rectDest.top + rectDest.Height()
					* pApp->PercentPrintPage() / 100;
			
			refimage.DisplayInHdc(*pDC, refimage.Rect(), rectDest);
		}
		else
		{
			// Don't scale when printing.
			refimage.DisplayInHdc(*pDC);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -