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.

137 lines
3.2 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.

/**************************************************************************************
文 件 名Contour2Polygon.h
*****************************************************************************************/
#pragma once
#include "mycurve.h"
#include "TBase/TMultiTree.h"
#include "curvegraph.h"
#include <set>
#include <map>
template<typename T>
void DeepEraseVector(std::vector<T>& vec)
{
for(int i = 0; i < (int)vec.size(); i ++ )
{
if(NULL != vec[i])
delete vec[i];
}
vec.clear();
}
namespace GObjects
{
//class CPolygonTree;
class CC2P : protected CCurveGraph
{
public:
CC2P(void);
virtual ~CC2P(void);
void ClearAll(void);
void SetLines(vector<CMyCurve*>& vec);
void SetHoles(vector<CMyCurve*>& scrFlts);
void SetBorder(CMyCurve& border);
void SetExtensivePara(double dext) { m_dext = dext; }
double GetExtensivePara(void) const { return m_dext; }
void CreatePolygons(void); //
vector<CMyCurve*>& GetPolygons() { return m_dstPolygons; }
//根据多边形散点z值获取当前多边形曲线z值
double GetPolygonValue(CMyCurve& curve);
static bool IsCurveInside(CMyCurve* pRange, CMyCurve* pSubj);
//override
protected:
virtual int GetCrossPoints(void);
virtual PT3Node* GetNextNode(PT3Node* pLastNode, PT3Node* pCurrentNode);
public:
//交叉点转向位置
class STurning
{
public:
/* SFltSec(void);*/
//自动整理 小在前 大在后
STurning(CCurveGraph::PT3Node* pLast, CCurveGraph::PT3Node* pCurrent, CCurveGraph::PT3Node* pNext, ESide eside);
/*bool operator==(const SFltSec& pd2) const;*/
bool operator<(const STurning& pt2) const;
private:
CCurveGraph::PT3Node* mp1;
CCurveGraph::PT3Node* mp2;
CCurveGraph::PT3Node* mp3;
//bool mbForw; //是否沿着断线方向
CCurveGraph::ESide mSide;
};
void Trace(void);
void TraceBorderPolygons(CMyCurve* border);
bool TraceFltSegPolygon(CMyCurve* curve, SCRPoint* startSCRPt, bool bBorder);
void TraceFltPolygons(CMyCurve* flt);
void TraceContourPolygons(CMyCurve* pContour);
CMyCurve* CreateOneOpenPolygon(list<PT3Node*>& lstNodes);
void TraceOutputPolygons(void);
void EnableCheckZ(bool b) { m_bCheckZ = b; }
//members
private:
//输入的成员变量
double m_dext;
CMyCurve* m_pBorder;
vector<CMyCurve*> m_lines;
vector<CMyCurve*> m_bd_faults;
//最终输出的多边形
vector<CMyCurve*> m_dstPolygons;
void TraceOutputCircles(list<CMyCurve*>& closingCurves);
void CombineOpenPolygons(void);
bool IsFltZ(double z);
void GetBorderCXNodes(void);
void FilterDstPolygons(void);
bool IsPolygonLegal(CMyCurve* pgn);
virtual bool IsNodeAvaliable(PT3Node* pNode) override;
private:
set<STurning> m_tracedTurnings; // tmp 记录已经追踪到的交叉点和相连结点的线段
//中间变量
private:
//计算出的中间成员变量
vector<CMyCurve*> m_openContPolygons;
vector<int> m_circleIndexes;
map<int, list<int> > m_mapFltNodes;
vector<CRect8> m_rectFlts;
double m_maxVal;
double m_minVal;
double m_conStep;
const double m_dFLTZ;
bool m_bCheckZ;
set<PT3Node*> m_borderCxNodes;
set<CMyCurve*> m_borderPolygons;
bool m_bBorderTracing;
};
};
using namespace GObjects;
//多边形树中一个结点
typedef TTreeNode<CMyCurve*> CPgnNode;
typedef TMultiTree<CMyCurve*> CPgnTree;