You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#ifndef AFX_EXT_CLASS
#define AFX_EXT_CLASS Q_DECL_IMPORT
#endif
#include "TBase/TGraph.h"
#include "mycurve.h"
#include <vector>
#include <iostream>
#include <map>
#include <set>
using namespace std;
namespace GObjects
{
class CCurveGraph
{
public:
CCurveGraph(void);
virtual ~CCurveGraph(void);
//读取曲线数据
virtual void ReadCurves(CCurveList& curList);
virtual void ReadCurves(vector<CMyCurve*>& curVec);
//获取曲线间交点 可按照具体曲线类型重写
virtual int GetCrossPoints(void);
//构建结点图
int ConstructNodeGraph(void);
void Clear(void); //清空
public:
enum ESide
{
eRight = 0, //右侧
eLeft = 1, //左侧
eCollineation = 2 //共线
};
typedef TGraphNode<GBase::CPoint3D> PT3Node;
typedef list<PT3Node* >::iterator PT3ITER;
typedef TGraph<GBase::CPoint3D> PT3Graph;
/** @brief 曲线交点结构体*/
class SCRPoint/*:public PT3Node*/
{
public:
SCRPoint() :m_pNode(0) {}
PT3Node* m_pNode; //交点处的结点
std::map<CMyCurve*, double> 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<PT3Node*>& 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<CMyCurve*>& clipCurves, vector<CMyCurve*>& subjCurves);
//获取vector<CCurve*>中所有曲线的外接矩形
int GetCurveRects(vector<CMyCurve*>& scrCurves, vector<GBase::CRect8>& dstRects);
bool IsIntersect(const GBase::CRect8& rt1, const GBase::CRect8& rt2);
//构建指定曲线的结点图 lst记录了曲线上的交叉点
int ConstructNodeGraph(CMyCurve* pc, list<SCRPoint* >& lst);
//生成交叉结点之间的普通结点
int CreateNormalNodes(CMyCurve* pc, double lstart, double lend, list<PT3Node*>& nodeList);
//将nodelist中的指针存入m_graph
void InsertNodes(list<PT3Node*>& nodeList);
//获取下一结点
virtual PT3Node* GetNextNode(PT3Node* pLastNode, PT3Node* pCurrentNode);
//从候选者中选取下一结点 返回序号
PT3Node* SelectNextFromCandidate(PT3Node* pLastNode, PT3Node* pCurrentNode, vector<PT3Node*>& candidate);
vector<CMyCurve*> m_curVec;
vector<SCRPoint*> m_crossPoints;///<所有交叉点
map<CMyCurve*, list<SCRPoint* > > m_curScx_map; // 每根曲线对应的交点指针 按照在cur中的桩号排序
PT3Graph m_graph; //结点连接图
std::set<PT3Node*> m_storedMNodes; //temporary InsertNodes函数用到
int m_startIndex; //temporary 生成交叉结点之间的普通结点时用到CreateNormalNodes
bool m_bForward; //当前遍历方向(向前,向后)
ESide m_nSide; // 0 为交叉口向右转向 1为向左转向 2为共线
};
};
using namespace GObjects;