📄 shiqian0197view.cpp
字号:
// Shiqian0197View.cpp : implementation of the CShiqian0197View class
//
#include "stdafx.h"
#include "Shiqian0197.h"
#include "Shiqian0197Doc.h"
#include "Shiqian0197View.h"
#include "mainfrm.h"
#include "Math.h"
#include "dibapi.h"
#include "RawToBmp.h"
#include "XIANXING.h"
#include "LvboUD.h"
#include "Rotate.h"
#include "MoveDlg.h"
#include "Zoomdlg.h"
#include "Zoom1dlg.h"
#include "YuzhiDlg1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PAI 3.1415
/////////////////////////////////////////////////////////////////////////////
// CShiqian0197View
IMPLEMENT_DYNCREATE(CShiqian0197View, CScrollView)
BEGIN_MESSAGE_MAP(CShiqian0197View, CScrollView)
//{{AFX_MSG_MAP(CShiqian0197View)
ON_COMMAND(ID_RAWTOBMP, OnRawtobmp)
ON_COMMAND(ID_XIANXINGBH, OnXianxingbh)
ON_COMMAND(ID_LVBO_TTLOW, OnLvboTtlow)
ON_COMMAND(ID_LVBO_FFLOW, OnLvboFflow)
ON_COMMAND(ID_LVBO_TTHIGH, OnLvboTthigh)
ON_COMMAND(ID_LVBO_FFHIGH, OnLvboFfhigh)
ON_COMMAND(ID_LVBO_MIDDLE, OnLvboMiddle)
ON_COMMAND(ID_LVBO_USERDEFINED, OnLvboUserdefined)
ON_COMMAND(ID_GEO_ZOOM_BIG, OnGeoZoomBig)
ON_COMMAND(ID_GEO_ZOOM_SMALL, OnGeoZoomSmall)
ON_COMMAND(ID_GEO_MOVE, OnGeoMove)
ON_COMMAND(ID_GEO_ROTATE, OnGeoRotate)
ON_COMMAND(ID_TZ_MORAVEC, OnTzMoravec)
ON_COMMAND(ID_TZ_FORSTNER, OnTzForstner)
ON_COMMAND(ID_XINGTAI_TRANSTOBINARY, OnXingtaiTranstobinary)
ON_COMMAND(ID_XINGTAI_FUSHI_SHUIPING, OnXingtaiFushiShuiping)
ON_COMMAND(ID_XINGTAI_FUSHI_CHUIZHI, OnXingtaiFushiChuizhi)
ON_COMMAND(ID_XINGTAI_FUSHI_QUANFANGWEI, OnXingtaiFushiQuanfangwei)
ON_COMMAND(ID_XINGTAI_KAIYUANSUAN, OnXingtaiKaiyuansuan)
ON_COMMAND(ID_XINGTAI_BIYUNSUAN, OnXingtaiBiyunsuan)
ON_COMMAND(ID_XINGTAI_PENGZHANG_SHUIPING, OnXingtaiPengzhangShuiping)
ON_COMMAND(ID_XINGTAI_PENGZHANG_CHUIZHI, OnXingtaiPengzhangChuizhi)
ON_COMMAND(ID_XINGTAI_PENGZHANG_QUANFANGWEI, OnXingtaiPengzhangQuanfangwei)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CShiqian0197View construction/destruction
CShiqian0197View::CShiqian0197View()
{
// TODO: add construction code here
}
CShiqian0197View::~CShiqian0197View()
{
}
BOOL CShiqian0197View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CShiqian0197View drawing
void CShiqian0197View::OnDraw(CDC* pDC)
{
CShiqian0197Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HDIB hDIB = pDoc->GetHDIB();
if (hDIB != NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y
::GlobalUnlock((HGLOBAL) hDIB);
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
CRect rcDest;
if (pDC->IsPrinting()) // printer DC
{
// get size of printer page (in pixels)
int cxPage = pDC->GetDeviceCaps(HORZRES);
int cyPage = pDC->GetDeviceCaps(VERTRES);
// get printer pixels per inch
int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
//
// Best Fit case -- create a rectangle which preserves
// the DIB's aspect ratio, and fills the page horizontally.
//
// The formula in the "->bottom" field below calculates the Y
// position of the printed bitmap, based on the size of the
// bitmap, the width of the page, and the relative size of
// a printed pixel (cyInch / cxInch).
//
rcDest.top = rcDest.left = 0;
rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
/ ((double)cxDIB * cxInch));
rcDest.right = cxPage;
}
else // not printer DC
{
rcDest = rcDIB;
}
::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
&rcDIB, pDoc->GetDocPalette());
}
}
void CShiqian0197View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CShiqian0197View printing
BOOL CShiqian0197View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CShiqian0197View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CShiqian0197View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CShiqian0197View diagnostics
#ifdef _DEBUG
void CShiqian0197View::AssertValid() const
{
CScrollView::AssertValid();
}
void CShiqian0197View::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
LRESULT CShiqian0197View::OnDoRealize(WPARAM wParam, LPARAM)
{
ASSERT(wParam != NULL);
CShiqian0197Doc* 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 CDibView::OnPaletteChanged\n");
}
}
return 0L;
}
CShiqian0197Doc* CShiqian0197View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CShiqian0197Doc)));
return (CShiqian0197Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CShiqian0197View message handlers
void CShiqian0197View::OnRawtobmp()
{
// TODO: Add your command handler code here
CRawToBmp dlg;
dlg.DoModal();
}
void CShiqian0197View::OnXianxingbh()
{
CShiqian0197Doc *pDoc=GetDocument();
ASSERT_VALID(pDoc);
CXIANXING dlg;
// dlg.DoModal();
if(dlg.DoModal()==IDOK)
{
UpdateData(false);
}
HDIB hDib=pDoc->GetHDIB();
// HDIB hDib=::ReadDIBFile(File);
// if(hDib!=NULL)
// {
LPSTR lpdib=(LPSTR)GlobalLock((HGLOBAL)hDib);
int width=DIBWidth(lpdib);
int height=DIBHeight(lpdib);
LPSTR lpDibBits=FindDIBBits(lpdib);
long linebytes=(width*8+31)/32*4;
for(int i=0;i<height;i++)
for( int j=0;j<width;j++)
{
lpDibBits[(height-i-1)*linebytes+j]=(BYTE)(dlg.m_fXielv*lpDibBits[(height-i-1)*linebytes+j]+dlg.m_iJieju);
if(*lpDibBits>=256)
*lpDibBits=255;
if(*lpDibBits<=0)
*lpDibBits=0;
}
// }
InvalidateRect(NULL,TRUE);
}
void CShiqian0197View::OnLvboTtlow()
{
CShiqian0197Doc* pDoc = GetDocument();
int iTempH=3,iTempW=3;
int iTempMX=1;
int iTempMY=1;
double PixelValue[9];
HDIB hDIB;
hDIB=pDoc->m_hDIB;
if (hDIB==NULL)
return;
LPSTR lpDIB=(LPSTR)GlobalLock((HGLOBAL)hDIB);
int width=DIBWidth(lpDIB);
int height=DIBHeight(lpDIB);
LPSTR lpDIBBits=FindDIBBits(lpDIB);
int bitcount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
// 给模板数组赋初值
PixelValue[0]=0.1;
PixelValue[1]=0.1;
PixelValue[2]=0.1;
PixelValue[3]=0.1;
PixelValue[4]=0.2;
PixelValue[5]=0.1;
PixelValue[6]=0.1;
PixelValue[7]=0.1;
PixelValue[8]=0.1;
LPSTR lpNewDIBBits;
HLOCAL hNewDIBBits;
unsigned char* lpSrc;
unsigned char* lpDst;
long i,j,k,l;
double fResult;
long lLineBytes= WIDTHBYTES(width*8);
hNewDIBBits = LocalAlloc(LHND, lLineBytes*height);
lpNewDIBBits = (char * )LocalLock(hNewDIBBits);
memcpy(lpNewDIBBits, lpDIBBits, lLineBytes * height);
for(i = iTempMY; i <height-iTempH+iTempMY+1; i++)
{
for(j = iTempMX; j <width-iTempW+iTempMX+1; j++)
{
lpDst = (unsigned char*)lpNewDIBBits+lLineBytes*(height-1-i)+j;
fResult = 0;
int m=0;
for (k = 0; k < iTempH; k++)
{
for (l = 0; l < iTempW; l++)
{
lpSrc = (unsigned char*)lpDIBBits+lLineBytes*(height-1-i+iTempMY-k)
+j-iTempMX+l;
fResult+=(*lpSrc)*PixelValue[m];
m++;
}
}
if(fResult > 255)
{
* lpDst = 255;
}
else if(fResult<0) fResult=0;
else
{
* lpDst = (unsigned char) (fResult + 0.5);
}
}
}
memcpy(lpDIBBits, lpNewDIBBits, lLineBytes*height);
LocalUnlock(hNewDIBBits);
LocalFree(hNewDIBBits);
// return TRUE;
InvalidateRect(NULL,TRUE);
// TODO: Add your command handler code here
}
void CShiqian0197View::OnLvboFflow()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
int iTempH;
int iTempW;
int iTempMX;
int iTempMY;
double PixelValue[25];
CShiqian0197Doc* pDoc = GetDocument();
HDIB hDIB;
hDIB=pDoc->m_hDIB;
if (hDIB==NULL)
return;
LPSTR lpDIB=(LPSTR)GlobalLock((HGLOBAL)hDIB);
int width=DIBWidth(lpDIB);
int height=DIBHeight(lpDIB);
LPSTR lpDIBBits=FindDIBBits(lpDIB);
int bitcount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
// 设置拉普拉斯模板参数
iTempW = 5;
iTempH = 5;
iTempMX = 2;
iTempMY = 2;
PixelValue[0] = 0.04;
PixelValue[1] = 0.04;
PixelValue[2] = 0.04;
PixelValue[3] = 0.04;
PixelValue[4] = 0.04;
PixelValue[5] = 0.04;
PixelValue[6] = 0.04;
PixelValue[7] = 0.04;
PixelValue[8] = 0.04;
PixelValue[9] = 0.04;
PixelValue[10] = 0.04;
PixelValue[11] = 0.04;
PixelValue[12] = 0.04;
PixelValue[13] = 0.04;
PixelValue[14] = 0.04;
PixelValue[15] = 0.04;
PixelValue[16] = 0.04;
PixelValue[17] = 0.04;
PixelValue[18] = 0.04;
PixelValue[19] = 0.04;
PixelValue[20] = 0.04;
PixelValue[21] = 0.04;
PixelValue[22] = 0.04;
PixelValue[23] = 0.04;
PixelValue[24] = 0.04;
LPSTR lpNewDIBBits;
HLOCAL hNewDIBBits;
unsigned char* lpSrc;
unsigned char* lpDst;
long i,j,k,l;
float fResult;
long lLineBytes= WIDTHBYTES(width*8);
hNewDIBBits = LocalAlloc(LHND, lLineBytes*height);
lpNewDIBBits = (char * )LocalLock(hNewDIBBits);
memcpy(lpNewDIBBits, lpDIBBits, lLineBytes * height);
for(i = iTempMY; i <height-iTempH+iTempMY+1; i++)
{
for(j = iTempMX; j <width-iTempW+iTempMX+1; j++)
{
lpDst = (unsigned char*)lpNewDIBBits+lLineBytes*(height-1-i)+j;
fResult = 0;
int m=0;
for (k = 0; k <iTempH; k++)
{
for (l = 0; l < iTempW; l++)
{
lpSrc = (unsigned char*)lpDIBBits+lLineBytes*(height-1-i+iTempMY-k)
+j-iTempMX+l;
fResult+=(*lpSrc)*PixelValue[m];
m++;
}
}
if(fResult<0) fResult=0;
else if(fResult > 255)
{
* lpDst = 255;
}
else
{
* lpDst = (unsigned char) (fResult + 0.5);
}
}
}
memcpy(lpDIBBits, lpNewDIBBits, lLineBytes*height);
LocalUnlock(hNewDIBBits);
LocalFree(hNewDIBBits);
InvalidateRect(NULL,TRUE);
}
void CShiqian0197View::OnLvboTthigh()
{
// TODO: Add your command handler code here
CShiqian0197Doc* pDoc=GetDocument();
int iTempH;
int iTempW;
int iTempMX;
int iTempMY;
float PixelValue[9];
HDIB hDIB;
hDIB=pDoc->m_hDIB;
if (hDIB==NULL)
return;
LPSTR lpDIB=(LPSTR)GlobalLock((HGLOBAL)hDIB);
int width=DIBWidth(lpDIB);
int height=DIBHeight(lpDIB);
LPSTR lpDIBBits=FindDIBBits(lpDIB);
int bitcount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
// 设置拉普拉斯模板参数
iTempW = 3;
iTempH = 3;
iTempMX = 1;
iTempMY = 1;
PixelValue[0] = -1.0;
PixelValue[1] = -1.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -