📄 dipdoc.cpp
字号:
CDibObject *blue = new CDibObject(m_pDibObject);
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
if (PointOperation.GetMixedChannel(blue))
{
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posTemplate);
CDipDoc* pDocument = (CDipDoc*) pDocTemplate->OpenDocumentFile(NULL);
pDocument->m_pDibObject = blue;
pDocument->m_bImageLoaded = TRUE;
CString sSplitCaption;
AfxFormatString1(sSplitCaption, IDS_SPLIT_BLUE_CAPTION, GetTitle());
pDocument->SetTitle(sSplitCaption);
//获取子框架窗口指针
CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
pChild->m_nWidth = m_pDibObject->GetWidth();
pChild->m_nHeight = m_pDibObject->GetHeight();
pChild->SetWindowPos( NULL, 0, 0, pChild->m_nWidth + 12,
pChild->m_nHeight + 38, SWP_NOZORDER | SWP_NOMOVE );
pDocument->UpdateAllViews(NULL);
}
else
AfxMessageBox(IDS_FAIL_SPLIT);
// 恢复光标
EndWaitCursor();
}
void CDipDoc::OnChannelGreen()
{
//获取应用程序类指针
CDipApp *pApp = GetApp();
//获取主框架窗口指针
CMainFrame *pFrame = GetMainFrame();
CDibObject *green = new CDibObject(m_pDibObject);
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
if (PointOperation.GetMixedChannel(green))
{
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posTemplate);
CDipDoc* pDocument = (CDipDoc*) pDocTemplate->OpenDocumentFile(NULL);
pDocument->m_pDibObject = green;
pDocument->m_bImageLoaded = TRUE;
CString sSplitCaption;
AfxFormatString1(sSplitCaption, IDS_SPLIT_GREEN_CAPTION, GetTitle());
pDocument->SetTitle(sSplitCaption);
//获取子框架窗口指针
CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
pChild->m_nWidth = m_pDibObject->GetWidth();
pChild->m_nHeight = m_pDibObject->GetHeight();
pChild->SetWindowPos( NULL, 0, 0, pChild->m_nWidth + 12,
pChild->m_nHeight + 38, SWP_NOZORDER | SWP_NOMOVE );
pDocument->UpdateAllViews(NULL);
}
else
AfxMessageBox(IDS_FAIL_SPLIT);
// 恢复光标
EndWaitCursor();
}
void CDipDoc::OnChannelMixed()
{
//获取应用程序类指针
CDipApp *pApp = GetApp();
//获取主框架窗口指针
CMainFrame *pFrame = GetMainFrame();
CDibObject *mixed = new CDibObject(m_pDibObject);
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
if (PointOperation.GetMixedChannel(mixed))
{
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posTemplate);
CDipDoc* pDocument = (CDipDoc*) pDocTemplate->OpenDocumentFile(NULL);
pDocument->m_pDibObject = mixed;
pDocument->m_bImageLoaded = TRUE;
CString sSplitCaption;
AfxFormatString1(sSplitCaption, IDS_SPLIT_MIXED_CAPTION, GetTitle());
pDocument->SetTitle(sSplitCaption);
//获取子框架窗口指针
CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
pChild->m_nWidth = m_pDibObject->GetWidth();
pChild->m_nHeight = m_pDibObject->GetHeight();
pChild->SetWindowPos( NULL, 0, 0, pChild->m_nWidth + 12,
pChild->m_nHeight + 38, SWP_NOZORDER | SWP_NOMOVE );
pDocument->UpdateAllViews(NULL);
}
else
AfxMessageBox(IDS_FAIL_SPLIT);
// 恢复光标
EndWaitCursor();
}
void CDipDoc::OnChannelRed()
{
//获取应用程序类指针
CDipApp *pApp = GetApp();
//获取主框架窗口指针
CMainFrame *pFrame = GetMainFrame();
CDibObject *red = new CDibObject(m_pDibObject);
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
if (PointOperation.GetMixedChannel(red))
{
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posTemplate);
CDipDoc* pDocument = (CDipDoc*) pDocTemplate->OpenDocumentFile(NULL);
pDocument->m_pDibObject = red;
pDocument->m_bImageLoaded = TRUE;
CString sSplitCaption;
AfxFormatString1(sSplitCaption, IDS_SPLIT_RED_CAPTION, GetTitle());
pDocument->SetTitle(sSplitCaption);
//获取子框架窗口指针
CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
pChild->m_nWidth = m_pDibObject->GetWidth();
pChild->m_nHeight = m_pDibObject->GetHeight();
pChild->SetWindowPos( NULL, 0, 0, pChild->m_nWidth + 12,
pChild->m_nHeight + 38, SWP_NOZORDER | SWP_NOMOVE );
pDocument->UpdateAllViews(NULL);
}
else
AfxMessageBox(IDS_FAIL_SPLIT);
// 恢复光标
EndWaitCursor();
}
void CDipDoc::OnUpdateChannelGreen(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}
void CDipDoc::OnUpdateChannelMixed(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}
void CDipDoc::OnUpdateChannelRed(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}
void CDipDoc::OnUpdateChannelBlue(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}
void CDipDoc::OnUpdateChannelSplit(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pDibObject->GetNumBits() >= 8);
}
void CDipDoc::OnUpdatePointThre(CCmdUI* pCmdUI)
{
//判断当前是否有图像对象
if( m_pDibObject == NULL ) return;
//在点处理CPointPro类中创建用来绘制直方图的数据
CPointPro PointOperation( m_pDibObject );
//判断是否为256色灰度图像
pCmdUI->Enable(PointOperation.IsGray256());
}
void CDipDoc::OnUpdatePointPseudocolor(CCmdUI* pCmdUI)
{
//判断当前是否有图像对象
if( m_pDibObject == NULL ) return;
//在点处理CPointPro类中创建用来绘制直方图的数据
CPointPro PointOperation( m_pDibObject );
//判断是否为256色灰度图像
pCmdUI->Enable(PointOperation.IsGray256());
}
void CDipDoc::OnEdgeTrace()
{
//创建点处理CPointPro类对象
CAreaPro AreaPro( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
AreaPro.EdgeTracing();
// 恢复光标
EndWaitCursor();
// 更新视图
UpdateAllViews(NULL);
}
void CDipDoc::OnEdgeContour()
{
//创建点处理CPointPro类对象
CAreaPro AreaPro( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
AreaPro.ContourPickUp();
// 恢复光标
EndWaitCursor();
// 更新视图
UpdateAllViews(NULL);
}
void CDipDoc::OnEdgeFill()
{
//创建种子填充方式选择对话框
CDlgSeedFill seedfill;
if(seedfill.DoModal() == IDOK)
{
//创建点处理CPointPro类对象
CAreaPro AreaPro( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
//选择种子填充方法
if(seedfill.m_iSeedMethod == 0)
AreaPro.Feeding1();
else
AreaPro.Feeding2();
// 恢复光标
EndWaitCursor();
// 更新视图
UpdateAllViews(NULL);
}
}
void CDipDoc::OnUpdateEdgeTrace(CCmdUI* pCmdUI)
{
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}
void CDipDoc::OnUpdateEdgeContour(CCmdUI* pCmdUI)
{
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}
void CDipDoc::OnDetectMinus()
{
// TODO: Add your command handler code here
//模板图像数据指针
unsigned char *pBitsTemp;
static int nIndex = 1;
CFileDialog FileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter );
FileDlg.m_ofn.nFilterIndex = (DWORD) nIndex;
if( FileDlg.DoModal() == IDOK )
{
CString strPathName = FileDlg.GetPathName();
nIndex = (int) FileDlg.m_ofn.nFilterIndex;
//设置等待光标
BeginWaitCursor();
CDibObject *pTemplate = new CDibObject( strPathName.GetBuffer(3) );
//取消等待光标
EndWaitCursor();
//读入图像文件失败
if( pTemplate == NULL )
{
AfxMessageBox("无法创建差影模板图像类对象!");
//返回FALSE
return;
}
//在点处理CPointPro类中创建用来绘制直方图的数据
CPointPro PointOperation( pTemplate );
//判断是否为256色灰度图像
if(!PointOperation.IsGray256())
{
AfxMessageBox("差影模板图像不是256级灰度图像,无法进行操作!");
//返回FALSE
return;
}
//原始图像大小
int nOldWidth = m_pDibObject->GetWidth();
int nOldHeight = m_pDibObject->GetHeight();
//模板图像大小
int nTempWidth = pTemplate->GetWidth();
int nTempHeight = pTemplate->GetHeight();
CRect rectOld(0, 0, nOldWidth, nOldHeight);
CRect rectTemp(0, 0, nTempWidth, nTempHeight);
//两个图像的大小应一致
if (rectOld != rectTemp)
{
AfxMessageBox("模板图像和原图像大小不一致,无法完成操作!");
return;
}
//创建点处理CPointPro类对象
CAreaPro AreaPro1( pTemplate );
// 更改光标形状
BeginWaitCursor();
pBitsTemp = AreaPro1.GetBitsPointer();
// 恢复光标
EndWaitCursor();
//创建点处理CPointPro类对象
CAreaPro AreaPro2( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
AreaPro2.Minusing(pBitsTemp);
// 恢复光标
EndWaitCursor();
// 更新视图
UpdateAllViews(NULL);
}
}
void CDipDoc::OnUpdateDetectMinus(CCmdUI* pCmdUI)
{
//判断当前是否有图像对象
if( m_pDibObject == NULL ) return;
//在点处理CPointPro类中创建用来绘制直方图的数据
CPointPro PointOperation( m_pDibObject );
//判断是否为256色灰度图像
pCmdUI->Enable(PointOperation.IsGray256());
}
void CDipDoc::OnDetectTemplate()
{
// TODO: Add your command handler code here
CDibObject *pTemplate;
static int nIndex = 1;
CFileDialog FileDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter );
FileDlg.m_ofn.nFilterIndex = (DWORD) nIndex;
if( FileDlg.DoModal() == IDOK )
{
CString strPathName = FileDlg.GetPathName();
nIndex = (int) FileDlg.m_ofn.nFilterIndex;
//设置等待光标
BeginWaitCursor();
pTemplate = new CDibObject( strPathName.GetBuffer(3) );
//取消等待光标
EndWaitCursor();
//读入图像文件失败
if( pTemplate == NULL )
{
AfxMessageBox("无法创建匹配模板图像类对象!");
//返回FALSE
return;
}
//在点处理CPointPro类中创建用来绘制直方图的数据
CPointPro PointOperation( pTemplate );
//判断是否为256色灰度图像
if(!PointOperation.IsGray256())
{
AfxMessageBox("匹配模板图像不是256级灰度图像,无法进行操作!");
//返回FALSE
return;
}
//原始图像大小
int nOldWidth = m_pDibObject->GetWidth();
int nOldHeight = m_pDibObject->GetHeight();
//模板图像大小
int nTempWidth = pTemplate->GetWidth();
int nTempHeight = pTemplate->GetHeight();
//两个图像的大小应一致
if (nTempWidth > nOldWidth || nTempHeight > nOldHeight)
{
AfxMessageBox("模板图像太大,无法完成操作!");
return;
}
//创建点处理CPointPro类对象
CAreaPro AreaPro( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
AreaPro.TemplateMatch(pTemplate);
// 恢复光标
EndWaitCursor();
// 更新视图
UpdateAllViews(NULL);
}
}
void CDipDoc::OnUpdateDetectTemplate(CCmdUI* pCmdUI)
{
//判断当前是否有图像对象
if( m_pDibObject == NULL ) return;
//在点处理CPointPro类中创建用来绘制直方图的数据
CPointPro PointOperation( m_pDibObject );
//判断是否为256色灰度图像
pCmdUI->Enable(PointOperation.IsGray256());
}
void CDipDoc::OnDetectProject()
{
//创建投影模式选择对话框
CDlgProject projectmode;
if(projectmode.DoModal() == IDOK)
{
//创建点处理CPointPro类对象
CAreaPro AreaPro( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
//选择投影模式
if(projectmode.m_iProjectMode == 0)
AreaPro.ProjectH();
else
AreaPro.ProjectV();
// 恢复光标
EndWaitCursor();
// 更新视图
UpdateAllViews(NULL);
}
}
void CDipDoc::OnUpdateDetectProject(CCmdUI* pCmdUI)
{
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
//只对8位二值图像起作用
pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}
void CDipDoc::OnUpdateEdgeFill(CCmdUI* pCmdUI)
{
//创建点处理CPointPro类对象
CPointPro PointOperation( m_pDibObject );
//只对8位二值图像起作用
pCmdUI->Enable(PointOperation.IsBlackandWhite256());
}
void CDipDoc::OnGeomMirh()
{
//创建点处理CImageGeoTrans类对象
CGeoTrans GeoTrans( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
//调用Mirror()函数进行垂直镜像
GeoTrans.Mirror(TRUE);
// 设置脏标记
// SetModifiedFlag(TRUE);
// 更新视图
UpdateAllViews(NULL);
// 恢复光标
EndWaitCursor();
}
void CDipDoc::OnGeomMirv()
{
//创建点处理CImageGeoTrans类对象
CGeoTrans GeoTrans( m_pDibObject );
// 更改光标形状
BeginWaitCursor();
//调用Mirror()函数进行水平镜像
GeoTrans.Mirror(FALSE);
// 设置脏标记
// SetModifiedFlag(TRUE);
// 更新视图
UpdateAllViews(NULL);
// 恢复光标
EndWaitCursor();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -