📄 mainfrm.cpp
字号:
isDbOK = TRUE;
//刷新数据表;
pDataGridView->UpdateTrainPointsGrid();
}
void CMainFrame::OnSegParaChanged()
//处理分割参数变化事件,由分割参数面板调用;
{
INT curevent = mySegmentPara->GetCurEvent();
switch (curevent)
{
case 0:
//建立新点类;
mySegmentPara->ClearEvent();
break;
case 1:
//添加了新的用于分割的点类
ptClassArrToSeg = mySegmentPara->GetSelectClass(
numberInPtClassArrToSeg, selIDInPtClassArrToSeg);
mySegmentPara->ClearEvent();
break;
case 2:
//删除旧的现存点类
mySegmentPara->ClearEvent();
break;
case 3:
//现存点类列表中的选择改变;
mySegmentPara->ClearEvent();
break;
case 4:
//移除一个用于分割的点类;
//添加了新的用于分割的点类
ptClassArrToSeg = mySegmentPara->GetSelectClass(
numberInPtClassArrToSeg, selIDInPtClassArrToSeg);
mySegmentPara->ClearEvent();
break;
case 5:
//用于分割的点类列表中的选择改变;
//添加了新的用于分割的点类
ptClassArrToSeg = mySegmentPara->GetSelectClass(
numberInPtClassArrToSeg, selIDInPtClassArrToSeg);
mySegmentPara->ClearEvent();
break;
default:
{}
}
}
void CMainFrame::RefreshRs()
//刷新记录集;
{
INT tempcount = myRs->GetRecordCount();
if (myRs!=NULL)
{
myRs->Close();
}
myRs = new CADORecordset(&myAdoDb);
//正常连接了数据库;
CString sqlquery;
sqlquery.Format("select id,name,width,height,his1dlen,rank from %s",
tableName);
if (!myRs->Open(sqlquery, CADORecordset::openUnknown))
//if (!myRs->Open(tableName, CADORecordset::openTable))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开图像数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
isDbOK = TRUE;
tempcount = myRs->GetRecordCount();
//刷新数据表;
pDataGridView->UpdateGridDetails(tableName);
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
myWndSplitter.CreateStatic(this, 2, 1);
myWndSplitter.CreateView( 0, 0,
RUNTIME_CLASS(CMyImageDBView),
CSize(0, 250), pContext ) ;
myWndSplitter.CreateView( 1, 0,
RUNTIME_CLASS(CDataGridView),
CSize(0, 10), pContext ) ;
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}
CString CMainFrame::GetSelectName()
//
{
myRs->MoveTo(selRow);
BOOL issuc = myRs->GetFieldValue("name", selName);
return selName;
}
void CMainFrame::OnColorToolbar()
{
isShowColorToolbar = !isShowColorToolbar;
if (isShowColorToolbar)
{
myPaletteBar.ShowWindow(SW_SHOW);
}else
{
myPaletteBar.ShowWindow(SW_HIDE);
}
}
void CMainFrame::OnUpdateColorToolbar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(isShowColorToolbar);
}
void CMainFrame::OnRegionsegShow()
//显示SegPara窗口;
{
if (!isDbOK)
{
CString tempstr;
tempstr.Format("未连接数据库!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
if ( mySegmentPara!=NULL && mySegmentPara->IsWindowVisible() )
{
mySegmentPara->DestroyWindow();
mySegmentPara = NULL;
}else
{
CRect frame;
GetWindowRect(frame);
INT x = frame.right - 90;
INT y = frame.top + 90;
mySegmentPara = new CSegmentPara;
mySegmentPara->Create(IDD_SEARCHPARA, this );
mySegmentPara->SetWindowText("分割信息");
mySegmentPara->ShowWindow(SW_SHOW);
//以下添加可用分割类;
LONG exitclasscount = seginfoRs->GetRecordCount();
if (exitclasscount>=1)
{
seginfoRs->MoveFirst();
}
while ( !seginfoRs->IsEOF() )
{
CString temps = "";
BOOL isok = seginfoRs->GetFieldValue("regionclass", temps);
if (isok)
{
mySegmentPara->AddExistClass(temps);
}
seginfoRs->MoveNext();
}
}
}
void CMainFrame::DelPtInExistClass(CString regionclass)
//刷新该所属类所在表(将类记录的训练点数减一,并刷新各相关信息);
{
//读现有训练点数,若为1,则直接删除该记录;
//若大于1,则将字段“训练点数”减一,并刷新各记录;
INT id = seginfoRs->GetRecordCount();
if (id>=1)
{
seginfoRs->MoveFirst();
}
CString findstr = "";
findstr.Format("regionclass=\'%s\'", regionclass);
BOOL isexistsame = seginfoRs->Find(findstr);
if (!isexistsame)
{
return;
}else
{
LONG curcount = -1;
BOOL tempb = seginfoRs->GetFieldValue("trainptcount", curcount);
seginfoRs->Edit();
tempb = seginfoRs->SetFieldValue("trainptcount", curcount-1);
seginfoRs->Update();
//以下计算各特征均值与方差;
//先建立LUV数组,准备读入各点颜色用于计算;
FLOAT lmean, lerr, umean, uerr, vmean, verr;//LUV均值与方差;
FLOAT texlmean, texlerr, texumean, texuerr, texvmean, texverr;//LUV纹理均值与方差;
DOUBLE *l, *u, *v;
DOUBLE *texl, *texu, *texv;
CADORecordset* temprs = new CADORecordset(&myAdoDb);
CString sqlquery;
sqlquery.Format("select * from %s where regionclass=\'%s\'",
trainpointTableName, regionclass);
if (!temprs->Open(sqlquery, CADORecordset::openUnknown))
{
CString tempstr;
tempstr.Format("打不开点类信息表!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
isTrainPointDbOK = FALSE;
return;
}else
{
LONG rcount = temprs->GetRecordCount();
BOOL tempb = FALSE;
//分配LUV数组内存;
l = new DOUBLE[rcount];
u = new DOUBLE[rcount];
v = new DOUBLE[rcount];
//分配LUV纹理数组内存;
texl = new DOUBLE[rcount];
texu = new DOUBLE[rcount];
texv = new DOUBLE[rcount];
//以下从数据库读入LUV值和LUV纹理值;
for (INT i=0; i<rcount; i++)
{
tempb = temprs->GetFieldValue("colorl", l[i]);
tempb = temprs->GetFieldValue("coloru", u[i]);
tempb = temprs->GetFieldValue("colorv", v[i]);
tempb = temprs->GetFieldValue("minmaxtexl", texl[i]);
tempb = temprs->GetFieldValue("minmaxtexu", texu[i]);
tempb = temprs->GetFieldValue("minmaxtexv", texv[i]);
temprs->MoveNext();
}
temprs->Close();
//以下计算均值与方差;
myMath.ClacuMean(l, rcount, lmean, lerr);
myMath.ClacuMean(u, rcount, umean, uerr);
myMath.ClacuMean(v, rcount, vmean, verr);
myMath.ClacuMean(texl, rcount, texlmean, texlerr);
myMath.ClacuMean(texu, rcount, texumean, texuerr);
myMath.ClacuMean(texv, rcount, texvmean, texverr);
}
//以下更新点类表中的均值与方差信息;
seginfoRs->MoveFirst();
isexistsame = seginfoRs->Find(findstr);
if (isexistsame)
{
seginfoRs->Edit();
tempb = seginfoRs->SetFieldValue("colorl", lmean);
tempb = seginfoRs->SetFieldValue("colorlw", lerr);
tempb = seginfoRs->SetFieldValue("coloru", umean);
tempb = seginfoRs->SetFieldValue("coloruw", uerr);
tempb = seginfoRs->SetFieldValue("colorv", vmean);
tempb = seginfoRs->SetFieldValue("colorvw", verr);
tempb = seginfoRs->SetFieldValue("minmaxtexl", texlmean);
tempb = seginfoRs->SetFieldValue("minmaxtexlw", texlerr);
tempb = seginfoRs->SetFieldValue("minmaxtexu", texumean);
tempb = seginfoRs->SetFieldValue("minmaxtexuw", texuerr);
tempb = seginfoRs->SetFieldValue("minmaxtexv", texvmean);
tempb = seginfoRs->SetFieldValue("minmaxtexvw", texverr);
seginfoRs->Update();
pDataGridView->UpdateExistsClassGrid();
}
}
}
void CMainFrame::AddExistClass(CString regionclass
, MyLUV luvcolor, MyLUV minmaxtex)
//添加新类信息或重新计算旧类信息;
{
//区域表中是否有该类名,若无,则添加类
//若有,则将字段“训练点数”加一;
INT id = seginfoRs->GetRecordCount() + 1;
if (id>1)
{
seginfoRs->MoveFirst();
}
CString findstr = "";
findstr.Format("regionclass=\'%s\'", regionclass);
BOOL isexistsame = seginfoRs->Find(findstr);
if (!isexistsame)
{
seginfoRs->AddNew();
seginfoRs->SetFieldValue("id", id);
seginfoRs->SetFieldValue("regionclass", regionclass);
seginfoRs->SetFieldValue("trainptcount", 1);
seginfoRs->SetFieldValue("colorl", luvcolor.l);
seginfoRs->SetFieldValue("coloru", luvcolor.u);
seginfoRs->SetFieldValue("colorv", luvcolor.v);
seginfoRs->SetFieldValue("colorlw", 0);
seginfoRs->SetFieldValue("coloruw", 0);
seginfoRs->SetFieldValue("colorvw", 0);
seginfoRs->SetFieldValue("minmaxtexl", minmaxtex.l);
seginfoRs->SetFieldValue("minmaxtexu", minmaxtex.u);
seginfoRs->SetFieldValue("minmaxtexv", minmaxtex.v);
seginfoRs->SetFieldValue("minmaxtexlw", 0);
seginfoRs->SetFieldValue("minmaxtexuw", 0);
seginfoRs->SetFieldValue("minmaxtexvw", 0);
seginfoRs->Update();
pDataGridView->UpdateExistsClassGrid();
}else
{
LONG curcount = -1;
BOOL tempb = seginfoRs->GetFieldValue("trainptcount", curcount);
seginfoRs->Edit();
tempb = seginfoRs->SetFieldValue("trainptcount", curcount+1);
seginfoRs->Update();
//以下计算各特征均值与方差;
//先建立LUV数组,准备读入各点颜色用于计算;
FLOAT lmean, lerr, umean, uerr, vmean, verr;//LUV均值与方差;
FLOAT texlmean, texlerr, texumean, texuerr, texvmean, texverr;//LUV纹理均值与方差;
DOUBLE *l, *u, *v;
DOUBLE *texl, *texu, *texv;
CADORecordset* temprs = new CADORecordset(&myAdoDb);
CString sqlquery;
sqlquery.Format("select * from %s where regionclass=\'%s\'",
trainpointTableName, regionclass);
if (!temprs->Open(sqlquery, CADORecordset::openUnknown))
{
CString tempstr;
tempstr.Format("打不开点类信息表!!!,:)");
AfxMessageBox(tempstr,NULL,MB_OK);
isTrainPointDbOK = FALSE;
return;
}else
{
LONG rcount = temprs->GetRecordCount();
BOOL tempb = FALSE;
//分配LUV数组内存;
l = new DOUBLE[rcount];
u = new DOUBLE[rcount];
v = new DOUBLE[rcount];
//分配LUV纹理数组内存;
texl = new DOUBLE[rcount];
texu = new DOUBLE[rcount];
texv = new DOUBLE[rcount];
//以下从数据库读入LUV值和LUV纹理值;
for (INT i=0; i<rcount; i++)
{
tempb = temprs->GetFieldValue("colorl", l[i]);
tempb = temprs->GetFieldValue("coloru", u[i]);
tempb = temprs->GetFieldValue("colorv", v[i]);
tempb = temprs->GetFieldValue("minmaxtexl", texl[i]);
tempb = temprs->GetFieldValue("minmaxtexu", texu[i]);
tempb = temprs->GetFieldValue("minmaxtexv", texv[i]);
temprs->MoveNext();
}
temprs->Close();
//以下计算均值与方差;
myMath.ClacuMean(l, rcount, lmean, lerr);
myMath.ClacuMean(u, rcount, umean, uerr);
myMath.ClacuMean(v, rcount, vmean, verr);
myMath.ClacuMean(texl, rcount, texlmean, texlerr);
myMath.ClacuMean(texu, rcount, texumean, texuerr);
myMath.ClacuMean(texv, rcount, texvmean, texverr);
}
//以下更新点类表中的均值与方差信息;
seginfoRs->MoveFirst();
isexistsame = seginfoRs->Find(findstr);
if (isexistsame)
{
seginfoRs->Edit();
tempb = seginfoRs->SetFieldValue("colorl", lmean);
tempb = seginfoRs->SetFieldValue("colorlw", lerr);
tempb = seginfoRs->SetFieldValue("coloru", umean);
tempb = seginfoRs->SetFieldValue("coloruw", uerr);
tempb = seginfoRs->SetFieldValue("colorv", vmean);
tempb = seginfoRs->SetFieldValue("colorvw", verr);
tempb = seginfoRs->SetFieldValue("minmaxtexl", texlmean);
tempb = seginfoRs->SetFieldValue("minmaxtexlw", texlerr);
tempb = seginfoRs->SetFieldValue("minmaxtexu", texumean);
tempb = seginfoRs->SetFieldValue("minmaxtexuw", texuerr);
tempb = seginfoRs->SetFieldValue("minmaxtexv", texvmean);
tempb = seginfoRs->SetFieldValue("minmaxtexvw", texverr);
seginfoRs->Update();
pDataGridView->UpdateExistsClassGrid();
}
}
}
void CMainFrame::AddTrainPoints(CString regionclass,
CString imagename, INT posx, INT posy,
MyLUV luvcolor, MyLUV minmaxtex)
//添加训练点信息至数据库,
{
//在训练点表中添加点信息记录;
INT id = trainpointRs->GetRecordCount() + 1;
trainpointRs->AddNew();
trainpointRs->SetFieldValue("id", id);
trainpointRs->SetFieldValue("regionclass", regionclass);
trainpointRs->SetFieldValue("imagename", imagename);
trainpointRs->SetFieldValue("posx", posx);
trainpointRs->SetFieldValue("posy", posy);
trainpointRs->SetFieldValue("colorl", luvcolor.l);
trainpointRs->SetFieldValue("coloru", luvcolor.u);
trainpointRs->SetFieldValue("colorv", luvcolor.v);
trainpointRs->SetFieldValue("minmaxtexl", minmaxtex.l);
trainpointRs->SetFieldValue("minmaxtexu", minmaxtex.u);
trainpointRs->SetFieldValue("minmaxtexv", minmaxtex.v);
trainpointRs->Update();
pDataGridView->UpdateTrainPointsGrid();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -