public static void FindMeshBorder(List <Vector2> vertes, List <int> indices, out List <List <Vector2> > borderLst) { int count = indices.Count / 3; Dictionary <string, EdgeObject> mEdgeDict = new Dictionary <string, EdgeObject>(); for (int i = 0; i < count; ++i) { int st = i * 3; for (int j = st; j < (st + 3); ++j) { int next = j + 1; if (next == (st + 3)) { next = st; } Vector2i edge = Vector2i.GetVector2i(indices[j], indices[next]); string str1 = edge.GetString(); if (!mEdgeDict.ContainsKey(str1)) { mEdgeDict.Add(str1, new EdgeObject(edge)); } else { mEdgeDict[str1].CountPlus(); } } } List <EdgeObject> oneList = mEdgeDict.Values.ToList().FindAll(t => { return(t.mCount == 1); }); GroupClosest <EdgeObject> group = new GroupClosest <EdgeObject>(oneList); List <List <EdgeObject> > results = group.Group(); borderLst = new List <List <Vector2> >(); foreach (List <EdgeObject> res in results) { List <Vector2> tmp = new List <Vector2>(); EdgeObject obj0 = res[0]; int first = obj0.mEdge[0]; int last = obj0.mEdge[1]; tmp.Add(vertes[first]); tmp.Add(vertes[last]); res.RemoveAt(0); while (res.Count > 0) { int index1 = res.FindIndex(o => { return(o.Include(last)); }); if (index1 == -1) { tmp.Clear(); break; } EdgeObject obj = res[index1]; int index = obj.IndexOf(last); index = 1 - index; last = obj.mEdge[index]; tmp.Add(vertes[last]); res.RemoveAt(index1); } if (tmp.Count > 2) { tmp.RemoveAt(tmp.Count - 1); borderLst.Add(tmp); } } }
public EdgeObject(int i, int j) { mEdge = Vector2i.GetVector2i(i, j); mCount = 1; }
public void SharedFace(int f1, int f2) { mSharedTriangles = Vector2i.GetVector2i(f1, f2); }
public static List <Vector2i> Scan(List <Vector2i> poly) { List <Vector2i> results = new List <Vector2i>(); Vector2i max = new Vector2i(int.MinValue, int.MinValue); Vector2i min = new Vector2i(int.MaxValue, int.MaxValue); foreach (Vector2i v in poly) { max = Vector2i.Max(v, max); min = Vector2i.Min(v, min); } List <Vector2i> trans = poly.Select(t => { return(t - min); }).ToList(); int height = max[1] - min[1]; List <ScanEdge> scanLines = new List <ScanEdge>(); int count = trans.Count; int count1 = count - 1; for (int i = 0; i < count; ++i) { Vector2i ps = trans[i]; int post = (i + 1) % count; Vector2i pe = trans[post]; if (ps[1] == pe[1]) // 水平 去掉 { Vector2i hori = Vector2i.GetVector2i(ps[0], pe[0]); for (int hi = hori[0]; hi <= hori[1]; ++hi) { results.Add(new Vector2i(hi, ps[1])); } continue; } int pre = (i + count1) % count; Vector2i pss = trans[pre]; int ppost = (post + 1) % count; Vector2i pee = trans[ppost]; double dx = (ps[0] - pe[0]) * 1.0f / (ps[1] - pe[1]); bool yiG0 = ps[1] < pe[1]; double startX = yiG0 ? ps[0] : pe[0]; int ymin = yiG0 ? ps[1] : pe[1]; int ymax = yiG0 ? pe[1] : ps[1]; if (pe[1] > ps[1]) { if (pee[1] >= pe[1]) { ymax -= 1; } } else { if (pss[1] >= ps[1]) { ymax -= 1; } } ScanEdge ep = new ScanEdge(); ep.mMinY = ymin; ep.mMaxY = ymax; ep.mStartX = startX; ep.mDx = dx; scanLines.Add(ep); } for (int i = 0; i < height; ++i) { List <ScanEdge> tmp = scanLines.FindAll(delegate(ScanEdge line) { return(line.Include(i)); }); tmp.Sort((e1, e2) => { //此处可以不考虑 斜率。 x相等时,不用考虑谁在前谁在后 return(e1.mStartX.CompareTo(e2.mStartX)); }); if (tmp.Count % 2 != 0) { throw new Exception("必须是偶数"); } for (int idx = 0; idx < tmp.Count; idx += 2) { int next = idx + 1; int x1 = (int)tmp[idx].mStartX; int x2 = (int)tmp[next].mStartX; if (x1 > x2) { continue; } for (int xi = x1; xi <= x2; ++xi) { results.Add(new Vector2i(xi, i)); } tmp[idx].Increase(); tmp[next].Increase(); } scanLines.RemoveAll((t) => t.mMaxY == i); } results = results.Select(t => { return(t + min); }).ToList(); return(results); }
public SharedEdge(int index, int i, int j, int other) { mEdgeVertexIndex = Vector2i.GetVector2i(i, j); mFaceIndex = index; mOtherVertex = other; }