ToCurves() private method

private ToCurves ( System curves, string fileName = "image.svg" ) : string
curves System
fileName string
return string
コード例 #1
0
        internal String CreateNewCurves()
        {
            bool hasEdge = true;
            TaggedUndirectedEdge <Pixel, EdgeTag> firstEdge;
            TaggedUndirectedEdge <Pixel, EdgeTag> lastEdge;
            Pixel lastPoint  = null;
            Pixel firstPoint = null;

            foreach (var edge in ng.Edges)
            {
                firstPoint = null;
                //localiza uma aresta visivel e que seja de valencia diferente de 2, ou seja o inicio de uma curva.
                if (edge.Tag.visible && (edge.Source.valence != 2 || edge.Target.valence != 2))
                {
                    //cria um array de pontos para esta curva
                    ArrayList curveOfEdges = new ArrayList();
                    //ir para inicio da curva, ou seja nodo com valencia != 2

                    firstEdge = edge;

                    if (firstEdge.Source.valence != 2 && firstEdge.Target.valence != 2)// curva de apenas dois pontos
                    {
                        edge.Tag.visible = false;
                        firstPoint       = null;
                        curveOfEdges.Add(firstEdge);
                        curvesOfEdges.Add(curveOfEdges);
                        if (edge.Tag.colorA != Color.Beige)
                        {
                            curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorA));
                        }
                        if (edge.Tag.colorB != Color.Beige)
                        {
                            curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorB));
                        }
                    }
                    else
                    {
                        edge.Tag.visible = false;
                        curveOfEdges.Add(firstEdge);
                        if (firstEdge.Target.valence != 2)
                        {
                            firstPoint = firstEdge.Target;
                            lastPoint  = firstEdge.Source;
                        }
                        else
                        {
                            firstPoint = firstEdge.Source;
                            lastPoint  = firstEdge.Target;
                        }
                    }

                    if (firstPoint == null)
                    {
                        hasEdge = false;
                    }
                    else
                    {
                        hasEdge = true;
                    }
                    lastEdge = firstEdge;

                    while (hasEdge)//enquanto existirem mais arestas nesta curva adiciona elas
                    {
                        hasEdge = false;
                        //Obtem proxima aresta
                        foreach (var e in ng.AdjacentEdges(lastPoint))
                        {
                            if (e.Tag.visible == true)
                            {
                                e.Tag.visible = false;

                                if (e.Target.Equals(lastPoint))
                                {
                                    lastPoint = e.Source;
                                }
                                else
                                {
                                    lastPoint = e.Target;
                                }

                                //Se a valencia for dois a curva continua
                                if (lastPoint.valence == 2 && lastPoint != firstPoint)
                                {
                                    curveOfEdges.Add(e);
                                    hasEdge = true;
                                }
                                else
                                {
                                    hasEdge = false;
                                    curveOfEdges.Add(e);
                                    curvesOfEdges.Add(curveOfEdges);
                                    if (edge.Tag.colorA != Color.Beige)
                                    {
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorA));
                                    }
                                    if (edge.Tag.colorB != Color.Beige)
                                    {
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorB));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Percorre as arestas que ficaram de fora por formarem um caminho fechado de arestas, todas com valencia 2
            foreach (var edge in ng.Edges)
            {
                ArrayList curveOfEdges = new ArrayList();
                if (edge.Tag.visible)
                {
                    firstEdge        = edge;
                    edge.Tag.visible = false;
                    curveOfEdges.Add(firstEdge);
                    firstPoint = firstEdge.Source;
                    hasEdge    = true;
                    lastPoint  = firstEdge.Target;

                    while (hasEdge)
                    {
                        hasEdge = false;
                        //Obtem proxima aresta
                        foreach (var e in ng.AdjacentEdges(lastPoint))
                        {
                            if (e.Tag.visible == true)
                            {
                                e.Tag.visible = false;

                                if (e.Target.Equals(lastPoint))
                                {
                                    lastPoint = e.Source;
                                }
                                else
                                {
                                    lastPoint = e.Target;
                                }

                                if (lastPoint.valence == 2 && lastPoint != firstPoint)
                                {
                                    hasEdge = true;
                                    curveOfEdges.Add(e);
                                }
                                else
                                {
                                    hasEdge = false;
                                    curveOfEdges.Add(e);
                                    curvesOfEdges.Add(curveOfEdges);
                                    if (edge.Tag.colorA != Color.Beige)
                                    {
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorA));
                                    }
                                    if (edge.Tag.colorB != Color.Beige)
                                    {
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorB));
                                    }
                                }
                            }
                        }
                    }
                }
            }



            SvgVector svg = new SvgVector();

            svg.Height = Height * scale;
            svg.Width  = Width * scale;
            svg.scale  = 1;//scale;
            return(svg.ToCurves(curvesOfEdgesToPoints(curvesOfEdges), "NewCurves.svg"));
        }
