📄 classifyinfodlg.cpp
字号:
m_nCurrentIndex = nClassCount;
m_nClassID = nClassCount;
m_clrColor = RGB(0,0,0);
m_bChange = TRUE;
SetDlgItemInt(IDC_CLASSID,m_nClassID);
SetDlgItemInt(IDC_CLASSCOLORRED,GetRValue(m_clrColor));
SetDlgItemInt(IDC_CLASSCOLORGREEN,GetGValue(m_clrColor));
SetDlgItemInt(IDC_CLASSCOLORBLUE,GetBValue(m_clrColor));
m_bChange = FALSE;
RECT Rect;
SetRect(&Rect,86,99,113,125);
MapDialogRect(&Rect);
InvalidateRect(&Rect);
pTemp = new CRSClassInfo();
pTemp->m_clrColor = m_clrColor;
pTemp->m_nValue = m_nClassID;
pTemp->m_szClassName = "";
pTemp->m_pdCenter = NULL;
pTemp->m_pdCovariance = NULL;
pTemp->m_nRegionNumber = 0;
pTemp->m_aTrainingRegion.RemoveAll();
m_pRSClassifyInfoFile->m_aClassInfoArray.Add(pTemp);
m_pRSClassifyInfoFile->m_nClassCount += 1;
GetDlgItem(IDC_SAVECLASSINFO)->EnableWindow(TRUE);
GetDlgItem(IDC_NEWCLASS)->EnableWindow(FALSE);
GetDlgItem(IDC_EXISTCLASS)->EnableWindow(FALSE);
}
void CClassInfoDlg1::OnExistclass()
{
m_nMethod = 1;
GetDlgItem(IDC_SAVECLASSINFO)->EnableWindow(TRUE);
GetDlgItem(IDC_NEWCLASS)->EnableWindow(FALSE);
GetDlgItem(IDC_EXISTCLASS)->EnableWindow(FALSE);
}
void CClassInfoDlg1::OnSelchangeClassnamelist()
{
if(m_nMethod == 0)
return;
else
{
int nIndex = m_ClassNameList.GetCurSel();
if(m_nCurrentIndex == nIndex)
return;
else
m_nCurrentIndex = nIndex;
CRSClassInfo * pTemp;
pTemp = (CRSClassInfo *)m_pRSClassifyInfoFile->m_aClassInfoArray.GetAt(m_nCurrentIndex);
m_nClassID = pTemp->m_nValue;
m_clrColor = pTemp->m_clrColor;
m_bChange = TRUE;
SetDlgItemInt(IDC_CLASSID,m_nClassID);
SetDlgItemInt(IDC_CLASSCOLORRED,GetRValue(m_clrColor));
SetDlgItemInt(IDC_CLASSCOLORGREEN,GetGValue(m_clrColor));
SetDlgItemInt(IDC_CLASSCOLORBLUE,GetBValue(m_clrColor));
m_bChange = FALSE;
RECT Rect;
SetRect(&Rect,86,99,113,125);
MapDialogRect(&Rect);
InvalidateRect(&Rect);
}
}
void CClassInfoDlg1::OnOK()
{
// 计算新的分类信息
m_pRSClassifyInfoFile->Calculate();
// 保存新的分类信息
CFileDialog fileDlg(FALSE,"*.CLS",
NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Classes Files(*.cls)|*.cls||",this);
if(fileDlg.DoModal()==IDOK)
{
CFile file;
if(0 != file.Open(fileDlg.GetPathName(),CFile::modeCreate|CFile::modeWrite))
{
m_pRSClassifyInfoFile->SaveAsFile(file);
file.Close();
}
else
{
AfxMessageBox("创建文件失败!");
return;
}
}
m_pView->m_nMouseAction = MOUSE_NOTHING;
m_pView->PostMessage(WM_COMMAND,ID_CLASS_END_PRACTICEREGION,0L);
/*
// 抛弃原有的分类信息
int classCount = m_pView->GetDocument()->m_pRSImage->m_nClassNumber;
LPRSTHEMATICINFO pTemp;
for(int i=0; i<classCount; i++)
{
pTemp = m_pView->GetDocument()->m_pRSImage->m_aThemeInfoArray.GetAt(i);
delete pTemp;
}
m_pView->GetDocument()->m_pRSImage->m_aThemeInfoArray.RemoveAll();
// 保存新的分类信息
classCount = m_pRSClassifyInfoFile->m_nClassCount;
CRSClassInfo * pTmp;
m_pView->GetDocument()->m_pRSImage->m_nClassNumber = classCount;
for(i=0; i<classCount; i++)
{
pTmp = (CRSClassInfo *)m_pRSClassifyInfoFile->m_aClassInfoArray.GetAt(i);
pTemp = new CRsThematicInfo();
pTemp->m_szClassName = pTmp->m_szClassName;
pTemp->m_nValue = pTmp->m_nValue;
pTemp->m_clrColor = pTmp->m_clrColor;
pTemp->m_pdCenter = (double *)new double[m_pRSClassifyInfoFile->m_nImageCount];
for(int j=0; j<m_pRSClassifyInfoFile->m_nImageCount; j++)
pTemp->m_pdCenter[j] = pTmp->m_pdCenter[j];
pTemp->m_pdCovariance = (double *)new double[m_pRSClassifyInfoFile->m_nImageCount*
m_pRSClassifyInfoFile->m_nImageCount];
for(j=0; j<m_pRSClassifyInfoFile->m_nImageCount; j++)
for(int k=0; k<m_pRSClassifyInfoFile->m_nImageCount; k++)
pTemp->m_pdCovariance[j*m_pRSClassifyInfoFile->m_nImageCount+k]
= pTemp->m_pdCovariance[j*m_pRSClassifyInfoFile->m_nImageCount+k];
m_pView->GetDocument()->m_pRSImage->m_aThemeInfoArray.Add(pTmp);
}
*/
// 销毁窗口的其他任务
//CDialog::OnOK();
}
void CClassInfoDlg1::OnPaint()
{
CPaintDC dc(this);
RECT Rect;
SetRect(&Rect,86,99,113,125);
MapDialogRect(&Rect);
CBrush Brush(m_clrColor);
CBrush *pOldBrush = dc.SelectObject(&Brush);
dc.Rectangle(&Rect);
dc.SelectObject(pOldBrush);
}
void CClassInfoDlg1::OnChangeClassColor()
{
if(m_bChange == TRUE)
return;
int nRed;
int nGreen;
int nBlue;
nRed = GetDlgItemInt(IDC_CLASSCOLORRED);
if(nRed < 0)
nRed = 0;
if(nRed > 255)
nRed = 255;
nGreen = GetDlgItemInt(IDC_CLASSCOLORGREEN);
if(nGreen < 0)
nGreen = 0;
if(nGreen > 255)
nGreen = 255;
nBlue = GetDlgItemInt(IDC_CLASSCOLORBLUE);
if(nBlue < 0)
nBlue = 0;
if(nBlue > 255)
nBlue = 255;
m_clrColor = RGB(nRed,nGreen,nBlue);
((CRSClassInfo *)(m_pRSClassifyInfoFile->m_aClassInfoArray.GetAt(m_nCurrentIndex)))->m_clrColor = m_clrColor;
RECT Rect;
SetRect(&Rect,86,99,113,125);
MapDialogRect(&Rect);
InvalidateRect(&Rect);
}
void CClassInfoDlg1::OnSaveclassinfo()
{
if(m_nPntCount != 0 && m_nPntNumber != 0)
{
UpdateData(TRUE);
CRSClassInfo * pTemp;
CString pszClassName;
GetDlgItemText(IDC_CLASSNAMELIST,pszClassName);
pTemp = (CRSClassInfo *)m_pRSClassifyInfoFile->m_aClassInfoArray.GetAt(m_nCurrentIndex);
pTemp->m_szClassName = pszClassName;
pTemp->m_nValue = m_nClassID;
pTemp->m_clrColor = m_clrColor;
// 保存内部点
m_pRSClassifyInfoFile->AddTrainingRegion(m_pPointArray,
m_nPntCount,m_nCurrentIndex);
if(m_nPntCount != 0)
{
delete []m_pPointArray;
m_nPntCount = 0;
}
// 保存边界点
m_pRSClassifyInfoFile->AddTrainingPolygon(m_pPntArray,
m_nPntNumber,m_nCurrentIndex);
if(m_nPntNumber != 0)
{
delete []m_pPntArray;
m_nPntNumber = 0;
}
m_nMethod = -1;
OnInitDialog();
}
}
bool CClassInfoDlg1::Create()
{
return CDialog::Create(CClassInfoDlg1::IDD,m_pView);
}
void CClassInfoDlg1::OnCancel()
{
m_pView->m_nMouseAction = MOUSE_NOTHING;
m_pView->PostMessage(WM_COMMAND,ID_CLASS_END_PRACTICEREGION,0L);
//CDialog::OnCancel();
}
/////////////////////////////////////////////////////////////////////////////
// CClassInfoResetDlg dialog
CClassInfoResetDlg::CClassInfoResetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClassInfoResetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CClassInfoResetDlg)
m_nID = 0;
m_szName = _T("");
m_nBlue = 0;
m_nGreen = 0;
m_nRed = 0;
//}}AFX_DATA_INIT
}
void CClassInfoResetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClassInfoResetDlg)
DDX_Text(pDX, IDC_CLASSID, m_nID);
DDX_Text(pDX, IDC_CLASSNAME, m_szName);
DDX_Text(pDX, IDC_COLORBLUE, m_nBlue);
DDX_Text(pDX, IDC_COLORGREEN, m_nGreen);
DDX_Text(pDX, IDC_COLORRED, m_nRed);
//}}AFX_DATA_MAP
m_bChange = FALSE;
}
BEGIN_MESSAGE_MAP(CClassInfoResetDlg, CDialog)
//{{AFX_MSG_MAP(CClassInfoResetDlg)
ON_BN_CLICKED(IDC_SETCOLOR, OnSetcolor)
ON_WM_PAINT()
ON_EN_CHANGE(IDC_COLORBLUE, OnChangeColor)
ON_EN_CHANGE(IDC_COLORGREEN, OnChangeColor)
ON_EN_CHANGE(IDC_COLORRED, OnChangeColor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClassInfoResetDlg message handlers
void CClassInfoResetDlg::OnSetcolor()
{
COLORREF m_clrColor = RGB(m_nRed,m_nGreen,m_nBlue);
CColorDialog ColorDlg(m_clrColor,CC_RGBINIT,this);
if(ColorDlg.DoModal() == IDOK)
{
m_clrColor = ColorDlg.GetColor();
m_nRed = GetRValue(m_clrColor);
m_nGreen = GetGValue(m_clrColor);
m_nBlue = GetBValue(m_clrColor);
m_bChange = TRUE;
SetDlgItemInt(IDC_COLORRED,m_nRed);
SetDlgItemInt(IDC_COLORGREEN,m_nGreen);
SetDlgItemInt(IDC_COLORBLUE,m_nBlue);
m_bChange = FALSE;
RECT Rect;
SetRect(&Rect,118,80,152,109);
MapDialogRect(&Rect);
InvalidateRect(&Rect);
}
}
void CClassInfoResetDlg::OnOK()
{
CDialog::OnOK();
}
void CClassInfoResetDlg::OnPaint()
{
CPaintDC dc(this);
RECT Rect;
SetRect(&Rect,118,80,152,109);
MapDialogRect(&Rect);
COLORREF m_clrColor = RGB(m_nRed,m_nGreen,m_nBlue);
CBrush Brush(m_clrColor);
CBrush *pOldBrush = dc.SelectObject(&Brush);
dc.Rectangle(&Rect);
dc.SelectObject(pOldBrush);
}
BOOL CClassInfoResetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_bChange = TRUE;
SetDlgItemText(IDC_CLASSNAME,m_szName);
SetDlgItemInt(IDC_CLASSID,m_nID);
SetDlgItemInt(IDC_COLORRED,m_nRed);
SetDlgItemInt(IDC_COLORGREEN,m_nGreen);
SetDlgItemInt(IDC_COLORBLUE,m_nBlue);
m_bChange = FALSE;
RECT Rect;
SetRect(&Rect,118,80,152,109);
MapDialogRect(&Rect);
InvalidateRect(&Rect);
return TRUE;
}
void CClassInfoResetDlg::OnChangeColor()
{
if(m_bChange == TRUE)
return;
m_nRed = GetDlgItemInt(IDC_COLORRED);
if(m_nRed < 0)
m_nRed = 0;
if(m_nRed > 255)
m_nRed = 255;
m_nGreen = GetDlgItemInt(IDC_COLORGREEN);
if(m_nGreen < 0)
m_nGreen = 0;
if(m_nGreen > 255)
m_nGreen = 255;
m_nBlue = GetDlgItemInt(IDC_COLORBLUE);
if(m_nBlue < 0)
m_nBlue = 0;
if(m_nBlue > 255)
m_nBlue = 255;
RECT Rect;
SetRect(&Rect,118,80,152,109);
MapDialogRect(&Rect);
InvalidateRect(&Rect);
}
/////////////////////////////////////////////////////////////////////////////
// CCombineClassDlg dialog
CCombineClassDlg::CCombineClassDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCombineClassDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCombineClassDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_aIDs.RemoveAll();
m_nResultID = -1;
m_nResult = -1;
}
CCombineClassDlg::~CCombineClassDlg()
{
/*
int * pInt = NULL;
for(int i=0; i<m_aIDs.GetSize(); i++)
{
pInt = (int *)m_aIDs.GetAt(i);
ASSERT(pInt != NULL);
delete pInt;
}
m_aIDs.RemoveAll();
*/
}
void CCombineClassDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCombineClassDlg)
DDX_Control(pDX, IDC_IDCOMBO, m_IDList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCombineClassDlg, CDialog)
//{{AFX_MSG_MAP(CCombineClassDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCombineClassDlg message handlers
void CCombineClassDlg::OnOK()
{
m_nResult = m_IDList.GetCurSel();
int * pTemp = (int *)m_aIDs.GetAt(m_nResult);
m_nResultID = *pTemp;
CDialog::OnOK();
}
BOOL CCombineClassDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int * pInt = NULL;
for(int i=0; i<m_aIDs.GetSize(); i++)
{
pInt = (int *)m_aIDs.GetAt(i);
ASSERT(pInt != NULL);
char temp[5];
sprintf(temp,"%d",*pInt);
CString strTemp = temp;
m_IDList.AddString(strTemp);
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -