www.pudn.com > MyImageDB(imageobject).rar > MainFrm.cpp, change:2004-05-30,size:22675b


 // MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "MyImageDB.h" 
 
#include "MainFrm.h" 
 
#include "dbconnectdlg.h" 
#include "include\ado.h" 
#include "Splash.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame 
 
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) 
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) 
	//{{AFX_MSG_MAP(CMainFrame) 
	ON_WM_CREATE() 
	ON_COMMAND(ID_DBCONNECT, OnDbConnect) 
	ON_COMMAND(ID_COLORTOOLBAR, OnColorToolbar) 
	ON_UPDATE_COMMAND_UI(ID_COLORTOOLBAR, OnUpdateColorToolbar) 
	ON_COMMAND(ID_REGIONSEGSHOW, OnRegionsegShow) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
static UINT indicators[] = 
{ 
	ID_SEPARATOR,           // status line indicator 
	ID_INDICATOR_CAPS, 
	ID_INDICATOR_NUM, 
	ID_INDICATOR_SCRL, 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame construction/destruction 
 
CMainFrame::CMainFrame() 
{ 
	ptClassArrToSeg = NULL;//选择列表信息 
	numberInPtClassArrToSeg = -1; 
	selIDInPtClassArrToSeg = -1; 
 
	mySegmentPara = NULL; 
    isShowSegpara = isShowColorToolbar = TRUE; 
	recordCount = -1; 
	isSegInfoDbOK = isTrainPointDbOK = isDbOK = FALSE;	 
	seginfoRs = trainpointRs = myRs = NULL; 
	selName = ""; 
	selRow = -1; 
	strConnection = ""; 
	tableName = ""; 
	userName = ""; 
} 
 
CMainFrame::~CMainFrame() 
{ 
	if (mySegmentPara!=NULL) 
	{ 
		delete mySegmentPara; 
		mySegmentPara = NULL; 
	} 
	if ( ptClassArrToSeg!=NULL) 
	{ 
		delete [] ptClassArrToSeg; 
		ptClassArrToSeg = NULL; 
	} 
	if ( mySegmentPara!=NULL) 
	{ 
		delete [] mySegmentPara; 
		mySegmentPara = NULL; 
	}	 
	if (myRs) 
	{ 
		myRs->Close(); 
	} 
	if (seginfoRs) 
	{ 
		seginfoRs->Close(); 
	} 
	if (trainpointRs) 
	{ 
		trainpointRs->Close(); 
	} 
 
	 
} 
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
 
	if (!m_wndStatusBar.Create(this) || 
		!m_wndStatusBar.SetIndicators(indicators, 
		  sizeof(indicators)/sizeof(UINT))) 
	{ 
		TRACE0("Failed to create status bar\n"); 
		return -1;      // fail to create 
	} 
 
	// TODO: Delete these three lines if you don't want the toolbar to 
	//  be dockable 
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
	EnableDocking(CBRS_ALIGN_ANY); 
	DockControlBar(&m_wndToolBar); 
 
	CRect rFrame; 
	GetWindowRect(rFrame); 
	INT x = rFrame.right - 90; 
	INT y = rFrame.top + 90; 
 
	//颜色信息面板; 
	myPaletteBar.Create(this, IDD_COLOR_PALETTE, CBRS_LEFT, ID_COLORTOOLBAR); 
	myPaletteBar.SetWindowText("颜色与位置"); 
	myPaletteBar.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT); 
	DockControlBar(&myPaletteBar); 
    //FloatControlBar(&myPaletteBar, CPoint(x, y), CBRS_ALIGN_TOP); 
	myPaletteBar.ShowWindow(SW_SHOW); 
 
/* 
	//分割信息面板; 
	mySegmentPara = new CSegmentPara; 
	mySegmentPara->Create(this, IDD_SEARCHPARA, CBRS_LEFT, ID_REGIONSEGSHOW); 
	mySegmentPara->SetWindowText("分割信息"); 
	//mySegmentPanel.EnableDocking(CBRS_ALIGN_RIGHT | CBRS_ALIGN_LEFT); 
	mySegmentPara->EnableDocking(CBRS_NOALIGN); 
	//DockControlBar(&mySegmentPanel); 
    FloatControlBar(mySegmentPara, CPoint(x, y), CBRS_ALIGN_TOP); 
	mySegmentPara->ShowWindow(SW_SHOW); 
*/ 
	 
	// CG: The following line was added by the Splash Screen component.
	CSplashWnd::ShowSplashScreen(this); 
	return 0; 
} 
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	if( !CFrameWnd::PreCreateWindow(cs) ) 
		return FALSE; 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return TRUE; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame diagnostics 
 
#ifdef _DEBUG 
void CMainFrame::AssertValid() const 
{ 
	CFrameWnd::AssertValid(); 
} 
 
void CMainFrame::Dump(CDumpContext& dc) const 
{ 
	CFrameWnd::Dump(dc); 
} 
 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame message handlers 
 
 
void CMainFrame::OnDbConnect()  
{ 
	CDbConnectDlg myconnect; 
	myconnect.DoModal(); 
    dbServer = myconnect.dbServer; 
	dbName = myconnect.dbName; 
	tableName = myconnect.tableName; 
	userName = myconnect.userName; 
	passWord = myconnect.passWord; 
 
	seginfoTableName = "segregioninfo";//这两个表名暂时固定; 
	trainpointTableName = "trainpoints"; 
	 
	strConnection.Format("Driver={SQL Server};Server=%s;Database=%s;Uid=;Pwd=;", dbServer, dbName); 
	myAdoDb.SetConnectionString(strConnection); 
 
	BOOL isok = myAdoDb.Open(); 
    CString sqlquery; 
 
	if (!isok) 
	{ 
		CString tempstr; 
		tempstr.Format("怎么搞的??打不开图像数据库!!!,:)"); 
		AfxMessageBox(tempstr,NULL,MB_OK); 
 
		return; 
	}else 
	{ 
		myRs = new CADORecordset(&myAdoDb); 
		//正常连接了数据库; 
		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; 
	} 
 
	recordCount = myRs->GetRecordCount();//得到表中的记录数; 
 
    //以下打开区域分割类表与训练点信息表; 
	seginfoRs = new CADORecordset(&myAdoDb); 
	sqlquery.Format("select * from %s", 
		seginfoTableName); 
	if (!seginfoRs->Open(sqlquery, CADORecordset::openUnknown)) 
	{ 
		CString tempstr; 
		tempstr.Format("打不开分割信息表!!!,:)"); 
		AfxMessageBox(tempstr,NULL,MB_OK); 
		isSegInfoDbOK = FALSE; 
		return;		 
	}else 
	{ 
		isSegInfoDbOK = TRUE; 
	} 
	 
	trainpointRs = new CADORecordset(&myAdoDb); 
	sqlquery.Format("select * from %s", 
		trainpointTableName); 
	if (!trainpointRs->Open(sqlquery, CADORecordset::openUnknown)) 
	{ 
		CString tempstr; 
		tempstr.Format("打不开点类信息表!!!,:)"); 
		AfxMessageBox(tempstr,NULL,MB_OK); 
		isTrainPointDbOK = FALSE; 
		return;		 
	}else 
	{ 
		isTrainPointDbOK = TRUE; 
		//以下刷新训练点信息表; 
	}		 
 
	//刷新数据表(包括图像数据表与分割类信息); 
	pDataGridView->UpdateGridDetails(tableName); 
} 
 
void CMainFrame::RefreshPtTableID(LONG deleteID, CString regionclass) 
//删除指定记录,并重排ID, 参数regionclass在本函数中不使用,只传递给DelPtInExistClass; 
{ 
	trainpointRs->Close(); 
	trainpointRs = new CADORecordset(&myAdoDb); 
	CString sqlquery; 
	sqlquery.Format("select id from %s", 
			trainpointTableName); 
	if (!trainpointRs->Open(sqlquery, CADORecordset::openUnknown)) 
	{ 
		//未正常连接指定表; 
		CString tempstr; 
		tempstr.Format("打不开训练点数据表!!!"); 
		AfxMessageBox(tempstr,NULL,MB_OK);			 
		return; 
	} 
	trainpointRs->Edit(); 
	LONG allcount = trainpointRs->GetRecordCount(); 
	if ( allcount == deleteID) 
	{ 
		trainpointRs->MoveLast(); 
		trainpointRs->Delete(); 
		trainpointRs->MoveFirst(); 
		trainpointRs->Update(); 
        RefreshRs(); 
 
		return;//直接删除最后一条记录; 
	} 
	 
	trainpointRs->MoveFirst(); 
	while( !trainpointRs->IsEOF() ) 
	{ 
		INT tempid = -1; 
		BOOL tempbool = trainpointRs->GetFieldValue("id", tempid); 
		if ( tempid==deleteID ) 
		{ 
			tempbool = trainpointRs->SetFieldValue("id", -1); 
			break; 
		} 
		trainpointRs->MoveNext();		 
	}  
	trainpointRs->MoveLast(); 
	trainpointRs->SetFieldValue("id", deleteID);//将最后一条记录放到被删位置; 
 
	trainpointRs->MoveFirst(); 
	trainpointRs->Update();//首先修改该记录ID; 
 
	trainpointRs->MoveFirst(); 
	//以下将该记录删除; 
	while( !trainpointRs->IsEOF() ) 
	{ 
		INT tempid = 1; 
		BOOL tempbool = trainpointRs->GetFieldValue("id", tempid); 
		if ( tempid==-1 ) 
		{ 
			recordCount = recordCount - 1;//记录数减1 
			tempbool = trainpointRs->Delete(); 
			break; 
		} 
		trainpointRs->MoveNext();		 
	}  
	trainpointRs->MoveFirst(); 
	trainpointRs->Update();//删除该记录; 
 
	RefreshPointsRs(); 
 
	//刷新该所属类所在表(将类记录的训练点数减一,并刷新各相关信息); 
	DelPtInExistClass(regionclass); 
 
	isDbOK = TRUE; 
} 
 
void CMainFrame::RefreshTableID(LONG deleteID) 
//刷新图像表记录ID; 
{ 
	myRs->Close(); 
	myRs = new CADORecordset(&myAdoDb); 
	CString sqlquery; 
	sqlquery.Format("select id from %s", 
			tableName); 
	if (!myRs->Open(sqlquery, CADORecordset::openUnknown)) 
	{ 
		//未正常连接指定表; 
		CString tempstr; 
		tempstr.Format("打不开图像数据表!!!"); 
		AfxMessageBox(tempstr,NULL,MB_OK);			 
		return; 
	} 
	myRs->Edit(); 
	LONG allcount = myRs->GetRecordCount(); 
	if ( allcount == deleteID) 
	{ 
		myRs->MoveLast(); 
		myRs->Delete(); 
		myRs->MoveFirst(); 
		myRs->Update(); 
        RefreshRs(); 
 
		return;//直接删除最后一条记录; 
	} 
	 
	myRs->MoveFirst(); 
	while( !myRs->IsEOF() ) 
	{ 
		INT tempid = -1; 
		BOOL tempbool = myRs->GetFieldValue("id", tempid); 
		if ( tempid==deleteID ) 
		{ 
			tempbool = myRs->SetFieldValue("id", -1); 
			break; 
		} 
		myRs->MoveNext();		 
	}  
	myRs->MoveLast(); 
	myRs->SetFieldValue("id", deleteID);//将最后一条记录放到被删位置; 
 
	myRs->MoveFirst(); 
	myRs->Update();//首先修改该记录ID; 
 
	myRs->MoveFirst(); 
	//以下将该记录删除; 
	while( !myRs->IsEOF() ) 
	{ 
		INT tempid = 1; 
		BOOL tempbool = myRs->GetFieldValue("id", tempid); 
		if ( tempid==-1 ) 
		{ 
			recordCount = recordCount - 1;//记录数减1 
			tempbool = myRs->Delete(); 
			break; 
		} 
		myRs->MoveNext();		 
	}  
	myRs->MoveFirst(); 
	myRs->Update();//删除该记录; 
	 
	RefreshRs(); 
	isDbOK = TRUE; 
} 
 
void CMainFrame::RefreshPointsRs() 
//刷新训练点记录集; 
{ 
	INT tempcount = trainpointRs->GetRecordCount(); 
	if (trainpointRs!=NULL) 
	{ 
		trainpointRs->Close(); 
	} 
 
	trainpointRs = new CADORecordset(&myAdoDb); 
	//正常连接了数据库; 
	 
	CString sqlquery; 
	sqlquery.Format("select * from %s", trainpointTableName); 
	if (!trainpointRs->Open(sqlquery, CADORecordset::openUnknown)) 
	{ 
		//未正常连接指定表; 
		CString tempstr; 
		tempstr.Format("打不开训练点数据表!!!"); 
		AfxMessageBox(tempstr,NULL,MB_OK);			 
		return; 
	} 
	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; iGetFieldValue("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; iGetFieldValue("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(); 
}