326 lines
7.3 KiB
C++
326 lines
7.3 KiB
C++
|
#include "Stdafx.h"
|
||
|
#include "ClosedFinder_Data.h"
|
||
|
|
||
|
//sArc////////////////////////////////////////////////////////////////////////
|
||
|
sArc::sArc()
|
||
|
{
|
||
|
m_Id = 0;
|
||
|
mTimeofSearch = 0;
|
||
|
}
|
||
|
Point_Key sArc::getBeginKey()
|
||
|
{
|
||
|
Point_Key key = 0;
|
||
|
if (!mPoints.empty())
|
||
|
{
|
||
|
key = (*mPoints.begin())->m_Id;
|
||
|
}
|
||
|
return key;
|
||
|
}
|
||
|
|
||
|
Point_Key sArc::getEndKey()
|
||
|
{
|
||
|
Point_Key key = 0;
|
||
|
if (!mPoints.empty())
|
||
|
{
|
||
|
key = (*mPoints.rbegin())->m_Id;
|
||
|
}
|
||
|
return key;
|
||
|
}
|
||
|
//sArcHalfEdge::ArcHalfEdge_iterator////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
sPoint* sArcHalfEdge::ArcHalfEdge_iterator::First()
|
||
|
{
|
||
|
sPoint* pRe = 0;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
iterator = mpEdge->mpArc->mPoints.begin();
|
||
|
pRe = (*iterator);
|
||
|
//
|
||
|
reverse_iterator = mpEdge->mpArc->mPoints.rend();
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
iterator = mpEdge->mpArc->mPoints.end();
|
||
|
//
|
||
|
reverse_iterator = mpEdge->mpArc->mPoints.rbegin();
|
||
|
pRe = (*reverse_iterator);
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
sPoint* sArcHalfEdge::ArcHalfEdge_iterator::Next()
|
||
|
{
|
||
|
sPoint* pRe = 0;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
iterator++;
|
||
|
pRe = (*iterator);
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
reverse_iterator++;
|
||
|
pRe = (*reverse_iterator);
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
bool sArcHalfEdge::ArcHalfEdge_iterator::IsEnd()
|
||
|
{
|
||
|
bool bRe = true;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
bRe = (iterator != mpEdge->mpArc->mPoints.end());
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
bRe = (reverse_iterator != mpEdge->mpArc->mPoints.rend());
|
||
|
}
|
||
|
|
||
|
return bRe;
|
||
|
}
|
||
|
|
||
|
sPoint* sArcHalfEdge::ArcHalfEdge_iterator::GetEnd()
|
||
|
{
|
||
|
sPoint* pRe = 0;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
pRe = *mpEdge->mpArc->mPoints.rbegin();
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
pRe = *mpEdge->mpArc->mPoints.begin();
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
|
||
|
}
|
||
|
|
||
|
const sPoint* sArcHalfEdge::ArcHalfEdge_const_iterator::First()
|
||
|
{
|
||
|
const sPoint* pRe = 0;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
iterator = mpEdge->mpArc->mPoints.begin();
|
||
|
if (IsEnd())
|
||
|
{
|
||
|
pRe = (*iterator);
|
||
|
}
|
||
|
//
|
||
|
reverse_iterator = mpEdge->mpArc->mPoints.rend();
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
iterator = mpEdge->mpArc->mPoints.end();
|
||
|
//
|
||
|
reverse_iterator = mpEdge->mpArc->mPoints.rbegin();
|
||
|
if (IsEnd())
|
||
|
{
|
||
|
pRe = (*reverse_iterator);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
const sPoint* sArcHalfEdge::ArcHalfEdge_const_iterator::Next()
|
||
|
{
|
||
|
const sPoint* pRe = 0;
|
||
|
if (!IsEnd())
|
||
|
{
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
iterator++;
|
||
|
pRe = (*iterator);
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
reverse_iterator++;
|
||
|
pRe = (*reverse_iterator);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
bool sArcHalfEdge::ArcHalfEdge_const_iterator::IsEnd() const
|
||
|
{
|
||
|
bool bRe = true;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
bRe = (iterator != mpEdge->mpArc->mPoints.end());
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
bRe = (reverse_iterator != mpEdge->mpArc->mPoints.rend());
|
||
|
}
|
||
|
|
||
|
return bRe;
|
||
|
}
|
||
|
|
||
|
const sPoint* sArcHalfEdge::ArcHalfEdge_const_iterator::GetEnd()
|
||
|
{
|
||
|
const sPoint* pRe = 0;
|
||
|
if (mpEdge->mDirection == EAD_Begin2End)
|
||
|
{
|
||
|
pRe = *mpEdge->mpArc->mPoints.rbegin();
|
||
|
}
|
||
|
else if (mpEdge->mDirection == EAD_End2Begin)
|
||
|
{
|
||
|
pRe = *mpEdge->mpArc->mPoints.begin();
|
||
|
}
|
||
|
|
||
|
return pRe;
|
||
|
}
|
||
|
|
||
|
sArcHalfEdge::sArcHalfEdge( sArc *pArc /*= 0*/ )
|
||
|
{
|
||
|
mpArc = pArc;
|
||
|
mDirection = EAD_Begin2End;
|
||
|
}
|
||
|
sArcHalfEdge::sArcHalfEdge( const sArcHalfEdge& src )
|
||
|
{
|
||
|
if (this != &src)
|
||
|
{
|
||
|
mpArc = src.mpArc;
|
||
|
mDirection = src.mDirection;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void sPolygon::AddEdge(const sArcHalfEdge& pEdge )
|
||
|
{
|
||
|
mArcHalfEdge.push_back(pEdge);
|
||
|
mArcHalfEdgeSort[pEdge.mpArc->m_Id] = &(*mArcHalfEdge.rbegin());
|
||
|
|
||
|
if (!pEdge.mpArc->mPoints.empty())
|
||
|
{
|
||
|
mBE_PointSort[(*pEdge.mpArc->mPoints.begin())->m_Id] = (*pEdge.mpArc->mPoints.begin());
|
||
|
mBE_PointSort[(*pEdge.mpArc->mPoints.rbegin())->m_Id] = (*pEdge.mpArc->mPoints.rbegin());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#define MARK_MAXNUMBER 9997
|
||
|
void sPolygon::CalMark()
|
||
|
{
|
||
|
//m_Id = m_Id + 1;
|
||
|
std::map<Arc_Key, sArcHalfEdge*>::const_iterator it = mArcHalfEdgeSort.begin();
|
||
|
|
||
|
int i = 1;
|
||
|
mMarkType = 0;
|
||
|
for(; it != mArcHalfEdgeSort.end(); it++)
|
||
|
{
|
||
|
mMarkType += T_MARK_TYPE ((MARK_MAXNUMBER * pow(3.0, i++)) + it->second->mpArc->m_Id* pow(2.5, i++));
|
||
|
//mMarkType += (MARK_MAXNUMBER * pow(10.0, i++)) + it->second->mpArc->m_Id;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool sPolygon::GetAverageMarkPoint(gp_Point& pt) const
|
||
|
{
|
||
|
std::map<Arc_Key, sArcHalfEdge*>::const_iterator it = mArcHalfEdgeSort.begin();
|
||
|
for(; it != mArcHalfEdgeSort.end(); it++)
|
||
|
{
|
||
|
const sArc* pArc = it->second->mpArc;
|
||
|
pt.SetX(pt.X() + pArc->mMarkPoint.X());
|
||
|
pt.SetY(pt.Y() + pArc->mMarkPoint.Y());
|
||
|
pt.SetZ(pt.Z() + pArc->mMarkPoint.Z());
|
||
|
}
|
||
|
size_t size = mArcHalfEdgeSort.size();
|
||
|
if (size > 0)
|
||
|
{
|
||
|
pt.SetCoord(pt.X() / size, pt.Y() / size, pt.Z() / size);
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool sPolygon::GetBE_CompositeKey( CompositeKey &Compkey ) const
|
||
|
{
|
||
|
bool bRe (false);
|
||
|
if (!mBE_PointSort.empty())
|
||
|
{
|
||
|
bRe = true;
|
||
|
Compkey.mKey1 = mBE_PointSort.begin()->first;
|
||
|
Compkey.mKey2 = mBE_PointSort.rbegin()->first;
|
||
|
}
|
||
|
|
||
|
return bRe;
|
||
|
}
|
||
|
|
||
|
bool sPolygon::GetBE_HalfEdge( std::map<Point_Key, std::map<Arc_Key, sArcHalfEdge> >& ptHalfEdge ) const
|
||
|
{
|
||
|
std::map<Point_Key, sPoint*>::const_iterator it = mBE_PointSort.begin();
|
||
|
for(; it != mBE_PointSort.end(); it++)
|
||
|
{
|
||
|
Point_Key ptKeySrc = it->first;
|
||
|
//
|
||
|
std::map<Arc_Key, sArcHalfEdge>* pData =
|
||
|
getMapValue<Point_Key, std::map<Arc_Key, sArcHalfEdge> >(ptHalfEdge, ptKeySrc, true);
|
||
|
|
||
|
std::vector<sArcHalfEdge>::const_iterator itHalf = mArcHalfEdge.begin();
|
||
|
for(; itHalf != mArcHalfEdge.end(); itHalf++)
|
||
|
{
|
||
|
sArcHalfEdge psArcHalfEdge = *itHalf;
|
||
|
sArcHalfEdge::ArcHalfEdge_const_iterator halfConstIt(&psArcHalfEdge);
|
||
|
if (halfConstIt.First()->m_Id != ptKeySrc) //判断第一个与当前点是否相等
|
||
|
{
|
||
|
psArcHalfEdge.ExchandeDirenction(); //设置为第一个点
|
||
|
}
|
||
|
|
||
|
sArcHalfEdge::ArcHalfEdge_const_iterator halfConstIt1(&psArcHalfEdge);
|
||
|
if (halfConstIt1.First()->m_Id == ptKeySrc) //第一个与当前点是否相等
|
||
|
{
|
||
|
(*pData)[itHalf->mpArc->m_Id] = psArcHalfEdge;
|
||
|
}
|
||
|
}
|
||
|
//for()
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool sPolygon::ExistArc( Arc_Key arcKey )
|
||
|
{
|
||
|
return (mArcHalfEdgeSort.find(arcKey) != mArcHalfEdgeSort.end());
|
||
|
}
|
||
|
|
||
|
bool sPolygon::ExistPoint( Point_Key PointKey )
|
||
|
{
|
||
|
return (mBE_PointSort.find(PointKey) != mBE_PointSort.end());
|
||
|
}
|
||
|
|
||
|
vector<Point_Key> sPolygon::GetPointKeySet()
|
||
|
{
|
||
|
vector<Point_Key> keySet;
|
||
|
for(map<Point_Key, sPoint*>::iterator iter = mBE_PointSort.begin(); iter != mBE_PointSort.end(); iter++)
|
||
|
{
|
||
|
keySet.push_back(iter->first);
|
||
|
}
|
||
|
return keySet;
|
||
|
}
|
||
|
|
||
|
//返回点所在边在多边形中的位置
|
||
|
int sPolygon::GetPointIndex(Point_Key PointKey)
|
||
|
{
|
||
|
if (mArcHalfEdge.empty())
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
Point_Key polyFirstId = 0; //当前的多边形弧段集合的起始点号
|
||
|
|
||
|
std::vector<sArcHalfEdge>::iterator iter = mArcHalfEdge.begin();
|
||
|
|
||
|
int index = 1;
|
||
|
for(;iter != mArcHalfEdge.end(); iter++, index++)
|
||
|
{
|
||
|
sArcHalfEdge edge = *iter;
|
||
|
Point_Key polyFirstId = edge.mpArc->mPoints[0]->m_Id;
|
||
|
Point_Key polyNexttId = edge.mpArc->mPoints[1]->m_Id;
|
||
|
if( polyFirstId == PointKey || polyNexttId == PointKey)
|
||
|
{
|
||
|
return index;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|