コード例 #1
0
 static void CreateBoneJointIfNeed(
     InsideEdgeLine insideEdge,
     GlyphTriangle first_p_tri,
     GlyphBoneJoint firstJoint,
     List <GlyphBone> newlyCreatedBones,
     List <GlyphBone> glyphBones)
 {
     if (insideEdge != null &&
         insideEdge.inside_joint == null)
     {
         InsideEdgeLine mainEdge = insideEdge;
         EdgeLine       nbEdge   = null;
         if (FindSameCoordEdgeLine(first_p_tri.N0, mainEdge, out nbEdge) ||
             FindSameCoordEdgeLine(first_p_tri.N1, mainEdge, out nbEdge) ||
             FindSameCoordEdgeLine(first_p_tri.N2, mainEdge, out nbEdge))
         {
             //confirm that nbEdge is INSIDE edge
             if (nbEdge.IsInside)
             {
                 GlyphBoneJoint joint = new GlyphBoneJoint((InsideEdgeLine)nbEdge, mainEdge);
                 GlyphBone      bone  = new GlyphBone(mainEdge.inside_joint, firstJoint);
                 newlyCreatedBones.Add(bone);
                 glyphBones.Add(bone);
             }
             else
             {
                 //?
             }
         }
         else
         {
             //?
         }
     }
 }
コード例 #2
0
        public GlyphBone(GlyphBoneJoint a, EdgeLine tipEdge)
        {
            JointA  = a;
            TipEdge = tipEdge;
            Vector2 midPoint = tipEdge.GetMidPoint();

            _len = Math.Sqrt(a.CalculateSqrDistance(midPoint));
            EvaluateSlope();
        }
コード例 #3
0
 public void CreateBoneLinkBetweenCentroidLine(List <GlyphBone> newlyCreatedBones)
 {
     foreach (CentroidLine line in _lines.Values)
     {
         List <GlyphBone> glyphBones  = line.bones;
         GlyphBoneJoint   firstJoint  = line._joints[0];
         GlyphTriangle    first_p_tri = firstJoint.P_Tri;
         //
         CreateBoneJointIfNeed(first_p_tri.e0 as InsideEdgeLine, first_p_tri, firstJoint, newlyCreatedBones, glyphBones);
         CreateBoneJointIfNeed(first_p_tri.e1 as InsideEdgeLine, first_p_tri, firstJoint, newlyCreatedBones, glyphBones);
         CreateBoneJointIfNeed(first_p_tri.e2 as InsideEdgeLine, first_p_tri, firstJoint, newlyCreatedBones, glyphBones);
     }
 }
コード例 #4
0
 static void CreateTipBoneIfNeed(
     InsideEdgeLine insideEdge, GlyphBoneJoint joint,
     List <GlyphBone> newlyCreatedBones, List <GlyphBone> glyphBones)
 {
     if (insideEdge != null &&
         insideEdge.inside_joint != null &&
         insideEdge.inside_joint != joint)
     {
         //create connection
         GlyphBone tipBone = new GlyphBone(insideEdge.inside_joint, joint);
         newlyCreatedBones.Add(tipBone);
         glyphBones.Add(tipBone);
     }
 }
コード例 #5
0
 /// <summary>
 /// find nearest joint that contains tri
 /// </summary>
 /// <param name="tri"></param>
 /// <returns></returns>
 public GlyphBoneJoint FindNearestJoint(GlyphTriangle tri)
 {
     for (int i = _joints.Count - 1; i >= 0; --i)
     {
         GlyphBoneJoint joint = _joints[i];
         //each pair has 1 bone joint
         //once we have 1 candidate
         if (joint.ComposeOf(tri))
         {
             //found another joint
             return(joint);
         }
     }
     return(null);
 }
コード例 #6
0
 static GlyphTriangle FindCommonTriangle(GlyphBoneJoint a, GlyphBoneJoint b)
 {
     if (a.P_Tri == b.P_Tri || a.P_Tri == b.Q_Tri)
     {
         return(a.P_Tri);
     }
     else if (a.Q_Tri == b.P_Tri || a.Q_Tri == b.Q_Tri)
     {
         return(a.Q_Tri);
     }
     else
     {
         return(null);
     }
 }
