public void AdjustPositionTest() { var pts00 = Util.circlePoints(100, 100, 50, 20); var pts11 = Util.circlePoints(200, 200, 50, 20); SkeletonAnnotation an = new SkeletonAnnotation(null); an.joints.Add(new JointAnnotation("00", new PointF(100, 100))); an.joints.Add(new JointAnnotation("10", new PointF(200, 100))); an.bones.Clear(); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[1])); var ms = new List <SegmentMeshInfo>(); ms.Add(new SegmentMeshInfo(pts00, null, pts00.Skip(-2).Take(5).ToList(), an, false)); ms.Add(new SegmentMeshInfo(pts11, null, pts11.Skip(8).Take(5).ToList(), an, false)); var pairs = new List <SegmentConnector.ConnectPair>(); pairs.Add(new SegmentConnector.ConnectPair(an.bones[0], ms[0], new CharacterRange(-2, 5), ms[1], new CharacterRange(8, 5))); SegmentConnector_Accessor.AdjustPosition(new List <SegmentMeshInfo>(), an, pairs); var path = ms[1].GetPath(); Assert.AreEqual(path.Average(pt => pt.X), 200, 5); Assert.AreEqual(path.Average(pt => pt.Y), 100, 5); }
public void UpdateSkeletalControlPointsTest() { Segment seg = new Segment("seg", null); SkeletonAnnotation segmentAnnotaiton = new SkeletonAnnotation(null); segmentAnnotaiton.joints.Add(new JointAnnotation("0", new PointF(0, 0))); segmentAnnotaiton.joints.Add(new JointAnnotation("1", new PointF(100, 100))); segmentAnnotaiton.joints.Add(new JointAnnotation("2", new PointF(-500, -50))); segmentAnnotaiton.bones.Add(new BoneAnnotation(segmentAnnotaiton.joints[0], segmentAnnotaiton.joints[1])); segmentAnnotaiton.bones.Add(new BoneAnnotation(segmentAnnotaiton.joints[1], segmentAnnotaiton.joints[2])); seg.an = segmentAnnotaiton; SegmentMeshInfo target = new SegmentMeshInfo(seg, true); SkeletonAnnotation refAnnotation = new SkeletonAnnotation(null); refAnnotation.joints.Add(new JointAnnotation("0", new PointF(0, 0))); refAnnotation.joints.Add(new JointAnnotation("1", new PointF(100, 0))); refAnnotation.joints.Add(new JointAnnotation("2", new PointF(0, 50))); refAnnotation.bones.Add(new BoneAnnotation(refAnnotation.joints[0], refAnnotation.joints[1])); refAnnotation.bones.Add(new BoneAnnotation(refAnnotation.joints[1], refAnnotation.joints[2])); refAnnotation.bones.Add(new BoneAnnotation(refAnnotation.joints[0], refAnnotation.joints[2])); target.UpdateSkeletalControlPoints(refAnnotation); }
public void AdjustScaleTest() { List <SegmentMeshInfo> ms = new List <SegmentMeshInfo>(); var path1 = Util.circlePoints(100, 100, 40, 20); var path2 = Util.circlePoints(200, 200, 30, 20); var r1 = new CharacterRange(0, 5); var r2 = new CharacterRange(10, 5); var section1 = path1.Skip(r1.First).Take(r1.Length).ToList(); var section2 = path2.Skip(r2.First).Take(r2.Length).ToList(); var curves1 = SegmentConnector_Accessor.SectionToCurves(path1, r1, 5, 30); var curves2 = SegmentConnector_Accessor.SectionToCurves(path2, r2, 5, 30); var an = new SkeletonAnnotation(null); an.joints.Add(new JointAnnotation("0", new PointF(100, 100))); an.joints.Add(new JointAnnotation("1", new PointF(200, 200))); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[1])); ms.Add(new SegmentMeshInfo(path1, null, section1, an, false)); ms.Add(new SegmentMeshInfo(path2, null, section2, an, false)); var pairs = new List <SegmentConnector.ConnectPair>(); pairs.Add(new SegmentConnector.ConnectPair(an.bones[0], ms[0], r1, ms[1], r2)); var w1 = SegmentConnector_Accessor.GetSectionWidth(ms[0].GetPath(), curves1, an.bones[0]); var w2 = SegmentConnector_Accessor.GetSectionWidth(ms[1].GetPath(), curves2, an.bones[0]); Assert.AreNotEqual(w1, w2, 1e-4); SegmentConnector_Accessor.AdjustScale(ms, an, pairs); w1 = SegmentConnector_Accessor.GetSectionWidth(ms[0].GetPath(), curves1, an.bones[0]); w2 = SegmentConnector_Accessor.GetSectionWidth(ms[1].GetPath(), curves2, an.bones[0]); Assert.AreEqual(w1, w2, 1e-4); }
public void SkeletonAnnotationConstructorTest() { SkeletonAnnotation an = null; // TODO: 適切な値に初期化してください bool copyBmp = false; // TODO: 適切な値に初期化してください SkeletonAnnotation target = new SkeletonAnnotation(an, true); target = new SkeletonAnnotation(an, false); }
// //テストを作成するときに、次の追加属性を使用することができます: // //クラスの最初のテストを実行する前にコードを実行するには、ClassInitialize を使用 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //クラスのすべてのテストを実行した後にコードを実行するには、ClassCleanup を使用 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //各テストを実行する前にコードを実行するには、TestInitialize を使用 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //各テストを実行した後にコードを実行するには、TestCleanup を使用 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///SkeletonFitting のテスト ///</summary> // [TestMethod()] public void FittingTest() { // セグメント SegmentMeshInfo target; SkeletonAnnotation an = new SkeletonAnnotation(null); an.joints = new List <JointAnnotation>() { new JointAnnotation("0", new PointF(10, 10)), new JointAnnotation("1", new PointF(110, 110)), }; an.bones = new List <BoneAnnotation>() { new BoneAnnotation(an.joints[0], an.joints[1]) }; List <PointF> path = Util.circlePoints(0, 0, 1, 20); for (int i = 0; i < path.Count; i++) { path[i] = new PointF(path[i].X * 100, path[i].Y * 50); } target = null;// new SegmentMeshInfo(); target.MoveTo(100, 200); target.Scale(1.2f, 1.2f); target.Rotate(30); // フィットさせたいスケルトン SkeletonAnnotation refAnnotation = new SkeletonAnnotation(null); refAnnotation.joints.Add(new JointAnnotation("0", new System.Drawing.PointF(80, 50))); refAnnotation.joints.Add(new JointAnnotation("1", new System.Drawing.PointF(30, 50))); refAnnotation.bones.Add(new BoneAnnotation(refAnnotation.joints[0], refAnnotation.joints[1])); SkeletonFitting.Fitting(target, refAnnotation); Assert.AreEqual(target.position.X, 0, 1e-4); Assert.AreEqual(target.position.Y, 0, 1e-4); Assert.AreEqual(target.scale.X, 1.2, 1e-4); Assert.AreEqual(target.scale.Y, 1.2, 1e-4); Assert.AreEqual(target.angle, 0, 1e-4); CheckList(target.an.joints.Select(j => j.position).ToList(), new List <PointF>() { new PointF(80, 50), new PointF(30, 50) }, 1e-4); }
public void GetCrossingBoneWithPathTest() { SkeletonAnnotation an = new SkeletonAnnotation(null); an.joints.Add(new JointAnnotation("0", new PointF(0, 0))); an.joints.Add(new JointAnnotation("1", new PointF(100, 0))); an.joints.Add(new JointAnnotation("2", new PointF(0, 50))); an.joints.Add(new JointAnnotation("3", new PointF(0, 100))); an.joints.Add(new JointAnnotation("4", new PointF(50, 150))); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[1])); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[2])); an.bones.Add(new BoneAnnotation(an.joints[3], an.joints[4])); Assert.AreEqual(SegmentMeshInfo_Accessor.GetCrossingBoneWithPath(an, null), null); Assert.AreEqual(SegmentMeshInfo_Accessor.GetCrossingBoneWithPath(an, new List <PointF>()), null); List <PointF> path = new List <PointF>() { new PointF(0, -50), new PointF(50, -50) }; Assert.AreEqual(SegmentMeshInfo_Accessor.GetCrossingBoneWithPath(an, path), null); path = new List <PointF>() { new PointF(50, -50), new PointF(50, 50) }; Assert.AreEqual(SegmentMeshInfo_Accessor.GetCrossingBoneWithPath(an, path), an.bones[0]); // 複数ボーンと交差してたら最初に見つかったものを返す path = new List <PointF>() { new PointF(50, -50), new PointF(-50, 50) }; Assert.AreEqual(SegmentMeshInfo_Accessor.GetCrossingBoneWithPath(an, path), an.bones[0]); path = new List <PointF>() { new PointF(50, 100), new PointF(50, 150), new PointF(0, 150) }; Assert.AreEqual(SegmentMeshInfo_Accessor.GetCrossingBoneWithPath(an, path), an.bones[2]); }
public void GetSkeletalTransformsTest() { SkeletonAnnotation orgAn = new SkeletonAnnotation(null); orgAn.joints.Add(new JointAnnotation("0", new PointF(0, 0))); orgAn.joints.Add(new JointAnnotation("1", new PointF(100, 100))); orgAn.joints.Add(new JointAnnotation("2", new PointF(-500, -50))); orgAn.bones.Add(new BoneAnnotation(orgAn.joints[0], orgAn.joints[1])); orgAn.bones.Add(new BoneAnnotation(orgAn.joints[1], orgAn.joints[2])); SkeletonAnnotation an = new SkeletonAnnotation(null); an.joints.Add(new JointAnnotation("0", new PointF(0, 0))); an.joints.Add(new JointAnnotation("1", new PointF(100, 0))); an.joints.Add(new JointAnnotation("2", new PointF(0, 50))); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[1])); an.bones.Add(new BoneAnnotation(an.joints[1], an.joints[2])); var dict = SegmentMeshInfo_Accessor.GetSkeletalTransforms(an, orgAn); Assert.AreEqual(dict.Count, 2); Assert.IsTrue(dict.ContainsKey(an.bones[0])); Assert.IsTrue(dict.ContainsKey(an.bones[1])); var pts = new[] { orgAn.joints[0].position, orgAn.joints[1].position }; dict[an.bones[0]].TransformPoints(pts); Assert.AreEqual(pts[0].X, 0, 1e-4); Assert.AreEqual(pts[0].Y, 0, 1e-4); Assert.AreEqual(pts[1].X, 100, 1e-4); Assert.AreEqual(pts[1].Y, 0, 1e-4); pts = new[] { orgAn.joints[1].position, orgAn.joints[2].position }; dict[an.bones[1]].TransformPoints(pts); Assert.AreEqual(pts[0].X, 100, 1e-4); Assert.AreEqual(pts[0].Y, 0, 1e-4); Assert.AreEqual(pts[1].X, 0, 1e-4); Assert.AreEqual(pts[1].Y, 50, 1e-4); }
public void InitializeControlPointsTest() { SegmentMeshInfo_Accessor.InitializeControlPoints(null, null, 0, null, null); ARAPDeformation arap = new ARAPDeformation(new List <PointF>() { new PointF(-10, -10), new PointF(10, -10), new PointF(-10, 10), new PointF(10, 10), }, new List <PointF>()); SkeletonAnnotation an = new SkeletonAnnotation(null); an.joints.Add(new JointAnnotation("0", new PointF(0, 0))); an.joints.Add(new JointAnnotation("1", new PointF(100, 0))); an.joints.Add(new JointAnnotation("2", new PointF(0, 50))); an.joints.Add(new JointAnnotation("3", new PointF(0, 100))); an.joints.Add(new JointAnnotation("4", new PointF(99, 100))); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[1])); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[2])); an.bones.Add(new BoneAnnotation(an.joints[3], an.joints[4])); Dictionary <BoneAnnotation, List <PointF> > boneToControl = new Dictionary <BoneAnnotation, List <PointF> >(); SegmentMeshInfo_Accessor.InitializeControlPoints(arap, an, 50, null, boneToControl); Assert.AreEqual(arap.controlPoints.Count, 6); Assert.AreEqual(boneToControl.Sum(kv => kv.Value.Count), 7); Assert.AreEqual(arap.controlPoints[0].X, 0); Assert.AreEqual(arap.controlPoints[1].X, 50, 1e-4); Assert.AreEqual(arap.controlPoints[2].X, 100); Assert.AreEqual(arap.controlPoints[3].X, 0); Assert.AreEqual(arap.controlPoints[3].Y, 50); Assert.AreEqual(arap.controlPoints[4].X, 0); Assert.AreEqual(arap.controlPoints[5].X, 99); }
public void GetSectionPairsTest() { var pairs = SegmentConnector_Accessor.GetSectionPairs(null, null); Assert.IsNull(pairs); pairs = SegmentConnector_Accessor.GetSectionPairs(null, new SkeletonAnnotation(null)); Assert.IsNull(pairs); pairs = SegmentConnector_Accessor.GetSectionPairs(new List <SegmentMeshInfo>(), null); Assert.IsNull(pairs); SkeletonAnnotation an = new SkeletonAnnotation(null); an.joints.Add(new JointAnnotation("0", new PointF(100, 100))); an.joints.Add(new JointAnnotation("1", new PointF(200, 200))); an.joints.Add(new JointAnnotation("2", new PointF(300, 100))); an.bones.Add(new BoneAnnotation(an.joints[0], an.joints[1])); an.bones.Add(new BoneAnnotation(an.joints[1], an.joints[2])); var _seg1 = new Segment("seg1", null); _seg1.path = Util.circlePoints(100, 100, 30, 20); _seg1.section = _seg1.path.Take(5).ToList(); _seg1.an = new SkeletonAnnotation(null); _seg1.an.joints.Add(new JointAnnotation("0", new PointF(100, 100))); _seg1.an.joints.Add(new JointAnnotation("1", new PointF(200, 200))); _seg1.an.bones.Add(new BoneAnnotation(_seg1.an.joints[0], _seg1.an.joints[1])); var _seg2 = new Segment("seg2", null); _seg2.path = Util.circlePoints(200, 200, 60, 20); _seg2.section = _seg2.path.Skip(10).Take(4).Concat(_seg2.path.Skip(15).Take(4)).ToList(); _seg2.an = new SkeletonAnnotation(null); _seg2.an.joints.Add(new JointAnnotation("0", new PointF(100, 100))); _seg2.an.joints.Add(new JointAnnotation("1", new PointF(200, 200))); _seg2.an.joints.Add(new JointAnnotation("2", new PointF(300, 100))); _seg2.an.bones.Add(new BoneAnnotation(_seg2.an.joints[0], _seg2.an.joints[1])); _seg2.an.bones.Add(new BoneAnnotation(_seg2.an.joints[1], _seg2.an.joints[2])); var _seg3 = new Segment("seg3", null); _seg3.path = Util.circlePoints(300, 150, 90, 20); _seg3.section = _seg3.path.Skip(5).Take(5).ToList(); _seg3.an = new SkeletonAnnotation(null); _seg3.an.joints.Add(new JointAnnotation("1", new PointF(200, 200))); _seg3.an.joints.Add(new JointAnnotation("2", new PointF(300, 100))); _seg3.an.bones.Add(new BoneAnnotation(_seg3.an.joints[0], _seg3.an.joints[1])); var seg1 = new SegmentMeshInfo(_seg1, false); var seg2 = new SegmentMeshInfo(_seg2, false); var seg3 = new SegmentMeshInfo(_seg3, false); var _pairs = SegmentConnector_Accessor.GetSectionPairs(new List <SegmentMeshInfo>() { seg1, seg2, seg3 }, an); Assert.AreEqual(_pairs.Count, 2); Assert.AreEqual(_pairs[0].bone, an.bones[0]); Assert.AreEqual(_pairs[0].meshInfo1, seg1); Assert.AreEqual(_pairs[0].meshInfo2, seg2); Assert.AreEqual(_pairs[1].bone, an.bones[1]); Assert.AreEqual(_pairs[1].meshInfo1, seg2); Assert.AreEqual(_pairs[1].meshInfo2, seg3); }
public void ExpandSegmentsTest() { List <SegmentMeshInfo> meshes = new List <SegmentMeshInfo>(); var p1 = Util.circlePoints(50, 100, 40, 20); var r1 = new CharacterRange(0, 6); var _s = p1.Skip(r1.First).Take(r1.Length).ToList(); SkeletonAnnotation an = new SkeletonAnnotation(null) { bones = new List <BoneAnnotation>() { GetBone(new PointF(50, 100), new PointF(150, 200)) } }; meshes.Add(new SegmentMeshInfo(p1, null, _s, an, false)); var p2 = Util.circlePoints(150, 200, 40, 20); var r2 = new CharacterRange(10, 6); var _s2 = p2.Skip(r2.First).Take(r2.Length).ToList(); meshes.Add(new SegmentMeshInfo(p2, null, _s2, an, false)); List <SegmentConnector.ConnectPair> pairs = new List <SegmentConnector.ConnectPair>() { new SegmentConnector.ConnectPair(an.bones.First(), meshes[0], r1, meshes[1], r2) }; int cnt = 0; foreach (var m in meshes) { var path = m.GetPath(); foreach (var p in path) { m.arap.AddControlPoint(p, p); } m.arap.BeginDeformation(); m.arap.ToBitmap().Save("../../../Test2/mesh" + cnt + "_before.png"); cnt++; } // ちゃんと領域がかぶっているか SegmentConnector_Accessor.ExpandSegments(meshes, an, pairs); cnt = 0; foreach (var m in meshes) { m.arap.EndDeformation(); m.arap.ToBitmap().Save("../../../Test2/mesh" + cnt + "_after.png"); cnt++; } var path1 = meshes[0].GetPath(); var path2 = meshes[1].GetPath(); Assert.AreEqual(path1[0].X, path2[16].X, 0.1); Assert.AreEqual(path1[19].X, path2[15].X, 0.1); Assert.AreEqual(path1[0].Y, path2[16].Y, 0.1); Assert.AreEqual(path1[19].Y, path2[15].Y, 0.1); Assert.AreEqual(path1[5].X, path2[9].X, 0.1); Assert.AreEqual(path1[6].X, path2[10].X, 0.1); Assert.AreEqual(path1[5].Y, path2[9].Y, 0.1); Assert.AreEqual(path1[6].Y, path2[10].Y, 0.1); // 接合面もきちんと動いているか PointF x, y; SegmentConnector_Accessor.GetCoordinateFromBone(an.bones[0], out x, out y); foreach (var m in meshes) { var path = m.GetPath(); foreach (var r in m.sections) { float _x0 = path[r.First].X - an.bones[0].src.position.X; float _y0 = path[r.First].Y - an.bones[0].src.position.Y; float xx0 = _x0 * x.X + _y0 * x.Y; float yy0 = _x0 * y.X + _y0 * y.Y; float _x1 = path[r.First + r.Length - 1].X - an.bones[0].src.position.X; float _y1 = path[r.First + r.Length - 1].Y - an.bones[0].src.position.Y; float xx1 = _x1 * x.X + _y1 * x.Y; float yy1 = _x1 * y.X + _y1 * y.Y; if (yy0 > yy1) { FLib.FMath.Swap(ref yy0, ref yy1); } var s = path.Skip(r.First + 1).Take(r.Length - 2).ToList(); foreach (var p in s) { float _x = p.X - an.bones[0].src.position.X; float _y = p.Y - an.bones[0].src.position.Y; float xx = _x * x.X + _y * x.Y; float yy = _x * y.X + _y * y.Y; if (m == meshes[0]) { Assert.IsTrue(xx > xx0); Assert.IsTrue(xx > xx1); } else { Assert.IsTrue(xx < xx0); Assert.IsTrue(xx < xx1); } Assert.IsTrue(yy0 < yy); Assert.IsTrue(yy < yy1); } } } }