visionview.cpp

来自「FIRA 3对3 机器人足球PC端控制程序。」· C++ 代码 · 共 2,092 行 · 第 1/5 页

CPP
2,092
字号
//	UpdateData(TRUE);
//	if(m_bFlagFindOpponent4)
//		bFlagFindOpponent[OPP4] = TRUE;
//	else
//		bFlagFindOpponent[OPP4] = FALSE;
//	UpdateData(FALSE);
}


// --------------------------------------------------------
void CVisionView::OnFlagFindOpponent5() 
{
	// TODO: Add your control notification handler code here
//	UpdateData(TRUE);
//	if(m_bFlagFindOpponent5)
//		bFlagFindOpponent[OPP5] = TRUE;
//	else
//		bFlagFindOpponent[OPP5] = FALSE;
//	UpdateData(FALSE);
}


// --------------------------------------------------------
// Param  : none
// Return : none
// Remark : 农扁 鞘磐傅阑 困秦 侨伎 农扁 烙拌蔼 沥窍扁
// --------------------------------------------------------
void CVisionView::OnSetPixelSize() 
{
	// TODO: Add your control notification handler code here
	if(bPlay)
		return;	

	//KillTimer(1);

	CSetPixelSize dlg;

	dlg.nLBoundBallSize = LowerBoundOfBallSize;
	dlg.nUBoundBallSize = UpperBoundOfBallSize;
	dlg.nLBoundBigTeamSize = LowerBoundOfBigTeamSize;
	dlg.nUBoundBigTeamSize = UpperBoundOfBigTeamSize;
	dlg.nLBoundSmallIDSize = LowerBoundOfSmallIDSize;
	dlg.nUBoundSmallIDSize = UpperBoundOfSmallIDSize;
	dlg.nLBoundOpponentSize = LowerBoundOfOpponentSize;
	dlg.nUBoundOpponentSize = UpperBoundOfOpponentSize;
	 
	dlg.nDefLBoundBallSize = DEF_LBOUND_BALL_SIZE;
	dlg.nDefUBoundBallSize = DEF_UBOUND_BALL_SIZE;
	dlg.nDefLBoundBigTeamSize = DEF_LBOUND_BIG_TEAM_SIZE;
	dlg.nDefUBoundBigTeamSize = DEF_UBOUND_BIG_TEAM_SIZE;
	dlg.nDefLBoundSmallIDSize = DEF_LBOUND_SMALL_ID_SIZE;
	dlg.nDefUBoundSmallIDSize = DEF_UBOUND_SMALL_ID_SIZE;
	dlg.nDefLBoundOpponentSize = DEF_LBOUND_OPPONENT_SIZE;
	dlg.nDefUBoundOpponentSize = DEF_UBOUND_OPPONENT_SIZE;
	
	if(dlg.DoModal() == IDOK){
		LowerBoundOfBallSize = dlg.nLBoundBallSize;
		UpperBoundOfBallSize = dlg.nUBoundBallSize;
		LowerBoundOfBigTeamSize = dlg.nLBoundBigTeamSize;
		UpperBoundOfBigTeamSize = dlg.nUBoundBigTeamSize;
		LowerBoundOfSmallIDSize = dlg.nLBoundSmallIDSize;
		UpperBoundOfSmallIDSize = dlg.nUBoundSmallIDSize;
		LowerBoundOfOpponentSize = dlg.nLBoundOpponentSize;
		UpperBoundOfOpponentSize = dlg.nUBoundOpponentSize;
	}
}


// --------------------------------------------------------
// Param  : none
// Return : none
// Remark : 肺嚎 农扁 汲沥 劝己拳
// --------------------------------------------------------
void CVisionView::OnSetRobotSize() 
{
	// TODO: Add your control notification handler code here
	if(bPlay)
		return;	

	//KillTimer(1);
			
	bSetRobotSize = TRUE;
	bSetColor = FALSE;
}


