Ejemplo n.º 1
0
            public bool IsColinear(EdgeLine other)
            {
                var similarDir = Direction.Equals(other.Direction, 0.001f) || Direction.Equals(other.Direction * -1f, 0.001f);

                return(similarDir && (Contains(other.P1) || Contains(other.P2)));

                //return Direction.Equals(other.Direction, 0.001f) || Direction.Equals(other.Direction * -1f, 0.001f);
            }
Ejemplo n.º 2
0
        public override double GetDistance(int y)
        {
            var xLine    = EdgeLine.GetXValueForY(y);
            var xActual  = (double)EdgeProcessor.GetEdgePt(y).X;
            var distance = xActual - xLine;

            return(distance);
        }
Ejemplo n.º 3
0
        protected override void OnTriangle(int triangleId, EdgeLine e0, EdgeLine e1, EdgeLine e2, double centroidX, double centroidY)
        {
            DrawEdge(painter, e0);
            DrawEdge(painter, e1);
            DrawEdge(painter, e2);

            _infoView.ShowTriangles(new GlyphTriangleInfo(triangleId, e0, e1, e2, centroidX, centroidY));
        }
Ejemplo n.º 4
0
            public EdgeLine ProjectEdge2D(FaceEdge edge)
            {
                var line = new EdgeLine(edge,
                                        FacePlane.ProjectPoint2D(PlaneAxisX, edge.P1),
                                        FacePlane.ProjectPoint2D(PlaneAxisX, edge.P2));

                line.Perpendicular = FacePlane.ProjectVector2D(PlaneAxisX, edge.PerpVec);
                return(line);
            }
Ejemplo n.º 5
0
 public GlyphTriangleInfo(int triangleId, EdgeLine e0, EdgeLine e1, EdgeLine e2, double centroidX, double centroidY)
 {
     this.Id        = triangleId;
     this.E0        = e0;
     this.E1        = e1;
     this.E2        = e2;
     this.CentroidX = centroidX;
     this.CentroidY = centroidY;
 }
Ejemplo n.º 6
0
            public TriangleWrapper(Triangle triangle)
            {
                Triangle    = triangle;
                Normal      = triangle.Normal;
                Center      = triangle.GetCenter();
                FacePlane   = new Plane(Center, Normal);
                FaceEdges   = new FaceEdge[3];
                PlanarEdges = new EdgeLine[3];

                PlaneAxisX = (Vertices[0].Position - Center).Normalized();
            }
Ejemplo n.º 7
0
        static void DrawEdge(AggCanvasPainter p, EdgeLine edge, float scale)
        {
            if (edge.IsOutside)
            {
                //free side
                switch (edge.SlopKind)
                {
                default:
                    p.StrokeColor = PixelFarm.Drawing.Color.Green;
                    break;

                case LineSlopeKind.Vertical:
                    if (edge.IsLeftSide)
                    {
                        p.StrokeColor = PixelFarm.Drawing.Color.Blue;
                    }
                    else
                    {
                        p.StrokeColor = PixelFarm.Drawing.Color.LightGray;
                    }
                    break;

                case LineSlopeKind.Horizontal:
                    if (edge.IsUpper)
                    {
                        p.StrokeColor = PixelFarm.Drawing.Color.Red;
                    }
                    else
                    {
                        p.StrokeColor = PixelFarm.Drawing.Color.LightGray;
                    }
                    break;
                }
            }
            else
            {
                switch (edge.SlopKind)
                {
                default:
                    p.StrokeColor = PixelFarm.Drawing.Color.LightGray;
                    break;

                case LineSlopeKind.Vertical:
                    p.StrokeColor = PixelFarm.Drawing.Color.Blue;
                    break;

                case LineSlopeKind.Horizontal:
                    p.StrokeColor = PixelFarm.Drawing.Color.Yellow;
                    break;
                }
            }
            p.Line(edge.x0 * scale, edge.y0 * scale, edge.x1 * scale, edge.y1 * scale);
        }
