www.pudn.com > Extract.cpp.zip > Extract.cpp.txt, change:2009-07-29,size:6293b


 
/*void CMyScrollView::ExtractFeatureCricle(CObList *pList) 
{ 
	if (pList!=NULL && pList->GetCount()>0) 
	{	 
		CScanPoint* dStartPt; 
		CScanPoint* dEndpt; 
		CObList* pCluste; 
		POSITION pos; 
		pos=pList->GetHeadPosition(); 
		while(pos!=NULL){ 
			pCluste=(CObList*)pList->GetNext(pos); 
			//取类中首尾两点 
			dStartPt=(CScanPoint*)pCluste->GetHead(); 
			dEndpt=(CScanPoint*)pCluste->GetTail(); 
			int nCount=pCluste->GetCount(); 
			//取当中两点,并分别利用余弦定理求出和首尾点三点的夹角 
			POSITION pospt[2]; 
			double dAngle[2]; 
			CScanPoint* dPoint[2]; 
			pospt[0]=pCluste->FindIndex(nCount/2-1); 
			dPoint[0]=(CScanPoint*)pCluste->GetAt(pospt[0]); 
			pospt[1]=pCluste->FindIndex(nCount/2+1); 
			dPoint[1]=(CScanPoint*)pCluste->GetAt(pospt[1]); 
			double a=CalculatePtDistance(dStartPt,dPoint[0]); 
			double b=CalculatePtDistance(dEndpt,dPoint[0]); 
			double c=CalculatePtDistance(dStartPt,dEndpt); 
			dAngle[0]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			a=CalculatePtDistance(dStartPt,dPoint[1]); 
			b=CalculatePtDistance(dEndpt,dPoint[1]); 
			dAngle[1]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			//提取圆的特征 
			if ((dAngle[0]>=90&&dAngle[0]<=135) && (dAngle[1]>=90&&dAngle[1]<=135) ) 
			{ 
				if (IsAngleErrorInLimit(dAngle[0],dAngle[1],5)) 
				{ 
					m_CircleList.AddTail(pCluste); 
				} 
			} 
 
		} 
 
	} 
 
} 
void CMyScrollView::ExtractFeatureLine(CObList *pList) 
{ 
	if (pList!=NULL && pList->GetCount()>0) 
	{	 
		CScanPoint* dStartPt; 
		CScanPoint* dEndpt; 
		CObList* pCluste; 
		POSITION pos; 
		pos=pList->GetHeadPosition(); 
		while(pos!=NULL){ 
			pCluste=(CObList*)pList->GetNext(pos); 
			//取类中首尾两点 
			dStartPt=(CScanPoint*)pCluste->GetHead(); 
			dEndpt=(CScanPoint*)pCluste->GetTail(); 
			 
			//取当中两点,并分别利用余弦定理求出和首尾点三点的夹角 
			int nCount=pCluste->GetCount(); 
			POSITION pospt[2]; 
			double dAngle[2]; 
			CScanPoint* dPoint[2]; 
			pospt[0]=pCluste->FindIndex(nCount/2-1); 
			dPoint[0]=(CScanPoint*)pCluste->GetAt(pospt[0]); 
			pospt[1]=pCluste->FindIndex(nCount/2+1); 
			dPoint[1]=(CScanPoint*)pCluste->GetAt(pospt[1]); 
			double a=CalculatePtDistance(dStartPt,dPoint[0]); 
			double b=CalculatePtDistance(dEndpt,dPoint[0]); 
			double c=CalculatePtDistance(dStartPt,dEndpt); 
			dAngle[0]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			a=CalculatePtDistance(dStartPt,dPoint[1]); 
			b=CalculatePtDistance(dEndpt,dPoint[1]); 
			dAngle[1]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			 
			//提取直线的特征 
			if (IsAngleErrorInLimit(dAngle[0],180,5) && IsAngleErrorInLimit(dAngle[1],180,5)) 
			{ 
				m_LineList.AddTail(pCluste); 
			} 
			 
		} 
		 
	} 
	 
} 
 
void CMyScrollView::ExtractFeatureCornerPair(CObList *pList) 
{ 
	if (pList!=NULL && pList->GetCount()>0) 
	{	 
		CScanPoint* dStartPt; 
		CScanPoint* dEndpt; 
		CObList* pCluste; 
		POSITION pos; 
		pos=pList->GetHeadPosition(); 
		while(pos!=NULL){ 
			pCluste=(CObList*)pList->GetNext(pos); 
			//取类中首尾两点 
			dStartPt=(CScanPoint*)pCluste->GetHead(); 
			dEndpt=(CScanPoint*)pCluste->GetTail(); 
			//先找到角板的拐角点 
			double a,b,c; 
			double dAngleMin=0; 
			double dAngleTmp; 
			CScanPoint* dCornerPt; 
			POSITION posPt; 
			CScanPoint* dPt; 
 
			pCluste->RemoveHead(); 
			pCluste->RemoveTail(); 
			posPt=pCluste->GetHeadPosition(); 
			 
			if (posPt!=NULL) 
			{ 
				dPt=(CScanPoint*)pCluste->GetNext(posPt); 
				a=CalculatePtDistance(dStartPt,dPt); 
				b=CalculatePtDistance(dEndpt,dPt); 
				c=CalculatePtDistance(dStartPt,dEndpt); 
				dAngleMin=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
				dCornerPt=dPt; 
			} 
			while (posPt!=NULL) 
			{ 
				dPt=(CScanPoint*)pCluste->GetNext(posPt); 
				a=CalculatePtDistance(dStartPt,dPt); 
				b=CalculatePtDistance(dEndpt,dPt); 
				c=CalculatePtDistance(dStartPt,dEndpt); 
				dAngleTmp=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
				if (dAngleTmp<dAngleMin) 
				{ 
					dAngleMin=dAngleTmp; 
					dCornerPt=dPt; 
					 
				} 
			} 
			pCluste->AddHead(dStartPt); 
			pCluste->AddTail(dEndpt); 
		//根据拐角点分割Cluste 
 
			CObList* pLine1List; 
			CObList* pLine2List; 
					 
			CScanPoint* pPointOrder; 
			CScanPoint* pPointConOrder; 
			 
			POSITION posStart; 
			posStart=pCluste->GetHeadPosition(); 
			while (pos!=NULL) { 
				pPointOrder=(CScanPoint*)pCluste->GetNext(pos); 
 
				 if (pPointOrder==dCornerPt) { 
				//找到拐角点,将pList分开,拐角点是下一链表的起始点 
					POSITION posEnd; 
					posEnd=pCluste->GetTailPosition(); 
					while (posEnd!=NULL) 
					{ 
						pPointConOrder=(CScanPoint*)pCluste->GetPrev(posEnd); 
						if (pPointConOrder==dCornerPt) 
						{ 
							break; 
						} 
						else{ 
							pLine2List->AddHead((CObject*)pPointConOrder); 
						} 
 
					} 
					break; 
				 } 
				 else{ 
					pLine1List->AddTail((CObject*)pPointOrder); 
				 } 
			} 
         //在分割后的类中分别选取两个点 
			int nCount[2]; 
			nCount[0]=pLine1List->GetCount(); 
			nCount[1]=pLine2List->GetCount(); 
			POSITION pospt[4]; 
			double dAngle[4]; 
			CScanPoint* dPoint[4]; 
			//第一个点 
			pospt[0]=pLine1List->FindIndex(nCount[0]/2-1); 
			dPoint[0]=(CScanPoint*)pLine1List->GetAt(pospt[0]); 
			a=CalculatePtDistance(dStartPt,dPoint[0]); 
			b=CalculatePtDistance(dEndpt,dPoint[0]); 
			c=CalculatePtDistance(dStartPt,dEndpt); 
			dAngle[0]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			//第二个点 
			pospt[1]=pLine1List->FindIndex(nCount[0]/2+1); 
			dPoint[1]=(CScanPoint*)pLine1List->GetAt(pospt[1]); 
			a=CalculatePtDistance(dStartPt,dPoint[1]); 
			b=CalculatePtDistance(dEndpt,dPoint[1]); 
			dAngle[1]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			//第三个点 
			pospt[2]=pLine2List->FindIndex(nCount[1]/2+1); 
			dPoint[2]=(CScanPoint*)pLine2List->GetAt(pospt[2]); 
			a=CalculatePtDistance(dStartPt,dPoint[2]); 
			b=CalculatePtDistance(dEndpt,dPoint[2]); 
			c=CalculatePtDistance(dStartPt,dEndpt); 
			dAngle[2]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			//第四个点 
			pospt[3]=pLine2List->FindIndex(nCount[1]/2+1); 
			dPoint[3]=(CScanPoint*)pLine2List->GetAt(pospt[3]); 
			a=CalculatePtDistance(dStartPt,dPoint[3]); 
			b=CalculatePtDistance(dEndpt,dPoint[3]); 
			dAngle[3]=RAD2ANG(acos((a*a+b*b-c*c)/2*a*b)); 
			if (dAngle[0]>dAngle[1] && dAngle[3]>dAngle[2]) 
			{ 
				m_CornerPairList.AddTail(pCluste); 
			} 
			 
		} 
		 
	} 
	 
}*/