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

📄 selfclusterdlg.cpp

📁 基于小波的SAR斑点处理
💻 CPP
字号:
// SelfClusterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RSIP.h"
#include "SelfClusterDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSelfClusterDlg dialog


CSelfClusterDlg::CSelfClusterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSelfClusterDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSelfClusterDlg)
	m_nClassNum = 10;
	m_nClusterTime = 10;
	m_nImgHeight = 0;
	m_nImgWidth = 0;
	m_static = _T("");
	//}}AFX_DATA_INIT
	m_nImageCount = 0;
}

CSelfClusterDlg::~CSelfClusterDlg()
{
	CString *pszTemp;
	for(int i=0; i<m_nImageCount; i++)
	{
		pszTemp = (CString *)(m_aImageArray[i]);
		delete pszTemp;
	}
	m_aImageArray.RemoveAll();
}

void CSelfClusterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSelfClusterDlg)
	DDX_Control(pDX, IDC_LIST1, m_ImageList);
	DDX_Text(pDX, IDC_CLASSNUM, m_nClassNum);
	DDV_MinMaxInt(pDX, m_nClassNum, 2, 255);
	DDX_Text(pDX, IDC_CLUSTERTIME, m_nClusterTime);
	DDV_MinMaxInt(pDX, m_nClusterTime, 2, 100);
	DDX_Text(pDX, IDC_IMGHEIGHT, m_nImgHeight);
	DDX_Text(pDX, IDC_IMGWIDTH, m_nImgWidth);
	DDX_Text(pDX, IDC_STATIC1, m_static);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSelfClusterDlg, CDialog)
	//{{AFX_MSG_MAP(CSelfClusterDlg)
	ON_BN_CLICKED(IDC_BROWSEFILE, OnBrowsefile)
	ON_BN_CLICKED(IDC_REMOVEIMAGE, OnRemoveimage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelfClusterDlg message handlers

void CSelfClusterDlg::OnBrowsefile() 
{
	CFileDialog fileDlg(TRUE,"*.DAT",
		NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, 
		"Image Files(*.dat)|*.dat||",this);
	char lpstrFile[32764];
	lpstrFile[0]='\0';
	fileDlg.m_ofn.lpstrFile=lpstrFile;
	fileDlg.m_ofn.nMaxFile=32764;
	if ( fileDlg.DoModal() == IDOK )
	{
		POSITION pos = fileDlg.GetStartPosition();
		while ( pos != NULL )
		{
			CString * lpstrPathName = new CString();
			*lpstrPathName = fileDlg.GetNextPathName( pos );

			if(m_nImageCount == 0)
			{
				CString szInfFileName;
				CFile infFile;

				lpstrPathName->TrimLeft();
				lpstrPathName->TrimRight();
				szInfFileName = lpstrPathName->Left(lpstrPathName->GetLength()-4) + ".inf";

				if(0 != infFile.Open(szInfFileName,CFile::modeRead))
				{
					infFile.Seek(2*sizeof(DWORD)+sizeof(int)+258,CFile::begin);
					infFile.Read(&m_nImgWidth,sizeof(int));
					infFile.Read(&m_nImgHeight,sizeof(int));
					SetDlgItemInt(IDC_IMGWIDTH,m_nImgWidth);
					SetDlgItemInt(IDC_IMGHEIGHT,m_nImgHeight);
					infFile.Close();
				}
				
				CFile File;
				if(0 == File.Open(*lpstrPathName,CFile::modeRead))
				{
					MessageBox("打不开数据文件!",
						"错误",
						MB_OK|MB_ICONINFORMATION);
					delete lpstrPathName;
					return;
				}

				if(File.GetLength() != unsigned long(m_nImgWidth * m_nImgHeight))
				{
					MessageBox("文件大小不匹配!",
						"错误",
						MB_OK|MB_ICONINFORMATION);
					File.Close();
					delete lpstrPathName;
					return;
				}
				File.Close();
			}
			else
			{
				CFile File;
				if(0 == File.Open(*lpstrPathName,CFile::modeRead))
				{
					MessageBox("打不开数据文件!",
						"错误",
						MB_OK|MB_ICONINFORMATION);
					delete lpstrPathName;
					return;
				}

				if(File.GetLength() != unsigned long(m_nImgWidth*m_nImgHeight))
				{
					MessageBox("文件大小不匹配!",
						"错误",
						MB_OK|MB_ICONINFORMATION);
					File.Close();
					delete lpstrPathName;
					return;
				}
				File.Close();
			}
			m_ImageList.AddString(*lpstrPathName);
			m_ImageList.SetCurSel(m_nImageCount);

			m_aImageArray.Add(lpstrPathName);
			
			m_nImageCount ++;
		}
	}
}

void CSelfClusterDlg::OnRemoveimage() 
{
	int nCurSel = m_ImageList.GetCurSel();
	if(nCurSel<0)
		return;
	
	CString *pszTemp;
	pszTemp = (CString *)(m_aImageArray[nCurSel]);
	delete pszTemp;

	m_aImageArray.RemoveAt(nCurSel);
	
	m_ImageList.DeleteString(nCurSel);
	m_ImageList.SetCurSel(0);

	m_nImageCount --;	
}

void CSelfClusterDlg::OnOK() 
{
	UpdateData();
	if(m_nClusterTime<=2 || m_nClassNum<=1)
	{
		MessageBox("输入值错误!",
			"错误",
			MB_OK|MB_ICONINFORMATION);
		return;
	}
	if(m_nImageCount<=2)
	{
		MessageBox("必须至少选取三幅图象",
			"错误",
			MB_OK|MB_ICONINFORMATION);
		return;
	}
	
	CDialog::OnOK();
}

/*
void CSelfClusterDlg::SetCaption(CString & str)
{
	SetWindowText(str);
}
*/

⌨️ 快捷键说明

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