Ejemplo n.º 8
0
        protected override void OnGlyphEdgeN(EdgeLine e)
        {
            float pxscale = this._pxscale;

            //TODO: reimplement this again

            //Vector2 cut_p = new Vector2(e.newEdgeCut_P_X, e.newEdgeCut_P_Y) * pxscale;
            //Vector2 cut_q = new Vector2(e.newEdgeCut_Q_X, e.newEdgeCut_Q_Y) * pxscale;
            //painter.FillRectLBWH(cut_p.X, cut_p.Y, 3, 3, PixelFarm.Drawing.Color.Red);
            //painter.FillRectLBWH(x1 * pxscale, y1 * pxscale, 6, 6, PixelFarm.Drawing.Color.OrangeRed);

            //_infoView.ShowGlyphEdge(e,
            //    e.newEdgeCut_P_X, e.newEdgeCut_P_Y,
            //    e.newEdgeCut_Q_X, e.newEdgeCut_Q_Y);
        }
Ejemplo n.º 9
0
        public void ShowBone(GlyphBone bone, GlyphBoneJoint jointA, EdgeLine tipEdge)
        {
            if (!_clearInfoView)
            {
                return;
            }
            _treeView.SuspendLayout();
            TreeNode jointNode = new TreeNode()
            {
                Text = bone.ToString(), Tag = new NodeInfo(bone, jointA, tipEdge)
            };

            _bonesNode.Nodes.Add(jointNode);

            _treeView.ResumeLayout();
        }
