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

📄 myfusionview.cpp

📁 影像融合与融合精度评价源码影像融合与融合精度评价源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	//虚拟鼠标点
	CRect clientrect;
	GetClientRect(clientrect);
	CPoint point;
	point.x=clientrect.right/2;
	point.y=clientrect.bottom/2;
	
	int CurZoomIndex=0;
	//判断当前比例
	for(int i=25;i>=0;i--)
	{
		if(m_Zoom>DisplayArray[i])
		{
			CurZoomIndex=i+1;
			break;
		}
		if(m_Zoom==DisplayArray[i])
		{
			CurZoomIndex=i;
			break;
		}
	}
	if(CurZoomIndex>25)
		CurZoomIndex=25;

	//鼠标点在缩放前图象上的位置
	CPoint  ShowPoint;
	ShowPoint.x = ptDIBOff.x + (int)((point.x-xOffDisplay)/m_Zoom);
	ShowPoint.y = ptDIBOff.y + (int)((point.y-yOffDisplay)/m_Zoom);

	//缩小显示
	if(CurZoomIndex>0)
		m_Zoom=DisplayArray[CurZoomIndex-1];
	else
		m_Zoom=DisplayArray[0];
	CSize sizeTotal((int)(Width*m_Zoom+0.5), (int)(Height*m_Zoom+0.5));
	SetScrollSizes(MM_TEXT, sizeTotal);

	//置于中间
	CRect client;
	GetClientRect(client);
	ptDIBOff.x = ShowPoint.x - (int) ( (double)client.Width() / 2 / m_Zoom + 0.5);  
	ptDIBOff.y = ShowPoint.y - (int) ( (double)client.Height() / 2 / m_Zoom + 0.5);  
	if((int)Width - ptDIBOff.x < (int) ( (double)client.Width() / m_Zoom + 0.5))
		ptDIBOff.x = Width - (int) ( (double)client.Width() / m_Zoom + 0.5);
	if((int)Height - ptDIBOff.y < (int) ( (double)client.Height() / m_Zoom + 0.5))
		ptDIBOff.y = Height - (int) ( (double)client.Height() / m_Zoom + 0.5);
	if(ptDIBOff.x<0) ptDIBOff.x=0;
	if(ptDIBOff.y<0) ptDIBOff.y=0;

	SetScrollPos(SB_HORZ,(int)(ptDIBOff.x*m_Zoom+0.5),TRUE);
	SetScrollPos(SB_VERT,(int)(ptDIBOff.y*m_Zoom+0.5),TRUE);


	
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	pAppFrame->NavigationDialog->PostMessage(WM_REDRAWDISPLAYRECT);

	bpbmpChanged=TRUE;
