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

📄 rsimagestarview.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// RSImageStarView.cpp : implementation of the CRSImageStarView class
//

#include "stdafx.h"
#include "RSImageStar.h"

#include "RSImageStarDoc.h"
#include "RSImageStarView.h"
#include "MainFrm.h"
#include "AdjustHueDlg.h"
#include "SubStretchDlg.h"
#include "FilterDlg.h"
#include "MyFontDlg.h"
#include "CoordDlg.h"
#include "math.h"


#pragma comment( lib, "MSIMG32.LIB")

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


extern HCURSOR			hHandGrabed;
extern HCURSOR			hHandWantGrab;
extern HCURSOR			hHandpoint;
extern HCURSOR          hCusorMove;
extern CRSImageStarView *m_pView;
/////////////////////////////////////////////////////////////////////////////
// CRSImageStarView


IMPLEMENT_DYNCREATE(CRSImageStarView, CScrollView)

BEGIN_MESSAGE_MAP(CRSImageStarView, CScrollView)
	//{{AFX_MSG_MAP(CRSImageStarView)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
	ON_WM_ERASEBKGND()
	ON_COMMAND(ID_IMAGE_HUE, OnImageHue)
	ON_COMMAND(ID_IMAGE_SEGMENT, OnImageSegment)
	ON_COMMAND(ID_IMAGE_STRETCH, OnImageStretch)
	ON_COMMAND(ID_IMAGE_ARITHMETIC, OnImageArithmetic)
	ON_WM_TIMER()
	ON_WM_SETCURSOR()
	ON_WM_CREATE()
	ON_COMMAND(ID_ZOOMIN, OnZoomIn)
	ON_COMMAND(ID_ZOOMOUT, OnZoomOut)
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_EDIT_CUT, OnEditCut)
	ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
	ON_COMMAND(ID_LAYER_MERGEVISUNIT, OnLayerMergevisunit)
	ON_UPDATE_COMMAND_UI(ID_LAYER_MERGEVISUNIT, OnUpdateLayerMergevisunit)
	ON_COMMAND(ID_LAYER_MERGEDOWNUNIT, OnLayerMergedownunit)
	ON_UPDATE_COMMAND_UI(ID_LAYER_MERGEDOWNUNIT, OnUpdateLayerMergedownunit)
	ON_COMMAND(ID_EDIT_POLY, OnEditPoly)
	ON_COMMAND(ID_EDIT_VPOLYLINE, OnEditVpolyline)
	ON_COMMAND(ID_IMAGE_BITMAP, OnImageBitmap)
	ON_UPDATE_COMMAND_UI(ID_IMAGE_BITMAP, OnUpdateImageBitmap)
	ON_COMMAND(ID_IMAGE_GRAY, OnImageGray)
	ON_UPDATE_COMMAND_UI(ID_IMAGE_GRAY, OnUpdateImageGray)
	ON_COMMAND(ID_IMAGE_INDEX, OnImageIndex)
	ON_UPDATE_COMMAND_UI(ID_IMAGE_INDEX, OnUpdateImageIndex)
	ON_COMMAND(ID_IMAGE_RGB, OnImageRgb)
	ON_UPDATE_COMMAND_UI(ID_IMAGE_RGB, OnUpdateImageRgb)
	ON_COMMAND(ID_EDIT_POSITION, OnEditPosition)
	ON_WM_SIZE()
	ON_COMMAND(IDC_PEN_COLOR, OnPencolor1)
	ON_COMMAND(IDC_FILL_COLOR, OnFillcolor1)
	ON_COMMAND(IDC_LAYER_COLOR,OnLayerColor)
	ON_WM_RBUTTONDBLCLK()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND_RANGE(ID_PALETTEERASE,ID_PALETTETEXT, OnPalette)
	ON_UPDATE_COMMAND_UI_RANGE(ID_PALETTEERASE,	ID_PALETTETEXT, OnUpdatePalette)

	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()

/////////////////////////////////////////////////////////////////////////////
// CRSImageStarView construction/destruction

