#pragma once #include "ClosedFinder_Tool.h" //pj /*typedef DWORD TimeofSearch; typedef ULONG T_KEY; typedef ULONG T_MARK_TYPE; */ typedef uint32_t TimeofSearch; typedef uint32_t T_KEY; typedef uint32_t T_MARK_TYPE; typedef T_KEY Point_Key; typedef T_KEY Arc_Key; typedef T_KEY Polygon_Key; typedef gp_Pnt gp_Point; enum EArcDirection { EAD_Begin2End , EAD_End2Begin , }; class CompositeKey { public: CompositeKey(T_KEY key1, T_KEY key2) { mKey1 = key1; mKey2 = key2; } CompositeKey(const CompositeKey& src) { *this = src; } CompositeKey& operator = (const CompositeKey& src) { if (this != &src) { mKey1 = src.mKey1; mKey2 = src.mKey2; } return *this; } bool operator < (const CompositeKey& src) const { if(mKey1 != src.mKey1) { return mKey1 < src.mKey1; } return mKey2 < src.mKey2; } /*Point_Key*/T_KEY mKey1; /*Point_Key*/T_KEY mKey2; }; //点 struct sPoint { sPoint() { m_Id = 0; } //key Point_Key m_Id; //key //data gp_Point m_PtCoor; }; //弧段 struct sArc { sArc(); public: Point_Key getBeginKey(); Point_Key getEndKey(); public: //key Arc_Key m_Id; //data std::vector mPoints; TimeofSearch mTimeofSearch ; //被遍历的次数 //扩展数据 Arc_Key m_IdSrc; //原始线段的ID gp_Point mMarkPoint; //标志点 }; //生成多边形的时候,弧段及其弧段的方向(半边数据结构) struct sArcHalfEdge { public: class ArcHalfEdge_iterator //iterator { friend struct sArcHalfEdge; public: ArcHalfEdge_iterator(sArcHalfEdge* pEdge): mpEdge(pEdge){} virtual sPoint* First(); virtual sPoint* Next(); virtual bool IsEnd(); public: sPoint* GetEnd(); private: std::vector::iterator iterator; std::vector::reverse_iterator reverse_iterator; private: sArcHalfEdge *mpEdge; }; class ArcHalfEdge_const_iterator //const iterator { friend struct sArcHalfEdge; public: ArcHalfEdge_const_iterator(const sArcHalfEdge* pEdge): mpEdge(pEdge){} virtual const sPoint* First() ; virtual const sPoint* Next() ; virtual bool IsEnd() const; public: const sPoint* GetEnd(); private: std::vector::const_iterator iterator; std::vector::const_reverse_iterator reverse_iterator; private: const sArcHalfEdge* mpEdge; }; public: sArcHalfEdge(sArc *pArc = 0); sArcHalfEdge(const sArcHalfEdge& src); public: void ExchandeDirenction() { mDirection = (mDirection == EAD_Begin2End) ? EAD_End2Begin : EAD_Begin2End; } sArc* mpArc; EArcDirection mDirection; }; struct sPolygon { sPolygon() { m_Id = 0; mIsIland = false; mMarkType = 0; } public: //添加边 void AddEdge(const sArcHalfEdge& pEdge); //计算多边形标志 void CalMark(); //边是否存在 bool ExistArc(Arc_Key arcKey); //点是否存在 bool ExistPoint(Point_Key PointKey); //返回点所在多边形中的位置 int GetPointIndex(Point_Key PointKey); public: bool GetAverageMarkPoint(gp_Point &pt) const; //标志点 bool GetBE_CompositeKey(CompositeKey &Compkey) const; //得到首尾的点复合号 bool GetBE_HalfEdge(std::map >& ptHalfEdge) const; //得到首尾点的所有半边数据结构信息 //获取顶点集合 vector GetPointKeySet(); public: //key Polygon_Key m_Id; //key //data std::vector mArcHalfEdge; bool mIsIland; //是否孤岛(可能是洞) private: //XData, no use now //按照弧线的编号的大小排序 std::map mArcHalfEdgeSort; //按照首尾点号大小排序 std::map mBE_PointSort; public: T_MARK_TYPE mMarkType; //多边形标志 };