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

📄 picwindow.cpp

📁 c语言实现的遥感图像处理的一些基本操作
💻 CPP
字号:
// PicWindow.cpp : implementation file
//

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

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

/////////////////////////////////////////////////////////////////////////////
// CPicWindow
CPicWindow::CPicWindow()
{
	head=NULL;
	curnode=NULL;
	endnode=NULL;
}

CPicWindow::~CPicWindow()
{
}


BEGIN_MESSAGE_MAP(CPicWindow, CStatic)
	//{{AFX_MSG_MAP(CPicWindow)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPicWindow message handlers

void CPicWindow::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	GetClientRect(&rect);
    CPen pen,pen1,*pOldPen;
	pen.CreatePen(PS_DOT,1, RGB(0, 0, 0));
    pOldPen = dc.SelectObject(&pen);
	for(int i=0;i<=4;i++)
	{
		dc.MoveTo(0,rect.Height()*(4-(i))/4);
		dc.LineTo(rect.Width(),rect.Height()*(4-(i))/4);
		dc.MoveTo(rect.Width()*(4-(i))/4,0);
		dc.LineTo(rect.Width()*(4-(i))/4,rect.Height());
	}
	if(head==NULL)
	{
		head=(struct node *)malloc(sizeof(struct node));
		head->x=rect.left;
		head->y=rect.bottom;
		head->next=NULL;
		head->pre=NULL;
		curnode=head;
		endnode=(struct node *)malloc(sizeof(struct node));
		endnode->x=rect.right;
		endnode->y=rect.top;
		endnode->next=NULL;
		endnode->pre=curnode;
		curnode->next=endnode;
		curnode=endnode;
	}
	struct node *temp;
	temp=head;
	pen1.CreatePen(PS_SOLID,1,RGB(255,255,0));
	dc.SelectObject(&pen1);
	int drawmode=dc.GetROP2();
	dc.SetROP2(R2_XORPEN);
	while(temp->next!=NULL)
	{
		dc.MoveTo(temp->x,temp->y);
		dc.LineTo(temp->next->x,temp->next->y);
	    dc.Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);
		temp=temp->next;
	}
	dc.Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);
    dc.SelectObject( pOldPen );
    dc.SetROP2(drawmode);
		// Do not call CStatic::OnPaint() for painting messages
}

void CPicWindow::AddNode(CPoint point) 
{
	struct node *temp,*temp1;
	temp=head;
	int flag=1;
	while((temp!=NULL)&&(flag))
	{
		if(temp->x>point.x)
		{
		   CDC *dc;
		   dc=GetDC();
           CPen pen,*pOldPen;
	       pen.CreatePen(PS_SOLID,1, RGB(255, 255, 0));
           pOldPen = dc->SelectObject(&pen);

		   int drawmode=dc->GetROP2();
		   dc->SetROP2(R2_XORPEN);
		   dc->MoveTo(temp->pre->x,temp->pre->y);
		   dc->LineTo(temp->x,temp->y);
		   dc->MoveTo(temp->pre->x,temp->pre->y);
		   dc->LineTo(point.x,point.y);
 		   dc->LineTo(temp->x,temp->y);
	       dc->Ellipse(point.x-4,point.y-4,point.x+4,point.y+4);
      
		   temp1=(struct node *)malloc(sizeof(struct node));
		   temp1->x=point.x;
		   temp1->y=point.y;
		   temp1->next=temp;
		   temp1->pre=temp->pre;
		   temp->pre->next=temp1;
		   temp->pre=temp1;
		   curnode=temp1;
		   flag=0;
		   dc->SelectObject(pOldPen);
		   dc->SetROP2(drawmode);
		   ReleaseDC(dc);
		}
		temp=temp->next;
	}
}

void CPicWindow::MoveNode(struct node* temp,CPoint point) 
{
    
	CDC *dc;
	dc=GetDC();
	CPen pen,*pOldPen;
	pen.CreatePen(PS_SOLID,1, RGB(255, 255, 0));
	pOldPen = dc->SelectObject(&pen);

	int drawmode=dc->GetROP2();
	dc->SetROP2(R2_XORPEN);
	if((temp->pre!=NULL)&&(temp->next!=NULL))
	{
       if(point.x>temp->next->x)
		   point.x=temp->next->x;
	   if(point.x<temp->pre->x)
		   point.x=temp->pre->x;
	   if(point.y>rect.bottom)
		   point.y=rect.bottom;
	   if(point.y<rect.top)
		   point.y=rect.top;
	   dc->MoveTo(temp->pre->x,temp->pre->y);
	   dc->LineTo(temp->x,temp->y);
	   dc->LineTo(temp->next->x,temp->next->y);
	   dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);    
       temp->x=point.x;
	   temp->y=point.y;
	   dc->MoveTo(temp->pre->x,temp->pre->y);
	   dc->LineTo(temp->x,temp->y);
	   dc->LineTo(temp->next->x,temp->next->y);
	   dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);  
	}
	else if(temp->pre==NULL)
	{
	   dc->MoveTo(temp->x,temp->y);
	   dc->LineTo(temp->next->x,temp->next->y);
	   dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);    
	   temp->y=point.y;
	   dc->MoveTo(temp->x,temp->y);
	   dc->LineTo(temp->next->x,temp->next->y);
	   dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);  
	}
	else
	{
	   dc->MoveTo(temp->x,temp->y);
	   dc->LineTo(temp->pre->x,temp->pre->y);	   
	   dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);    
	   temp->y=point.y;
	   dc->MoveTo(temp->x,temp->y);
	   dc->LineTo(temp->pre->x,temp->pre->y);
	   dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);  
	}
}

BOOL CPicWindow::DeleteNode() 
{
	struct node *temp,*temp1;
	if((curnode->pre!=NULL)&&(curnode->next!=NULL))
	{
		temp=curnode;
		CDC *dc;
		dc=GetDC();
		CPen pen,*pOldPen;
	    pen.CreatePen(PS_SOLID,1, RGB(255, 255, 0));
        pOldPen = dc->SelectObject(&pen);
		   
		int drawmode=dc->GetROP2();
		dc->SetROP2(R2_XORPEN);
		dc->MoveTo(temp->pre->x,temp->pre->y);
		dc->LineTo(temp->x,temp->y);
		dc->LineTo(temp->next->x,temp->next->y);
		dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);
		temp->next->pre=temp->pre;
		temp->pre->next=temp->next;
		temp1=curnode->pre;
		if(temp->next->next==NULL)
		  curnode=temp->pre;
		else
		  curnode=temp->next;
		free(temp);
		temp=curnode;
		dc->MoveTo(temp1->x,temp1->y);
		dc->LineTo(temp1->next->x,temp1->next->y);
		dc->SelectObject(pOldPen);
		dc->SetROP2(drawmode);
		ReleaseDC(dc);
		return true;
	}
	else
	{
        AfxMessageBox("接点已经全部删除!");
		return false;
	}
}

void CPicWindow::RestoreNode()
{
	struct node *temp,*temp1;
	temp=head;
	CDC *dc;
	dc=GetDC();
	CPen pen,*pOldPen;
	pen.CreatePen(PS_SOLID,1,RGB(255,255,0));
	pOldPen=dc->SelectObject(&pen);
	int drawmode=dc->GetROP2();
	dc->SetROP2(R2_XORPEN);
	while(temp->next!=NULL)
	{
		dc->MoveTo(temp->x,temp->y);
		dc->LineTo(temp->next->x,temp->next->y);
	    dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);
		temp=temp->next;
	}
	dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);

	temp=head;
	while(temp->next!=NULL)
	{
       temp1=temp->next;
	   if(temp->pre!=NULL)
	     free(temp);
	   temp=temp1;
	}
	head->next=endnode;
	head->x=rect.left;
	head->y=rect.bottom;
	endnode->pre=head;
	endnode->x=rect.right;
	endnode->y=rect.top;
	temp=head;
	curnode=endnode;
	while(temp->next!=NULL)
	{
		dc->MoveTo(temp->x,temp->y);
		dc->LineTo(temp->next->x,temp->next->y);
	    dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);
		temp=temp->next;
	}
	dc->Ellipse(temp->x-4,temp->y-4,temp->x+4,temp->y+4);
    dc->SelectObject(pOldPen );
    dc->SetROP2(drawmode);
	ReleaseDC(dc);
}

⌨️ 快捷键说明

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