CRSImageStarView::CRSImageStarView()
{
	// TODO: add construction code here
//画符号的操作变量
	m_symbol=0;
	
//
	m_InVRect=CRect(0,0,0,0);
	m_DrawRect=CRect(0,0,0,0);
    m_DrawType=0;
	m_ToolOption=0;

	time=-1;
	flagtime=0;
	flagLB=m_MoveRgn=false;
     m_hDibEmpty=false;
	m_PreView=m_InValidateRect=false;
	m_PolyLine=m_Poly=false;
    pos.x=-100;

    strfont="";
    logfont.lfUnderline=false;
	logfont.lfStrikeOut=false;
    logfont.lfHeight=30;
    strcpy(logfont.lfFaceName,"Arial");
     
	m_fScale=float(1.0);
	m_pDoc=NULL;
//*****************************	
	m_bDrawFreeline = false;
	m_bErasing      = false;
    m_bDrawingRubber= false;
	m_bDrawRect     = false;
    m_TextCurve     = false;
	m_TextColor   = RGB(0,0,0);

	m_nPenStyle   = PS_SOLID;
	m_nPenWidth   = 1;
	m_crPenColor  = TransColor;
	m_crFillColor = TransColor;
}

CRSImageStarView::~CRSImageStarView()
{
//	bitmap.DeleteObject();
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
//	pMain->m_wndMyDialogBar.DeleteItem();
	pMain->m_wndMyDialogBar.SetButtonColor(RGB(255,255,255));
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CRSImageStarView drawing

void CRSImageStarView::OnDraw(CDC* pDC)
{
//	m_pDoc = GetDocument();
	ASSERT_VALID(m_pDoc);
	// TODO: add draw code for native data here
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
	pMain->m_wndBrowseBar.DrawMiniImage();
  	if(m_pDoc->m_Dib!=NULL)
	{
	// 显示图像
	    GetClientRect(&m_ClientRect);
	    pDC->DPtoLP(m_ClientRect);
//	    BeginWaitCursor();
		if(!m_PreView)
		{
		   CDC dcmem;
		   dcmem.CreateCompatibleDC(pDC);

		   CBitmap* pOldBitmap = dcmem.SelectObject(&bitmap);

		   m_pDoc->tempptr=m_pDoc->head;
 //把各层图象输出到内存DC中
		   if(!m_InValidateRect)
		   {
			   if(m_pDoc->head!=NULL)
			   {
				   CPoint point=m_pDoc->tempptr->LUpoint;
				   point.x=int(point.x*m_fScale);
				   point.y=int(point.y*m_fScale);
				   if(m_pDoc->tempptr->flagwrite==TRUE)
				      m_pDoc->tempptr->dib->m_hDIB=m_pDoc->m_Dib->m_hDIB;
				   if((m_DrawRect.Width()>2)&&(m_pDoc->tempptr->dib->m_hDIB!=NULL))
					   m_pDoc->tempptr->dib->m_WorkRect=m_DrawRect;

				   if(m_pDoc->tempptr->flagdraw==TRUE)
					   m_pDoc->tempptr->dib->DrawMemDC(&dcmem,m_ClientRect,point,m_fScale,true);
				   m_pDoc->tempptr=m_pDoc->tempptr->next;

				   while((m_pDoc->tempptr!=NULL))
				   {
					   point=m_pDoc->tempptr->LUpoint;
					   point.x=int(point.x*m_fScale);
					   point.y=int(point.y*m_fScale);
					   if(m_pDoc->tempptr->flagwrite==TRUE)
						   m_pDoc->tempptr->dib->m_hDIB=m_pDoc->m_Dib->m_hDIB;
                       m_pDoc->tempptr->dib->m_WorkRect=m_DrawRect;

					   if(m_pDoc->tempptr->flagdraw==TRUE)
						   m_pDoc->tempptr->dib->DrawMemDC(&dcmem,m_ClientRect,point,m_fScale);
					   m_pDoc->tempptr=m_pDoc->tempptr->next;
				   }
			   }
			   //内存DC中图象显示的屏幕
			   CPoint point;
			   point.x=point.y=0;
			   m_pDoc->head->dib->DrawMemDCtoDC(pDC,&dcmem,&bitmap,m_ClientRect,point,m_fScale);
		   }
//对给定画图的矩形区进行快速更新
		   else
		   {
		       m_InValidateRect=false;
			   pDC->DPtoLP(&m_InVRect);
			   if(m_pDoc->head!=NULL)
			   {
				   m_pDoc->tempptr=m_pDoc->head;
				   CPoint point=m_pDoc->tempptr->LUpoint;
				   point.x=int(point.x*m_fScale);
				   point.y=int(point.y*m_fScale);
				   if(m_pDoc->tempptr->flagdraw==TRUE)
				   {
                       m_pDoc->tempptr->dib->m_ReRect=true;
					   m_pDoc->tempptr->dib->DrawMemDC(&dcmem,m_InVRect,point,m_fScale,true);
				   }
				   m_pDoc->tempptr=m_pDoc->tempptr->next;
				   while((m_pDoc->tempptr!=NULL))
				   {
					   point=m_pDoc->tempptr->LUpoint;
					   point.x=int(point.x*m_fScale);
					   point.y=int(point.y*m_fScale);
					   
					   if(m_pDoc->tempptr->flagdraw==TRUE)
					   {
                           m_pDoc->tempptr->dib->m_ReRect=true;
						   m_pDoc->tempptr->dib->DrawMemDC(&dcmem,m_InVRect,point,m_fScale);
					   }
					   m_pDoc->tempptr=m_pDoc->tempptr->next;
				   }
			   }
			   
//内存DC中图象显示到屏幕
			   CPoint point;
			   point.x=point.y=0;	
			   m_pDoc->head->dib->DrawMemDCtoDC(pDC,&dcmem,&bitmap,m_InVRect,point,m_fScale);
		   }
		   dcmem.SelectObject(pOldBitmap);
		   ::DeleteDC(dcmem);
		}	
       
//进行图象处理功能效果的实时予览,当前显示m_hPreDib屏幕图象的图象块句柄,
//		m_PreView予览标志
	    if((m_pDoc->m_Dib->m_hPreDib!=NULL)&&(m_PreView))
		{
	       LPBYTE lpDIBHdr  = (LPBYTE) ::GlobalLock((HGLOBAL)m_pDoc->m_Dib->m_hPreDib);
		   LPBITMAPINFO lpmap=(LPBITMAPINFO)lpDIBHdr;
		   int m=lpmap->bmiHeader.biBitCount;
		   int nn=m_pDoc->curptr->dib->GetColorMapNum(m)*sizeof(RGBQUAD);
		   int width=lpmap->bmiHeader.biWidth;
		   int height=lpmap->bmiHeader.biHeight;
		   CPoint pos=GetScrollPosition();
           LPBYTE lpDIBBits=(lpDIBHdr+lpmap->bmiHeader.biSize+nn);
		   StretchDIBits(pDC->m_hDC,                    // hDC
				    pos.x,             // DestX
				    pos.y,              // DestY
				    width,        // nDestWidth
				    height,// nDestHeight
				    0,0,
				    width,height,
				    lpDIBBits,  // lpBits
				    lpmap,     // lpBitsInfo
					DIB_RGB_COLORS,
					SRCCOPY);      
          GlobalUnlock(m_pDoc->m_Dib->m_hPreDib);
		}
//		EndWaitCursor();
	}
}

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

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	m_pDoc = GetDocument();
	ASSERT_VALID(m_pDoc);
 	m_fSize=sizeTotal;

//使整幅图象以一定比例显示在给定窗口
	if(m_pDoc->head!=NULL)
	{
		sizeTotal=m_pDoc->m_Dib->GetDimensions();
		m_fSize=sizeTotal;

        CRect rect;
		GetClientRect(&rect);
		float scale=rect.Height()/float(sizeTotal.cy);
		float scale1=rect.Width()/float(sizeTotal.cx);
		if((scale<scale1)&&((scale<1.0)||(scale1<1.0)))
		{
			while(scale<1.0)
			{
				scale*=2.0;
				m_fScale/=2.0;
				sizeTotal.cx/=2;
				sizeTotal.cy/=2;
			}
		}
		else if((scale<1.0)||(scale1<1.0))
		{
			while(scale1<1.0)
			{
				scale1*=2.0;
				m_fScale/=2.0;
				sizeTotal.cx/=2;
				sizeTotal.cy/=2;
			}
		}
	}
	SetScrollSizes(MM_TEXT, sizeTotal);
	if(m_pDoc->head!=NULL)
	   ResizeParentToFit();
}

