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

📄 rsimagestarview.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
📖 第 1 页 / 共 5 页
字号:

		temppoint=startpoint;
		DibToClient(temppoint);

		if(pos.x>=0)
		{		
			if(m_ToolOption==SELECT)	
				dc.Rectangle(temppoint.x,temppoint.y,endpoint.x,endpoint.y);
			else if(m_ToolOption==ROUND)	
				dc.RoundRect(temppoint.x,temppoint.y,endpoint.x,endpoint.y,
				int(abs(endpoint.x-temppoint.x)/5.0),int(abs(endpoint.y-temppoint.y)/5.0));
			else if(m_ToolOption==OVAL)	
				dc.Ellipse(temppoint.x,temppoint.y,endpoint.x,endpoint.y);
			else if(m_ToolOption==RECT)	
				dc.Rectangle(temppoint.x,temppoint.y,endpoint.x,endpoint.y);
		}
		pos=pt;
		if(m_ToolOption==SELECT)	
			dc.Rectangle(temppoint.x,temppoint.y,pt.x,pt.y);
		else if(m_ToolOption==ROUND)	
			dc.RoundRect(temppoint.x,temppoint.y,pt.x,pt.y,
			int(abs(pt.x-temppoint.x)/5.0),int(abs(pt.y-temppoint.y)/5.0));
		else if(m_ToolOption==OVAL)	
			dc.Ellipse(temppoint.x,temppoint.y,pt.x,pt.y);
		else if(m_ToolOption==RECT)	
			dc.Rectangle(temppoint.x,temppoint.y,pt.x,pt.y);

		dc.SetROP2(nOldRop);
		dc.SelectObject(pOldPen);
		endpoint=pt;
	}

	else if(m_bDrawingRubber)
	{
		SetCursor(m_Cross);
		CPen pen(m_nPenStyle, int(m_nPenWidth*m_fScale+0.5), RGB(0,0,0));

		CClientDC dc(this);
		OnPrepareDC(&dc);

        int nOldRop;
		CPen* pOldPen;
		CPoint pt = point;
	    dc.DPtoLP(&pt);

		{		
			nOldRop = dc.SetROP2(R2_NOTXORPEN);
		    pOldPen = dc.SelectObject(&pen);

            temppoint=startpoint;
			DibToClient(temppoint);
			if(pos.x!=-100)
			{
				dc.MoveTo(temppoint);
				dc.LineTo(pos);
			}
			dc.MoveTo(temppoint);
			CPoint postemp=pt;
			dc.LineTo(postemp);
			dc.SetROP2(nOldRop);
		    dc.SelectObject(pOldPen);
		}
		pos=pt;
 		endpoint=pt;
	}

	else if(m_ToolOption==POLYLINE)
	{
		SetCursor( m_Cross);
		if(m_PolyLine)
		{
			CClientDC dc(this);
			OnPrepareDC(&dc);
			CPoint pt = point;
			dc.DPtoLP(&pt);
	
			CPen pen(m_nPenStyle,int(m_nPenWidth*m_fScale+0.5), RGB(0,0,0));
			CPen* pOldPen = dc.SelectObject(&pen);
			int nOldRop = dc.SetROP2(R2_NOTXORPEN);
			if(pos.x!=-100)
			{
				dc.MoveTo(temppoint);
				dc.LineTo(pos);
			}
			dc.MoveTo(temppoint);
			dc.LineTo(pt);
			dc.SetROP2(nOldRop);
			dc.SelectObject(&pOldPen);
            pos=pt;
		}
	}

	CMainFrame *pFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
	CStatusBar *pStatus=(CStatusBar *)pFrame->GetDescendantWindow(AFX_IDW_STATUS_BAR);
   
	if(pStatus)
	{
		CString str;
		CDC *dc;
		dc=GetDC();
		int r,g,b;
	    COLORREF curcolor;
	    curcolor=dc->GetPixel(point);
        OnPrepareDC(dc);
        CPoint ppoint=point;
	    dc->DPtoLP(&ppoint);
		ClientToDib(ppoint);
		if(ppoint.x>m_fSize.cx||ppoint.y>m_fSize.cy)
			return;

		r=GetRValue(curcolor);
	    g=GetGValue(curcolor);
	    b=GetBValue(curcolor);
		str.Format("坐标 x= %d  y= %d  RGB(%d  %d  %d)",ppoint.x,ppoint.y,r,g,b);
	    pStatus->SetPaneStyle(0,SBPS_NORMAL);
		pStatus->SetPaneText(0,str);
	    ReleaseDC(dc);
	}
	CScrollView::OnMouseMove(nFlags, point);
}

