public List <CadFigure> FilterRootFigure(List <CadFigure> srcList) { HashSet <CadFigure> set = new HashSet <CadFigure>(); foreach (CadFigure fig in srcList) { set.Add(FigUtil.GetRootFig(fig)); } List <CadFigure> ret = new List <CadFigure>(); ret.AddRange(set); return(ret); }
// option: // e.g. // a100q30 max area = 100, min degree = 30 // a100q max area = 100, min degree = default (20) // min degree < 34 // Other options see // https://www.cs.cmu.edu/~quake/triangle.switch.html // public void Triangulate(uint figID, string option) { CadFigure tfig = Controller.DB.GetFigure(figID); if (tfig == null || tfig.Type != Types.POLY_LINES) { return; } if (tfig.PointCount < 3) { return; } CadFigure cfig = FigUtil.Clone(tfig); Vector3d org = cfig.PointList[0].vector; Vector3d dir = Vector3d.UnitZ; Vector3d faceNormal = CadUtil.TypicalNormal(cfig.PointList); Vector3d rotateV = default; double t = 0; if (!faceNormal.EqualsThreshold(dir) && !(-faceNormal).EqualsThreshold(dir)) { rotateV = CadMath.Normal(faceNormal, dir); t = -CadMath.AngleOfVector(faceNormal, dir); CadUtil.RotateFigure(cfig, org, rotateV, t); } //Controller.CurrentLayer.AddFigure(cfig); VertexList vl = cfig.GetPoints(12); CadMesh m = IglW.Triangulate(vl, option); HeModel hem = HeModelConverter.ToHeModel(m); CadFigureMesh fig = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH); fig.SetMesh(hem); for (int i = 0; i < fig.PointCount; i++) { CadVertex v = fig.PointList[i]; v.Z = org.Z; fig.PointList[i] = v; } if (t != 0) { CadUtil.RotateFigure(fig, org, rotateV, -t); } CadOpeList root = new CadOpeList(); CadOpe ope; ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig.ID); Session.AddOpe(ope); Controller.CurrentLayer.AddFigure(fig); ope = new CadOpeRemoveFigure(Controller.CurrentLayer, figID); Session.AddOpe(ope); Controller.CurrentLayer.RemoveFigureByID(figID); Controller.CurrentFigure = null; Session.PostRemakeObjectTree(); }