コード例 #2
0
        internal String CreateNewCurves()
        {
            bool hasEdge = true;
            TaggedUndirectedEdge<Pixel, EdgeTag> firstEdge;
            TaggedUndirectedEdge<Pixel, EdgeTag> lastEdge;
            Pixel lastPoint = null;
            Pixel firstPoint = null;

            foreach (var edge in ng.Edges)
            {
                firstPoint = null;
                //localiza uma aresta visivel e que seja de valencia diferente de 2, ou seja o inicio de uma curva.
                if (edge.Tag.visible && (edge.Source.valence != 2 || edge.Target.valence != 2))
                {
                    //cria um array de pontos para esta curva
                    ArrayList curveOfEdges = new ArrayList();
                    //ir para inicio da curva, ou seja nodo com valencia != 2

                    firstEdge = edge;

                    if (firstEdge.Source.valence != 2 && firstEdge.Target.valence != 2)// curva de apenas dois pontos
                    {
                        edge.Tag.visible = false;
                        firstPoint = null;
                        curveOfEdges.Add(firstEdge);
                        curvesOfEdges.Add(curveOfEdges);
                        if (edge.Tag.colorA != Color.Beige)
                            curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorA));
                        if (edge.Tag.colorB != Color.Beige)
                            curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorB));

                    }
                    else
                    {
                        edge.Tag.visible = false;
                        curveOfEdges.Add(firstEdge);
                        if (firstEdge.Target.valence != 2)
                        {
                            firstPoint = firstEdge.Target;
                            lastPoint = firstEdge.Source;
                        }
                        else
                        {
                            firstPoint = firstEdge.Source;
                            lastPoint = firstEdge.Target;
                        }
                    }

                    if (firstPoint == null)
                        hasEdge = false;
                    else
                        hasEdge = true;
                    lastEdge = firstEdge;

                    while (hasEdge)//enquanto existirem mais arestas nesta curva adiciona elas
                    {
                        hasEdge = false;
                        //Obtem proxima aresta
                        foreach (var e in ng.AdjacentEdges(lastPoint))
                        {
                            if (e.Tag.visible == true)
                            {
                                e.Tag.visible = false;

                                if (e.Target.Equals(lastPoint))
                                { lastPoint = e.Source; }
                                else
                                { lastPoint = e.Target; }

                                //Se a valencia for dois a curva continua
                                if (lastPoint.valence == 2 && lastPoint != firstPoint)
                                {
                                    curveOfEdges.Add(e);
                                    hasEdge = true;
                                }
                                else
                                {
                                    hasEdge = false;
                                    curveOfEdges.Add(e);
                                    curvesOfEdges.Add(curveOfEdges);
                                    if (edge.Tag.colorA != Color.Beige)
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorA));
                                    if (edge.Tag.colorB != Color.Beige)
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorB));
                                }
                            }
                        }
                    }

                }

            }

            //Percorre as arestas que ficaram de fora por formarem um caminho fechado de arestas, todas com valencia 2
            foreach (var edge in ng.Edges)
            {
                ArrayList curveOfEdges = new ArrayList();
                if (edge.Tag.visible)
                {
                    firstEdge = edge;
                    edge.Tag.visible = false;
                    curveOfEdges.Add(firstEdge);
                    firstPoint = firstEdge.Source;
                    hasEdge = true;
                    lastPoint = firstEdge.Target;

                    while (hasEdge)
                    {
                        hasEdge = false;
                        //Obtem proxima aresta
                        foreach (var e in ng.AdjacentEdges(lastPoint))
                        {
                            if (e.Tag.visible == true)
                            {
                                e.Tag.visible = false;

                                if (e.Target.Equals(lastPoint))
                                { lastPoint = e.Source; }
                                else
                                { lastPoint = e.Target; }

                                if (lastPoint.valence == 2 && lastPoint != firstPoint)
                                {
                                    hasEdge = true;
                                    curveOfEdges.Add(e);
                                }
                                else
                                {
                                    hasEdge = false;
                                    curveOfEdges.Add(e);
                                    curvesOfEdges.Add(curveOfEdges);
                                    if (edge.Tag.colorA != Color.Beige)
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorA));
                                    if (edge.Tag.colorB != Color.Beige)
                                        curvesC.Add(new Curve(curveOfEdges, edge.Tag.colorB));
                                }
                            }
                        }
                    }
                }
            }

            SvgVector svg = new SvgVector();
            svg.Height = Height * scale;
            svg.Width = Width * scale;
            svg.scale = 1;//scale;
            return svg.ToCurves(curvesOfEdgesToPoints(curvesOfEdges), "NewCurves.svg");
        }