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

📄 myfusionview.cpp

📁 影像融合与融合精度评价源码影像融合与融合精度评价源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	case 4:
		title+=_T("% (8位索引色)");
		break;
	case 5:
		title+=_T("% (灰度)");
		break;
	case 6:
		title+=_T("% (16位真彩色)");
		break;
	case 7:
		title+=_T("% (24位真彩色)");
		break;
	case 8:
		title+=_T("% (32位真彩色)");
		break;
	case 9:
		CString ColorModalTmp;
		ColorModalTmp.Format(" (%d位索引色包含%d个颜色数)",pDoc->BitsPerPixel,pDoc->ColorNum);
		title+=_T("%");
		title+=ColorModalTmp;
		break;
	}
	
	pDoc->SetTitle(title);
	return TRUE;
}

void CMYFUSIONView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	if (bActivate)
	{
		ASSERT(pActivateView == this);
		OnDoRealize((WPARAM)m_hWnd, 0);   // same as SendMessage(WM_DOREALIZE);
	}
	
	
	//TRUE OR FALSE 控制关闭视时浏览对话框中是否显示图象
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	pAppFrame->NavigationDialog->bpbmpChanged=TRUE;
	pAppFrame->NavigationDialog->PostMessage(WM_REDRAWDISPLAYRECT);
	
	CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
LRESULT CMYFUSIONView::OnDoRealize(WPARAM wParam, LPARAM)
{
	ASSERT(wParam != NULL);
	CMYFUSIONDoc* pDoc = GetDocument();
	if (pDoc->GetHDIB() == NULL)
		return 0L;  // must be a new document
	
	CPalette* pPal = pDoc->GetDocPalette();
	if (pPal != NULL)
	{
		CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
		ASSERT_KINDOF(CMainFrame, pAppFrame);
		
		CClientDC appDC(pAppFrame);
		// All views but one should be a background palette.
		// wParam contains a handle to the active view, so the SelectPalette
		// bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
		CPalette* oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
		
		if (oldPalette != NULL)
		{
			UINT nColorsChanged = appDC.RealizePalette();
			if (nColorsChanged > 0)
				pDoc->UpdateAllViews(NULL);
			appDC.SelectPalette(oldPalette, TRUE);
		}
		else
		{
			TRACE0("\tSelectPalette failed in CMYFUSIONView::OnPaletteChanged\n");
		}
	}
	
	return 0L;
}

void CMYFUSIONView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	CRect client;
	GetClientRect(client);
	
	float	MoveZoom = m_Zoom;
	
	// Determine the new position of scroll box.
	switch (nSBCode)
	{
	case SB_LEFT:      // Scroll to far left.
		break;
		
	case SB_RIGHT:      // Scroll to far right.
		break;
		
	case SB_ENDSCROLL:   // End scroll.
		break;
		
	case SB_LINELEFT:      // Scroll left. 16 screen point
		ptDIBOff.x = ptDIBOff.x - (int)(16./MoveZoom+0.5);
		break;
		
	case SB_LINERIGHT:   // Scroll right. 16 screen point
		ptDIBOff.x = ptDIBOff.x + (int)(16./MoveZoom+0.5);
		break;
		
	case SB_PAGELEFT:    // Scroll one page left. 1 screen content
		ptDIBOff.x = ptDIBOff.x - (int)(client.Width()/MoveZoom+0.5);
		break;
		
	case SB_PAGERIGHT:      // Scroll one page right. 1 screen content
		ptDIBOff.x = ptDIBOff.x + (int)(client.Width()/MoveZoom+0.5);
		break;
		
	case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
		// of the scroll box at the end of the drag operation.
		{
			SCROLLINFO   info;
			GetScrollInfo(SB_HORZ,&info, SIF_ALL);
			
			ptDIBOff.x = (int)( (double)info.nPos / MoveZoom  +0.5);
		}
		break;
	case SB_THUMBTRACK:		// Drag scroll box to specified position. nPos is the
		// position that the scroll box has been dragged to.
		{
			SCROLLINFO   info;
			GetScrollInfo(SB_HORZ,&info, SIF_ALL);
			
			ptDIBOff.x = (int)( (double)info.nTrackPos / MoveZoom  +0.5);
		}
		break;
	}
	
	if((int)Width - ptDIBOff.x < (int) ( (double)client.Width() / MoveZoom + 0.5))
		ptDIBOff.x = Width - (int) ( (double)client.Width() / MoveZoom + 0.5);
	if(ptDIBOff.x<0) ptDIBOff.x=0;
	SetScrollPos(SB_HORZ,(int)(ptDIBOff.x*MoveZoom+0.5),TRUE);	
	
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	pAppFrame->NavigationDialog->PostMessage(WM_REDRAWDISPLAYRECT);
	
	bpbmpChanged=TRUE;
	RedrawViewRect();
}

void CMYFUSIONView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	CRect client;
	GetClientRect(client);
	
	float	MoveZoom= m_Zoom;
	
	// Determine the new position of scroll box.
	switch (nSBCode)
	{
	case SB_TOP:      // Scroll to far top.
		break;
		
	case SB_BOTTOM:      // Scroll to far bottom.
		break;
		
	case SB_ENDSCROLL:   // End scroll.
		break;
		
	case SB_LINEUP:      // Scroll up. 16 screen point
		ptDIBOff.y = ptDIBOff.y - (int)(16./MoveZoom+0.5);
		break;
		
	case SB_LINEDOWN:   // Scroll down. 16 screen point
		ptDIBOff.y = ptDIBOff.y + (int)(16./MoveZoom+0.5);
		break;
		
	case SB_PAGEUP:    // Scroll one page up. 1 screen content
		ptDIBOff.y = ptDIBOff.y - (int)(client.Width()/MoveZoom+0.5);
		break;
		
	case SB_PAGEDOWN:      // Scroll one page down. 1 screen content
		ptDIBOff.y = ptDIBOff.y + (int)(client.Width()/MoveZoom+0.5);
		break;
		
	case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
		// of the scroll box at the end of the drag operation.
		{
			SCROLLINFO   info;
			GetScrollInfo(SB_VERT,&info, SIF_ALL);
			
			ptDIBOff.y = (int)( (double)info.nPos  / MoveZoom  +0.5);
		}
		break;
	case SB_THUMBTRACK:		// Drag scroll box to specified position. nPos is the
		// position that the scroll box has been dragged to.
		{
			SCROLLINFO   info;
			GetScrollInfo(SB_VERT,&info, SIF_ALL);
			
			ptDIBOff.y = (int)( (double)info.nTrackPos  / MoveZoom  +0.5);
		}
		break;
	}
	
	if((int)Height - ptDIBOff.y < (int) ( (double)client.Height() / MoveZoom + 0.5))
		ptDIBOff.y = Height - (int) ( (double)client.Height() / MoveZoom + 0.5);
	if(ptDIBOff.y<0) ptDIBOff.y=0;
	SetScrollPos(SB_VERT,(int)(ptDIBOff.y*MoveZoom+0.5),TRUE);	
	
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	pAppFrame->NavigationDialog->PostMessage(WM_REDRAWDISPLAYRECT);
	
	bpbmpChanged=TRUE;
	RedrawViewRect();
}

void CMYFUSIONView::OnMouseMove(UINT nFlags, CPoint point) 
{
	//Zoomin Window
	double	xZoom,yZoom;
	xZoom = (double)rcDest.Width()/(double)rcDIB.Width();
	yZoom = (double)rcDest.Height()/(double)rcDIB.Height();
	double lfptDIBOffx,lfptDIBOffy;	//鼠标点在当前图象上的位置	
	CPoint  ShowPoint;              //检索像素的位置
	lfptDIBOffx = ptDIBOff.x + (point.x-xOffDisplay-(int)(xZoom/2))/xZoom;
	lfptDIBOffy = ptDIBOff.y + (point.y-yOffDisplay-(int)(yZoom/2))/yZoom;
	ShowPoint.x = (int)(lfptDIBOffx+0.5);
	ShowPoint.y = (int)(lfptDIBOffy+0.5);		
	if(ShowPoint.x >= 0 && ShowPoint.y >= 0 && ShowPoint.y<(int)Height && ShowPoint.x<(int)Width)
	{
		CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
		ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
		pAppFrame->ZoomInDlg->pView=this;
		pAppFrame->ZoomInDlg->bpbmpChanged=TRUE;
		pAppFrame->ZoomInDlg->bIndest=FALSE;
		pAppFrame->ZoomInDlg->DIBInMid=ShowPoint;
		pAppFrame->ZoomInDlg->PostMessage(WM_REDRAWZOOMIN);
		
		if(NormalStatus==IMAGE_MEASURE)
			pAppFrame->ZoomInDlg->bMoveWithMouse=FALSE;//!(pAppFrame->ZoomInDlg->bMoveWithMouse);
	}	

    SetCursor(m_HCursor);
	  if(m_Drag)
	  {
		  CGraph dc(this);
		  dc.SetROP2(R2_NOT);
		  CMYFUSIONDoc *pDoc=GetDocument();
          
    m_pPrev=point;
	  }
	
	CScrollView::OnMouseMove(nFlags, point);
}

void CMYFUSIONView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	switch (nChar) {
    case VK_HOME:
        OnVScroll(SB_TOP, 0, NULL);
        OnHScroll(SB_LEFT, 0, NULL);
        break;
    case VK_END:
        OnVScroll(SB_BOTTOM, 0, NULL);
        OnHScroll(SB_RIGHT, 0, NULL);
        break;
    case VK_UP:
        OnVScroll(SB_LINEUP, 0, NULL);
        break;
    case VK_DOWN:
        OnVScroll(SB_LINEDOWN, 0, NULL);
        break;
    case VK_PRIOR:
        OnVScroll(SB_PAGEUP, 0, NULL);
        break;
    case VK_NEXT:
        OnVScroll(SB_PAGEDOWN, 0, NULL);
        break;
    case VK_LEFT:
        OnHScroll(SB_LINELEFT, 0, NULL);
        break;
    case VK_RIGHT:
        OnHScroll(SB_LINERIGHT, 0, NULL);
        break;
    default:
        break;
    }
	CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CMYFUSIONView::OnDestroy() 
{
	CScrollView::OnDestroy();
	
	// TODO: Add your message handler code here
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	if(pAppFrame->ZoomInDlg->pView == this)
	{
		pAppFrame->ZoomInDlg->pView = NULL;
		pAppFrame->ZoomInDlg->SendMessage(WM_REDRAWZOOMIN);
	}
	// TODO: Add your message handler code here
	
}


void CMYFUSIONView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_Drag)
	{
		m_Drag=0;
		ReleaseCapture();
		ClipCursor(NULL);
	}
	
	if(m_PointNum>=3)
	{
		CGraph dc(this);
		dc.AreaFill(m_PointNum,Points,RGB(255,0,0));
		m_PointNum=0;
	}
    CGraph dc(this);
		 
	CScrollView::OnRButtonDown(nFlags, point);
}



void CMYFUSIONView::OnEnvalueAverage() 
{
	// TODO: Add your command handler code here
	//计算图像灰度平均值
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	HDIB hdib= pDoc->GetHDIB();
	LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) hdib);
	
	
	if( pDib == NULL )
	{
		AfxMessageBox("该图象为空!",MB_ICONSTOP);
		return ;
	}
	CImageEnvalue env;
	int AverGray = env.ImageAverage(pDib);
	//弹出消息框
	CString str;
	str.Format ("图像灰度平均值为  %d",AverGray);
	AfxMessageBox(str);	
}

void CMYFUSIONView::OnEnvalueEntropy() 
{
	// TODO: Add your command handler code here
	// 计算影像的信息熵
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	HDIB hdib= pDoc->GetHDIB();
	LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) hdib);
	if( pDib == NULL )
	{
		AfxMessageBox("该图象为空!",MB_ICONSTOP);
		return ;
	}
	CImageEnvalue env;
	double nshannon =env.Shannon(pDib);
	//弹出消息框
	CString str;
	str.Format ("图像的熵为  %f",nshannon);
	AfxMessageBox(str);
}

void CMYFUSIONView::OnEnvalueRelation() 
{
	//////////计算影像的原多光谱影像与融合后影像的相关系数
	//获取两图像指针 
	CMYFUSIONApp* app=(CMYFUSIONApp*)AfxGetApp();//获得当前APP
	POSITION p = app->GetFirstDocTemplatePosition(); //p是第一个文档模板的首位置
	while(p!= NULL) 
	{ 
		CDocTemplate * pDocTemplate = app->GetNextDocTemplate(p);// 获取第一个文档模板的首位置指针
		POSITION p1 = pDocTemplate->GetFirstDocPosition(); //p1是第一个文档模板中第一个文档的首位置
		while(p1 != NULL) 
		{ 
			CMYFUSIONDoc * pDocument = (CMYFUSIONDoc*)pDocTemplate->GetNextDoc(p1); //pDocument是第一个文档模板中第一个文档的首位置指针
	    	if(pDocument->GetPathName()==app->pathname2)
			{
				hmul=pDocument->m_hDIB;
			}
		    else if(pDocument->lpPathName==_T("FusionResult"))
			{
			    hout=pDocument->m_hDIB;
			}
		} 		 
	}
	
	CImageEnvalue env;
	double nrelation =env.relation(hmul,hout);
	//弹出消息框
	CString str;
	str.Format ("图像的相关系数为  %.4f",nrelation);
	AfxMessageBox(str);
	
}

void CMYFUSIONView::OnEnvalueGrade() 
{
	// TODO: Add your command handler code here
	// 计算影像的梯度
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	
	HDIB hdib= pDoc->GetHDIB();
	LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) hdib);
	if( pDib == NULL )
	{
		AfxMessageBox("该图象为空!",MB_ICONSTOP);
		return ;
	}
	CImageEnvalue env;
	double standerd =env.grade(pDib);
	//弹出消息框
	CString str;
	str.Format ("图像的梯度为  %f",standerd);
	AfxMessageBox(str);
}

void CMYFUSIONView::OnEnvalueStanderd() 
{
	// TODO: Add your command handler code here
	//  计算影像的标准差
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	HDIB hdib= pDoc->GetHDIB();
	LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) hdib);
	if( pDib == NULL )
	{
		AfxMessageBox("该图象为空!",MB_ICONSTOP);
		return ;
	}
	CImageEnvalue env;
	double standerd =env.standerd(pDib);
	//弹出消息框

⌨️ 快捷键说明

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