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

📄 myfusionview.cpp

📁 影像融合与融合精度评价源码影像融合与融合精度评价源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// MYFUSIONView.cpp : implementation of the CMYFUSIONView class
//

#include "stdafx.h"
#include "MYFUSION.h"
#include "MYFUSIONDoc.h"
#include "MYFUSIONView.h"
#include "dibapi.h"
#include "mainfrm.h"
#include "BitMapDC.h"
#include <malloc.h>
#include "ImageEnvalue.h"
#include "DLGOPEN.h"
#include "FusionAlgrithm.h"
#include "FeatureAlgrithm.h"
#include "cREPORT.h"
#include "FUNDLG.h"
#include "cFUNCTIONDLG.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMYFUSIONView

IMPLEMENT_DYNCREATE(CMYFUSIONView, CScrollView)

BEGIN_MESSAGE_MAP(CMYFUSIONView, CScrollView)
	//{{AFX_MSG_MAP(CMYFUSIONView)
	ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_WM_MOUSEMOVE()
	ON_WM_KEYDOWN()
	ON_WM_DESTROY()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_ENVALUE_AVERAGE, OnEnvalueAverage)
	ON_COMMAND(ID_ENVALUE_ENTROPY, OnEnvalueEntropy)
	ON_COMMAND(ID_ENVALUE_RELATION, OnEnvalueRelation)
	ON_COMMAND(ID_ENVALUE_GRADE, OnEnvalueGrade)
	ON_COMMAND(ID_ENVALUE_STANDERD, OnEnvalueStanderd)
	ON_COMMAND(ID_FUSION_HIS, OnFusionHis)
	ON_COMMAND(ID_FUSION_YIQ, OnFusionYiq)
	ON_COMMAND(ID_FUSION_AVERAGE, OnFusionAverage)
	ON_COMMAND(ID_FUSION_OPENIMAGE, OnFusionOpenimage)
	ON_COMMAND(ID_FEATURE_CANNY, OnFeatureCanny)
	ON_COMMAND(ID_FUSION_DAVERAGE, OnFusionDaverage)
	ON_COMMAND(ID_FUSION_BROVEY, OnFusionBrovey)
	ON_COMMAND(ID_FEATURE_SOBEL, OnFeatureSobel)
	ON_COMMAND(ID_FEATURE_ROBERTS, OnFeatureRoberts)
	ON_COMMAND(ID_FUSION_CANSOBL, OnFusionCansobl)
	ON_COMMAND(ID_FUSION_HPF, OnFusionHpf)
	ON_COMMAND(ID_WINDOW_CLOSEALLWIN, OnWindowCloseallwin)
	ON_COMMAND(ID_ENVALUE_REPORT, OnEnvalueReport)
	ON_COMMAND(ID_ENVALUE_FUCTION, OnEnvalueFuction)
	ON_COMMAND(ID_ENVALUE_DISTRIBFUC, OnEnvalueDistribfuc)
	ON_COMMAND(ID_FUSION_D4Wave, OnFUSIOND4Wave)
	ON_COMMAND(ID_ENVALUE_Warp, OnENVALUEWarp)
	ON_COMMAND(ID_FUSION_PCA, OnFusionPca)
	ON_COMMAND(ID_REGISTRATION_CHOOSEPOINT, OnRegistrationChoosepoint)
	ON_UPDATE_COMMAND_UI(ID_ENVALUE_FUCTION, OnUpdateEnvalueFuction)
	ON_UPDATE_COMMAND_UI(ID_ENVALUE_DISTRIBFUC, OnUpdateEnvalueDistribfuc)
	ON_UPDATE_COMMAND_UI(ID_ENVALUE_RELATION, OnUpdateEnvalueRelation)
	ON_UPDATE_COMMAND_UI(ID_ENVALUE_Warp, OnUpdateENVALUEWarp)
	//}}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()

float DisplayArray[]={0.001f, 0.0025f, 0.005f, 0.01f, 
                      0.02f, 0.03f, 0.04f, 0.05f,
                      0.0625f, 0.0833f, 0.125f, 0.1667f,
                      0.25f, 0.3333f, 0.5f, 0.6667f,
                      1.0f,  2.0f, 3.0f, 4.0f,
                      5.0f,  6.0f, 7.0f, 8.0f,
                      12.0f,16.0f};



/////////////////////////////////////////////////////////////////////////////
// CMYFUSIONView construction/destruction

CMYFUSIONView::CMYFUSIONView()
{
    pbmp=NULL;
	m_Zoom = 1.0;
	
	app=(CMYFUSIONApp*)AfxGetApp();
	m_PointNum=0;
	m_Drag=0;
	m_HCursor=AfxGetApp()->LoadStandardCursor(IDC_CROSS);

}