void CRSImageStarView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    m_InValidateRect=false;
	pos.x=-100;

	if (m_bDrawFreeline)
	{
		m_bDrawFreeline = FALSE;
		ReleaseCapture();
	}
	else if (m_bErasing)
	{
		m_bErasing = FALSE;
		ReleaseCapture();
	}

	else if(m_ToolOption==PAINT)
	{
		SetCursor(m_Paint);
		CClientDC dc(this);
		OnPrepareDC(&dc);

        m_InVRect=m_DrawRect;
		dc.LPtoDP(m_InVRect);
		m_InValidateRect=true;
		InvalidateRect(m_InVRect,false);
//		Invalidate(false);
	}
    else if(m_bDrawRect&&(!m_MoveRgn))
	{
		m_bDrawRect=false;
		pos.x=-100;
		temppoint=startpoint;
		DibToClient(temppoint);

		if(temppoint.x>endpoint.x)
		{
			m_DrawRect.left=endpoint.x;
			m_DrawRect.right=temppoint.x;
		}
		else
		{
			m_DrawRect.left=temppoint.x;
			m_DrawRect.right=endpoint.x;
		}
		if(temppoint.y>endpoint.y)
		{
			m_DrawRect.top=endpoint.y;
			m_DrawRect.bottom=temppoint.y;
		}
		else
		{
			m_DrawRect.top=temppoint.y;
			m_DrawRect.bottom=endpoint.y;
		}
		m_DibRect=m_DrawRect;
		ClientToDib(m_DibRect);
		m_DrawType=m_ToolOption;
        CreateRgn();
	}

	else if(m_bDrawingRubber&&(m_ToolOption==LINE))
	{
        m_bDrawingRubber=false;
		m_InValidateRect=true;

		CPen pen(m_nPenStyle, m_nPenWidth, m_crPenColor);

		CClientDC dc(this);
		OnPrepareDC(&dc);

		CPoint pt = point;
		dc.DPtoLP(&pt);
		ClientToDib(pt);

		CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
		CPen* pOldPen = pDibDC->SelectObject(&pen);
        pDibDC->MoveTo(startpoint);
		pDibDC->LineTo(pt);
		pDibDC->SelectObject(pOldPen);
		m_pDoc->curptr->dib->EndPaint();
        CRect rect;
		
		if(startLpPoint.x<point.x)
        {
		   rect.left=startLpPoint.x-3;
		   rect.right=point.x+3;
		}
		else
		{
		   rect.left=point.x-3;
		   rect.right=startLpPoint.x+3;
		}
		if(startpoint.y<pt.y)
		{
		   rect.top =startLpPoint.y-3;
		   rect.bottom=point.y+3;
		}
		else
		{
		   rect.top =point.y-3;
		   rect.bottom=startLpPoint.y+3;
		}
		m_InVRect=rect;
		InvalidateRect(rect,false);
		ReleaseCapture();
	}
    else if(m_ToolOption==ImageBrowse)
		ReleaseCapture();

	else if(m_ToolOption==POLYLINE)
	{
		CPen pen(m_nPenStyle, m_nPenWidth, m_crPenColor);
		CClientDC dc(this);
		OnPrepareDC(&dc);

		CPoint pt = point;
		dc.DPtoLP(&pt);
        temppoint=pt;
		ClientToDib(pt);
		CDC * pDibDC = m_pDoc->curptr->dib->BeginPaint(&dc);
		CPen* pOldPen = pDibDC->SelectObject(&pen);
        pDibDC->MoveTo(m_TempPoint);
		pDibDC->LineTo(pt);
		pDibDC->SelectObject(pOldPen);
		m_pDoc->curptr->dib->EndPaint();

        int width=int(m_nPenWidth*m_fScale+3.5);
		CRect rect;
		if(m_TempPoint.x<pt.x)
		{
			rect.left=m_TempPoint.x-width;
			rect.right=pt.x+width;
		}
		else
		{
			rect.left=pt.x-width;
			rect.right=m_TempPoint.x+width;
		}
		if(m_TempPoint.y<pt.y)
		{
			rect.top=m_TempPoint.y-width;
			rect.bottom=pt.y+width;
		}
		else
		{
			rect.top=pt.y-width;
			rect.bottom=m_TempPoint.y+width;
		}

		m_InValidateRect=true;
		m_InVRect=rect;
		DibToClient(m_InVRect);
		dc.LPtoDP(m_InVRect);
		m_TempPoint=pt;
		InvalidateRect(m_InVRect,false);
	}

	flagLB=false; 
	m_MoveRgn=false;
	CScrollView::OnLButtonUp(nFlags, point);
}