コード例 #7
0
        public GlyphBone(GlyphBoneJoint a, GlyphBoneJoint b)
        {
#if DEBUG
            if (a == b)
            {
                throw new NotSupportedException();
            }
#endif

            JointA = a;
            JointB = b;
            Vector2 bpos = b.OriginalJointPos;
            _len = Math.Sqrt(a.CalculateSqrDistance(bpos));
            EvaluateSlope();
        }
コード例 #8
0
 public bool FindBoneJoint(GlyphTriangle tri,
                           out CentroidLine foundOnBranch,
                           out GlyphBoneJoint foundOnJoint)
 {
     foreach (CentroidLine line in _lines.Values)
     {
         if ((foundOnJoint = line.FindNearestJoint(tri)) != null)
         {
             foundOnBranch = line;
             return(true);
         }
     }
     foundOnBranch = null;
     foundOnJoint  = null;
     return(false);
 }
コード例 #9
0
        /// <summary>
        /// add information about edges to each triangle and create BoneJoint and Tip
        /// </summary>
        public GlyphBoneJoint AnalyzeEdgesAndCreateBoneJoint()
        {
#if DEBUG
            if (p == q)
            {
                throw new NotSupportedException();
            }
#endif

            //2 contact triangles share GlyphBoneJoint.
            //--------------------------------------
            //[C]
            //Find relation between edges of 2 triangle p and q
            //....
            //pick up a edge of p and compare to all edge of q
            //do until complete
            GlyphBoneJoint boneJoint = null;
            InsideEdgeLine p_edge, q_edge;
            if (FindCommonInsideEdges(p, q, out p_edge, out q_edge))
            {
                //create joint
                boneJoint = new GlyphBoneJoint(p_edge, q_edge);
                double slopeAngle = CalculateCentroidPairSlopeNoDirection(this);
                //
                EdgeLine foundTipEdge = null;
                if ((foundTipEdge = CreateTipEdgeIfNeed(slopeAngle, p, p_edge)) != null)
                {
                    //P
                    boneJoint.SetTipEdge_P(foundTipEdge);
                }
                if ((foundTipEdge = CreateTipEdgeIfNeed(slopeAngle, q, q_edge)) != null)
                {
                    //Q
                    boneJoint.SetTipEdge_Q(foundTipEdge);
                }
            }
            return(boneJoint);
        }
コード例 #10
0
 public void SetHeadConnnection(CentroidLine anotherCentroidLine, GlyphBoneJoint foundOnJoint)
 {
     this.anotherCentroidLine = anotherCentroidLine;
     this.foundOnJoint        = foundOnJoint;
 }
コード例 #11
0
        /// <summary>
        /// create a set of GlyphBone
        /// </summary>
        /// <param name="newlyCreatedBones"></param>
        public void CreateBones(List <GlyphBone> newlyCreatedBones)
        {
            foreach (CentroidLine line in _lines.Values)
            {
                List <GlyphBoneJoint> jointlist = line._joints;
                //start with empty bone list
                List <GlyphBone> glyphBones = line.bones;
                int j = jointlist.Count;

                if (j == 0)
                {
                    continue;
                }
                //
                GlyphBoneJoint joint = jointlist[0]; //first
                {
                    GlyphTriangle firstTri = joint.P_Tri;
                    //test 3 edges, find edge that is inside
                    //and the joint is not the same as first_pair.BoneJoint
                    CreateTipBoneIfNeed(firstTri.e0 as InsideEdgeLine, joint, newlyCreatedBones, glyphBones);
                    CreateTipBoneIfNeed(firstTri.e1 as InsideEdgeLine, joint, newlyCreatedBones, glyphBones);
                    CreateTipBoneIfNeed(firstTri.e2 as InsideEdgeLine, joint, newlyCreatedBones, glyphBones);
                }

                for (int i = 0; i < j; ++i)
                {
                    //for each GlyphCentroidPair
                    //create bone that link the GlyphBoneJoint of the pair
                    joint = jointlist[i];
                    //if (joint.dbugId > 20)
                    //{
                    //}
                    if (joint.TipEdgeP != null)
                    {
                        GlyphBone tipBone = new GlyphBone(joint, joint.TipEdgeP);
                        newlyCreatedBones.Add(tipBone);
                        glyphBones.Add(tipBone);
                    }
                    //-----------------------------------------------------
                    if (i < j - 1)
                    {
                        //not the last one
                        GlyphBoneJoint nextJoint = jointlist[i + 1];
                        GlyphBone      bone      = new GlyphBone(joint, nextJoint);
                        newlyCreatedBones.Add(bone);
                        glyphBones.Add(bone);
                    }

                    if (joint.TipEdgeQ != null)
                    {
                        GlyphBone tipBone = new GlyphBone(joint, joint.TipEdgeQ);
                        newlyCreatedBones.Add(tipBone);
                        glyphBones.Add(tipBone);
                    }
                }


                //for (int i = 1; i < j; ++i)
                //{
                //    joint = jointlist[i]; //first
                //    {
                //        GlyphTriangle tri = joint.P_Tri;
                //        //test 3 edges, find edge that is inside
                //        //and the joint is not the same as first_pair.BoneJoint
                //        CreateTipBoneIfNeed(tri.e0 as InsideEdgeLine, joint, newlyCreatedBones, glyphBones);
                //        CreateTipBoneIfNeed(tri.e1 as InsideEdgeLine, joint, newlyCreatedBones, glyphBones);
                //        CreateTipBoneIfNeed(tri.e2 as InsideEdgeLine, joint, newlyCreatedBones, glyphBones);
                //    }
                //}
            }
        }