// --------------------------------------------------------
// Param  : nFlags, point
// Return : none
// Remark : 付快胶 框流烙俊 措茄 勤甸矾
// --------------------------------------------------------
void CVisionView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(bPlay)
		return;	

	short h, w, x, y;
	BYTE *pZoomBuffer;
	CClientDC objDC(this);
	CPen pen, *pOldPen;
	
	if(bEndZoom && point.x >= (DispSizeX + ZOOM_OFFX) && point.x < (DispSizeX + ZOOM_OFFX + ZOOM_SIZE * ZOOM_SCALE)
		&& point.y >= ZOOM_OFFY && point.y < (ZOOM_OFFY + ZOOM_SIZE * ZOOM_SCALE)){ 
		SelectedRectInZoom.right = point.x;
		SelectedRectInZoom.bottom = point.y; 
		pZoomBuffer = ZoomBuffer;
		for(h = 0;h < ZOOM_SIZE * ZOOM_SCALE;h += ZOOM_SCALE)
			for(w = 0;w < ZOOM_SIZE * ZOOM_SCALE;w += ZOOM_SCALE){             
				for(x = 0;x < ZOOM_SCALE;x++)
					for(y = 0;y < ZOOM_SCALE;y++)
						objDC.SetPixel(DispSizeX + ZOOM_OFFX + w + x, ZOOM_OFFY + h + y, RGB(*pZoomBuffer, *(pZoomBuffer + 1), *(pZoomBuffer + 2)));
				pZoomBuffer += 4;
			}
		pen.CreatePen(PS_DOT, 0, RGB(0, 0, 0));
		pOldPen = objDC.SelectObject(&pen);
		objDC.MoveTo(SelectedRectInZoom.left, SelectedRectInZoom.top);
		objDC.LineTo(SelectedRectInZoom.left, SelectedRectInZoom.bottom);
		objDC.LineTo(SelectedRectInZoom.right, SelectedRectInZoom.bottom); 
		objDC.MoveTo(SelectedRectInZoom.left, SelectedRectInZoom.top);
		objDC.LineTo(SelectedRectInZoom.right, SelectedRectInZoom.top);
		objDC.LineTo(SelectedRectInZoom.right, SelectedRectInZoom.bottom);
		objDC.SelectObject(pOldPen);                         
		pen.DeleteObject();   
	}
	
	CFormView::OnMouseMove(nFlags, point);
}