/////////////////////////////////////////////////////////////////////////////
// CRSImageStarView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CRSImageStarView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CRSImageStarView message handlers

void CRSImageStarView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_pDoc = GetDocument();
	ASSERT_VALID(m_pDoc);
    if(m_pDoc->head!=NULL)
	{
		m_pDoc->m_Dib->CreateMicroImg();
	    m_pDoc->curptr->dib->GetHistogram();
		if(m_fSize.cy==100)
		{
			CSize sizeTotal=m_pDoc->m_Dib->GetDimensions();
			m_fSize=sizeTotal;
			
			CRect rect;
			rect.left=rect.top=0;
	        rect.bottom = int(::GetSystemMetrics(SM_CYSCREEN) *0.85);
            rect.right = int(::GetSystemMetrics(SM_CXSCREEN) *0.85); 			float scale=rect.Height()/float(sizeTotal.cy);
			float scale1=rect.Width()/float(sizeTotal.cx);
			if((scale<scale1)&&((scale<1.0)||(scale1<1.0)))
			{
				while(scale<1.0)
				{
					scale*=2.0;
					m_fScale/=2.0;
					sizeTotal.cx/=2;
					sizeTotal.cy/=2;
				}
			}
			else if((scale<1.0)||(scale1<1.0))
			{
				while(scale1<1.0)
				{
					scale1*=2.0;
					m_fScale/=2.0;
					sizeTotal.cx/=2;
					sizeTotal.cy/=2;
				}
			}
			SetScrollSizes(MM_TEXT, sizeTotal);
			ResizeParentToFit();
		}
	}
	CRect rect;
	GetClientRect(&rect);
	InvalidateRect(rect, false);				// 更新视类图像	
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
	pMain->m_wndBrowseBar.Invalidate();	    
}

