static HashSet <int> GetEdgeCodeNearLine(List <PointF> pts, Dictionary <int, List <int> > es, List <PointF> line) { HashSet <int> edgeCodes = new HashSet <int>(); // 分割線と交差しているエッジ if (pts == null || es == null || line == null) { return(edgeCodes); } foreach (var ee in es) { foreach (int _j in ee.Value) { int i = ee.Key; int j = _j; if (i > j) { FMath.Swap(ref i, ref j); } if (FMath.IsCrossed(pts[i], pts[j], line)) { edgeCodes.Add(i * pts.Count + j); } } } return(edgeCodes); }
bool IsCrossed(PointF[] path) { if (path == null) { return(false); } bool crossed = false; if (path.Length >= 3) { PointF src0 = path[path.Length - 2]; PointF dst0 = path[path.Length - 1]; for (int i = 0; i <= path.Length - 4; i++) { PointF src1 = path[i]; PointF dst1 = path[i + 1]; if (FMath.IsCrossed(src0, dst0, src1, dst1)) { crossed = true; break; } } } return(crossed); }
static BoneAnnotation GetCrossingBoneWithPath(SkeletonAnnotation an, List <PointF> section) { if (an == null || an.bones == null) { return(null); } if (section == null) { return(null); } foreach (var b in an.bones) { PointF p0 = b.src.position; PointF p1 = b.dst.position; for (int i = 0; i < section.Count - 1; i++) { if (FMath.IsCrossed(p0, p1, section[i], section[i + 1])) { return(b); } } } return(null); }
public void IsCrossedTest() { PointF p1 = new PointF(-1, -1); PointF p2 = new PointF(1, 1); PointF p3 = new PointF(-1, -1); PointF p4 = new PointF(1, 1); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), false); p3 = new PointF(-1, -1); p4 = new PointF(0, 0); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), false); p3 = new PointF(0, 0); p4 = new PointF(1, 1); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), false); p3 = new PointF(-1, -1); p4 = new PointF(1, 0); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), true); p3 = new PointF(-1, 0); p4 = new PointF(1, 1); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), true); p3 = new PointF(0, 0); p4 = new PointF(1, -1); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), true); p3 = new PointF(-1, 1); p4 = new PointF(0, 0); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), true); p3 = new PointF(-1, 1); p4 = new PointF(1, -1); Assert.AreEqual(FMath.IsCrossed(p1, p2, p3, p4), true); }
// 接合面とボーンの交差判定 // ボーンのひとつの端点は内で逆の端点は外 static Dictionary <BoneAnnotation, CrossBoneSection> GetBoneSectionCrossDict(List <PointF> path, List <CharacterRange> sections, SkeletonAnnotation an) { var crossDict = new Dictionary <BoneAnnotation, CrossBoneSection>(); if (path == null || path.Count <= 0 || an == null || an.bones == null) { return(crossDict); } foreach (var section in sections) { var pts = new List <PointF>(); for (int i = section.First; i < section.First + section.Length; i++) { pts.Add(path[i % path.Count]); } foreach (var b in an.bones) { if (FMath.IsCrossed(b.src.position, b.dst.position, pts)) { bool srcIn = FMath.IsPointInPolygon(b.src.position, path); bool dstIn = FMath.IsPointInPolygon(b.dst.position, path); if (srcIn && !dstIn) { crossDict[b] = new CrossBoneSection(b, section, 1); } if (!srcIn && dstIn) { crossDict[b] = new CrossBoneSection(b, section, -1); } } } } return(crossDict); }
Bitmap ToBitmap(List <int> labels, int w, int h, List <PointF> partingLine, List <TriMesh> tris) { Brush[] colors = new[] { Brushes.Red, Brushes.Blue, Brushes.Green, Brushes.Yellow, Brushes.Black, Brushes.DarkRed, Brushes.DarkBlue, Brushes.DarkGreen, Brushes.Orange, Brushes.Gray, Brushes.LightBlue, }; Bitmap bmp = new Bitmap(w * 16, h * 16); using (Graphics g = Graphics.FromImage(bmp)) { foreach (var t in tris) { PointF pt0 = IdxToPoint(t.idx0, w, 10); PointF pt1 = IdxToPoint(t.idx1, w, 10); PointF pt2 = IdxToPoint(t.idx2, w, 10); if (FMath.IsCrossed(pt0, pt1, partingLine)) { g.DrawLine(new Pen(Brushes.Blue), pt0, pt1); } else { g.DrawLine(new Pen(Brushes.Black), pt0, pt1); } if (FMath.IsCrossed(pt1, pt2, partingLine)) { g.DrawLine(new Pen(Brushes.Blue), pt1, pt2); } else { g.DrawLine(new Pen(Brushes.Black), pt1, pt2); } if (FMath.IsCrossed(pt0, pt2, partingLine)) { g.DrawLine(new Pen(Brushes.Blue), pt0, pt2); } else { g.DrawLine(new Pen(Brushes.Black), pt0, pt2); } } for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { g.FillEllipse(colors[labels[x + y * w] % colors.Length], x * 10, y * 10, 3, 3); } } if (partingLine != null && partingLine.Count >= 2) { g.DrawLines(new Pen(Brushes.Black), partingLine.ToArray()); } } return(bmp); }