#pragma once #include #include #include #include using std::string; using std::fstream; using std::vector; //基础图元 enum ElementType { eNull = -1, ePoint = 0, eRect = 1, eLine = 2, eDfg = 3 }; class AFX_EXT_CLASS GBaseObj { public: GBaseObj(); virtual ~GBaseObj(); GBaseObj& operator=(const GBaseObj& other); void SetName(string strName); void SetName(char* strname); void SetName(const char* strname); void SetLayer(const char* strLayer); void SetLayer(string strLayer); void SetColor(COLORREF clr); string GetName(void); string GetLayer(void); COLORREF GetColor(void); ElementType GetType(void); void SetPosition(const char* strname); string GetPosition(void); protected: void SetType(ElementType type); string m_strName; //名称 string m_strLayer; //层位 COLORREF m_color; //颜色 ElementType m_type; //类型 string m_strPosition; // 编号 }; //点类 class AFX_EXT_CLASS GPoint3D:public GBaseObj { public: GPoint3D(void); GPoint3D(double x, double y, double z); bool operator<(const GPoint3D& other) const; bool operator==(const GPoint3D& other) const; GPoint3D& operator=(const GPoint3D& other); void Write(FILE* fw); double Distance2D(const GPoint3D& other) const; void Rotate(double xs, double ys, double radian); void Rotate(double xs, double ys, double cosa, double sina); ~GPoint3D(void); double x0; double y0; double z0; }; //矩形类 class AFX_EXT_CLASS GRect8 :public GBaseObj { public: GRect8(void); GRect8(double l, double r, double b, double t); bool IsIntersected(const GRect8& other) const; void GetCenter(double& x, double& y); double Width(void); double Height(void); void Create(double x0, double y0, double width, double height); double left; double right; double bottom; double top; }; //曲线类 class AFX_EXT_CLASS GPline :public GBaseObj { public: GPline(void); ~GPline(void); void operator+=(double t); void Clear(void); int ReadFile(std::ifstream& ifs); //读取一条线 x,y,z void AddPoint(const GPoint3D& pt); void SetPoint(int idx, double xx, double yy, double zz = 0); void SetPoint(int idx, const GPoint3D& pt); void SetPoints(const std::list& ptlst); //设置整条曲线 int GetCount(void) const;//返回点个数 GRect8 GetRect(void) const;//获取曲线包络矩形框 ////获取当前线与other的交点,存入list,cxpIndexs,此算法不严格,交点索引可能与交点不对应 int GetCrossPoints(const GPline& other, std::list& cxpts, std::list& cxpIndexs); //获取点所在位置 istart为起始点序号,factor为所处线段比例 int GetLocation(double x0, double y0, double& factor); bool GetCoordinate(double l0, double & x, double& y, double& z, int& locationIndex); //获取多边形中心 void GetGravityCenter(double& x0, double& y0); //判断当前线与other是否相交 bool IsIntersected(const GPline& other) const; //判断other是否在当前曲线多边形内部,若是返回1,否返回0, 部分在,部分不在返回2 int IsInside(const GPline& other) const; //判断点是否在多边形内部,是返回1,否返回0 在线上返回2 int IsInside(double x0, double y0) const; //判断点是否在多边形内部,是返回1,否返回0 在线上返回2 int IsInside(const GRect8& rect) const; void FromRect(const GRect8& rect); bool IsClosed(double esp); //是否闭合 //获取两个多边形的相交多边形solution,无相交返回false bool GetIntersectedPolygon(const GPline& other, GPline& solution); //计算曲线多边形面积 double Area(void) const; double X(int i)const; double Y(int i) const; double Z(int i) const; double L(int i) const; void Write(FILE* fw); GPoint3D GetPoint(int idx) const; double GetLength(void); void GetLocation(void); //获取所有桩号 //获取平均走向(-PI/2,PI/2] double GetAverageDirection(void); //曲线以(x0,y0)为中心逆时针旋转radian弧度 void Rotate(double xs, double ys, double radian); void Rotate(double xs, double ys, double cosa, double sina); void Reverse(); private: std::vector m_points; std::vector m_locations; }; //x0,y0为中心点,斜率k 生成一条线,长度为len AFX_EXT_CLASS GPline* CreateLine(double x0, double y0, double sina, double cosa, double len); //生成一组测线 xs ,ys起点, xe ye 终点 角度lndirect, len为线1/2长度 AFX_EXT_CLASS int CreateLines(vector& dstLines, double xs, double ys, double xe, double ye, double dx, double dy, double lndirect, double len);