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

📄 gatherdlg.cpp

📁 一个关于聚类应用的程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// GatherDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Gather.h"
#include "GatherDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

CDC dcComp;
CDC dcComp1;
//CDC done;

myRGB rgb[10];//用来存储样本中心点
myRGB rgb1[10];//画线中介存储器
//myRGB rgb2;
//myRGB rgb3;

DIS DisTance;//距离结构体
int DisBiaoZhi;//鼠标移动的标志位

int x,y;///坐标点
int wide,hieght;
int i,j;
int s4b,s3a,x1;
int psx,psy,pex,pey;
int psx1,psy1,pex1,pey1;
int psx2,psy2,pex2,pey2;
int dian=0;//点选标志
int kuang=0;//框选标志
int xianxing=0;//线性分类标志

int z0[2]={0,0},z1[2]={0,0},z2[2]={0,0};//绘一维模式坐标图Y轴的坐标
int z3[2]={0,0},z4[2]={0,0},z5[2]={0,0};//绘一维模式坐标图Y轴的坐标
int z6[2]={0,0},z7[2]={0,0},z8[2]={0,0},z9[2]={0,0};//绘一维模式坐标图Y轴的坐标

int mmm0=0,mmm1=0,mmm2=0,mmm3=0,mmm4=0;//WetherMove()函数调用标志
int mmm5=0,mmm6=0,mmm7=0,mmm8=0,mmm9=0;//WetherMove()函数调用标志

int kex,key;//框选末点坐标
int ksx,ksy;
int ClassNum;//类数
int GeW,ShiW,BaiW;
int JiShuShangXian;
//int JuLeiCiShuXianShi=0;
int leineiyangbengeshu=0;
int juleimoshi;//1 R,2 G,3 B,4 RG,5 RB,6 GB,7 RGB
int FindCenterCount=0;//找中心点计数
int kSign=0;//当框选超过类数时的报警标志
int l;//绘何种图的标志
int m=0;//PintRGB()函数的标志
//int r,g,b;
int s1=0,s2=0;//标志
CString ClrText;

CBitmap bitmap1;
CBitmap bitmap;
CRect  rect;

int jj=0;//ShowRGB()函数调用
int jjj=0;//WetherMove()函数调用
int RUNcishu=1;//WetherMove()函数用到

BITMAP bmInfo1;
BITMAP bmInfo;
//////////坐标原点//////
int xstart=20;
int ystart=440;
//////////////////////
int xend=20;
int yend=700;

int xstart1=300;
int ystart1=700;
////////////坐标原点//////
int xs=320;
int ys=440;
/////////////////////////
int xe=320;
int ye=700;

int xs1=620;
int ys1=700;
/////////////////////////////

int gdata[700][500];
int rdata[700][500];
int bdata[700][500];

int gdata1[700][500]={0};
int rdata1[700][500]={0};
int bdata1[700][500]={0};

///用来存储聚类中归类过程类别数据的数组/////
int gdt[10][240000];
int rdt[10][240000];
int bdt[10][240000];



class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGatherDlg dialog

CGatherDlg::CGatherDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGatherDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGatherDlg)
	m_x = 0;
	m_y = 0;
	m_r = 0;
	m_g = 0;
	m_b = 0;
	m_wide = 0;
	m_hieght = 0;
	JuLeiCiShuXianShi = 0;
	m_strRG = _T("");
	m_strRB = _T("");
	m_strBG = _T("");
	m_strRGB = _T("");
	m_strR = _T("");
	m_strG = _T("");
	m_strB = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGatherDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGatherDlg)
	DDX_Control(pDX, IDC_LIST2, m_list1);
//	DDX_Control(pDX, IDC_COMBO3, m_Combolei);
	DDX_Control(pDX, IDC_COMBO6, m_BaiWei);
	DDX_Control(pDX, IDC_COMBO5, m_ShiWei);
	DDX_Control(pDX, IDC_COMBO4, m_GeWei);
	DDX_Control(pDX, IDC_COMBO2, m_Combo1);
	DDX_Control(pDX, IDC_COMBO1, m_Combo);
	DDX_Control(pDX, IDC_LIST1, m_list);
//	DDX_Text(pDX, IDC_EDIT1, m_x);
//	DDX_Text(pDX, IDC_EDIT2, m_y);
//	DDX_Text(pDX, IDC_EDIT3, m_r);
//	DDX_Text(pDX, IDC_EDIT4, m_g);
//	DDX_Text(pDX, IDC_EDIT5, m_b);
//DX_Text(pDX, IDC_EDIT6, m_wide);
//	DDX_Text(pDX, IDC_EDIT7, m_hieght);
	DDX_Text(pDX, IDC_EDIT9, JuLeiCiShuXianShi);