コード例 #12
0
        //
        public void Walk(GlyphDynamicOutline dynamicOutline)
        {
#if DEBUG
            _dynamicOutline = dynamicOutline;
            int triNumber = 0;
            if (WalkTrianglesAndEdges)
            {
                foreach (GlyphTriangle tri in _dynamicOutline.dbugGetGlyphTriangles())
                {
                    float centroidX, centriodY;
                    tri.CalculateCentroid(out centroidX, out centriodY);
                    OnTriangle(triNumber++, tri.e0, tri.e1, tri.e2, centroidX, centriodY);
                }
            }
            //---------------
            List <GlyphContour> contours = _dynamicOutline._contours;

            List <CentroidLineHub> centroidLineHubs = _dynamicOutline.dbugGetCentroidLineHubs();
            foreach (CentroidLineHub lineHub in centroidLineHubs)
            {
                Dictionary <GlyphTriangle, CentroidLine> lines = lineHub.GetAllCentroidLines();
                Vector2 hubCenter = lineHub.CalculateAvgHeadPosition();

                OnBegingLineHub(hubCenter.X, hubCenter.Y);
                foreach (CentroidLine line in lines.Values)
                {
                    List <GlyphBoneJoint> joints = line._joints;
                    int pairCount = joints.Count;

                    for (int i = 0; i < pairCount; ++i)
                    {
                        GlyphBoneJoint joint = joints[i];
                        if (WalkCentroidBone)
                        {
                            float px, py, qx, qy;
                            joint.dbugGetCentroidBoneCenters(out px, out py, out qx, out qy);
                            OnCentroidLine(px, py, qx, qy);
                            //--------------------------------------------------
                            if (joint.TipEdgeP != null)
                            {
                                Vector2 pos = joint.TipPointP;
                                OnCentroidLineTip_P(px, py, pos.X, pos.Y);
                            }
                            if (joint.TipEdgeQ != null)
                            {
                                Vector2 pos = joint.TipPointQ;
                                OnCentroidLineTip_Q(qx, qy, pos.X, pos.Y);
                            }
                        }
                        if (WalkGlyphBone)
                        {
                            OnBoneJoint(joint);
                        }
                    }
                    if (WalkGlyphBone)
                    {
                        //draw bone list
                        DrawBoneLinks(line);
                    }
                }
                //
                OnEndLineHub(hubCenter.X, hubCenter.Y, lineHub.GetHeadConnectedJoint());
            }
            //----------------

            List <GlyphContour> cnts = _dynamicOutline._contours;
            int j = cnts.Count;
            for (int i = 0; i < j; ++i)
            {
                GlyphContour      cnt    = cnts[i];
                List <GlyphPoint> points = cnt.flattenPoints;
                int n = points.Count;
                for (int m = 0; m < n; ++m)
                {
                    OnGlyphEdgeN(points[m].E0);
                }
            }
#endif
        }
コード例 #13
0
 protected abstract void OnEndLineHub(float centerX, float centerY, GlyphBoneJoint joint);
コード例 #14
0
 protected abstract void OnBoneJoint(GlyphBoneJoint joint);