matcherView.cpp
资源名称:matcher.rar [点击查看]
上传用户:quan1896
上传日期:2013-04-17
资源大小:94k
文件大小:11k
源码类别:
2D图形编程
开发平台:
Visual C++
- // matcherView.cpp : implementation of the CMatcherView class
- //
- #include "stdafx.h"
- #include "matcher.h"
- #include "MyOpenCV.h"
- #include "matcherDoc.h"
- #include "matcherView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMatcherView
- IMPLEMENT_DYNCREATE(CMatcherView, CScrollView)
- BEGIN_MESSAGE_MAP(CMatcherView, CScrollView)
- //{{AFX_MSG_MAP(CMatcherView)
- ON_WM_MOUSEMOVE()
- ON_WM_CONTEXTMENU()
- ON_COMMAND(ID_DELETE, OnDelete)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMatcherView construction/destruction
- CMatcherView::CMatcherView()
- {
- // TODO: add construction code here
- //已转移至OnUpdate中
- // m_frame1.Create(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),24);
- LastHitIndex=-1;
- }
- CMatcherView::~CMatcherView()
- {
- }
- BOOL CMatcherView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CScrollView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMatcherView drawing
- void CMatcherView::OnDraw(CDC* pDC)
- {
- CMatcherDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- m_frame1.Show(pDC->GetSafeHdc(),0,0,pDoc->m_imgsize1.width,pDoc->m_imgsize1.height,0,0);
- ReleaseDC(pDC);
- }
- void CMatcherView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMatcherView printing
- BOOL CMatcherView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMatcherView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMatcherView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMatcherView diagnostics
- #ifdef _DEBUG
- void CMatcherView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CMatcherView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CMatcherDoc* CMatcherView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMatcherDoc)));
- return (CMatcherDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMatcherView message handlers
- //Called by the framework after the view’s document has been modified;
- // this function is called by CDocument::UpdateAllViews
- void CMatcherView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // TODO: Add your specialized code here and/or call the base class
- CMatcherDoc* pDoc = GetDocument();
- //使Scrollbar符合图像大小
- if(pDoc->IMG1OPEN)
- SetScrollSizes(MM_TEXT,CSize(pDoc->m_imgsize1.width,pDoc->m_imgsize1.height));
- //保证每次创建的显示图像内存大小与待打开图像大小一致
- m_frame1.Create(pDoc->m_imgsize1.width,pDoc->m_imgsize1.height,24);
- //填充显示图像内存区域
- if(pDoc->IMG1OPEN)
- {
- ShownImage1=m_frame1.GetImage();
- cvSetImageROI(ShownImage1,cvRect(0,0,pDoc->m_imgsize1.width,pDoc->m_imgsize1.height));
- cvCopy(pDoc->showImg1,ShownImage1);
- Invalidate(FALSE);
- }
- }
- //创建浮动弹出菜单(用于删除匹配点对)
- void CMatcherView::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- // TODO: Add your message handler code here
- if(LastHitIndex!=-1)
- {
- CMenu menu;
- menu.LoadMenu(IDR_POPUP);
- menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
- point.x,point.y,this);
- }
- }
- //相应弹出菜单-删除选择的匹配点对
- void CMatcherView::OnDelete()
- {
- // TODO: Add your command handler code here
- CMatcherDoc* pDoc = GetDocument();
- if(LastHitIndex!=-1)
- {
- //改变删除匹配点对颜色
- int x1,y1,x2,y2;
- x1=cvRound(pDoc->Fmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Fmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Fmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Fmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(0,0,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(0,0,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(0,0,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(0,0,0),1,0);
- //在状态输出窗口2显示信息
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;//得到主窗口指针
- CString strText;
- strText.Format(">>NO.%d->(%f,%f)-----Deleted !",
- LastHitIndex,pDoc->Fmatches1[LastHitIndex].x,
- pDoc->Fmatches1[LastHitIndex].y);
- pFrame->m_wndOutput2.m_ListCtrl.DeleteItem(0);
- pFrame->m_wndOutput2.m_ListCtrl.InsertItem(0,strText);
- //删除选择的匹配点对
- pDoc->Fmatches1[LastHitIndex]=pDoc->Fmatches1[pDoc->nFmatches];
- pDoc->Fmatches2[LastHitIndex]=pDoc->Fmatches2[pDoc->nFmatches];
- pDoc->nFmatches--;
- pDoc->UpdateAllViews(NULL);
- }
- }
- //手工删除或添加匹配点对
- void CMatcherView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- //在状态栏显示鼠标坐标
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- CStatusBar* PStatus=&pFrame->m_wndStatusBar;
- CString statusmessage;
- statusmessage.Format("X: %d ; Y: %d ",point.x,point.y);
- PStatus->SetPaneText(1,statusmessage);
- CMatcherDoc* pDoc = GetDocument();
- if((pDoc->RANSACDONE||pDoc->GUIMATDONE)&&pDoc->ENMANUALDEL)
- {
- //以下基于Fmatches和Gmatches的代码分开写,是以代码量换速度
- //基于Fmatches------------------------------------------------------------------
- if(pDoc->RANSACDONE&&!pDoc->GUIMATDONE&&pDoc->ManParPage.m_ManDelBase==0)
- {
- for(int i=0;i<pDoc->nFmatches;i++)
- {
- CRect rect;
- rect.left =(long)pDoc->Fmatches1[i].x-2;
- rect.right=(long)pDoc->Fmatches1[i].x+2;
- rect.top=(long)pDoc->Fmatches1[i].y-2;
- rect.bottom=(long)pDoc->Fmatches1[i].y+2;
- if(rect.PtInRect(point)&&(LastHitIndex!=i))
- {
- //改变击中角点及连线颜色
- int x1,y1,x2,y2;
- if(LastHitIndex==-1)
- {
- LastHitIndex=i;
- x1=cvRound(pDoc->Fmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Fmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Fmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Fmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- }
- else
- {
- x1=cvRound(pDoc->Fmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Fmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Fmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Fmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(0,255,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,255,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(0,255,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,255,0),1,0);
- LastHitIndex=i;
- x1=cvRound(pDoc->Fmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Fmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Fmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Fmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- }
- pDoc->UpdateAllViews(NULL);
- //在输出窗口2显示状态信息
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;//得到主窗口指针
- CString strText;
- strText.Format(">>NO.%d->(%f,%f)",i,pDoc->Fmatches1[i].x,pDoc->Fmatches1[i].y);
- pFrame->m_wndOutput2.m_ListCtrl.InsertItem(0,strText);
- }
- }
- }
- //基于Gmatches------------------------------------------------------------------
- else if(pDoc->GUIMATDONE&&pDoc->ManParPage.m_ManDelBase==1)
- {
- for(int i=0;i<pDoc->nGmatches;i++)
- {
- CRect rect;
- rect.left =(long)pDoc->Gmatches1[i].x-2;
- rect.right=(long)pDoc->Gmatches1[i].x+2;
- rect.top=(long)pDoc->Gmatches1[i].y-2;
- rect.bottom=(long)pDoc->Gmatches1[i].y+2;
- if(rect.PtInRect(point)&&(LastHitIndex!=i))
- {
- //改变击中角点及连线颜色
- int x1,y1,x2,y2;
- if(LastHitIndex==-1)
- {
- LastHitIndex=i;
- x1=cvRound(pDoc->Gmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Gmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Gmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Gmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- }
- else
- {
- x1=cvRound(pDoc->Gmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Gmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Gmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Gmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(0,255,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,255,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(0,255,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,255,0),1,0);
- LastHitIndex=i;
- x1=cvRound(pDoc->Gmatches1[LastHitIndex].x);
- y1=cvRound(pDoc->Gmatches1[LastHitIndex].y);
- x2=cvRound(pDoc->Gmatches2[LastHitIndex].x);
- y2=cvRound(pDoc->Gmatches2[LastHitIndex].y);
- //view1
- quPlotCross(pDoc->showImg1,cvPoint(x1,y1),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg1,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- //view2
- quPlotCross(pDoc->showImg2,cvPoint(x2,y2),CV_RGB(255,0,0),1,4);
- cvLine(pDoc->showImg2,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(255,0,0),1,0);
- }
- pDoc->UpdateAllViews(NULL);
- //在输出窗口2显示状态信息
- CMainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;//得到主窗口指针
- CString strText;
- strText.Format(">>NO.%d->(%f,%f)",i,pDoc->Gmatches1[i].x,pDoc->Gmatches1[i].y);
- pFrame->m_wndOutput2.m_ListCtrl.InsertItem(0,strText);
- }
- }
- }
- }
- CScrollView::OnMouseMove(nFlags, point);
- }