//	DDX_Text(pDX, IDC_EDIT8, m_strRG);
//	DDX_Text(pDX, IDC_EDIT10, m_strRB);
//	DDX_Text(pDX, IDC_EDIT11, m_strBG);
//	DDX_Text(pDX, IDC_EDIT12, m_strRGB);
//	DDX_Text(pDX, IDC_EDIT13, m_strR);
//	DDX_Text(pDX, IDC_EDIT14, m_strG);
//	DDX_Text(pDX, IDC_EDIT15, m_strB);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGatherDlg, CDialog)
	//{{AFX_MSG_MAP(CGatherDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5RUN)
	ON_BN_CLICKED(IDC_BUTTON6, OnButtonInition)
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8ChongZhi)
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9xianshizhongxin)
	ON_BN_CLICKED(IDC_BUTTON10, OnButton10ZiDong)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGatherDlg message handlers

BOOL CGatherDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here


	m_Combo.InsertString(0,"一维R模式");
	m_Combo.InsertString(1,"一维G模式");
	m_Combo.InsertString(2,"一维B模式");
	m_Combo.InsertString(3,"二维RG模式");
	m_Combo.InsertString(4,"二维RB模式");
	m_Combo.InsertString(5,"二维BG模式");
	m_Combo.InsertString(6,"三维RGB模式");
	m_Combo.SetCurSel(0);

	m_Combo1.InsertString(0,"一类");
	m_Combo1.InsertString(1,"二类");
	m_Combo1.InsertString(2,"三类");
	m_Combo1.InsertString(3,"四类");
	m_Combo1.InsertString(4,"五类");
	m_Combo1.InsertString(5,"六类");
	m_Combo1.InsertString(6,"七类");
	m_Combo1.InsertString(7,"八类");
	m_Combo1.InsertString(8,"九类");
	m_Combo1.InsertString(9,"十类");
	m_Combo1.SetCurSel(0);

	m_GeWei.InsertString(0,"0");
	m_GeWei.InsertString(1,"1");
	m_GeWei.InsertString(2,"2");
	m_GeWei.InsertString(3,"3");
	m_GeWei.InsertString(4,"4");
	m_GeWei.InsertString(5,"5");
	m_GeWei.InsertString(6,"6");
	m_GeWei.InsertString(7,"7");
	m_GeWei.InsertString(8,"8");
	m_GeWei.InsertString(9,"9");
	m_GeWei.SetCurSel(0);

	m_ShiWei.InsertString(0,"0");
	m_ShiWei.InsertString(1,"1");
	m_ShiWei.InsertString(2,"2");
	m_ShiWei.InsertString(3,"3");
	m_ShiWei.InsertString(4,"4");
	m_ShiWei.InsertString(5,"5");
	m_ShiWei.InsertString(6,"6");
	m_ShiWei.InsertString(7,"7");
	m_ShiWei.InsertString(8,"8");
	m_ShiWei.InsertString(9,"9");
	m_ShiWei.SetCurSel(0);

	m_BaiWei.InsertString(0,"0");
	m_BaiWei.InsertString(1,"1");
	m_BaiWei.InsertString(2,"2");
	m_BaiWei.InsertString(3,"3");
	m_BaiWei.InsertString(4,"4");
	m_BaiWei.InsertString(5,"5");
	m_BaiWei.InsertString(6,"6");
	m_BaiWei.InsertString(7,"7");
	m_BaiWei.InsertString(8,"8");
	m_BaiWei.InsertString(9,"9");
	m_BaiWei.SetCurSel(0);

