public PatchSkeletonJoint GetNearestJoint(PointF point, float threshold, Matrix transform) { PatchSkeletonJoint nearest = null; float minSqDist = threshold * threshold; foreach (var joint in joints) { PointF[] jointPt = new[] { joint.position }; transform.TransformPoints(jointPt); float dx = point.X - jointPt[0].X; float dy = point.Y - jointPt[0].Y; float sqDist = dx * dx + dy * dy; if (minSqDist > sqDist) { nearest = joint; minSqDist = sqDist; } } return(nearest); }
// 超簡易的なFK // 子ノードを親ノードと同じだけ平行移動させる public static void MoveJoint(PatchSkeleton skl, PatchSkeletonJoint joint, PointF to) { if (skl == null) { return; } if (joint == null) { return; } float dx = to.X - joint.position.X; float dy = to.Y - joint.position.Y; joint.position = to; HashSet <PatchSkeletonJoint> haschecked = new HashSet <PatchSkeletonJoint>(); haschecked.Add(joint); MoveJoint(skl, skl.bones.Where(b => b.src == joint).Select(b => b.dst).ToList(), dx, dy, haschecked); }
public static PatchSkeleton Load(string filepath, Bitmap refSkeletonBmp) { if (!File.Exists(filepath)) { return(null); } filepath = Path.GetFullPath(filepath); var an = new PatchSkeleton(); an.joints = File.ReadAllLines(filepath) .Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains(':')) .Select(line => { var tokens = line.Split(':'); if (tokens.Length != 2) { return(null); } var xys = tokens[1].Split(','); if (xys.Length != 2) { return(null); } float x, y; if (!float.TryParse(xys[0], out x) || !float.TryParse(xys[1], out y)) { return(null); } return(new PatchSkeletonJoint(tokens[0], new PointF(x, y))); }) .Where(j => j != null) .ToList(); an.bones = File.ReadAllLines(filepath) .Where(line => !string.IsNullOrWhiteSpace(line) && line.Contains('>')) .Select(line => { var tokens = line.Split('>'); if (tokens.Length != 2) { return(null); } PatchSkeletonJoint src = null, dst = null; foreach (var j in an.joints) { if (j.name == tokens[0]) { src = j; } if (j.name == tokens[1]) { dst = j; } } if (src == null || dst == null) { return(null); } return(new PatchSkeletonBone(src, dst)); }) .Where(b => b != null) .ToList(); return(an); }
public PatchSkeletonBone(PatchSkeletonJoint src, PatchSkeletonJoint dst) { this.src = src; this.dst = dst; }