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.
248 lines
5.3 KiB
C++
248 lines
5.3 KiB
C++
#pragma once
|
|
#include "MLPlNode.h"
|
|
#include "MLPoint.h"
|
|
#include "MLRect.h"
|
|
|
|
#define MLDPline MLPline
|
|
|
|
class MLPointAry;
|
|
class MLRect;
|
|
class MLMICROSTRUCTURE_EXPORT MLPline
|
|
{
|
|
public:
|
|
MLPline(void);
|
|
MLPline(const QPolygonF& polygonf);
|
|
MLPline(const QVector<MLPlNode>& nodeAry);
|
|
~MLPline(void);
|
|
|
|
// 元素数
|
|
__declspec(property(get=getName, put = setName)) char* name;
|
|
__declspec(property(get=getNodeAry, put = setNodeAry)) QVector<MLPlNode> nodeAry;
|
|
|
|
public:
|
|
const char* getName() const;
|
|
void setName(const char* name);
|
|
|
|
QVector<MLPlNode>& getNodeAry();
|
|
void setNodeAry(const QVector<MLPlNode>& nodeAry);
|
|
void setNodeAry(const QPolygonF& polygon);
|
|
|
|
// 得到节点个数
|
|
int getCount() const;
|
|
|
|
// 是否为空
|
|
bool isEmpty();
|
|
|
|
// 是否为闭合线
|
|
bool isClose(double dis = 20.0);
|
|
|
|
// 向曲线头添加节点数据
|
|
void addHeadPt(const MLPlNode& node);
|
|
void addHeadPt(const MLPoint& point);
|
|
void addHeadPt(double x, double y, double z=0);
|
|
void addHeadPt(const MLPline& pline);
|
|
|
|
// 向曲线头添加节点数据(原曲线反向)
|
|
void addHeadPtRev(const MLPline& pline);
|
|
void addHeadPtRev(const MLPointAry& pointAry);
|
|
|
|
// 向曲线尾添加节点数据
|
|
void addTailPt(const MLPlNode& node);
|
|
void addTailPt(const MLPoint& point);
|
|
void addTailPt(double x,double y,double z=0);
|
|
void addTailPt(const MLPline& pline);
|
|
void addTailPt(const QPoint& point);
|
|
void addTailPt(const QPointF& point);
|
|
|
|
// 向曲线尾添加节点数据(原曲线反向)
|
|
void addTailPtRev(const MLPline& pline);
|
|
void addTailPtRev(const MLPointAry& pointAry);
|
|
|
|
// 行到头点
|
|
const MLPlNode& getHeadPt() const;
|
|
MLPlNode& getHeadPt();
|
|
|
|
// 得到尾点
|
|
const MLPlNode& getTailPt() const;
|
|
MLPlNode& getTailPt();
|
|
|
|
// 得到结点
|
|
const MLPlNode& getAtPt(int index) const;
|
|
|
|
// 设置结点
|
|
void setAtPt(int index, const MLPlNode& node);
|
|
|
|
// 插入节点
|
|
void insertAfter(int index, const MLPlNode& node);
|
|
void insertBefore(int index, const MLPlNode& node);
|
|
|
|
// 移出头点
|
|
void removeHead();
|
|
|
|
// 移出尾点
|
|
void removeTail();
|
|
|
|
// 移出结点
|
|
void removeAt(int index);
|
|
|
|
// 移出结点
|
|
void removeRt(const MLRect& dRect);
|
|
|
|
// 移出小于角度点(弧度)
|
|
void removeAtFrAngle(double angle);
|
|
|
|
// 移出小于角度点(角度)
|
|
void removeAtFrAngle2(double angle);
|
|
|
|
// 移出所有结点
|
|
void removeAll();
|
|
|
|
// 重置节点个数
|
|
void resize(int count);
|
|
|
|
// 曲线节点反向
|
|
void reversePt();
|
|
|
|
MLPlNode& operator[]( int index );
|
|
const MLPlNode& operator[]( int index ) const;
|
|
|
|
const MLPlNode* getData() const;
|
|
|
|
MLPline* clone();
|
|
|
|
// 拷贝
|
|
void copy(const MLPline& pline);
|
|
|
|
// 拷贝数据点
|
|
void copyPt(const QVector<MLPlNode>& noteAry);
|
|
|
|
// 拷贝数据点
|
|
void copyPt(const MLPline& pline);
|
|
|
|
// 向曲线头增加闭合点
|
|
void closeHeadPt();
|
|
|
|
// 向曲线尾增加闭合点
|
|
void closeTailPt();
|
|
|
|
// 得到点数组
|
|
MLPointAry getPointAry(int beginIndex ,int endIndex);
|
|
MLPline getPline(int beginIndex ,int endIndex);
|
|
|
|
// 计算外包围盒
|
|
MLRect calculateBox();
|
|
void resetBox();
|
|
MLRect getBox();
|
|
|
|
// 得到曲线长度
|
|
double getLength();
|
|
double getLength(int index);
|
|
|
|
// 曲线面积
|
|
double getArea();
|
|
|
|
// 得到曲线长度
|
|
void calculateLength();
|
|
|
|
// 得到曲线所围成的面积
|
|
void calculateArea() ;
|
|
|
|
// 计算节点角度
|
|
void calculateAngle();
|
|
|
|
// 计算曲线质心点
|
|
MLPoint calculateCentroid();
|
|
|
|
// 曲线去冗余
|
|
void redundant(double error=1.0);
|
|
|
|
// 查找线点相近点索此
|
|
int findIndex(const MLPoint& point, double delt=0.1);
|
|
|
|
// 计算点是否在多边形内
|
|
bool contains(const MLPoint& point);
|
|
bool contains(const MLPlNode& node);
|
|
bool contains(double x, double y);
|
|
|
|
// 是否完全包含此线
|
|
bool containsWhole(const MLPline& other);
|
|
|
|
// 读取曲线
|
|
bool read(const QString& Path);
|
|
bool read(QFile& fr); //
|
|
void read(QDataStream &in);
|
|
|
|
// 输出曲线
|
|
void write(const QString& Path);
|
|
void write(QFile& fw);
|
|
void write(QDataStream &out);
|
|
void write(QTextStream& out);
|
|
|
|
// 转指针数据
|
|
void toXyData(double*& pX, double*& pY, int& count);
|
|
|
|
// 转为Qt 格式
|
|
void toQPolygonF(QPolygonF&);
|
|
QPolygonF toQPolygonF()const;
|
|
|
|
// 曲线重采样
|
|
void sampling(MLPline &curve, double step);
|
|
|
|
// 得到首尾距离
|
|
double getHeadTailDistance() const;
|
|
|
|
// 得到点到折线最近线段垂直距离
|
|
double getNearest(const MLPlNode& node, int& index, MLPlNode& dptDest);
|
|
|
|
// 两点之间距离
|
|
double getDistance(const MLPlNode& node1, const MLPlNode& node2) const;
|
|
|
|
// 得到索引之间的距离
|
|
double getDistance(int index1, int index2);
|
|
|
|
// 两点垂直点之间距离
|
|
double getVerticalDistance(const MLPlNode& dPoint1, const MLPlNode& dPoint2);
|
|
|
|
// 两点垂直点之间反向距离
|
|
double getReverseDistance(const MLPlNode& dPoint1, const MLPlNode& dPoint2);
|
|
|
|
// 按角度转为单线
|
|
void toSinglePline(QList<MLPline *>& singleCurveList, double Angle);
|
|
|
|
// 创建椭圆多边形
|
|
void createEllipse(const MLPoint& point, double radius);
|
|
|
|
private:
|
|
char m_name[64]; // 曲线名称
|
|
QVector<MLPlNode> m_nodeAry;// 曲线节点列表
|
|
double m_dLength;
|
|
double m_dArea;
|
|
|
|
MLRect m_box;
|
|
};
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
class MLMICROSTRUCTURE_EXPORT MLDPlineRedundant
|
|
{
|
|
public:
|
|
MLDPlineRedundant(void);
|
|
MLDPlineRedundant(double *oldx, double *oldy, double *oldz, double *oldl, int oldnum, int *mark);
|
|
MLDPlineRedundant(double *oldx, double *oldy, int oldnum, int *mark);
|
|
~MLDPlineRedundant(void);
|
|
|
|
public:
|
|
//执行曲线冗余处理
|
|
void execute(double dbError = -1.0);
|
|
|
|
// 冗余处理后节点数
|
|
int getMarkNum();
|
|
|
|
private:
|
|
void getNewPoint(int n1,int n2);
|
|
int m_nMarkNum;
|
|
int *m_pMark;
|
|
double m_dbMinDistance; //最小距离
|
|
int num;
|
|
double *x,*y,*z,*l;
|
|
}; |