// --------------------------------------------------------
// Param  : nFlags, point
// Return : none
// Remark : 付快胶 哭率 滚瓢 喘覆俊 措茄 勤甸矾
//			祸 汲沥, 侨伎 农扁 汲沥, 肺嚎 农扁 汲沥 殿狼 
//			敲贰弊俊 蝶扼 秦寸 累诀 贸府 
// --------------------------------------------------------
void CVisionView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_bEnableInitPos && point.x >= 0 && point.x < DispSizeX && point.y >= 0 && point.y < DispSizeY){
		switch(nInitPosBall) {
		case BALL :
			iPositionOfBall[0] = (short)point.x;
			iPositionOfBall[1] = (short)point.y;
			bFlagBallFound = TRUE;
		//	nInitPosBall = HOME1;
			break;
		case HOME1 :
			iPositionOfHomeRobot[HOME1][0] = (short)point.x;
			iPositionOfHomeRobot[HOME1][1] = (short)point.y;
			bFlagHomeRobotFound[HOME1] = TRUE;
		//	nInitPosBall = HOME2;
			break;
		case HOME2 :
			iPositionOfHomeRobot[HOME2][0] = (short)point.x;
			iPositionOfHomeRobot[HOME2][1] = (short)point.y;
			bFlagHomeRobotFound[HOME2] = TRUE;
		//	nInitPosBall = HGOALIE;
//			nInitPosBall = HOME3;
			break;
/*		case HOME3 :
			iPositionOfHomeRobot[HOME3][0] = (short)point.x;
			iPositionOfHomeRobot[HOME3][1] = (short)point.y;
			bFlagHomeRobotFound[HOME3] = TRUE;
			nInitPosBall = HOME4;
			break;
		case HOME4 :
			iPositionOfHomeRobot[HOME4][0] = (short)point.x;
			iPositionOfHomeRobot[HOME4][1] = (short)point.y;
			bFlagHomeRobotFound[HOME4] = TRUE;
			nInitPosBall = HGOALIE;
			break;
*/		case HGOALIE :
			iPositionOfHomeRobot[HGOALIE][0] = (short)point.x;
			iPositionOfHomeRobot[HGOALIE][1] = (short)point.y;
			bFlagHomeRobotFound[HGOALIE] = TRUE;
		//	nInitPosBall = OPPONENT1;
			break;
		case OPPONENT1 :
			iPositionOfOpponent[OPP1][0] = (short)point.x;
			iPositionOfOpponent[OPP1][1] = (short)point.y;
			bFlagOpponentFound[OPP1] = TRUE;
		//	nInitPosBall = OPPONENT2;
			break;
		case OPPONENT2 :
			iPositionOfOpponent[OPP2][0] = (short)point.x;
			iPositionOfOpponent[OPP2][1] = (short)point.y;
			bFlagOpponentFound[OPP2] = TRUE;
		//	nInitPosBall = OPPONENT3;
			break;
		case OPPONENT3 :
			iPositionOfOpponent[OPP3][0] = (short)point.x;
			iPositionOfOpponent[OPP3][1] = (short)point.y;
			bFlagOpponentFound[OPP3] = TRUE;
		//	nInitPosBall = BALL;
//			nInitPosBall = OPPONENT4;
			break;
/*		case OPPONENT4 :
			iPositionOfOpponent[OPP4][0] = (short)point.x;
			iPositionOfOpponent[OPP4][1] = (short)point.y;
			bFlagOpponentFound[OPP4] = TRUE;
			nInitPosBall = OPPONENT5;
			break;
		case OPPONENT5 :
			iPositionOfOpponent[OPP5][0] = (short)point.x;
			iPositionOfOpponent[OPP5][1] = (short)point.y;
			bFlagOpponentFound[OPP5] = TRUE;
			nInitPosBall = BALL;
			break;
*/		}
	}
	else if( (bSetColor || bSetRobotSize) && point.x >= 0 && point.x < DispSizeX && point.y >= 0 && point.y < DispSizeY){ 
		MdigHalt(MilDigitizerId);
		Zoom(point);
		bBeginZoom = TRUE;
		bEndZoom = FALSE;
		MdigGrabContinuous(MilDigitizerId, MilImageBufferId);
	}
	else if( (bSetColor || bSetRobotSize) && bBeginZoom && point.x >= (DispSizeX + ZOOM_OFFX) && point.x < (DispSizeX + ZOOM_OFFX + ZOOM_SIZE * ZOOM_SCALE)
		&& point.y >= ZOOM_OFFY && point.y < (ZOOM_OFFY + ZOOM_SIZE * ZOOM_SCALE)){ 
		SelectedRectInZoom.right = SelectedRectInZoom.left = point.x;
		SelectedRectInZoom.top = SelectedRectInZoom.bottom = point.y;
		bBeginZoom = FALSE;
		bEndZoom = TRUE;
	}
	else if( bSetRobotSize && bEndZoom && point.x >= (DispSizeX + ZOOM_OFFX) && point.x < (DispSizeX + ZOOM_OFFX + ZOOM_SIZE * ZOOM_SCALE)
		&& point.y >= ZOOM_OFFY && point.y < (ZOOM_OFFY+ZOOM_SIZE*ZOOM_SCALE)){ 
		// Calculate robot size
		SizeXofRobot = abs(point.x - SelectedRectInZoom.left) / ZOOM_SCALE;
		SizeYofRobot = abs(point.y - SelectedRectInZoom.top) / ZOOM_SCALE;
		if(SizeXofRobot==0)		SizeXofRobot = DEF_SIZE_X_ROBOT;
		if(SizeYofRobot==0)		SizeYofRobot = DEF_SIZE_Y_ROBOT;
		SizeXofRobot = (SizeXofRobot + SizeYofRobot)/2;
		SizeYofRobot = SizeXofRobot;
		char tmp[40];
		sprintf(tmp, "robot size = %d x %d ", SizeXofRobot, SizeYofRobot); 
		MessageBox(tmp);
		// get robot size
		
		/////////////////////////////////////////////////
		// Choi.W.H  2000.02.24
		DistanceBetweenBigTeamAndSmallID = (short)(sqrt(2.) * SizeXofRobot);
		//DistanceBetweenBigTeamAndSmallID = (short)(sqrt(2) / 2. * SizeXofRobot);
		// Choi.W.H  2000.02.24
		/////////////////////////////////////////////////

		// Clear pixels of zoom area		
		//Invalidate();
		bSetRobotSize =	FALSE;
		bBeginZoom	=	FALSE;
		bEndZoom	=	FALSE;
	}
	else if( bSetColor && bEndZoom && point.x >= (DispSizeX + ZOOM_OFFX) && point.x < (DispSizeX + ZOOM_OFFX + ZOOM_SIZE * ZOOM_SCALE)
		&& point.y >= ZOOM_OFFY && point.y < (ZOOM_OFFY + ZOOM_SIZE * ZOOM_SCALE)){ 
		// Determine ranges of RGB in selected rectangle in zoom window
		MinMaxOfRGB(point);
		// Initialize values of SetColor Dialog
		ptrSetColor->bSetColor = TRUE;
		InitSetColorDlg();
		if(ptrSetColor->DoModal() == IDOK)
			SetColorUpdate();
		bSetColor	=	FALSE;
		bBeginZoom	=	FALSE;
		bEndZoom	=	FALSE;
	}
	
	CFormView::OnLButtonDown(nFlags, point);
}


// --------------------------------------------------------
// Param  : point
// Return : none
// Remark : 祸 汲沥矫 急琶等 康开 犬措窍咯 弊府扁
// --------------------------------------------------------
void CVisionView::Zoom(CPoint point)
{   
	short w, h, x, y, remainder;
	BYTE *pZoomBuffer;
	CClientDC objDC(this);

	// Determine zoom window with the size ZOOM_SIZE x ZOOM_SIZE
	if(point.x < ZOOM_HALFSIZE && point.y < ZOOM_HALFSIZE){
		ZoomLeft = 0;
		ZoomTop = 0;
	}
	else if(point.x > (DispSizeX-1-ZOOM_HALFSIZE) && point.y < ZOOM_HALFSIZE){
		ZoomLeft = DispSizeX-1-ZOOM_SIZE;
		ZoomTop = 0;
	}
	else if(point.x < ZOOM_HALFSIZE && point.y > (DispSizeY-1-ZOOM_HALFSIZE)){
		ZoomLeft = 0;
		ZoomTop = DispSizeY-1-ZOOM_SIZE;
	}
	else if(point.x > (DispSizeX-1-ZOOM_HALFSIZE) && point.y > (DispSizeY-1-ZOOM_HALFSIZE)){
		ZoomLeft = DispSizeX-1-ZOOM_SIZE;
		ZoomTop = DispSizeY-1-ZOOM_SIZE;
	}
	else if(point.x < ZOOM_HALFSIZE){
		ZoomLeft = 0;
		ZoomTop = point.y-ZOOM_HALFSIZE;
	}
	else if(point.x > (DispSizeX-1-ZOOM_HALFSIZE) ){
		ZoomLeft = DispSizeX-1-ZOOM_SIZE;
		ZoomTop = point.y-ZOOM_HALFSIZE;
	}
	else if(point.y < ZOOM_HALFSIZE){
		ZoomLeft = point.x-ZOOM_HALFSIZE;
		ZoomTop = 0;
	}
	else if(point.y > (DispSizeY-1-ZOOM_HALFSIZE)){
		ZoomLeft = point.x-ZOOM_HALFSIZE;
		ZoomTop = DispSizeY-1-ZOOM_SIZE;
	}
	else {
		ZoomLeft = point.x-ZOOM_HALFSIZE;
		ZoomTop = point.y-ZOOM_HALFSIZE;
	}
	remainder = ZoomLeft % 4;	// trivial
	ZoomLeft -= remainder;
	// Get color data to ZoomBuffer
	MbufGetColor2d(MilImageBufferId, M_RGB32+M_PACKED, M_ALL_BAND, ZoomLeft, ZoomTop, ZOOM_SIZE, ZOOM_SIZE, ZoomBuffer);
	pZoomBuffer = ZoomBuffer;
	// draw the selected object area at Zoom Window
	for(h = 0;h < ZOOM_SIZE*ZOOM_SCALE;h += ZOOM_SCALE){
		for(w = 0;w < ZOOM_SIZE*ZOOM_SCALE;w += ZOOM_SCALE){             
			for(x = 0;x < ZOOM_SCALE;x++)
				for(y = 0;y < ZOOM_SCALE;y++)
					objDC.SetPixel(DispSizeX+ZOOM_OFFX+w+x, ZOOM_OFFY+h+y, RGB(*pZoomBuffer, *(pZoomBuffer+1), *(pZoomBuffer+2)));
			pZoomBuffer += 4;
		}
	}
}