/*	m_Combolei.InsertString(0,"第1类");
	m_Combolei.InsertString(1,"第2类");
	m_Combolei.InsertString(2,"第3类");
	m_Combolei.InsertString(3,"第4类");
	m_Combolei.InsertString(4,"第5类");
	m_Combolei.InsertString(5,"第6类");
	m_Combolei.InsertString(6,"第7类");
	m_Combolei.InsertString(7,"第8类");
	m_Combolei.InsertString(8,"第9类");
	m_Combolei.InsertString(9,"第10类");
	m_Combolei.SetCurSel(0);*/
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGatherDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGatherDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}


}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGatherDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGatherDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	CClientDC pDC2(this);
	if(point.x<wide&&point.y<hieght&&dian==1)
	{COLORREF clr = pDC2.GetPixel(point.x,point.y); //获取当前鼠标点像素值
	
	m_r=GetRValue(clr);
	m_g=GetGValue(clr);
	m_b=GetBValue(clr);

	rgb[FindCenterCount].R=m_r;
    rgb[FindCenterCount].G=m_g;
	rgb[FindCenterCount].B=m_b;
	rgb1[FindCenterCount].R=m_r;
    rgb1[FindCenterCount].G=m_g;
	rgb1[FindCenterCount].B=m_b;
	FindCenterCount++;
	            if(juleimoshi==7)
				{
		

				}
	/////////////////////一维模式///////////////////////////////////////               
				if(juleimoshi==1)
				{

				}
				
				if(juleimoshi==2)
				{

				}
				
				if(juleimoshi==3)
				{

				}
				///////////////////二维模式///////////////////////////////////
				if(juleimoshi==4)
				{
                    COLORREF crColor=pDC2.SetPixel( m_r+xs,m_g+ys, clr);
				}
				
				if(juleimoshi==5)
				{
                    COLORREF crColor=pDC2.SetPixel( m_r+xs,m_b+ys, clr);
				}
				
				if(juleimoshi==6)
				{
                    COLORREF crColor=pDC2.SetPixel( m_b+xs,m_g+ys, clr);
				}
	
	

	m_y=point.y;
	m_x=point.x;
	x=m_x;
	y=m_y;
	ShowRGB(x, y, kex, key,1);//1为点选
	}
	if(point.x<wide&&point.y<hieght&&kuang==1)
	{
		COLORREF clr = pDC2.GetPixel(point.x,point.y); //获取当前鼠标点像素值
		
		m_r=GetRValue(clr);
		m_g=GetGValue(clr);
		m_b=GetBValue(clr);
		m_y=point.y;
		m_x=point.x;
		x=m_x;
		y=m_y;

	}
	if(!(point.x<wide&&point.y<hieght&&dian==1)&&!(point.x<wide&&point.y<hieght&&kuang==1))
	{
		m_y=0;
		m_x=0;
		m_r=0;
		m_g=0;
		m_b=0;
	}
		

	ReleaseDC(&pDC2);
	UpdateData(FALSE);
	
	
	CDialog::OnLButtonDown(nFlags, point);
}

void CGatherDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	CClientDC pDC5(this);

	
  if(point.x<wide&&point.y<hieght&&kuang==1)
	{
		key=point.y;
		kex=point.x;
     
	    
		
	
		rgb[FindCenterCount]=FineCenter(x,y,kex,key);
		rgb1[FindCenterCount]=FineCenter(x,y,kex,key);
		FindCenterCount++;
		ShowRGB(x, y, kex, key,0);//零为框选
		SetPixelk(x, y, kex, key);
		if(kSign=0)
		{
			MessageBox("不能再选了!");
		}
        //kSign--;
		//pDC5.SelectObject(oldpen1);
	}



  UpdateData(FALSE);
    ReleaseDC(&pDC5);
	
	CDialog::OnLButtonUp(nFlags, point);
}

void CGatherDlg::SetPixelk(int x, int y, int x1, int y1)
{
	//UpdateData(FALSE);
	COLORREF crColor4;
	CClientDC pDC6(this);
	COLORREF Colorstore3;
	for(i=x;i<=x1;i++)
	   {	for(j=y;j<=y1;j++)
	{
		Colorstore3 = pDC6.GetPixel(i,j); //获取当前鼠标点像素值
		//原点(700,10)
		if(juleimoshi==4)//r,g
		{crColor4=pDC6.SetPixel( rdata[i][j]+xstart,gdata[i][j]+ystart, Colorstore3);
		//m=1;
		}
		if(juleimoshi==5)//r,b
		{crColor4=pDC6.SetPixel( rdata[i][j]+xstart,bdata[i][j]+ystart, Colorstore3);
		//m=1;
		}
        if(juleimoshi==6)//b,g
		{crColor4=pDC6.SetPixel( bdata[i][j]+xstart,gdata[i][j]+ystart, Colorstore3);
		//m=1;
		}
		
		
	}
	}
	ReleaseDC(&pDC6);

}

myRGB CGatherDlg::FineCenter(int x, int y, int x11, int y11)
{
	myRGB rgbF;
	rgbF.B=0;
	rgbF.G=0;
	rgbF.R=0;
	for(i=x;i<=x11;i++)
	   {	for(j=y;j<=y11;j++)
	{
		rgbF.R=rgbF.R+rdata[i][j];
		rgbF.G=rgbF.G+gdata[i][j];
		rgbF.B=rgbF.B+bdata[i][j];
		

⌨️ 快捷键说明

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