CMYFUSIONView::~CMYFUSIONView()
{
	if(pbmp!=NULL)
		delete pbmp;

    DrawDibClose(hdd);

}

BOOL CMYFUSIONView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,
		(HBRUSH)::GetStockObject(WHITE_BRUSH),0);

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMYFUSIONView drawing

void CMYFUSIONView::OnDraw(CDC* pDC)
{
	CMYFUSIONDoc* pDoc = GetDocument();

	ASSERT_VALID(pDoc);

	HDIB hDIB;
	float ShowZoom;

	hDIB = pDoc->m_hDIB;
	ShowZoom=m_Zoom;

	if(hDIB==NULL)	return;

	CRect client;

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

	if (pDC->IsPrinting())   // printer DC
	{
		CRect rcDIBPrint,rcDestPrint;

		pDC->GetClipBox(client);

		rcDIBPrint.top = rcDIBPrint.left = 0;
		rcDIBPrint.right = cxDIB;
		rcDIBPrint.bottom = cyDIB;

		// 是打印,计算输出图像的位置和大小,以便符合页面
		// 获取打印页面的水平宽度(象素)
		int cxPage = pDC->GetDeviceCaps(HORZRES   );
		// 获取打印页面的垂直高度(象素)
		int cyPage = pDC->GetDeviceCaps(VERTRES   );
		// 获取打印机每英寸象素数
		int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
		int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
				
		// 计算打印图像大小(缩放,根据页面宽度调整图像大小)
		int PrintHeight, PrintWidth;
		if( (double)rcDIBPrint.Width()/(double)cxPage > (double)rcDIBPrint.Height()/(double)cyPage )
		{
			PrintWidth=cxPage;
			PrintHeight=(int)((double)cyDIB/(double)cxDIB*cxPage);
		}
		else
		{
			PrintHeight=cyPage;
			PrintWidth=(int)((double)cxDIB/(double)cyDIB*cyPage);
		}
		rcDestPrint.left=(cxPage-PrintWidth)/2;
		rcDestPrint.top=(cyPage-PrintHeight)/2;
		rcDestPrint.right=rcDestPrint.left+PrintWidth;
		rcDestPrint.bottom=rcDestPrint.top+PrintHeight;

		// paint background
		pDC->PatBlt(0,0,6000,6000,WHITENESS);
		//display Image
		::PaintDIB(pDC->m_hDC, &rcDestPrint, hDIB, &rcDIBPrint, pDoc->m_palDIB);
	}
	else   // not printer DC
	{
		GetClientRect(client);

		//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(bInitDraw || 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 );
				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;
			bInitDraw=FALSE;
		}
		//just bitblt the clip CBitmap to screen
		else
		{
			CRect newrcDest=rcDest+CPoint(xOffDisplay,yOffDisplay);

			FillSolidRectUser( pDC, client, newrcDest);

			pDC->SetViewportOrg(xOffDisplay, yOffDisplay);

//			pDC->GetClipBox(client);
			DrawBitmap(pbmp, pDC, client,CPoint(client.left,client.top));
		}
	}
		
	//app=(CDibLookApp*)AfxGetApp();
	//
	//	//画矩形
	//	if(app->Sampledlg!=NULL)
	//	{
	//		CPoint offsetPosition=GetScrollPosition();
	//		int i;
	//		CPen pen;
	//		pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
	//		CPen * pOldPen = pDC->SelectObject(&pen);
	//
	//		LOGBRUSH logBrush;
	//		logBrush.lbStyle = BS_NULL;
	//		logBrush.lbHatch = HS_CROSS;
	//
	//		CBrush brush;
	//		brush.CreateBrushIndirect(&logBrush);
	//		CBrush* pOldBrush = pDC->SelectObject(&brush);
	//
	//		if(!app->Sampledlg->IsAdd)
	//		{
	//			int m_tSize = app->Sampledlg->RectPoint.GetSize();
	//			for(i=0;i<m_tSize;i++)
	//			{	
	//				CRect m_t = app->Sampledlg->RectPoint.GetAt(i);
	//				m_t.left -= offsetPosition.x;m_t.right  -= offsetPosition.x;
	//				m_t.top  -= offsetPosition.y;m_t.bottom -= offsetPosition.y;
	//				pDC->Rectangle(m_t);
	//			}
	//		}
	//		else
	//		{	
	//		  CSample *  psample;
	//	      psample=new CSample;
	//		  POSITION 	position;
	//		  for(position = app->Sampledlg->SampleList.GetHeadPosition();position!=NULL;)
	//		  {
	//			  psample=(CSample*)app->Sampledlg->SampleList.GetAt(position);
	//			  int m_tSize = psample -> m_MyRect.GetSize();
	//
	//					for(i=0;i<m_tSize;i++)
	//					{	
	//						CRect m_t = psample->m_MyRect.GetAt(i);
	//						m_t.left -= offsetPosition.x;m_t.right  -= offsetPosition.x;
	//						m_t.top  -= offsetPosition.y;m_t.bottom -= offsetPosition.y;
	//							pDC->Rectangle(m_t);
	//						CString  str="Class ";
	//						str+=psample->m_AreaClassName;
	//						pDC->TextOut(m_t.left-10,m_t.top-25,str);
	//					}
	//				app->Sampledlg->SampleList.GetNext(position);
	//		  }
	//		  pDC->SelectObject(pOldPen);
	//		  pDC->SelectObject(pOldBrush);
	//		}
	//	}
	
}