void CRSImageStarView::DrawSelectionRect(CDC* pDC)
{
   CRect rect;
   rect=m_DrawRect;
   CPen pen;
   pen.CreatePen(PS_DOT,1,RGB(0,0,0));
   CPen *oldpen=pDC->SelectObject(&pen);
   pDC->SelectStockObject(NULL_BRUSH );
   pDC->Rectangle(&rect);
   pDC->SelectObject(oldpen);
}

void CRSImageStarView::OnEditCopy() 
{
	// TODO: Add your command handler code here
//把要拷贝的区域逻辑坐标转化为图象坐标
	CPoint Luppoint,Rbottompoint;
    
    CRect rect;
	rect=m_DibRect;

	Luppoint.x=rect.left;
	Luppoint.y=rect.top;
	Rbottompoint.x=rect.right;
	Rbottompoint.y=rect.bottom;
//拷贝选择区域到剪切板
    m_pDoc->m_Dib->GetCopyHandle(Luppoint,Rbottompoint);
	m_pDoc->m_Dib->CopyToClipboard();
}

void CRSImageStarView::OnUpdateEditCopy(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
    CRect rect;
	rect=m_DrawRect;
    pCmdUI->Enable((rect.Width()>=2)&&(rect.Height()>=2));	
}


void CRSImageStarView::OnEditPaste() 
{
	// TODO: Add your command handler code here
//粘贴剪切板数据到当前层的m_hDIB句柄中,浮动显示
    m_pDoc->m_Dib->PasteFromClipboard();
	LPBYTE lpDib = (LPBYTE) ::GlobalLock(m_pDoc->m_Dib->m_hDIB);
    ASSERT(lpDib);
    LPBITMAPINFO lpbmi=(LPBITMAPINFO)lpDib;
	int width=lpbmi->bmiHeader.biWidth;
    int height=lpbmi->bmiHeader.biHeight;
    GlobalUnlock(m_pDoc->m_Dib->m_hDIB);
//计算粘贴到图象中的位置
    CRect rect;
    CClientDC dc(this);
    OnPrepareDC(&dc);
	GetClientRect(&rect);
	dc.DPtoLP(rect);
    ClientToDib(rect);

	if(rect.right>m_fSize.cx)
		rect.right=m_fSize.cx;
	if(rect.bottom>m_fSize.cy)
		rect.bottom=m_fSize.cy;

	m_DrawRect.left   = (rect.left+rect.right-width)/2;
	m_DrawRect.top    = (rect.top+rect.bottom-height)/2;
	m_DrawRect.right  = (rect.left+rect.right+width)/2;
	m_DrawRect.bottom = (rect.top+rect.bottom+height)/2;

	if(m_DrawRect.left<0)
	{
		m_DrawRect.right-=m_DrawRect.left;
		m_DrawRect.left=0;
	}
	if(m_DrawRect.top<0)
	{
		m_DrawRect.bottom-=m_DrawRect.top;
		m_DrawRect.top=0;
	}
    m_hDibEmpty=true;
    m_DibRect=m_DrawRect;
    DibToClient(m_DrawRect);
	if(m_pDoc->pHead!=NULL)
	{
		CPoint pos;
		pos.x=m_pDoc->curptr->dib->m_RgnRect.left-m_DibRect.left;
		pos.y=m_pDoc->curptr->dib->m_RgnRect.top-m_DibRect.top;
		m_pDoc->pTempPt=m_pDoc->pHead;
		while(m_pDoc->pTempPt!=NULL)
		{
			m_pDoc->pTempPt->point-=pos;
			m_pDoc->pTempPt=m_pDoc->pTempPt->next;
		}
	}
    CreateRgn();

	if(time==-1)
	  time=SetTimer(1,300,NULL);
    Invalidate(false);
}

