NewImage() private method

private NewImage ( EdgeTag>.UndirectedGraph g, System.Drawing.Shapes shapes, string fileName = "image.svg" ) : string
g EdgeTag>.UndirectedGraph
shapes System.Drawing.Shapes
fileName string
return string
コード例 #1
0
        /*
         * Detectar os ciclos dentro do grafo para transforma-los em objetos coloridos
         */
        internal String CreateShapes()
        {
            Shapes    shapes          = new Shapes();
            Shape     shape           = new Shape();
            ArrayList processedCurves = new ArrayList();

            Pixel lastPixel  = null;
            Pixel firstPixel = null;
            Color color;
            bool  hasCurve = true;

            foreach (Curve curve in curvesC)
            {
                Curve processingCurve = curve;
                color = processingCurve.color;
                if (!processedCurves.Contains(processingCurve))
                {
                    processedCurves.Add(processingCurve);
                    ArrayList curveArray = (ArrayList)processingCurve.curve;

                    firstPixel = getFirstPixel(curveArray);
                    lastPixel  = getLastPixel(curveArray);
                    shape.Add(curve);
                    if (!firstPixel.Equals(lastPixel)) // se primeiro e ultimo são iguais, então o circuito já esta fechado
                    {
                        hasCurve = true;
                        while (hasCurve)
                        {
                            foreach (Curve newCurve in curvesC)                                                            // verifico todas as curvas procurando uma que comece ou termine com o ultimo pixel da pesquisada
                            {
                                if ((newCurve.color == color && newCurve != curve && !processedCurves.Contains(newCurve))) // Precisa ser uma curva não processessada e com cor igual
                                {
                                    hasCurve = false;
                                    ArrayList newCurveArray = (ArrayList)newCurve.curve;
                                    TaggedUndirectedEdge <Pixel, EdgeTag> firstNewEdge = (TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0];
                                    TaggedUndirectedEdge <Pixel, EdgeTag> lastNewEdge  = (TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[newCurveArray.Count - 1];

                                    if (firstNewEdge.Source.Equals(lastPixel) || firstNewEdge.Target.Equals(lastPixel) || lastNewEdge.Target.Equals(lastPixel) || lastNewEdge.Source.Equals(lastPixel)) // se a curva analizada possui o primeiro ou ultimo pixel igual a um pixel do lastEdge // simplificado apenas para conter um dos pixeis da ultima aresta da curva
                                    {
                                        if (firstNewEdge.Source.Equals(lastPixel) || firstNewEdge.Target.Equals(lastPixel))
                                        {
                                            if (newCurveArray.Count == 1)
                                            {
                                                if (((TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0]).Source.Equals(lastPixel))
                                                {
                                                    lastPixel = ((TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0]).Target;
                                                }
                                                else
                                                {
                                                    lastPixel = ((TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0]).Source;
                                                }
                                            }
                                            else
                                            {
                                                lastPixel = getLastPixel(newCurveArray);
                                            }
                                        }
                                        else
                                        {
                                            if (newCurveArray.Count == 1)
                                            {
                                                if (((TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0]).Source.Equals(lastPixel))
                                                {
                                                    lastPixel = ((TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0]).Target;
                                                }
                                                else
                                                {
                                                    lastPixel = ((TaggedUndirectedEdge <Pixel, EdgeTag>)newCurveArray[0]).Source;
                                                }
                                            }
                                            else
                                            {
                                                lastPixel = getFirstPixel(newCurveArray);
                                                newCurveArray.Reverse();
                                            }
                                        }


                                        processedCurves.Add(newCurve);
                                        if (!lastPixel.Equals(firstPixel))
                                        {
                                            shape.Add(newCurve);
                                            hasCurve = true;
                                            break;
                                        }
                                        else // terminou o grupo de curvas
                                        {
                                            shape.Add(newCurve);
                                            shapes.Add(shape);
                                            hasCurve = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        shapes.Add(shape);
                    }
                    shape = new Shape();
                }
            }

            //remove shapes iguais de cores diferentes
            ArrayList remove = new ArrayList();

            foreach (Shape shapeItem in shapes)
            {
                foreach (Shape shapeItem2 in shapes)
                {
                    if (!remove.Contains(shapeItem) && !remove.Contains(shapeItem2) && shapeItem.getColor() != Color.Beige && shapeItem2.getColor() != Color.Beige)
                    {
                        if (shapeItem.getColor() != shapeItem2.getColor() && shapeItem.isSameShape(shapeItem2))
                        {
                            Color c = new Color();
                            //localiza o pixel de cor dentro do poligono
                            foreach (Pixel v in g.Vertices)
                            {
                                if (v.pixelInsidePolygon(shapeItem.ToPoints()))
                                {
                                    c = v.color;
                                    break;
                                }
                            }

                            if (shapeItem.getColor() == c)
                            {
                                remove.Add(shapeItem2);
                                break;
                            }
                            else
                            if (shapeItem2.getColor() == c)
                            {
                                remove.Add(shapeItem);
                                break;
                            }
                        }
                    }
                }
            }


            foreach (Shape item in remove)
            {
                shapes.Remove(item);
            }

            //Ordena do objeto com maior area para os de menor area
            shapes.Sort();

            SvgVector svg = new SvgVector();

            svg.Height = Height * scale;
            svg.Width  = Width * scale;
            svg.scale  = 1;

            return(svg.NewImage(g, shapes, "NewImage.svg"));
        }
コード例 #2
0
        /*
         * Detectar os ciclos dentro do grafo para transforma-los em objetos coloridos
         */
        internal String CreateShapes()
        {
            Shapes shapes = new Shapes();
            Shape shape = new Shape();
            ArrayList processedCurves = new ArrayList();

            Pixel lastPixel = null;
            Pixel firstPixel = null;
            Color color;
            bool hasCurve = true;
            foreach (Curve curve in curvesC)
            {

                Curve processingCurve = curve;
                color = processingCurve.color;
                if (!processedCurves.Contains(processingCurve))
                {
                    processedCurves.Add(processingCurve);
                    ArrayList curveArray = (ArrayList)processingCurve.curve;

                    firstPixel = getFirstPixel(curveArray);
                    lastPixel = getLastPixel(curveArray);
                    shape.Add(curve);
                    if (!firstPixel.Equals(lastPixel)) // se primeiro e ultimo são iguais, então o circuito já esta fechado
                    {
                        hasCurve = true;
                        while (hasCurve)
                        {

                            foreach (Curve newCurve in curvesC) // verifico todas as curvas procurando uma que comece ou termine com o ultimo pixel da pesquisada
                            {

                                if ((newCurve.color == color && newCurve != curve && !processedCurves.Contains(newCurve) )) // Precisa ser uma curva não processessada e com cor igual
                                {

                                    hasCurve = false;
                                    ArrayList newCurveArray = (ArrayList)newCurve.curve;
                                    TaggedUndirectedEdge<Pixel, EdgeTag> firstNewEdge = (TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0];
                                    TaggedUndirectedEdge<Pixel, EdgeTag> lastNewEdge = (TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[newCurveArray.Count - 1];

                                    if (firstNewEdge.Source.Equals(lastPixel) || firstNewEdge.Target.Equals(lastPixel) || lastNewEdge.Target.Equals(lastPixel) || lastNewEdge.Source.Equals(lastPixel)) // se a curva analizada possui o primeiro ou ultimo pixel igual a um pixel do lastEdge // simplificado apenas para conter um dos pixeis da ultima aresta da curva
                                    {
                                        if (firstNewEdge.Source.Equals(lastPixel) || firstNewEdge.Target.Equals(lastPixel))
                                        {
                                            if (newCurveArray.Count == 1)
                                            {
                                                if (((TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0]).Source.Equals(lastPixel))
                                                    lastPixel = ((TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0]).Target;
                                                else
                                                    lastPixel = ((TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0]).Source;
                                            }
                                            else lastPixel = getLastPixel(newCurveArray);
                                        }
                                        else
                                        {
                                            if (newCurveArray.Count == 1)
                                            {
                                                if (((TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0]).Source.Equals(lastPixel))
                                                    lastPixel = ((TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0]).Target;
                                                else
                                                    lastPixel = ((TaggedUndirectedEdge<Pixel, EdgeTag>)newCurveArray[0]).Source;
                                            }
                                            else
                                            {
                                                lastPixel = getFirstPixel(newCurveArray);
                                                newCurveArray.Reverse();
                                            }
                                        }

                                        processedCurves.Add(newCurve);
                                        if (!lastPixel.Equals(firstPixel))
                                        {
                                            shape.Add(newCurve);
                                            hasCurve = true;
                                            break;
                                        }
                                        else // terminou o grupo de curvas
                                        {
                                            shape.Add(newCurve);
                                            shapes.Add(shape);
                                            hasCurve = false;
                                        }

                                    }
                                }

                            }

                        }
                    }
                    else
                    {
                        shapes.Add(shape);

                    }
                    shape = new Shape();
                }

            }

            //remove shapes iguais de cores diferentes
            ArrayList remove = new ArrayList();

            foreach (Shape shapeItem in shapes)
            {
                foreach (Shape shapeItem2 in shapes)
                {
                    if (!remove.Contains(shapeItem) && !remove.Contains(shapeItem2) && shapeItem.getColor() != Color.Beige && shapeItem2.getColor() != Color.Beige)
                        if ( shapeItem.getColor() != shapeItem2.getColor() && shapeItem.isSameShape(shapeItem2) )
                        {
                            Color c = new Color();
                            //localiza o pixel de cor dentro do poligono
                            foreach (Pixel v in g.Vertices)
                            {
                                if (v.pixelInsidePolygon(shapeItem.ToPoints()))
                                {
                                    c = v.color;
                                    break;
                                }
                            }

                            if (shapeItem.getColor() == c)
                            {
                                remove.Add(shapeItem2);
                                break;
                            }else
                            if (shapeItem2.getColor() == c)
                            {
                                remove.Add(shapeItem);
                                break;
                            }

                        }
                }

            }

            foreach (Shape item in remove)
            {
                shapes.Remove(item);

            }

            //Ordena do objeto com maior area para os de menor area
            shapes.Sort();

            SvgVector svg = new SvgVector();
            svg.Height = Height * scale;
            svg.Width = Width * scale;
            svg.scale = 1;

            return svg.NewImage(g, shapes, "NewImage.svg");
        }