#pragma once #ifndef AFX_EXT_CLASS #define AFX_EXT_CLASS Q_DECL_IMPORT #endif #include "TBase/TGraph.h" #include "mycurve.h" #include #include #include #include using namespace std; namespace GObjects { class CCurveGraph { public: CCurveGraph(void); virtual ~CCurveGraph(void); //读取曲线数据 virtual void ReadCurves(CCurveList& curList); virtual void ReadCurves(vector& curVec); //获取曲线间交点 可按照具体曲线类型重写 virtual int GetCrossPoints(void); //构建结点图 int ConstructNodeGraph(void); void Clear(void); //清空 public: enum ESide { eRight = 0, //右侧 eLeft = 1, //左侧 eCollineation = 2 //共线 }; typedef TGraphNode PT3Node; typedef list::iterator PT3ITER; typedef TGraph PT3Graph; /** @brief 曲线交点结构体*/ class SCRPoint/*:public PT3Node*/ { public: SCRPoint() :m_pNode(0) {} PT3Node* m_pNode; //交点处的结点 std::map curLMap; //存储交点位置 相应曲线指针与对应桩号 //是否可以合并 inline bool canSplice(const SCRPoint& cr) const { if (0 == m_pNode || 0 == cr.m_pNode) return false; if (fabs(m_pNode->GetValue().x0 - cr.m_pNode->GetValue().x0) < 1e-6 && fabs(m_pNode->GetValue().y0 - cr.m_pNode->GetValue().y0) < 1e-6) return true; return false; } //将两个交点合并 inline void Splice(SCRPoint& crpt) { curLMap.insert(crpt.curLMap.begin(), crpt.curLMap.end()); } }; //通过给定lstClosedNodes中的后两个,获取闭合链路,当查找的新点==pStart时,查找成功 bLeftSide = 岔路口是否左侧转向 virtual bool TraceClosedLinks(PT3Node* pStart, list& foundNodes, ESide side, bool bForward); //判断结点是否可用 virtual bool IsNodeAvaliable(PT3Node* pNode) { return true; } //获取2在1的哪侧 static CCurveGraph::ESide GetV2Side(double x1, double y1, double x2, double y2); //运算调用 protected: void SetSide(ESide side) { m_nSide = side; } //指定左右方向 //构造两个曲线数组的交点,如果两容器地址一致,则两两相交 int GetCrossPoints(vector& clipCurves, vector& subjCurves); //获取vector中所有曲线的外接矩形 int GetCurveRects(vector& scrCurves, vector& dstRects); bool IsIntersect(const GBase::CRect8& rt1, const GBase::CRect8& rt2); //构建指定曲线的结点图 lst记录了曲线上的交叉点 int ConstructNodeGraph(CMyCurve* pc, list& lst); //生成交叉结点之间的普通结点 int CreateNormalNodes(CMyCurve* pc, double lstart, double lend, list& nodeList); //将nodelist中的指针存入m_graph void InsertNodes(list& nodeList); //获取下一结点 virtual PT3Node* GetNextNode(PT3Node* pLastNode, PT3Node* pCurrentNode); //从候选者中选取下一结点 返回序号 PT3Node* SelectNextFromCandidate(PT3Node* pLastNode, PT3Node* pCurrentNode, vector& candidate); vector m_curVec; vector m_crossPoints;///<所有交叉点 map > m_curScx_map; // 每根曲线对应的交点指针 按照在cur中的桩号排序 PT3Graph m_graph; //结点连接图 std::set m_storedMNodes; //temporary InsertNodes函数用到 int m_startIndex; //temporary 生成交叉结点之间的普通结点时用到CreateNormalNodes bool m_bForward; //当前遍历方向(向前,向后) ESide m_nSide; // 0 为交叉口向右转向 1为向左转向 2为共线 }; }; using namespace GObjects;