void CRSImageStarView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
    m_pView=(CRSImageStarView*)pActivateView;

//更新浏览框,生成对应视的浏览图
	pMain->m_wndBrowseBar.Invalidate(true);	
	if(m_pView==NULL)
	   m_pView = (CRSImageStarView*)pMain->GetActiveFrame()->GetActiveView();

//更新图层框,生成对应视的图层
    if(m_pView!=NULL)
	{
		if(m_pView->m_pDoc->filename!=pMain->m_wndMyDialogBar.filename)
		 if(pActivateView!=pDeactiveView)
			pMain->m_wndMyDialogBar.OpenItem();
		else
			pMain->m_wndMyDialogBar.OpenItem();
	}
	else
	    pMain->m_wndMyDialogBar.OpenItem();

    pMain->m_wndPaintParamBar.Restore();
	CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}


void CRSImageStarView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    CClientDC dc(this);
    OnPrepareDC(&dc);
	startLpPoint=point;
    CPoint ppoint=point;
	dc.DPtoLP(&ppoint);
	startpoint=ppoint;
    endpoint=startpoint;
    temppoint=startpoint;

 	ClientToDib(startpoint);
    flagLB=true;
//在视图中画符号
	if(m_symbol==1)	
	{
        m_pDoc->curptr->dib->m_ReDraw=true;
		CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
//		CPen* pOldPen = pDibDC->SelectObject(&pen);
//		pDibDC->MoveTo(startpoint);
//		pDibDC->LineTo(pt);
//		pDibDC->SelectObject(pOldPen);
	
        symbol.DrawPot(pDibDC,FileNamePot,startpoint);
		m_pDoc->curptr->dib->EndPaint();
		Invalidate(false);
	}

//当拷贝矩形框不为空时,进行浮动拷贝块的拖动
    if(m_ToolOption==MOVE)
	{
		 if(m_DrawType==ROUND)
			 int mmm=0;
		 if(m_DrawRect.Width()<=1)
		 {
			 AfxMessageBox("没有选中的区域!");
             flagLB=false;
			 return;
		 }
		 if((m_hDibEmpty==false)&&(flagLB)&&(m_DrawRect.PtInRect(ppoint)))
		 {
	          CSize size=m_pDoc->m_Dib->GetDimensions();
		      CPoint Luppoint,Rbottompoint;

	          Luppoint.x=m_DibRect.left;
	          Luppoint.y=m_DibRect.top;
	          Rbottompoint.x=m_DibRect.right;
	          Rbottompoint.y=m_DibRect.bottom;
              
		      m_pDoc->tempptr=m_pDoc->head;
			  while(m_pDoc->tempptr!=NULL)
              {
				  if(m_pDoc->tempptr->flagwrite==TRUE)
                  {
					  m_pDoc->tempptr->dib->m_ReDraw=true;
					  m_pDoc->tempptr->dib->GetCopyHandle(Luppoint,Rbottompoint); 
                      m_pDoc->m_Dib->m_hDIB=m_pDoc->tempptr->dib->m_hDIB;
				      m_hDibEmpty=true;
				  }
				  m_pDoc->tempptr=m_pDoc->tempptr->next;
			  }

			  COLORREF FillColor;
			  if(m_pDoc->curptr->pre==NULL)
				  FillColor=m_crFillColor;
			  else
			      FillColor=TransColor;

⌨️ 快捷键说明

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