📄 moravec_longview.cpp
字号:
// Moravec_longView.cpp : implementation of the CMoravec_longView class
//
#include "stdafx.h"
#include "Moravec_long.h"
#include "Moravec_longDoc.h"
#include "Moravec_longView.h"
#define W 5
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMoravec_longView
IMPLEMENT_DYNCREATE(CMoravec_longView, CScrollView)
BEGIN_MESSAGE_MAP(CMoravec_longView, CScrollView)
//{{AFX_MSG_MAP(CMoravec_longView)
ON_COMMAND(ID_Moravec, OnMoravec)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_Section, OnSection)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMoravec_longView construction/destruction
CMoravec_longView::CMoravec_longView()
{
// TODO: add construction code here
m_tpoint = new tpoint;
m_tpoint = NULL;
sectionpoint = new tpoint;
k = 0;
m = 0;
m_ifdown = false;
m_wsetsecton = false;
m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
}
CMoravec_longView::~CMoravec_longView()
{
delete m_tpoint;
}
BOOL CMoravec_longView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMoravec_longView drawing
void CMoravec_longView::OnDraw(CDC* pDC)
{
CMoravec_longDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDib *Pbit = pDoc->pDib ;
CPoint point(0,0);
Pbit->Draw(pDC, point, Pbit->GetDimensions());
if(m)
{
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
CPen *oldpen = pDC->SelectObject(&pen);
pDC->MoveTo(stpoint.point.x-5,stpoint.point.y);
pDC->LineTo(stpoint.point.x+5,stpoint.point.y);
pDC->MoveTo(stpoint.point.x,stpoint.point.y-5);
pDC->LineTo(stpoint.point.x,stpoint.point.y+5);
}
else
{
for(int i=0;i<k;i++)
{
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
CPen *oldpen = pDC->SelectObject(&pen);
pDC->MoveTo(m_tpoint[i].point.x-5,m_tpoint[i].point.y);
pDC->LineTo(m_tpoint[i].point.x+5,m_tpoint[i].point.y);
pDC->MoveTo(m_tpoint[i].point.x,m_tpoint[i].point.y-5);
pDC->LineTo(m_tpoint[i].point.x,m_tpoint[i].point.y+5);
//delete oldpen;
}
}
if(m_wsetsecton)
{
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(255,255,0));
CPen *oldpen = pDC->SelectObject(&pen);
pDC->MoveTo(m_startpoint.x,m_startpoint.y);
pDC->LineTo(m_endpoint.x,m_startpoint.y);
pDC->MoveTo(m_startpoint.x,m_startpoint.y);
pDC->LineTo(m_startpoint.x,m_endpoint.y);
pDC->MoveTo(m_startpoint.x,m_endpoint.y);
pDC->LineTo(m_endpoint.x,m_endpoint.y);
pDC->MoveTo(m_endpoint.x,m_startpoint.y);
pDC->LineTo(m_endpoint.x,m_endpoint.y);
}
}
void CMoravec_longView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
CMoravec_longDoc* pDoc = GetDocument();
if(pDoc->pDib->fileopen==1) /////添加滚动条。
{
sizeTotal.cx = pDoc->pDib->GetDimensions().cx;
sizeTotal.cy = pDoc->pDib->GetDimensions().cy;
}
else
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CMoravec_longView printing
BOOL CMoravec_longView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMoravec_longView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMoravec_longView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMoravec_longView diagnostics
#ifdef _DEBUG
void CMoravec_longView::AssertValid() const
{
CScrollView::AssertValid();
}
void CMoravec_longView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CMoravec_longDoc* CMoravec_longView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMoravec_longDoc)));
return (CMoravec_longDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMoravec_longView message handlers
int CMoravec_longView::Min(int* m,int n)
{
int temp;
int i;
temp = m[0];
for(i=0;i<n;i++)
{
if(temp>m[i])
temp = m[i];
}
return temp;
}
tpoint CMoravec_longView::Max(tpoint* m,int n)
{
int temp,i,j;
temp = m[0].D;
j = 0;
for(i=0;i<n;i++)
{
if(temp<m[i].D)
{
temp = m[i].D;
j = i;
}
}
return m[j];
}
void CMoravec_longView::OnMoravec() //Moravec算子程序
{
// TODO: Add your command handler code here
int i,j;
BYTE *m_pGrayImg;
int *m_D;
CMoravec_longDoc* pDoc = GetDocument();
CDib *Pt ;
Pt = pDoc->pDib ;
int width=Pt->GetDimensions().cx ;
width=(width*8+31)/32*4;
int height=Pt->GetDimensions().cy;
m_pGrayImg =( (BYTE*) Pt->m_lpImage);
m_tpoint = new tpoint [width*height];
m_D = new int [width*height];
k=0;
for(i=2;i<height-2;i++)
for(j=2;j<width-2;j++)
{
int *temp;
temp = new int [4];
temp[0] = (m_pGrayImg[(i-2)*width+j]-m_pGrayImg[(i-1)*width+j])^2
+(m_pGrayImg[(i-1)*width+j]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[(i+1)*width+j])^2
+(m_pGrayImg[(i+1)*width+j]-m_pGrayImg[(i+2)*width+j])^2;
temp[1] = (m_pGrayImg[(i-2)*width+(j-2)]-m_pGrayImg[(i-1)*width+(j-1)])^2
+(m_pGrayImg[(i-1)*width+(j-1)]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[(i+1)*width+(j+1)])^2
+(m_pGrayImg[(i+1)*width+(j+1)]-m_pGrayImg[(i+2)*width+(j+2)])^2;
temp[2] = (m_pGrayImg[(i-2)*width+(j+2)]-m_pGrayImg[(i-1)*width+(j+1)])^2
+(m_pGrayImg[(i-1)*width+(j+1)]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[(i+1)*width+(j+1)])^2
+(m_pGrayImg[(i+1)*width+(j-1)]-m_pGrayImg[(i+2)*width+(j-2)])^2;
temp[3] = (m_pGrayImg[i*width+(j-2)]-m_pGrayImg[i*width+(j-1)])^2
+(m_pGrayImg[i*width+(j-1)]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[i*width+(j+1)])^2
+(m_pGrayImg[i*width+(j+1)]-m_pGrayImg[i*width+(j+2)])^2;
m_D[i*width+j] = Min(temp,4);
if(m_D[i*width+j]>W)
{
m_tpoint[k].point.x = j;//width-
m_tpoint[k].point.y = height-i;//
m_tpoint[k].D = m_D[i*width+j];
m_tpoint[k].gray = m_pGrayImg[i*width+j];
k++;
}
delete [] temp;
}
pDoc->UpdateAllViews(NULL);
}
void CMoravec_longView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_tpoint)
{
SetCapture();
::SetCursor(m_hCross);
m_startpoint = point;
m_ifdown = true;
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CMoravec_longView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_tpoint)
{
if(m_ifdown)
{
m_endpoint = point;
m_ifdown = false;
ReleaseCapture();
}
SectionSelect(m_startpoint,m_endpoint);
}
CScrollView::OnLButtonUp(nFlags, point);
}
void CMoravec_longView::SectionSelect(CPoint point1, CPoint point2)
{
int i;
m = 0;
// int *temp;
sectionpoint = new tpoint [k];
for(i=0;i<k;i++)
{
if(((m_tpoint[i].point.x<m_endpoint.x&&m_tpoint[i].point.x>m_startpoint.x)||
(m_tpoint[i].point.x>m_endpoint.x&&m_tpoint[i].point.x<m_startpoint.x))&&
((m_tpoint[i].point.y<m_endpoint.y&&m_tpoint[i].point.y>m_startpoint.y)||
(m_tpoint[i].point.y>m_endpoint.y&&m_tpoint[i].point.y<m_startpoint.y)))
{
sectionpoint[m] = m_tpoint[i];
m++;
}
}
/* temp = new int [k];
for(i=0;i<m;i++)
{
temp[i] = sectionpoint[i].D;
}
*/
// int max = Max(temp,m);
// stpoint = sectionpoint[max];
stpoint = Max(sectionpoint,m);
m_wsetsecton = true;
CMoravec_longDoc* pDoc = GetDocument();
pDoc->UpdateAllViews(NULL);
// delete temp;
}
void CMoravec_longView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* if(m_tpoint)
{
if(m_ifdown)
{
m_endpoint = point;
m_wsetsecton = true;
CMoravec_longDoc* pDoc = GetDocument();
pDoc->UpdateAllViews(NULL);
}
}
*/
CScrollView::OnMouseMove(nFlags, point);
}
void CMoravec_longView::OnSection()
{
// TODO: Add your command handler code here
CMoravec_longDoc* pDoc = GetDocument();
int i,j;
BYTE *m_pGrayImg; //a1,*a2,*a3,*a4,*a5,*a6,*a7,*a8,*a9;
CDib *Pt ;
Pt = pDoc->pDib ;
int width=Pt->GetDimensions().cx ;
width=(width*8+31)/32*4;
int height=Pt->GetDimensions().cy;
m_pGrayImg =( (BYTE*) Pt->m_lpImage);
tpoint *tempoint;
k = 0;
int t = 0;
tempoint = new tpoint [width*height];
m_tpoint = new tpoint [width*height];
for(i=2;i<height-2;i++)
for(j=2;j<width-2;j++)
{
int *temp;
temp = new int [4];
temp[0] = (m_pGrayImg[(i-2)*width+j]-m_pGrayImg[(i-1)*width+j])^2
+(m_pGrayImg[(i-1)*width+j]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[(i+1)*width+j])^2
+(m_pGrayImg[(i+1)*width+j]-m_pGrayImg[(i+2)*width+j])^2;
temp[1] = (m_pGrayImg[(i-2)*width+(j-2)]-m_pGrayImg[(i-1)*width+(j-1)])^2
+(m_pGrayImg[(i-1)*width+(j-1)]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[(i+1)*width+(j+1)])^2
+(m_pGrayImg[(i+1)*width+(j+1)]-m_pGrayImg[(i+2)*width+(j+2)])^2;
temp[2] = (m_pGrayImg[(i-2)*width+(j+2)]-m_pGrayImg[(i-1)*width+(j+1)])^2
+(m_pGrayImg[(i-1)*width+(j+1)]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[(i+1)*width+(j+1)])^2
+(m_pGrayImg[(i+1)*width+(j-1)]-m_pGrayImg[(i+2)*width+(j-2)])^2;
temp[3] = (m_pGrayImg[i*width+(j-2)]-m_pGrayImg[i*width+(j-1)])^2
+(m_pGrayImg[i*width+(j-1)]-m_pGrayImg[i*width+j])^2
+(m_pGrayImg[i*width+j]-m_pGrayImg[i*width+(j+1)])^2
+(m_pGrayImg[i*width+(j+1)]-m_pGrayImg[i*width+(j+2)])^2;
int D = Min(temp,4);
tempoint[t].point.x = j;//width-
tempoint[t].point.y = height-i;//
tempoint[t].D = D;
tempoint[t].gray = m_pGrayImg[i*width+j];
t++;
delete [] temp;
}
for(i=0;i<height-4;i=i+13)
for(j=0;j<width-4;j=j+13)
{
int s=0;
tpoint *tp;
tp = new tpoint [width*height];
for(int m=i;m<i+5;m++)
for(int n=j;n<j+5;n++)
{
tp[s] = tempoint[m*width+n];
s++;
}
/* int *temp;
temp = new int [s];
for(int a=0;a<s;a++)
{
temp[a] = tp[a].D;
}
int max = Max(temp,s);
*/
tpoint temp = Max(tp,s);
if(temp.D>W)
{
m_tpoint[k] = temp;
k++;
}
delete [] tp;
// delete [] temp;
}
delete [] tempoint;
pDoc->UpdateAllViews(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -