#pragma once #include "Geometry.h" // ADDED BY XUEFENG 201808 // FOR CODES COMBINE // ADDED BY XUEFENG 2018.04 typedef std::pair Point_Arc_Pair; typedef std::pair Point_Point_Pair; // End Added // END ADDED class TopoDS_Wire; class CInsectionInfo { public: CInsectionInfo(void); ~CInsectionInfo(void); public: //点所属边 std::vector m_vctBelongWireIDs; //点坐标 gp_Pnt m_PtCoor; //点id int m_Id; //std::map m_mapdis2start; }; class CHalfEdgeKey { public: //起始点id int m_iStartPointID; //结束点id int m_iEndPointID; //线段id int m_iIntersectionInfoID; CHalfEdgeKey() { m_iStartPointID = 0 ; m_iEndPointID = 0 ; m_iIntersectionInfoID = 0 ; //ElemKey = 0 ; } bool operator < ( const CHalfEdgeKey rhs) const { if(m_iIntersectionInfoID < rhs.m_iIntersectionInfoID) { return true; } else if(m_iIntersectionInfoID == rhs.m_iIntersectionInfoID) { // if(ElemKey < rhs.ElemKey) // { // return true; // } // if(ElemKey == rhs.ElemKey) // { if(m_iStartPointID < rhs.m_iStartPointID) { return true; } else if(m_iStartPointID == rhs.m_iStartPointID) { if(m_iEndPointID < rhs.m_iEndPointID) { return true; } } //} } return false; } }; class CInsectionSectionInfo { public: CInsectionSectionInfo(void){}; ~CInsectionSectionInfo(void){}; public: Standard_Real GetDistance2Start(); public: // CInsectionInfo m_startInsection; // CInsectionInfo m_endInsection; //起始点id int m_startInsection; //结束点id int m_endInsection; //线段id int m_Id; //所属原边id int m_BelongWireID; }; class CResultData { public: //原线id int m_iWireID; //起始位置 double m_dStartRatio; //终止位置 double m_dEndRatio; //与原线方向是否相反 int m_iFlag; // 1 -1 protected: private: }; class CSplitAllInsectionCurves { public: CSplitAllInsectionCurves(void); //*********** flag ********************************* 交点约束 CSplitAllInsectionCurves(std::map& m_Curves, std::map& m_Points); //********************************************************* ~CSplitAllInsectionCurves(void); public: //初始化线数据 void Init(const std::vector& wires,const std::vector& seqNo); //初始化线数据,包含边界 void Init(const std::vector& wires,const std::vector& strNames,std::vector& borderWireID); //初始化线数据,包含基础面(用于拆分多边形) void Init(const std::vector& wires, TopoDS_Face baseFace); //初始化线数据 void Init(const std::vector& wires); //初始化线数据 void Init(std::map& wires, std::vector ids); //执行网格面算法 bool Build(bool bsolid=false);//srq 2011-6-3 //获取所有闭合的网格 bool GetAllWires(bool bsolid); //将多边形进行拆分,获取最终用于生成面的网格 bool GetAllFaces(bool bsolid); //显示线端点信息 void ShowBSplineStartEndPoint(const Handle(Geom_BSplineCurve) BSplineCurve); // void GetClosedShapes(std::map& shapes); // void GetClosedCurves(std::map>& ClosedBSplineCurves); // void GetIntersectionPoints(std::map& mapAllInsectionPoints){mapAllInsectionPoints =m_mapAllInsectionPoints; } // std::map> GetClosedZoomPointID(){return m_mapClosedZooms;}; // std::map GetErrorClosedZoomID(); // std::vector,int>> GetIntersectionTimeSearchs(); //获取闭合线框集合 std::map> GetClosedResultDatas(){return m_ClosedResults;}; //获取原线名称 std::string GetWireName(int iID); //获取最终网格结果 map> GetResult(); //获取原始边 TopoDS_Edge GetIWireByID(int id); private: //*********** flag ********************************* 交点约束 std::map m_mapPoints; std::map m_mapCurves; //********************************************************* //所有原始边集合 std::map m_mapAllWires; //所有交点集合 std::map m_mapAllInsectionPoints; //所原始边被交点拆分后,线段集合 std::map m_mapAllInsectionSectionInfo; //主从周边点集合 std::map> m_mapInsectionAround; //记录周边点号 std::map> m_mapClosedZooms; //闭合线框id int m_ClosedZoomID; //记录周边线号 std::map> m_mapClosedWires; // std::map m_mapClosedShape; //闭合的b样条线框集合 std::map> m_mapClosedBSplineCurves; // std::map m_mapSuccessGenFaces; //采用半边边界方法取封闭区域 //半边是否被使用 std::map m_mapHalfEdgesUsed; //线段被使用的次数 std::map m_mapIntersectinInfoTimeSearchs; //闭合线框边集合 std::map> m_ClosedResults; //原始边名称 std::map m_mapWireID2Name; //允许误差 double m_precision; //yc 20131031 //原始边的包围盒 std::map m_mapWireBox; //yc 201307424 //边界,搜索到的闭合线框的边不能都在边界中 std::vector border; // TopoDS_Face baseFace; //闭合线框结果集合 map> mapResultWires; private: //yc 20131031 //创建原始线框的包围盒 void CreateWireBox(); //判断两条边是否已经求交 bool haveInsect(std::vector>& haveInsects,int id1,int id2,bool autosave = true); //检查交点 void CalcInsectionSections(); //*********** flag ********************************* 交点约束 void CalcInsectionPoints(); //********************************************************** //获取线的端点 void GetWireStartEndPoint(const TopoDS_Wire& wire,gp_Pnt& sp,gp_Pnt& ep); //获取线的端点 void GetEdgeStartEndPoint(const TopoDS_Edge& edge,gp_Pnt& sp,gp_Pnt& ep); // bool GetWireIDbyIntersectionPointID(int InsectionPoint1,int InsectionPoint2,int& wireId); // bool GetWireIDbyIntersectionInfoID(int InsectionSectionInfoid,int& wireId); //获取线段上所有交点 void FindWirePoints(int iWireID,std::vector& ptids); //将线上交点进行排序 void SortByWire(int iWireID,std::vector& ptids); //将线上交点进行排序 void SortByWire(int iWireID,std::vector& pts); //获取线上点到线起始点的长度 Standard_Real GetPoint2StartByWire(const TopoDS_Edge& wire,const gp_Pnt& pt); //获取线段长度 Standard_Real GetEdgeLength(const TopoDS_Edge& aE ); // bool isOnPlan(vector vctBSplineCurves, gp_Pln& pln); //获取交点id bool haveInsectPoint(gp_Pnt pt,int& iBelongid); // bool GetNextPointCollect(int iMasterID,vector& slaveids); //iStep 取值从2-4 // bool GetClosedPoints(int iMasterID,int iStep); // bool IsExistClosedZoom(const vector& slaveids); //将vector转化为set std::set convertvct2set(const vector& slaveids); // bool IsIncludeClosedZoom(const vector& srcids,const vector& slaveids); //将id集合转化为字符串 std::string Set2String(const std::set& setids); //两点截取线段 bool TrimWireBy2Points(const gp_Pnt& pt1,const gp_Pnt& pt2,const TopoDS_Wire& srcwire,TopoDS_Edge& newwire,TopoDS_Edge& basicedge); //判断点是否在线上 bool IsPointOnEdge(const TopoDS_Edge& edge,const gp_Pnt& pt1); //判断点是否在线上 bool IsPointOnWire(const TopoDS_Wire& wire,const gp_Pnt& pt1); //两点截取线段 bool TrimEdgeBy2Points(const TopoDS_Edge& edge,const gp_Pnt& pt1,const gp_Pnt& pt2,TopoDS_Edge& newEdge); // bool GetInsectionSectionInfoId(int InsectionPoint1,int InsectionPoint2,int& InsectionSectionInfoId); //将topo转化为B样条曲线 Handle(Geom_BSplineCurve) GetBSplineCurve(const TopoDS_Shape& aS); //将topo转化为B样条曲线 Handle(Geom_BSplineCurve) ConvertEdge2BSplineCurve(const TopoDS_Edge& edge); //两点截取线段 Handle(Geom_BSplineCurve) TrimWire2BSplineCurve(const TopoDS_Edge& basicWire,const gp_Pnt& pt1,const gp_Pnt& pt2,Standard_Real& dF,Standard_Real& dL); //两点截取线段 Handle(Geom_BSplineCurve) TrimWire2BSplineCurve(const TopoDS_Edge& basicWire,const Standard_Real& dF,const Standard_Real& dL); //搜索闭合线框 bool GetClosedZooms(); // bool ModifyHalfEdgeUse(int ptid1,int ptid2); // int GetHalfEdgeUseStep(int ptid1,int ptid2); // void AddHalfEdgeUse(const std::vector& ids); // Handle(Geom_BSplineCurve) MergeSubBSpline(const vector& subarcids,int iWireid,Standard_Real& dF,Standard_Real& dL); // Handle(Geom_BSplineCurve) FindSrcBSpline(const vector& vctBSplineCurves,const vector& resultdatas, const vector>& wiresectids,int isectioninfoid,CResultData& data); //如果封闭区域中有存在外轮廓,则去掉 void ClearMaxEdgeBoundingBox(); //多边形拟合成4边行 bool GetPolygonBSplineSurfaceByMorethan4Sides(const vector& vctBSplineCurves,vector& newvctBSplineCurves); // void SortClosedSidesByClock(const vector& slaveids,vector& newvctBSplineCurves,vector& newvctResultDatas); // bool IsCloseBSplines( vector& vctBSplineCurves,vector& newvctResultDatas); // bool IsExsitNextEdge(const vector>& pairPoints,int iCurrentIndex); // 返回多边形面 TopoDS_Shell TopoDS_Shape GetPolygonBSplineSurfaceByMorethan4Sides(vector& vctCurve); // 拆分多边形成多个三角形 每个三角形生成一个TopoDS_Face void PolygonSplit(vector& vctCurve, vector &vctTopoFace); // 返回相邻边的连接点 gp_Pnt GetConnectionPoint(Handle(Geom_BSplineCurve)& curve1, Handle(Geom_BSplineCurve)& curve2); //返回相邻边的连接点 gp_Pnt GetConnectionPoint(TopoDS_Edge egde1, TopoDS_Edge edge2); // void TriangleEdge(vector& edgeSet); //通过判断角度 拟合多边形 void CheckPolygonBSpline(const vector& vctBSplineCurves,vector& newvctBSplineCurves); //通过判断端点角度和法向夹角,拟合多边形 void CheckPolygonBSpline1(const vector& vctBSplineCurves,vector& newvctBSplineCurves); // void CheckPolygonBSpline2(const vector& vctBSplineCurves,vector& newvctBSplineCurves); //通过判断边夹角,进行拟合 void MergeEdge(map>& edgeSet, map>& edgePoint, map& nextEdge, map& nextEdgeAngle, map& edgeDir); //拟合指定两条边 void Merge(int index, map>& edgeSet, map>& edgePoint, map& nextEdge, map& nextEdgeAngle, map& edgeDir); //获取夹角最大的边 int MaxAngleIndex( map& edgeAngle); //判断两条边是否平行 bool IsParallel(const TopoDS_Edge& e1, const TopoDS_Edge& e2); //边边求交点 double DistanceEE(TopoDS_Edge& e1, TopoDS_Edge& e2, gp_Pnt& p); //边边求交点 double SectionPoints( TopoDS_Edge& e1, TopoDS_Edge& e2, double tol, vector& pSet ); double SectionPoints( std::map::const_iterator& e1, std::map::const_iterator& e2, double tol, vector& pSet ); //20180101 added by czb,错误时输出边的序号 //计算相邻三点之间的夹角,如果夹角大于178度,则删除中间点 void ClearPoints(vector &pointSet,vector indexSet); // 拆分多边形 yc 20140804 start map> SplitPolygon(vector vctBSplineCurves); //拆分多边形,基于基面,获取拆分交线 map> SplitPolygon(vector edgeSet, TopoDS_Face baseFace); //生成面 TopoDS_Face MakeFace(vector edgeSet); //生成面 TopoDS_Face MakeFace(vector vctBSplineCurves); //通过判断边夹角,拆分多边形 map> SplitPolygonByAngle(vector edgeSet,vector pointSet, vector angleSet1, vector angleSet2, TopoDS_Face baseFace); //获取满足条件的夹角id int FindAngleIndex( vector angleSet1, vector angleSet2, double val1, double val2); //计算边夹角,返回端点夹角与临近点夹角的最大值 double ComputeAngle(TopoDS_Edge e1 ,TopoDS_Edge e2); //平面法向角度 double ComputeAngle3(TopoDS_Edge e1 ,TopoDS_Edge e2); //临近点角度 double ComputeAngle2(TopoDS_Edge e1 ,TopoDS_Edge e2); //端点角度 double ComputeAngle1(TopoDS_Edge e1 ,TopoDS_Edge e2); //获取夹角最大的点id int GetPointByAngle(int index, vector pointSet); //拟合面求交线 vector CreateNewEdge(int startId, int endId, vector pointSet, TopoDS_Face baseFace); //放样方式 求平均 vector CreateNewEdge(int startId, int endId, vector pointSet, vector edgeSet); public: // 通过差值重构边 yc 20140804 end TopoDS_Edge RebuildEdge(TopoDS_Edge edge, gp_Pnt p1, gp_Pnt p2, bool isReverse); //获取原始闭合线框,即未经拆分 map> GetOldResult(); // ADDED BY XUEFENG 20180731 // FOR CODES COMBINE // ADDED BY XUEFENG 2018.04 public: // typedef std::pair Point_Arc_Pair; std::vector< std::vector > SuccessfulGridVector; // 每次循环得到的封闭回路,可以有多个 std::vector SuccessfulGridWireNumVector; std::vector< std::vector > finalFoundGridFaceVector; // 最终得到的所有封闭回路的结果 // Grid NEW Algorithm std::map< int, int > m_mapArcIdOrigWiredId; // std::map std::map< int, std::map > m_mapFromPointStartToEndArc; // std::map< int pointId, , ... , > std::map< int, Point_Point_Pair > m_mapArc_point1_point2; // std::vector< arcId, ,...,> std::map< int, int > m_mapArc_CanBeUsedNum; void GridAlgorithm_Recursion(int firstPointId, int prePointId, int preArcId, int realStep, bool strictStep, std::vector existPointArcs); bool GridAlgorithm_FindExistOrNot(int newPoint, std::vector existPointsArcs); // 对比递归调用中新发现的点是否已经走过 std::vector GridAlgorithm_Copy_PointArc_Vector(std::vector existPointsArcs); bool GridAlgorithm_JudgeTheSameWire(int arcId1, int arcId2); bool GridAlgorithm_JudgeInTheSameWire(int arcId1, std::vector existPointArcs); void GridAlgorithm_ConstructGrid( ); void GridAlgorithm_DoPrepairData(); std::vector GridAlgorithm_FindSmallestAndNewOne(); // 每次循环找到wire边数最小的封闭回路 std::vector GridAlgorithm_FindSmallestArcAndNewOne();// 每次循环找到arc数最小的封闭回路 ADDED BY XUEFENG void GridAlgorithm_DoCleanAffairs(); void GridAlgorithm_DoRemoveArcActions(); // 移除已经确定不会再被用的边点 void GridAlgorithm_DoRemoveArcActionsOnlyArcs();// 仅仅移除绝对不会再被用的边 bool GridAlgorithm_CompareExistFinalVector(std::vector inputPA); // 对比新发现的封闭回路与已经存在的封闭回路是否相同 bool GridAlgorithm_FindOverlapWithFinalVector(std::vector inputPA);// ADDED BY XUEFENG 20190902 bool GridAlgorithm_BigVecIncludeSmallVec(std::vector existVector, std::vector newVector); std::vector GridAlgorithm_DoSortArcVector(std::vector inputPA); void GridAlgorithm_FinalVectorToResult(); // 将最后生成的封闭回路的数据转化为m_ClosedResults数据类型 bool GridAlgorithm_JudgeCurvesClosed(std::vector closeCurves); public: // XUEFENG ADDED 201805 初始化线数据,加约束曲线 void ExpInit(const std::vector& wires,const std::vector& seqNo, const std::vector& expSeqNo); private: // ADDED BY XUEFENG 201805 std::vector m_expWireSeqNo; //所有约束边集合 std::map m_mapAllExpWires; //约束边名称 std::map m_mapExpWireID2Name; // END ADDED // END ADDED };