www.pudn.com > roadextr.rar > roadextrView.cpp
// roadextrView.cpp : implementation of the CRoadextrView class
//
#include "stdafx.h"
#include "roadextr.h"
#include "roadextrDoc.h"
#include "roadextrView.h"
#include "valdef.h "
#include "DefValue.h"
//#include "road.h"
#include "mainfrm.h"
#include "roadnet.h"
#include "canny.h"
#include "WMlib.h"
#include "bline.h"
#include "imgp.h"
#include "imgp2.h"
#include "strline.h"
#include "string.h"
#include "extractlib.h"
#include "rdDLG0.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRoadextrView
IMPLEMENT_DYNCREATE(CRoadextrView, CScrollView)
BEGIN_MESSAGE_MAP(CRoadextrView, CScrollView)
//{{AFX_MSG_MAP(CRoadextrView)
ON_COMMAND(ID_STRROADNET, OnStrroadnet)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CRoadextrView construction/destruction
CRoadextrView::CRoadextrView()
{
// TODO: add construction code here
nExtrType = NOT_USE;
bSnap = FALSE;
bClose = FALSE;
bCorner = FALSE;
bShowBMP = TRUE;
bCatchEdge = false;
bGetInitRect = bGetInitRENZI = false;
bSegmentation = false;
bMSLine=bMBSPLine=bSLine=bCentLine=bDbLine=FALSE;
dwPtSegmentNum=dwOneLinePtNum=0L;
// wSeedCount=wSeedNum=0;
ni=0;
nScrX=nScrY=nImgBeginX=nImgBeginY=nMouseMvFg=0;
pdwNumCp=pdwSegmentCount;
sflag=1;
nRecTotal = 0;
bDigRecog =FALSE;
pobjTotal = (mmOBJECT *)malloc(TOTAL_OBJ_COUNT* sizeof(mmOBJECT));
pobjRec = (mmOBJECTRec *)malloc(1000* sizeof(mmOBJECTRec));
// pptSeed = (dfPOINT *)malloc(100*sizeof(dfPOINT));
pdwSegmentCount = (DWORD *)malloc(100*sizeof(DWORD));
pucImgBuf = (unsigned char *)malloc(3000*3000*sizeof(unsigned char));
pucImgBuf2 = (unsigned char *)malloc(3000*3000*sizeof(unsigned char));
pptCross = (dfPOINT *)malloc(1000*sizeof(dfPOINT));
pdigInfo = (digINFO *)malloc(1000*sizeof(digINFO));
pucImgBlk = (unsigned char *)malloc(1000*1000*sizeof(char));
pCorner = (CornerPt *)malloc(5000*sizeof(CornerPt));
pdfCornerPT = (dfPOINT *)malloc(5000*sizeof(dfPOINT));
pdfInCornerPT = (dfPOINT *)malloc(5000*sizeof(dfPOINT));
pHouPDZJ= (HouPDZJPt *)malloc(300*sizeof(HouPDZJPt));
pCurSegNo = new CurSegNo[3000];
bCopyImage = false;
// pStatus = NULL;
nTotalCount=0;
nObjID = 0;
// pptContrl=pptCen=pptRoadL=pptRoadR=NULL;
nExtrType=0;
nShortLineTh = 1;
nCrossPtC = 0;
nDigStrC = 0;
strDig = "2234";
nPolyPtCount = 0;
nCornerPtC = 0;
nInCornerPtC= 0;
bShowInputPt = TRUE;
bShowVectors = FALSE;
bHouPDZJ = FALSE;
fZoomRate = 1.0;
nCurSegC=0;
}
CRoadextrView::~CRoadextrView()
{
}
BOOL CRoadextrView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CRoadextrView drawing
void CRoadextrView::OnDraw(CDC* pDC)
{
CRoadextrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
BOOL bPrinting = pDC->IsPrinting();
CxImage* ima = pDoc->GetImage();
if (ima) {
pucWholeImg=ima->GetBits();
nWholeImgH=ima->GetHeight();
nWholeImgW=ima->GetWidth();
int cxDIB =nWholeImgW; // Size of DIB - x
int cyDIB =nWholeImgH; // Size of DIB - y
nScrX = GetScrollPosition().x;
nScrY = GetScrollPosition().y;
RECT prectView[1];
CRoadextrView::GetClientRect(prectView);
//Left-Bottom coordinate of the image in the view window
nImgBeginX = nScrX;
nImgBeginY = cyDIB - prectView->bottom - nScrY;
nWholeImgW = nWholeImgW%4==0?nWholeImgW:nWholeImgW+(4-nWholeImgW%4);
nViewWinHeight = prectView->bottom;
//Left-Bottom coordinate of the image in the view window
if (pDoc->GetStretchMode()) {
CRect rect;
// GetClientRect(&rect);
rect.top=0;
rect.left = 0;
rect.bottom = ima->GetHeight();
rect.right = ima->GetWidth();
ima->Draw(pDC->GetSafeHdc(), rect);
}
else {
float zoom=pDoc->GetZoomFactor();
if (zoom==1)
ima->Draw(pDC->GetSafeHdc());
else
ima->Draw(pDC->GetSafeHdc(),
CRect(0,0,(int)(ima->GetWidth()*zoom),(int)(ima->GetHeight()*zoom)));
}
}
/////paint the extracted Objects in the child scroll window view
/////显示提取结果
CClientDC dc(this);
CPen pen(PS_SOLID,1,DRAW_PEN_COLOR);
CPen pen2(PS_SOLID,1,RECO_DIG_COLOR);
CPen * pOldPen2 = NULL;
CPen penSeedPt(PS_SOLID,1,SEED_PT_COLOR);
CPen XorPen(PS_SOLID,1,XOR_PEN_COLOR);
pOldPen2 = dc.SelectObject(&pen);///select draw pen
dc.SetROP2(R2_COPYPEN);
if(bShowVectors)
{
/////draw all extracion result
DrawAllObjects(pobjTotal,pobjRec,nTotalCount,nRecTotal,nImgBeginX,nImgBeginY,
nViewWinHeight,nWholeImgH,&dc,fZoomRate);
DrawAllCrosses(pptCross,nCrossPtC,nImgBeginX,nImgBeginY,nViewWinHeight,nWholeImgH,
&dc,fZoomRate);
}
ShowAllSegsNo(pCurSegNo,nCurSegC,nImgBeginX,nImgBeginY,
nViewWinHeight,nWholeImgH,&dc,fZoomRate);
if(bShowInputPt)
DrawAllInCornerPoints(pdfInCornerPT,nInCornerPtC,nImgBeginX,
nImgBeginY,nViewWinHeight,&dc);
DrawAllCornerPoints(pdfCornerPT,nCornerPtC,nImgBeginX,nImgBeginY,
nViewWinHeight,nWholeImgH,&dc,fZoomRate);
// DrawAllCornerPoints(pCurSegNo,pCurSegNo,nImgBeginX,nImgBeginY,nViewWinHeight,
// nWholeImgH,&dc,fZoomRate);
// if(nPolyPtCount)
dc.SelectObject(pOldPen2);
if(bDigRecog/*&&bDrawRecDig*/)
{ if(bDrawRecDig)
{// dc.Rectangle(nx1,ny1,nx2,ny2);
DrawLine(&dc,nx1,ny1,nx2,ny1);
DrawLine(&dc,nx2,ny1,nx2,ny2);
DrawLine(&dc,nx2,ny2,nx1,ny2);
DrawLine(&dc,nx1,ny2,nx1,ny1);
}
else
{// LPCTSTR str;
// str = "2234";
// dc.SetTextColor(RECO_DIG_COLOR);
// dc.TextOut(nx2,ny2,strDig,4);
}
}
// if(bGetInit)
// {
// int x1,y1,x2,y2,xm,ym;
// x1 = int(pptSeed[0].dfX-nImgBeginX);
// y1 = int(nViewWinHeight -pptSeed[0].dfY+nImgBeginY);
// x2 = int(pptSeed[1].dfX-nImgBeginX);
// y2 = int(nViewWinHeight -pptSeed[1].dfY+nImgBeginY);
// xm = (x1+x2)/2; ym = (y1+y2)/2;
// int d = (int)sqrt((double)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
// DrawLine(&dc,x1,y1,x2,y2);
//
// ////// 画提取范围
// DrawLine(&dc,int(xm-d/2),int(ym+d/2),int(xm+d/2),int(ym+d/2));
// DrawLine(&dc,int(xm+d/2),int(ym+d/2),int(xm+d/2),int(ym-d/2));
// DrawLine(&dc,int(xm+d/2),int(ym-d/2),int(xm-d/2),int(ym-d/2));
// DrawLine(&dc,int(xm-d/2),int(ym-d/2),int(xm-d/2),int(ym+d/2));
//
// }
pOldPen2 = dc.SelectObject(&pen2);
dc.SetROP2(R2_COPYPEN);
dc.SetTextColor(RECO_DIG_COLOR);
DrawDigRect(pdigInfo,nDigStrC,nImgBeginX,nImgBeginY,
nViewWinHeight,&dc);
dc.SelectObject(pOldPen2);
/////set the object ID and object count
//char strMsg[30];
CStatusBar *pStatus = (CStatusBar *)
AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
sprintf(strMsg,"ObjectID: %d",nObjID);
pStatus->SetPaneText(1,strMsg);
sprintf(strMsg,"Object Count: %d",nTotalCount);
pStatus->SetPaneText(2,strMsg);
}
void CRoadextrView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CRoadextrView printing
BOOL CRoadextrView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CRoadextrView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CRoadextrView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CRoadextrView diagnostics
#ifdef _DEBUG
void CRoadextrView::AssertValid() const
{
CScrollView::AssertValid();
}
void CRoadextrView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CRoadextrDoc* CRoadextrView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRoadextrDoc)));
return (CRoadextrDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRoadextrView message handlers
void CRoadextrView::OnStrroadnet()
{
// TODO: Add your command handler code here
if(nWholeImgH*nWholeImgW<=3000*3000)
memcpy(pucImgBuf,pucWholeImg,nWholeImgH*nWholeImgW*sizeof(char));
int pnJunctionC[1];
// FILE *fp;
// BYTE *pImg;
rdDLG0 CrdDLG0;
// fp = fopen("c:\\ImgData\\25pcen.raw","rb+");
// fread(pucImgBuf,sizeof(BYTE),1804*1500,fp);
// SetShortSegDeletedInObjecrtList(pobjTotal,nTotalCount,180.0); ///// 1500,1804,
if( CrdDLG0.DoModal() == IDOK )
{
BeginWaitCursor();
nTotalCount = StrRdNetExtr(pucImgBuf,nWholeImgH,nWholeImgW,//// nWholeImgH,nWholeImgW
pobjTotal,(int)(CrdDLG0.m_fRdWidln),
(int)(CrdDLG0.m_fMaxWid),CrdDLG0.m_nRdGry,
pptCross,pnJunctionC,CrdDLG0.m_fGplen,CrdDLG0.m_fMinLenOpt);
nCrossPtC = *pnJunctionC;
bShowVectors=TRUE;
EndWaitCursor();
}
// fclose(fp);
Invalidate(FALSE);
}