//	RedrawViewRect();


	if(m_Zoom>=DisplayArray[25] && NormalStatus==ZOOM_IN)
	{
		NormalStatus=ZOOM_NOIN;
		SetCurrentState();
		::SetCursor(m_ZoomNoCross);
	}
	if(m_Zoom>DisplayArray[0] && NormalStatus==ZOOM_NOOUT)
	{
		NormalStatus=ZOOM_OUT;
		SetCurrentState();
		::SetCursor(m_ZoomOutCross);
	}
	if(NormalStatus==ZOOM_NOIN && m_Zoom<DisplayArray[25])
	{
		NormalStatus=ZOOM_IN;
		SetCurrentState();
		::SetCursor(m_ZoomInCross);
	}
}
void CMYFUSIONView::AdjustZoomIn()
{
	//虚拟鼠标点
	CRect clientrect;
	GetClientRect(clientrect);
	CPoint point;
	point.x=clientrect.right/2;
	point.y=clientrect.bottom/2;

	int CurZoomIndex=0;
	//判断当前比例
	for(int i=25;i>=0;i--)
	{
		if(m_Zoom>=DisplayArray[i])
		{
			CurZoomIndex=i;
			break;
		}
	}

	//鼠标点在缩放前图象上的位置
	CPoint  ShowPoint;
	ShowPoint.x = ptDIBOff.x + (int)((point.x-xOffDisplay)/m_Zoom);
	ShowPoint.y = ptDIBOff.y + (int)((point.y-yOffDisplay)/m_Zoom);

	//放大显示
	if(CurZoomIndex<25)
		m_Zoom=DisplayArray[CurZoomIndex+1];
	CSize sizeTotal((int)(Width*m_Zoom+0.5), (int)(Height*m_Zoom+0.5));
	SetScrollSizes(MM_TEXT, sizeTotal);

	//置于中间
	CRect client;
	GetClientRect(client);
	ptDIBOff.x = ShowPoint.x - (int) ( (double)client.Width() / 2 / m_Zoom + 0.5);  
	ptDIBOff.y = ShowPoint.y - (int) ( (double)client.Height() / 2 / m_Zoom + 0.5);  
	if((int)Width - ptDIBOff.x < (int) ( (double)client.Width() / m_Zoom + 0.5))
		ptDIBOff.x = Width - (int) ( (double)client.Width() / m_Zoom + 0.5);
	if((int)Height - ptDIBOff.y < (int) ( (double)client.Height() / m_Zoom + 0.5))
		ptDIBOff.y = Height - (int) ( (double)client.Height() / m_Zoom + 0.5);
	if(ptDIBOff.x<0) ptDIBOff.x=0;
	if(ptDIBOff.y<0) ptDIBOff.y=0;

	SetScrollPos(SB_HORZ,(int)(ptDIBOff.x*m_Zoom+0.5),TRUE);
	SetScrollPos(SB_VERT,(int)(ptDIBOff.y*m_Zoom+0.5),TRUE);

	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	pAppFrame->NavigationDialog->PostMessage(WM_REDRAWDISPLAYRECT);

	bpbmpChanged=TRUE;
//	RedrawViewRect();


	if(m_Zoom>=DisplayArray[25] && NormalStatus==ZOOM_IN)
	{
		NormalStatus=ZOOM_NOIN;
		SetCurrentState();
		::SetCursor(m_ZoomNoCross);
	}
	if(m_Zoom<=DisplayArray[0] &&  NormalStatus==ZOOM_OUT)
	{
		NormalStatus=ZOOM_NOOUT;
		SetCurrentState();
		::SetCursor(m_ZoomNoCross);
	}
	if(m_Zoom>DisplayArray[0] && NormalStatus==ZOOM_NOOUT)
	{
		NormalStatus=ZOOM_OUT;
		SetCurrentState();
		::SetCursor(m_ZoomOutCross);
	}
}
void CMYFUSIONView::AdjustZoomNav(float m_oldZoom)
{
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	//虚拟鼠标点
	CRect clientrect;
	GetClientRect(clientrect);
	CPoint point;
	point.x=clientrect.right/2;
	point.y=clientrect.bottom/2;
	
	//鼠标点在缩放前图象上的位置
	CPoint  ShowPoint;
	ShowPoint.x = ptDIBOff.x + (int)((point.x-xOffDisplay)/m_oldZoom);
	ShowPoint.y = ptDIBOff.y + (int)((point.y-yOffDisplay)/m_oldZoom);
	
	CSize sizeTotal((int)(Width*m_Zoom+0.5), (int)(Height*m_Zoom+0.5));
	SetScrollSizes(MM_TEXT, sizeTotal);
	
	//置于中间
	CRect client;
	GetClientRect(client);
	ptDIBOff.x = ShowPoint.x - (int) ( (double)client.Width() / 2 / m_Zoom + 0.5);  
	ptDIBOff.y = ShowPoint.y - (int) ( (double)client.Height() / 2 / m_Zoom + 0.5);  
	if((int)Width - ptDIBOff.x < (int) ( (double)client.Width() / m_Zoom + 0.5))
		ptDIBOff.x = Width - (int) ( (double)client.Width() / m_Zoom + 0.5);
	if((int)Height - ptDIBOff.y < (int) ( (double)client.Height() / m_Zoom + 0.5))
		ptDIBOff.y = Height - (int) ( (double)client.Height() / m_Zoom + 0.5);
	if(ptDIBOff.x<0) ptDIBOff.x=0;
	if(ptDIBOff.y<0) ptDIBOff.y=0;
	
	SetScrollPos(SB_HORZ,(int)(ptDIBOff.x*m_Zoom+0.5),TRUE);
	SetScrollPos(SB_VERT,(int)(ptDIBOff.y*m_Zoom+0.5),TRUE);
	
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMainFrame )));
	pAppFrame->NavigationDialog->PostMessage(WM_REDRAWDISPLAYRECT);
	
	bpbmpChanged=TRUE;
	RedrawViewRect();
	
	if(m_Zoom>=DisplayArray[25] && NormalStatus==ZOOM_IN)
	{
		NormalStatus=ZOOM_NOIN;
		SetCurrentState();
		::SetCursor(m_ZoomNoCross);
	}
	if(m_Zoom<=DisplayArray[0] &&  NormalStatus==ZOOM_OUT)
	{
		NormalStatus=ZOOM_NOOUT;
		SetCurrentState();
		::SetCursor(m_ZoomNoCross);
	}
	if(m_Zoom>DisplayArray[0] && NormalStatus==ZOOM_NOOUT)
	{
		NormalStatus=ZOOM_OUT;
		SetCurrentState();
		::SetCursor(m_ZoomOutCross);
	}
	if(NormalStatus==ZOOM_NOIN && m_Zoom<DisplayArray[25])
	{
		NormalStatus=ZOOM_IN;
		SetCurrentState();
		::SetCursor(m_ZoomInCross);
	}
}