void CMYFUSIONView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	
	CMYFUSIONDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	bInitDraw = TRUE;
	bpbmpChanged = FALSE;
	ptDIBOff = CPoint(0,0);
	xOffDisplay=yOffDisplay=0;
	hdd  = DrawDibOpen(); 
	
	nFullWidth=::GetSystemMetrics(SM_CXSCREEN);
	nFullHeight=::GetSystemMetrics(SM_CYSCREEN);
	
	rcDest = CRect(0,0,nFullWidth,nFullHeight);
	
	
	CMDIFrameWnd* pAppFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
	ASSERT_KINDOF(CMDIFrameWnd, pAppFrame);
	CRect rc;
	pAppFrame->GetClientRect(&rc);
	
	HDIB hDIB   = pDoc->m_hDIB;
	if(hDIB == NULL) 
	{
		CSize sizeTotal(100, 100);
		SetScrollSizes(MM_TEXT, sizeTotal);
	}
	else
	{
		Width   = pDoc->m_sizeDoc.cx;
		Height	= pDoc->m_sizeDoc.cy;
		
		if(pDoc->ColorNum == 0 )
			L_Width = (sizeof(DWORD) - (3*Width)%sizeof(DWORD) )%sizeof(DWORD);
		else 
			L_Width = (sizeof(DWORD) -    Width %sizeof(DWORD) )%sizeof(DWORD);
			/*
			if(pDoc->ColorModal == 5 ||pDoc->ColorModal == 4 )//BYTE count
			L_Width = (sizeof(DWORD) -    Width %sizeof(DWORD) )%sizeof(DWORD);
			else if(pDoc->ColorModal == 7)//BYTE count
			L_Width = (sizeof(DWORD) - (3*Width)%sizeof(DWORD) )%sizeof(DWORD);
			else if(pDoc->ColorModal == 1 || pDoc->ColorModal == 2)//bit count
			L_Width = 32 - Width%32 ;
			else if(pDoc->ColorModal == 3 )//bit count
			L_Width = 32 - (Width*4)%32 ;
			else if(pDoc->ColorModal == 6 )//BYTE count
			L_Width = (Width%2) * 2;
			else if(pDoc->ColorModal == 8 )//BYTE count
			L_Width = 0 ;
			else
			L_Width = 0 ;
		*/		
		LPSTR pDIB	= (LPSTR) ::GlobalLock((HGLOBAL) hDIB);	
		image	= (BYTE *)::FindDIBBits (pDIB);
		::GlobalUnlock((HGLOBAL) hDIB);
	}
	
	float xZoom,yZoom;
	xZoom=(rc.Width()-200)/(float)Width;
	yZoom=(rc.Height()-50)/(float)Height;
	m_Zoom = (xZoom < yZoom ) ? xZoom : yZoom;
	if(m_Zoom>1.0)
		m_Zoom=1.0;
	if(m_Zoom<DisplayArray[0])
		m_Zoom=DisplayArray[0];
	//判断当前比例
	for(int i=25;i>=0;i--)
	{
		if(m_Zoom>=DisplayArray[i])
		{
			m_Zoom=DisplayArray[i];
			break;
		}
	}
	
	CSize sizeTotal((int)(Width*m_Zoom+0.5), (int)(Height*m_Zoom+0.5));
	SetScrollSizes(MM_TEXT, sizeTotal);
	
	if (rc.Width() >= sizeTotal.cx && rc.Height() >= sizeTotal.cy &&
		(sizeTotal.cx>0 || sizeTotal.cy>0))
		ResizeParentToFit(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// CMYFUSIONView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMYFUSIONView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMYFUSIONView message handlers
void CMYFUSIONView::AdjustZoomOut()
{

⌨️ 快捷键说明

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