Ejemplo n.º 10
0
        void DrawBoneJoint(PixelFarm.Drawing.Painter painter, GlyphBoneJoint joint)
        {
            //--------------
            EdgeLine p_contactEdge = joint.dbugGetEdge_P();
            //mid point
            Vector2 jointPos = joint.OriginalJointPos * _pxscale;//scaled joint pos

            painter.FillRect(jointPos.X, jointPos.Y, 4, 4, PixelFarm.Drawing.Color.Yellow);
            if (joint.TipEdgeP != null)
            {
                EdgeLine tipEdge = joint.TipEdgeP;
                double   p_x, p_y, q_x, q_y;
                tipEdge.dbugGetScaledXY(out p_x, out p_y, out q_x, out q_y, _pxscale);
                //
                painter.Line(
                    jointPos.X, jointPos.Y,
                    p_x, p_y,
                    PixelFarm.Drawing.Color.White);
                painter.FillRect(p_x, p_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker

                //
                painter.Line(
                    jointPos.X, jointPos.Y,
                    q_x, q_y,
                    PixelFarm.Drawing.Color.White);
                painter.FillRect(q_x, q_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker
            }
            if (joint.TipEdgeQ != null)
            {
                EdgeLine tipEdge = joint.TipEdgeQ;
                double   p_x, p_y, q_x, q_y;
                tipEdge.dbugGetScaledXY(out p_x, out p_y, out q_x, out q_y, _pxscale);
                //
                painter.Line(
                    jointPos.X, jointPos.Y,
                    p_x, p_y,
                    PixelFarm.Drawing.Color.White);
                painter.FillRect(p_x, p_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker

                //
                painter.Line(
                    jointPos.X, jointPos.Y,
                    q_x, q_y,
                    PixelFarm.Drawing.Color.White);
                painter.FillRect(q_x, q_y, 3, 3, PixelFarm.Drawing.Color.Green); //marker
            }
        }
Ejemplo n.º 11
0
        public void ShowGlyphEdge(EdgeLine e, float x0, float y0, float x1, float y1)
        {
            if (!_clearInfoView)
            {
                return;
            }

            NodeInfo nodeInfo = new NodeInfo(NodeInfoKind.GlyphEdge, x0, y0, x1, y1);
            TreeNode nodeEdge = new TreeNode();

            nodeEdge.Tag  = nodeInfo;
            nodeEdge.Text = "(" + x0 + "," + y0 + "), (" + x1 + "," + y1 + ")";
            //if (edge.cutPointOnBone != System.Numerics.Vector2.Zero)
            //{
            //    nodeEdge.Text += " cut:" + edge.cutPointOnBone;
            //}
            _glyphEdgesNode.Nodes.Add(nodeEdge);
        }
Ejemplo n.º 12
0
        private void DrawIt()
        {
            Brush nodeBrush = (SolidColorBrush) new BrushConverter().ConvertFrom("#507EA5");
            Brush edgeBrush = (SolidColorBrush) new BrushConverter().ConvertFrom("#B9BCBF");

            SolidColorBrush textBrush           = new SolidColorBrush(Color.FromRgb(255, 255, 255));
            SolidColorBrush textBackgroundBrush = (SolidColorBrush) new BrushConverter().ConvertFrom("#97B7D2");

            foreach (var graphEdge in _viewModel.Graph.Edges)
            {
                var line = AddEdge(graphEdge, edgeBrush);
                EdgeLine.Add(graphEdge, line);
            }

            foreach (var graphNode in _viewModel.Graph.Nodes)
            {
                var ellipse = AddNode(graphNode.Name, graphNode.X, graphNode.Y, nodeBrush, textBrush, textBackgroundBrush);
                NodeEllipse.Add(graphNode, ellipse);
            }
        }
Ejemplo n.º 13
0
        public void ShowEdge(EdgeLine edge)
        {
#if DEBUG
            HasDebugMark = false; //reset for this

            //---------------
            if (_testEdgeCount == _addDebugMarkOnEdgeNo)
            {
                HasDebugMark = true;
            }
            _testEdgeCount++;
            if (!_clearInfoView)
            {
                return;
            }

            GlyphPoint pnt_P = edge.P;
            GlyphPoint pnt_Q = edge.Q;

            //-------------------------------

            NodeInfo nodeInfo = new NodeInfo(NodeInfoKind.TessEdge, edge, _edgeLines.Count);
            TreeNode nodeEdge = new TreeNode();
            nodeEdge.Tag  = nodeInfo;
            nodeEdge.Text = "e id=" + edge.dbugId + ",count="
                            + _testEdgeCount + " : " + pnt_P.ToString() +
                            "=>" + pnt_Q.ToString();

            if (edge.dbugNoPerpendicularBone)
            {
                nodeEdge.Text += "_X_ (no perpendicular_bone)";
            }

            _tessEdgesNode.Nodes.Add(nodeEdge);
            //-------------------------------

            _edgeLines.Add(edge);
#endif
        }
Ejemplo n.º 14
0
        public void ShowJoint(GlyphBoneJoint joint)
        {
            if (!_clearInfoView)
            {
                return;
            }
            //--------------
#if DEBUG
            EdgeLine p_contactEdge = joint.dbugGetEdge_Q();
            //mid point
            var jointPos = joint.OriginalJointPos;
            //painter.FillRectLBWH(jointPos.X * pxscale, jointPos.Y * pxscale, 4, 4, PixelFarm.Drawing.Color.Yellow);

            TreeNode jointNode = new TreeNode()
            {
                Tag = new NodeInfo(joint)
            };

            jointNode.Text = "j:" + joint.ToString();
            _jointsNode.Nodes.Add(jointNode);

            if (joint.HasTipP)
            {
                jointNode.Nodes.Add(new TreeNode()
                {
                    Text = "tip_p:" + joint.TipPointP, Tag = new NodeInfo(NodeInfoKind.RibEndPoint, joint.TipPointP)
                });
            }
            if (joint.HasTipQ)
            {
                jointNode.Nodes.Add(new TreeNode()
                {
                    Text = "tip_q:" + joint.TipPointQ, Tag = new NodeInfo(NodeInfoKind.RibEndPoint, joint.TipPointQ)
                });
            }
#endif
        }
Ejemplo n.º 15
0
 private void Clear()
 {
     MainCanvas.Children.Clear();
     NodeEllipse.Clear();
     EdgeLine.Clear();
 }
Ejemplo n.º 16
0
        void debugDrawTriangulatedGlyph(GlyphFitOutline glyphFitOutline, float pixelScale)
        {
            p.StrokeColor = PixelFarm.Drawing.Color.Magenta;
            List <GlyphTriangle> triAngles = glyphFitOutline.dbugGetTriangles();
            int j = triAngles.Count;
            //
            double prev_cx = 0, prev_cy = 0;
            //
            bool drawBone = this.chkDrawBone.Checked;

            for (int i = 0; i < j; ++i)
            {
                //---------------
                GlyphTriangle tri = triAngles[i];
                EdgeLine      e0  = tri.e0;
                EdgeLine      e1  = tri.e1;
                EdgeLine      e2  = tri.e2;
                //---------------
                //draw each triangles
                DrawEdge(p, e0, pixelScale);
                DrawEdge(p, e1, pixelScale);
                DrawEdge(p, e2, pixelScale);
                //---------------
                //draw centroid
                double cen_x = tri.CentroidX;
                double cen_y = tri.CentroidY;
                //---------------
                p.FillColor = PixelFarm.Drawing.Color.Yellow;
                p.FillRectLBWH(cen_x * pixelScale, cen_y * pixelScale, 2, 2);
                if (!drawBone)
                {
                    //if not draw bone then draw connected lines
                    if (i == 0)
                    {
                        //start mark
                        p.FillColor = PixelFarm.Drawing.Color.Yellow;
                        p.FillRectLBWH(cen_x * pixelScale, cen_y * pixelScale, 7, 7);
                    }
                    else
                    {
                        p.StrokeColor = PixelFarm.Drawing.Color.Red;
                        p.Line(
                            prev_cx * pixelScale, prev_cy * pixelScale,
                            cen_x * pixelScale, cen_y * pixelScale);
                    }
                    prev_cx = cen_x;
                    prev_cy = cen_y;
                }
            }
            //---------------
            //draw bone
            if (drawBone)
            {
                List <GlyphBone> bones = glyphFitOutline.dbugGetBones();
                j = bones.Count;
                for (int i = 0; i < j; ++i)
                {
                    GlyphBone b = bones[i];
                    if (i == 0)
                    {
                        //start mark
                        p.FillColor = PixelFarm.Drawing.Color.Yellow;
                        p.FillRectLBWH(b.p.CentroidX * pixelScale, b.p.CentroidY * pixelScale, 7, 7);
                    }
                    //draw each bone
                    p.StrokeColor = PixelFarm.Drawing.Color.Red;
                    p.Line(
                        b.p.CentroidX * pixelScale, b.p.CentroidY * pixelScale,
                        b.q.CentroidX * pixelScale, b.q.CentroidY * pixelScale);
                }
            }
            //---------------
        }
 public void Init()
 {
     instance = new EdgeLine();
 }
Ejemplo n.º 18
0
 public NodeInfo(NodeInfoKind nodeKind, EdgeLine edge, int edgeNo)
 {
     this.edge       = edge;
     this.TessEdgeNo = edgeNo;
     this.NodeKind   = nodeKind;
 }
Ejemplo n.º 19
0
        void DrawEdge(PixelFarm.Drawing.Painter painter, EdgeLine edge)
        {
            if (edge.IsOutside)
            {
                //free side
                {
                    GlyphPoint p = edge.P;
                    GlyphPoint q = edge.Q;

                    DrawPointKind(painter, p);
                    DrawPointKind(painter, q);
                    _infoView.ShowEdge(edge);
                    switch (edge.SlopeKind)
                    {
                    default:
                        painter.StrokeColor = PixelFarm.Drawing.Color.Green;
                        break;

                    case LineSlopeKind.Vertical:
                        if (edge.IsLeftSide)
                        {
                            painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                        }
                        else
                        {
                            painter.StrokeColor = PixelFarm.Drawing.Color.LightGray;
                        }
                        break;

                    case LineSlopeKind.Horizontal:

                        if (edge.IsUpper)
                        {
                            painter.StrokeColor = PixelFarm.Drawing.Color.Red;
                        }
                        else
                        {
                            //lower edge
                            painter.StrokeColor = PixelFarm.Drawing.Color.Magenta;
                        }
                        break;
                    }
                }
                float scale = this._pxscale;
                //show info: => edge point
                if (this.DrawPerpendicularLine && _infoView.HasDebugMark)
                {
                    double prevWidth = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.Line(edge.PX * scale, edge.PY * scale, edge.QX * scale, edge.QY * scale, PixelFarm.Drawing.Color.Yellow);
                    painter.StrokeWidth = prevWidth;

                    //draw
                    GlyphPoint p = edge.P;
                    GlyphPoint q = edge.Q;

                    //
                    //AssocBoneCollection p_bones = glyphEdge._P.dbugGetAssocBones();
                    //if (p_bones != null)
                    //{
                    //    Vector2 v2 = new Vector2(q.x, q.y);
                    //    foreach (GlyphBone b in p_bones)
                    //    {
                    //        Vector2 v3 = b.GetMidPoint();
                    //        painter.Line(v2.X * scale, v2.Y * scale, v3.X * scale, v3.Y * scale, PixelFarm.Drawing.Color.Yellow);
                    //    }
                    //}

                    //AssocBoneCollection q_bones = glyphEdge._Q.dbugGetAssocBones();
                    //if (q_bones != null)
                    //{
                    //    Vector2 v2 = new Vector2(p.x, p.y);
                    //    foreach (GlyphBone b in q_bones)
                    //    {

                    //        //Vector2 v2 = new Vector2(q.x, q.y);
                    //        Vector2 v3 = b.GetMidPoint();
                    //        painter.Line(v2.X * scale, v2.Y * scale, v3.X * scale, v3.Y * scale, PixelFarm.Drawing.Color.Green);
                    //    }
                    //}

                    {
                        //TODO: reimplement this again
                        //Vector2 orginal_MidPoint = glyphEdge.GetMidPoint() * _pxscale;
                        //Vector2 newMidPoint = glyphEdge.GetNewMidPoint() * _pxscale;
                        //painter.FillRectLBWH(newMidPoint.X, newMidPoint.Y, 3, 3, PixelFarm.Drawing.Color.Red);
                        //painter.Line(newMidPoint.X, newMidPoint.Y, orginal_MidPoint.X, orginal_MidPoint.Y, PixelFarm.Drawing.Color.LightGray);


                        //painter.FillRectLBWH(glyphEdge.newEdgeCut_P_X * _pxscale, glyphEdge.newEdgeCut_P_Y * _pxscale, 6, 6, PixelFarm.Drawing.Color.Blue);
                        //painter.FillRectLBWH(glyphEdge.newEdgeCut_Q_X * _pxscale, glyphEdge.newEdgeCut_Q_Y * _pxscale, 6, 6, PixelFarm.Drawing.Color.Blue);
                    }
                }
                else
                {
                    painter.DrawLine(edge.PX * scale, edge.PY * scale, edge.QX * scale, edge.QY * scale);
                }

                {
                    GlyphPoint p = edge.P;
                    GlyphPoint q = edge.Q;
                    //---------
                    {
                        //TODO: reimplement this again
                        //Vector2 orginal_MidPoint = glyphEdge.GetMidPoint() * _pxscale;
                        //Vector2 newMidPoint = glyphEdge.GetNewMidPoint() * _pxscale;

                        //if (DrawEdgeMidPoint)
                        //{
                        //    painter.FillRectLBWH(newMidPoint.X, newMidPoint.Y, 3, 3, PixelFarm.Drawing.Color.Red);
                        //}
                        ////
                        //painter.Line(newMidPoint.X, newMidPoint.Y, orginal_MidPoint.X, orginal_MidPoint.Y, PixelFarm.Drawing.Color.LightGray);

                        //painter.FillRectLBWH(glyphEdge.newEdgeCut_P_X * _pxscale, glyphEdge.newEdgeCut_P_Y * _pxscale, 4, 4, PixelFarm.Drawing.Color.Blue);
                        //painter.FillRectLBWH(glyphEdge.newEdgeCut_Q_X * _pxscale, glyphEdge.newEdgeCut_Q_Y * _pxscale, 4, 4, PixelFarm.Drawing.Color.Blue);
                    }
                    //---------
                    if (this.DrawPerpendicularLine)
                    {
                        var asOutsideEdge = edge as OutsideEdgeLine;
                        if (asOutsideEdge != null)
                        {
                            DrawPerpendicularEdgeControlPoints(painter, asOutsideEdge);
                        }
                    }
                }
            }
            else
            {
                //draw inside edge
                painter.Line(
                    edge.PX * _pxscale, edge.PY * _pxscale,
                    edge.QX * _pxscale, edge.QY * _pxscale,
                    PixelFarm.Drawing.Color.Gray);
            }
        }
Ejemplo n.º 20
0
 public NodeInfo(GlyphBone bone, GlyphBoneJoint a, EdgeLine tipEdge)
 {
     this.bone     = bone;
     this.NodeKind = NodeInfoKind.Bone;
 }
 public NodeInfo(Bone bone, Joint a, EdgeLine tipEdge)
 {
     _bone         = bone;
     this.NodeKind = NodeInfoKind.Bone;
 }