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

📄 levelfmsview.cpp

📁 此应用程序不仅表明了基本的使用Microsoft基础类
💻 CPP
字号:
// levelfmsView.cpp : implementation of the CLevelfmsView class
//

#include "stdafx.h"
#include "levelfms.h"

#include "levelfmsDoc.h"
#include "levelfmsView.h"

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

#define LEN_SAMPLE sizeof(struct Sample)
#define LEN_CLUSTER sizeof(struct Cluster)
#define N_MS_ITER   100


/////////////////////////////////////////////////////////////////////////////
// CLevelfmsView

IMPLEMENT_DYNCREATE(CLevelfmsView, CScrollView)

BEGIN_MESSAGE_MAP(CLevelfmsView, CScrollView)
	//{{AFX_MSG_MAP(CLevelfmsView)
	ON_COMMAND(ID_Fms, OnFms)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CLevelfmsView construction/destruction

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

}

CLevelfmsView::~CLevelfmsView()
{
}

BOOL CLevelfmsView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLevelfmsView drawing

void CLevelfmsView::OnDraw(CDC* pDC)
{

    // 显示等待光标
	BeginWaitCursor();

	CLevelfmsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	// 获取DIB
	HDIB hDIB = pDoc->GetHDIB();
	
	// 判断DIB是否为空
	if (hDIB != NULL)
	{
		LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
		
		// 获取DIB宽度
		int cxDIB = (int) ::DIBWidth(lpDIB);
		
		// 获取DIB高度
		int cyDIB = (int) ::DIBHeight(lpDIB);

		lWidth = (long)::DIBWidth(lpDIB);
		
		lHeight = (long)::DIBHeight(lpDIB);
		
		::GlobalUnlock((HGLOBAL) hDIB);
		
		CRect rcDIB;
		rcDIB.top = rcDIB.left = 0;
		rcDIB.right = cxDIB;
		rcDIB.bottom = cyDIB;
		
		CRect rcDest;
		
		// 判断是否是打印
		if (pDC->IsPrinting())
		{
			// 是打印,计算输出图像的位置和大小,以便符合页面
			
			// 获取打印页面的水平宽度(象素)
			int cxPage = pDC->GetDeviceCaps(HORZRES);
			
			// 获取打印页面的垂直高度(象素)
			int cyPage = pDC->GetDeviceCaps(VERTRES);
			
			// 获取打印机每英寸象素数
			int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
			int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
			
			// 计算打印图像大小(缩放,根据页面宽度调整图像大小)
			rcDest.top = rcDest.left = 0;
			rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
				/ ((double)cxDIB * cxInch));
			rcDest.right = cxPage;
			
			// 计算打印图像位置(垂直居中)
			int temp = cyPage - (rcDest.bottom - rcDest.top);
			rcDest.bottom += temp/2;
			rcDest.top += temp/2;
			
		}
		else   
			// 非打印
		{
			// 不必缩放图像
			rcDest = rcDIB;
		}
		
		// 输出DIB
		::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
			&rcDIB, pDoc->GetDocPalette());
	}
	
	// 恢复正常光标
	EndWaitCursor();





}

void CLevelfmsView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CLevelfmsView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLevelfmsView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLevelfmsView message handlers

void CLevelfmsView::OnFms() 
{
	// TODO: Add your command handler code here

	CLevelfmsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	LPSTR lpDIB;


	lpDIB = (LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());

	hdib_image = (HDIB) ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,lWidth*lHeight+40+1024);
	
	lpimage = (LPSTR)::GlobalLock((HGLOBAL) hdib_image);
	
	memset(lpimage,(BYTE)255, lWidth*lHeight+40+1024);
	
	memcpy(lpimage,lpDIB,lWidth*lHeight+40+1024);

	lpimageDIBBits =::FindDIBBits(lpimage); 

	int i;
	int j;
	int p;
	struct Sample *pSample,*pTemp;
	struct Sample *pSample_head;
	struct Cluster *pCluster;
	struct Cluster *pCluster_head;
	struct Cluster *pCluster_temp;
	LPSTR lpSrc;
	LONG lLineBytes;
	
	pSample_head = NULL;
	pCluster_head = NULL;
	p = 0;
	i = 0;
	j = 0;
	lLineBytes=WIDTHBYTES(lWidth*8);

	pSample = (struct Sample *)malloc(LEN_SAMPLE);

	for (i = 0; i<lHeight; i++)
	{
		for(j = 0; j<lWidth; j++)
		{   
			lpSrc = lpimageDIBBits + lLineBytes*(lHeight-1-i) + j;
		
			           
    		pSample->x = j;

			pSample->y = i;

			pSample->gray = *lpSrc;

			pSample->label = 0;

			pTemp = (struct Sample *)malloc(LEN_SAMPLE);
			
			if(p == 0) 
			{
				pSample_head = pSample;
			}
		
			 pSample->next = pTemp;

			 pSample = pSample->next;
			
    	     p = p+1;

	
		}
	}
    
  pSample = NULL;
  
  int u;
  int v;
  int q;
  

  u = 0;
  v = 0;
  q = 1; //标号

  pCluster = (struct Cluster *)malloc(LEN_CLUSTER);
  
  pCluster->x = pSample_head->x;
  
  pCluster->y = pSample_head->y;
  
  pCluster->gray = pSample_head->gray;
  
  pCluster->label = 1;

  pCluster->count = 1;

  pCluster->next = NULL;

  pCluster_head = pCluster;

  pSample = pSample_head;

  for (u = 2; u<p+1; u++)
  {   
	  pSample = pSample->next;

	  for (v = 1; v<q+1; v++)
	  {
         if(abs(pSample->gray-pCluster->gray)<35)
		 {
			
			 pSample->label = pCluster->label;

			 pCluster->count = pCluster->count+1;

		          
		 }
         if(pCluster->next!= NULL)
		 pCluster = pCluster->next;


	  }

	  if(pSample->label==0)
	  {
		  q = q+1;
		  
		  pCluster_temp =  (struct Cluster *)malloc(LEN_CLUSTER);
		  
		  pCluster_temp->x = pSample->x;
		  
		  pCluster_temp->y = pSample->y;
		  
		  pCluster_temp->gray = pSample->gray;
		  
		  pCluster_temp->label = q;
		  
		  pCluster_temp->count = 1;

		  pCluster_temp->next = NULL;
		  
		  pCluster->next = pCluster_temp;
		  
		  
	  }

	  pCluster = pCluster_head;
    

  }

  int c[30][N_MS_ITER];

  int sum[30];
  
  for (i = 0; i<30; i++)
  {	  
	  for(j = 0; j<N_MS_ITER; j++)
	  {
		  c[i][j] = 0;
	  }
      
	  sum[i] = 0;

  }

  pCluster = pCluster_head;

  for(i=1; i<q; i++)
  {
	 c[i][1] = pCluster->gray;
	 
	 pCluster = pCluster->next;
  }

	
	


	
	
}

⌨️ 快捷键说明

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