// --------------------------------------------------------
// Param  : point
// Return : none
// Remark : 
// --------------------------------------------------------
void CVisionView::MinMaxOfRGB(CPoint point)
{
	long w, h, left, top, width, height;
	BYTE *pZoomBuffer;
	int y, u, v;
	int r, g, b;

	if(SelectedRectInZoom.left < point.x){
		left = SelectedRectInZoom.left;
		width = point.x - left;
	}
	else{
		left = point.x;
		width = SelectedRectInZoom.left - left;
	}
	if(SelectedRectInZoom.top < point.y){
		top = SelectedRectInZoom.top;
		height = point.y - top;
	}
	else{
		top = point.y;
		height = SelectedRectInZoom.top - top;
	}
	
	left = (left - (DispSizeX + ZOOM_OFFX)) / ZOOM_SCALE;
	top	= (top - ZOOM_OFFY) / ZOOM_SCALE;
	width /= ZOOM_SCALE;
	height /= ZOOM_SCALE;

	pZoomBuffer = ZoomBuffer;
		
	Rmin = Gmin = Bmin = 255;
	Rmax = Gmax = Bmax = 0;
	for(h=0;h<ZOOM_SIZE;h++) {
		if(h >= top && h <= (top + height) ) {
			for(w=0;w<ZOOM_SIZE;w++){
				if(w >= left && w <= (left + width) ) {
					r = *pZoomBuffer;
					g = *(pZoomBuffer+1);
					b = *(pZoomBuffer+2);
					
					y = (int)(0.299*r + 0.587*g + 0.114*b);
					y = min(255,max(y,0));
					u = (int)(0.565*(b-y) + 128);
					u = min(255,max(u,0));
					v = (int)(0.713*(r-y) + 128);
					v = min(255,max(v,0));

					
					if(y > Rmax)
						Rmax = y;
					if(y < Rmin)
						Rmin = y;
					if(u > Gmax)
						Gmax = u;
					if(u < Gmin)
						Gmin = u;
					if(v > Bmax)
						Bmax = v;
					if(v < Bmin)
						Bmin = v;
					
					
					/*
					if(r > Rmax)
						Rmax = r;
					if(r < Rmin)
						Rmin = r;
					if(g > Gmax)
						Gmax = g;
					if(g < Gmin)
						Gmin = g;
					if(b > Bmax)
						Bmax = b;
					if(b < Bmin)
						Bmin = b;
					*/

⌨️ 快捷键说明

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