void CRSImageStarView::OnUpdateEditPaste(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable((m_pDoc->m_Dib->PasteAvailable())&&(m_pDoc->m_Dib!=NULL));
}


BOOL CRSImageStarView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
    CPoint totalsize=GetTotalSize();
	CRect rect;
	GetClientRect(&rect);
	if((totalsize.x>rect.Width())&&(totalsize.y>rect.Height()))
	     return false;
	else
	    return CScrollView::OnEraseBkgnd(pDC);
}

void CRSImageStarView::OnUpdatePalette(CCmdUI* pCmdUI)
{
	pCmdUI->SetCheck( m_ToolOption==pCmdUI->m_nID);
}

void CRSImageStarView::OnPalette(UINT nID)
{
    m_ToolOption=nID;
	m_symbol=0;
}

void CRSImageStarView::OnImageHue() 
{
//图象亮度,对比度调整
	// TODO: Add your command handler code here
    m_PreView=true;
	CDC *dc=GetDC();
	CPoint point=m_pDoc->curptr->LUpoint;
	point.x=int(point.x*m_fScale);
	point.y=int(point.y*m_fScale);
//拷贝显示区图象到内存,供预览时调用
    BOOL flag=m_pDoc->m_Dib->GetImgFromView(dc,m_ClientRect,point,m_fScale);
	ReleaseDC(dc);
    if(!flag)
		return;
    CAdjustHueDlg  dlg;
	if(dlg.DoModal()==IDOK)
	{
		int m=dlg.m_nslid1;
		int n=dlg.m_nslid2;
		BeginWaitCursor();
		if(m!=100)
		{
			m_pDoc->curptr->dib->AdjustBrightness(m);
			m_pDoc->SetModifiedFlag();
		}
		if(n!=100)
		{
		  m_pDoc->curptr->dib->AdjustContrast(n);
		  m_pDoc->SetModifiedFlag();
		}
		EndWaitCursor();
	}
    m_pDoc->UpdateAllViews(NULL);
    m_PreView=false;
}


void CRSImageStarView::OnImageSegment() 
{
	// TODO: Add your command handler code here

}

void CRSImageStarView::OnImageStretch() 
{
	// TODO: Add your command handler code here
//图象分段线形拉伸
    m_PreView=true;
	CDC *dc=GetDC();
	CPoint point=m_pDoc->curptr->LUpoint;
	point.x=int(point.x*m_fScale);
	point.y=int(point.y*m_fScale);
//拷贝显示区图象到内存,供预览时调用
    BOOL flag=m_pDoc->m_Dib->GetImgFromView(dc,m_ClientRect,point,m_fScale);
	ReleaseDC(dc);
    if(!flag)
		return;
    CSubStretchDlg  dlg;
	if(dlg.DoModal()==IDOK)
	{
       CPoint pos[128];
       float scale[128];
	   for(int i=0;i<dlg.ncount;i++)
	   {
		   pos[i]=dlg.pos[i];
		   scale[i]=dlg.scale[i];
	   }
	   BeginWaitCursor();
       m_pDoc->curptr->dib->AdjustImage(pos,scale);
	   EndWaitCursor();
	}
	m_pDoc->UpdateAllViews(NULL);    		
    m_PreView=false;
}

void CRSImageStarView::OnImageArithmetic() 
{
	// TODO: Add your command handler code here
//图象滤波
    m_PreView=true;
	CDC *dc=GetDC();
	CPoint point=m_pDoc->curptr->LUpoint;
	point.x=int(point.x*m_fScale);
	point.y=int(point.y*m_fScale);
//拷贝显示区图象到内存,供预览时调用
    BOOL flag=m_pDoc->m_Dib->GetImgFromView(dc,m_ClientRect,point,m_fScale);
	ReleaseDC(dc);
    if(!flag)
		return;
	char matr[3][3];
	CFilterDlg dlg;
	if(dlg.DoModal()==IDOK)
	{
		BeginWaitCursor();
		int count=0;
        for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
			{
				matr[i][j]=dlg.num[count];
				count++;
			}
		m_pDoc->curptr->dib->FilterW3(matr);

⌨️ 快捷键说明

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