void  SetCurrentState()
{
	CString msg;
	switch(NormalStatus)
	{
	case 	DO_NOTHING:
		msg.Format("状态:空闲");
		break;
	case	ZOOM_IN:
		msg.Format("状态:放大");
		break;
	case 	ZOOM_OUT:
		msg.Format("状态:缩小");
		break;
	case 	ZOOM_NOIN:  
		msg.Format("状态:放大");
		break;
	case 	ZOOM_NOOUT:
		msg.Format("状态:缩小");
		break;
	case 	ZOOM_IN_WINDOW:
		msg.Format("状态:开窗放大");
		break;
	case 	IMAGE_MOVE:
		msg.Format("状态:漫游");
		break;
	case 	IMAGE_MEASURE:
		msg.Format("状态:量测");
		break;
	default:
		msg.Format("");
		break;
	}
	CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
	pAppFrame->m_wndStatusBar.SetPaneText(1,msg);
	pAppFrame->m_wndStatusBar.UpdateWindow();
}
void FillSolidRectUser(CDC * pDC, const CRect oldrcDest,const CRect newrcDest, COLORREF bkColor /*= NULL */)
{
	if(bkColor==NULL)	bkColor=RGB(192,192,192);
	if(oldrcDest.top < newrcDest.top || oldrcDest.bottom > newrcDest.bottom 
		|| oldrcDest.left < newrcDest.left || oldrcDest.right > newrcDest.right )
	{
		pDC->SetViewportOrg(0, 0);
		
		CRect fillRect,IntersectDest;
		IntersectDest.IntersectRect(oldrcDest,newrcDest);
		
		if(oldrcDest.left < IntersectDest.left)
		{
			fillRect = oldrcDest;
			fillRect.right = IntersectDest.left;
			pDC->FillSolidRect(fillRect, bkColor);
		}
		if(oldrcDest.right > IntersectDest.right)
		{
			fillRect = oldrcDest;
			fillRect.left = IntersectDest.right;
			pDC->FillSolidRect(fillRect, bkColor);
		}
		if(oldrcDest.top < IntersectDest.top)
		{
			fillRect.top = oldrcDest.top;
			fillRect.bottom = IntersectDest.top;
			fillRect.left = IntersectDest.left;
			fillRect.right = IntersectDest.right;
			pDC->FillSolidRect(fillRect, bkColor);
		}
		if(oldrcDest.bottom > IntersectDest.bottom)
		{
			fillRect.top = IntersectDest.bottom;
			fillRect.bottom = oldrcDest.bottom;
			fillRect.left = IntersectDest.left;
			fillRect.right = IntersectDest.right;
			pDC->FillSolidRect(fillRect, bkColor);
		}
	}
}
void CMYFUSIONView::RedrawViewRect(CRect  rcCrop )
{
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	CDC *pDC = GetDC();

	HDIB hDIB;
	float ShowZoom;
	hDIB = pDoc->m_hDIB;
	ShowZoom=m_Zoom;

	if(hDIB==NULL)	return;

	SetWindowTitle();

	CRect client;

	int cxDIB,cyDIB;
	cxDIB=pDoc->m_sizeDoc.cx;
	cyDIB=pDoc->m_sizeDoc.cy;

	GetClientRect(client);

//	CRect oldrcDest=rcDest+CPoint(xOffDisplay,yOffDisplay);

	//draw in the middle of window
	xOffDisplay=yOffDisplay=0;	
	if((double)client.Width()>Width*ShowZoom){
		xOffDisplay=(int)(((double)client.Width()-Width*ShowZoom)/2+0.5);
		if(xOffDisplay<0) xOffDisplay=0;}
	if((double)client.Height()>Height*ShowZoom){
		yOffDisplay=(int)(((double)client.Height()-Height*ShowZoom)/2+0.5);
		if(yOffDisplay<0) yOffDisplay=0;}

	//over draw all the child window,then save screen content to CBitmap
	if(bpbmpChanged)
	{
		rcDIB.left =  ptDIBOff.x;
		rcDIB.right = rcDIB.left + (int)( (double)(nFullWidth) / ShowZoom +0.5 );
		if(rcDIB.right > (int)Width)	rcDIB.right = Width;
		rcDIB.top  =   ptDIBOff.y;
		rcDIB.bottom =  rcDIB.top + (int)( (double)(nFullHeight) / ShowZoom +0.5 );
		if(rcDIB.bottom > (int)Height)	rcDIB.bottom = Height;

		CRect  rcDIBNormal = rcDIB;

		//NOTE:we need do some additional adjustment
		if(ShowZoom != 1.0){
			rcDIB.top = Height - rcDIB.top ;
			rcDIB.bottom = Height - rcDIB.bottom ;}				
		rcDIB.NormalizeRect();

		rcDest.left = 0;
		rcDest.top  = 0;
		rcDest.right = rcDest.left + (int)( (double)rcDIB.Width() * ShowZoom +0.5 );
		rcDest.bottom = rcDest.top + (int)( (double)rcDIB.Height() * ShowZoom +0.5 );

		if(pbmp!=NULL)	delete pbmp;
		CBitmapDC bitmapDC(nFullWidth, nFullHeight, pDC,RGB(192,192,192));
		if( m_Zoom <= 1.0f )
			::PaintDIB(bitmapDC.m_hDC, &rcDest, hDIB, &rcDIB, pDoc->m_palDIB);
		else
		{
			LPBITMAPINFOHEADER lpbi       = (LPBITMAPINFOHEADER)GlobalLock(hDIB );
			lpbi->biClrUsed=0;
			DrawDibBegin(hdd,bitmapDC.m_hDC,rcDest.Width(),rcDest.Height(),lpbi,
				rcDIBNormal.Width(),rcDIBNormal.Height(),DDF_SAME_HDC);
  		    if(DrawDibDraw(hdd,bitmapDC.m_hDC,rcDest.left,rcDest.top,rcDest.Width(),rcDest.Height(),lpbi,(LPVOID)image,
						rcDIBNormal.left,rcDIBNormal.top,rcDIBNormal.Width(),rcDIBNormal.Height(),DDF_SAME_HDC ) == FALSE )
			{
				::PaintDIB(bitmapDC.m_hDC, &rcDest, hDIB, &rcDIB, pDoc->m_palDIB);
				GlobalUnlock(hDIB); 
			}
			DrawDibEnd ( hdd );
			GlobalUnlock(hDIB); 
		}
		
		pbmp=bitmapDC.Close();

		CRect newrcDest=rcDest+CPoint(xOffDisplay,yOffDisplay);
		FillSolidRectUser( pDC, client, newrcDest);

		pDC->SetViewportOrg(xOffDisplay, yOffDisplay);
		DrawBitmap(pbmp, pDC, client, CPoint(0,0));

		bpbmpChanged=FALSE;
	}
	//just bitblt the clip CBitmap to screen
	else
	{
		CRect newrcDest=rcDest+CPoint(xOffDisplay,yOffDisplay);
		FillSolidRectUser( pDC, client, newrcDest);

		pDC->SetViewportOrg(xOffDisplay, yOffDisplay);

		if(rcCrop==CRect(-1,-1,-1,-1))
			DrawBitmap(pbmp, pDC, client,CPoint(client.left,client.top));
		else
			DrawBitmap(pbmp, pDC, rcCrop,CPoint(rcCrop.left,rcCrop.top));
	}

	ReleaseDC(pDC);

	//加上关键断反倒会引起线程阻塞
//	EnterCriticalSection(&CCImageDevView::m_csSysLock);
	{
		//执行完毕,发消息到视图执行其它的画图语句(矢量数据)
		PostMessage(WM_DRAWTHREAD_EXIT);
	}
//	LeaveCriticalSection(&CCImageDevView::m_csSysLock);
}
BOOL CMYFUSIONView::SetWindowTitle()
{
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	char drive[_MAX_DRIVE];   
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];   
	char ext[_MAX_EXT];
	_splitpath(pDoc->lpPathName, drive, dir, fname, ext);//分离路径名
	
	/*				0--未知
				1--二值
				2--1位索引色
				3--4位索引色
				4--8位索引色
				5--灰度
				6--16位索引色
				7--24位真彩色
				8--32位真彩色
				9--包含ColorNum个颜色数BitsPerPixel位的索引色
	*/
	CString  title;
	title.Format("%s%s @ %.1f",fname,ext,m_Zoom*100);
	
	switch(pDoc->ColorModal)
	{
	case 0:
		title+=_T("%");
		break;
	case 1:
		title+=_T("% (二值)");
		break;
	case 2:
		title+=_T("% (1位索引色)");
		break;
	case 3:
		title+=_T("% (4位索引色)");
		break;

⌨️ 快捷键说明

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