public ConformShapes(Net net)
 {
     m_net = net;
     m_type = ConformShapeType.FixFrame;
     m_mask = null;
     m_bFirstPass = true;
     m_Ratio = 1.0;
 }
Beispiel #2
0
        public DrawNet(Net net)
            : base(new Size(width, height))
        {
            m_net = net;
            ScaleNet();

            m_bitmap = new Bitmap( m_Size.Width, m_Size.Height);
            Pen BlackPen = new Pen(Color.Black, linewidth);
            Pen GrayPen = new Pen(Color.FromArgb(100,100,100), linewidth);
            Brush BlackBrush = new SolidBrush(Color.Black);
            Brush WhiteBrush = new SolidBrush(Color.White);
            Graphics g = Graphics.FromImage( m_bitmap );

            g.FillRectangle(WhiteBrush, 0, 0, width, height);
            Point tmp;

            for( int i=0; i<net.Size; i++ )
            {
                for( int j=0; j<net.Size; j++ )
                {
                    if( net[i,j] == null ) continue;
                    Point pos = Original(i, j);

                    //Draw horizontal
                    if( net[i,j].East != null )
                    {
                        tmp = Original(i+1,j);
                        g.DrawLine(GrayPen, pos.X, pos.Y, tmp.X, tmp.Y);
                    }
                    //Draw vertical
                    if(net[i, j].North != null)
                    {
                        tmp = Original(i, j+1);
                        g.DrawLine(GrayPen, pos.X, pos.Y, tmp.X, tmp.Y);
                    }
                    g.FillEllipse(BlackBrush, pos.X - circlerad, pos.Y - circlerad, circlerad * 2, circlerad*2);

                    //Draw horizontal
                    pos = Destination(i, j);
                    if (net[i, j].East != null)
                    {
                        tmp = Destination(net[i, j].East);
                        g.DrawLine(GrayPen, pos.X, pos.Y, tmp.X, tmp.Y);
                    }
                    //Draw vertical
                    if (net[i, j].North != null)
                    {
                        tmp = Destination(net[i, j].North);
                        g.DrawLine(GrayPen, pos.X, pos.Y, tmp.X, tmp.Y);
                    }
                    g.FillEllipse(BlackBrush, pos.X - circlerad, pos.Y - circlerad, circlerad * 2, circlerad * 2);
                }
            }
        }
 public ConformShapes(Net net, ConformShapeType type, String filename, double ratio)
     : this(net, type)
 {
     m_mask = new DMSImage(filename);
     m_Ratio = ratio;
 }
 public ConformShapes(Net net, ConformShapeType type, String filename)
     : this(net, type)
 {
     m_mask = new DMSImage(filename);
 }
 public ConformShapes(Net net, ConformShapeType type, double ratio)
     : this(net, type)
 {
     m_Ratio = ratio;
 }
 public ConformShapes(Net net, ConformShapeType type)
     : this(net)
 {
     m_type = type;
 }
        //good to go
        private void Triangle2Rouleaux()
        {
            if (m_bFirstPass)
            {
                m_net = new TriangularNet(m_net.Size);
            }

            double Sqrt3 = Math.Sqrt(3.0);
            int full = (m_net.Size - 1);
            int half = m_net.Size / 2;

            //zero out what we don't need
            for (int i = 0; i < m_net.Size; i++)
            {
                for (int j = 0; j < m_net.Size; j++)
                {
                    if (m_net[i, j] != null)
                    {
                        if ( i < j )
                        {
                            m_net[i, j] = null;
                        }
                    }
                }
            }

            Point2D A = new Point2D(0, 1.0 / Math.Sqrt(2.0));
            Point2D B = new Point2D(-Sqrt3 / (2.0 * Math.Sqrt(2.0)), -1.0 / (2.0 * Math.Sqrt(2.0)) );
            Point2D C = new Point2D(Sqrt3 / (2.0 * Math.Sqrt(2.0)), -1.0 / (2.0 * Math.Sqrt(2.0)) );
            double radius = (A - B).R;

            AlignToArc AlignAB = new AlignToArc(C, radius, A, B);
            AlignToArc AlignBC = new AlignToArc(A, radius, B, C);
            AlignToArc AlignAC = new AlignToArc(B, radius, C, A);

            m_net.SetNeighbors();

            //align arcs
            m_net.AlignEdge(m_net[full, full], m_net[full, 0], AlignAC);
            m_net.AlignEdge(m_net[0, 0], m_net[full, full], AlignAB);
            m_net.AlignEdge(m_net[0, 0], m_net[full, 0], AlignBC);

            //align points
            m_net[0, 0].Alignment = new AlignFixed(B);
            m_net[full, full].Alignment = new AlignFixed(A);
            m_net[full, 0].Alignment = new AlignFixed(C);
        }
        //good to go
        private void Hexagon2Circle()
        {
            int full = (m_net.Size - 1);
            int third = m_net.Size / 3;
            int twothirds = m_net.Size * 2 / 3;

            if (m_bFirstPass)
            {
                m_net = new TriangularNet(m_net.Size);
                for (int i = 0; i < m_net.Size; i++)
                {
                    for (int j = 0; j < m_net.Size; j++)
                    {
                        if (m_net[i, j] != null)
                        {
                            m_net[i, j].Position *= 3.0 / m_net.Size;
                            m_net[i, j].Position += new Point2D(-2.0, -1.0);
                        }
                    }
                }
            }

            //zero out what we don't need
            for (int i = 0; i < m_net.Size; i++)
            {
                for (int j = 0; j < m_net.Size; j++)
                {
                    if (m_net[i, j] != null)
                    {
                        if (i < j ||           // remove top half of triangle
                            i < third ||       // clip one corner
                            j > twothirds ||    // clip second corner
                            i > j + twothirds ) // clip third corner
                        {
                            m_net[i, j] = null;
                        }
                    }
                }
            }

            m_net.SetNeighbors();

            //align arcs
            AlignToArc AlignToCircle = new AlignToArc(Point2D.Origin, 1.0);

            m_net.AlignEdge(m_net[twothirds, twothirds], m_net[full, twothirds], AlignToCircle);
            m_net.AlignEdge(m_net[full, twothirds], m_net[full, third], AlignToCircle);
            m_net.AlignEdge(m_net[full, third], m_net[twothirds, 0], AlignToCircle);
            m_net.AlignEdge(m_net[twothirds, 0], m_net[third, 0], AlignToCircle);
            m_net.AlignEdge(m_net[third, 0], m_net[third, third], AlignToCircle);
            m_net.AlignEdge(m_net[third, third], m_net[twothirds, twothirds], AlignToCircle);

            //Align Points
            m_net[full, third].Alignment = new AlignFixed( Point2D.FromPolar(1.0, 0.0 * Math.PI) );
            m_net[full, twothirds].Alignment = new AlignFixed( Point2D.FromPolar(1.0, (1.0/3.0) * Math.PI) );
            m_net[twothirds, twothirds].Alignment = new AlignFixed( Point2D.FromPolar(1.0, (2.0/3.0) * Math.PI) );
            m_net[third, third].Alignment = new AlignFixed( Point2D.FromPolar(1.0, Math.PI) );
            m_net[third, 0].Alignment = new AlignFixed( Point2D.FromPolar(1.0, (4.0/3.0) * Math.PI) );
            m_net[twothirds, 0].Alignment = new AlignFixed( Point2D.FromPolar(1.0, (5.0/3.0) * Math.PI) );
        }
Beispiel #9
0
 public NetMap(System.Drawing.Size size, DMSImage source, Color Background, Net net, XfrmMode mode)
     : this(size, source, Background, net)
 {
     m_Xfrm = mode;
 }
Beispiel #10
0
 //private static Rotation tweak = new Rotation();
 public NetMap( System.Drawing.Size size, DMSImage source, Color Background, Net net )
     : base(size, source, Background)
 {
     m_Net = net;
 }
Beispiel #11
0
        static void Main(string[] args)
        {
            if (args.Count<string>() != 2)
            {
                System.Console.Write("Usage: conformer.exe <input image> <output net>\n");
                return;
            }

            Net net = new Net(63);
            ConformShapes shaper = new ConformShapes(net,
                //ConformShapeType.Bitmap2Rectangle, args[0], 1.0);
                //ConformShapeType.Bitmap2Circle, args[0]);
                //ConformShapeType.Diamond2Lens);
                //ConformShapeType.Triangle2Rouleaux);
                //ConformShapeType.Hexagon2Circle);
                //ConformShapeType.Square2Paralellogram);
                //ConformShapeType.Parallelogram2Square);
                //ConformShapeType.Triangle, Math.Sqrt(3.0));
                //ConformShapeType.Square2Circle);
                //ConformShapeType.Square2Rectangle, 2.0);
                ConformShapeType.HalfCross2Circle1);
                //ConformShapeType.Square2Heart);
                //ConformShapeType.Square2Oval);
                //ConformShapeType.HyperbolizeExample);
                //ConformShapeType.XtoCircle);
                //ConformShapeType.Square2Triangle);
            net = shaper.ApplyShape();

            char ch = 's';
            double oldenergy = net.Energy;
            bool bHillClimb = false;
            net.Save();
            while (ch != 'q')
            {
                System.Console.Write( ch.ToString() + "; " + oldenergy.ToString() + "; (" + net.Size.ToString() + "x" + net.Size.ToString() + "); " + net.Count.ToString() + " pts\n");
                for (long i = 0; i < 10000; i++)
                {
                    int col = r.Next(net.Size);
                    int row = r.Next(net.Size);
                    switch (ch)
                    {
                        case 'q': break;
                        case 'h': bHillClimb = !bHillClimb; ch = 's'; break;
                        case 'H': bHillClimb = !bHillClimb; ch = 'j'; break;
                        case 'E': if (net[col, row] != null) net[col, row].Stretch(true); break;
                        case 'e': if (net[col, row] != null) net[col, row].Stretch(false); break;
                        case 'j': if (net[col, row] != null) net[col, row].Jitter(1.0 / 50); break;
                        case 's': if (net[col, row] != null) net[col, row].Step(); break;
                        case 'w': net.Write(args[1], false); ch = 's'; break;
                        case 'd': net.DoubleResolution(); shaper.ApplyShape(); ch = 'w'; break;
                        default: ch = 's'; break;
                    }
                }

                if( bHillClimb )
                {
                    double newenergy = net.Energy;
                    if (newenergy > oldenergy)
                        net.Restore();
                }

                net.Save();
                oldenergy = net.Energy;
                if (System.Console.KeyAvailable) ch = System.Console.ReadKey().KeyChar;
            }

            net.Write(args[1], true);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            String filenameout = args[0];
            DMSImage ImageOut;

            if (args.Count() < 1)
            {
                Console.WriteLine("Usage: scratchrenderer.exe <filein>");
                return;
            }

            #if true //load source into ImageIn
            DMSImage ImageIn;
            try
            {
                ImageIn = new DMSImage(args[0]);
            }
            catch
            {
                Console.WriteLine("Invalid arguments");
                return;
            }

            String fileextension = args[0].Substring( args[0].Length - 4 );
            filenameout = args[0].Substring(0,args[0].Length-4);
            filenameout += "_" + fileextension;
            #elif false
            int[] weights = {
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                0xd0, 0xeb, 0xd4, 0xff, 0x8a, 0x69, 0xff, 0x84, 0x9f, 0xaf,
                0xff, 0xd2, 0xf7, 0xfa, 0xf1, 0xf0, 0xff, 0xdd, 0x8e, 0x57,
                0xff, 0x4a, 0x4e, 0x5e, 0x7d, 0xff, 0x8c, 0xa3, 0xff, 0xb2,
                0xb9, 0xd4, 0xd7, 0xff, 0xfa, 0xf7, 0xdc, 0xff, 0xbb, 0x84,
                0x52, 0x3f, 0x3d, 0xff, 0x45, 0x54, 0x55, 0x40, 0x40, 0x40,
                0x40, 0xff, 0x40, 0x40, 0xbe, 0xff, 0xcb, 0xdc, 0xe9, 0xe0,
                0xff, 0xb7, 0xb8, 0x5d, 0xff, 0x3b, 0x2c, 0x25, 0x27, 0x36,
                0xff, 0x40, 0x40, 0x40, 0x40, 0x40, 0xff, 0x40, 0x40, 0x40,
                0x40, 0x40, 0x40, 0x40, 0xff, 0xba, 0xbf, 0xae, 0xff, 0x82,
                0x55, 0x37, 0x27, 0xff, 0x17, 0x17, 0x1c, 0xff, 0x40, 0x40,
                0x40, 0x40, 0x40, 0x40, 0xff, 0x40, 0x40, 0x40, 0xff, 0x40,
                0x40, 0x40, 0x40, 0xab, 0x9a, 0xff, 0x7a, 0x59, 0x40, 0x2a,
                0xff, 0x1a, 0x19, 0x17, 0xff, 0x40, 0x40, 0x40, 0x40, 0x40,
                0x40, 0xff, 0x40, 0x40, 0x40, 0xff, 0x40, 0x40, 0x40, 0x40,
                0x40, 0x7c, 0xFF, 0x4d, 0x3c, 0x2e, 0x20, 0xFF, 0x18, 0x40,
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

            new Texter("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 256, -1).getImage().Save(filenameout);
            //            new Texter("     " +
            //                       "JOY TO THE WORLD THE LORD IS COME " +
            //                       "LET EARTH RECEIVE HER KING " +
            //                       "LET EVERY HEART PREPARE HIM ROOM " +
            //                       "AND HEAVEN AND NATURE SING " +
            //                       "AND HEAVEN AND NATURE SING " +
            //                       "AND HEAVEN AND HEAVEN AND NATURE SING" +
            //                       "     ", weights, 256, 37274 ).getImage().Save(filenameout);
            return;
            #endif

            //stretch radius: layout nice
            //Mosaicker finalmosaic = new Mosaicker(ImageIn.Width, ImageIn.Height, 4, 3, 20);
            //for (int sym = 1; sym <= 12; sym++) finalmosaic.AddRenderer(new StretchRadius(ImageIn, sym), (sym-1) %4, (sym-1) /4);
            //ImageOut = new DMSImage(new SuperSampler(finalmosaic, 2));

            //ImageOut = new DMSImage(new ComplexMap(new Size(300, 300), ImageIn, Color.Gray));

            // ImageOut = new DMSImage(new Bookball(new Size(9000, 6000), ImageIn, Color.Gray, null/*new DMSImage(args[1]) - overlay image*/ ) );

            //ImageOut = new DMSImage(new Filler(ImageIn));

            /*
            ImageOut = new DMSImage(new TestPattern(new Size(400, 200),
                                                             Color.SkyBlue,
                                                             Color.Black,
                                                             TestPatternType.MercatorCheckerBoardPlane,
                                                             0, 0));
             */

            //ImageOut = new DMSImage(new SpiralText(ImageIn, int.Parse(args[1])));

            // ImageOut = new DMSImage( new ConformalDoubler(ImageIn) );

            //ImageOut = new DMSImage(new Tetrahedral(ImageIn)); // black and white
            //ImageOut = new DMSImage(new Icosahedral()); // black and white
            //ImageOut = new DMSImage(new Octohedral(ImageIn)); // black and white

            //ImageOut = new DMSImage( new Equirect2Ortho( new Icosahedral(ImageIn), 3300) );
            // ImageOut = new DMSImage(new Icosahedral(ImageIn));

            // ImageOut = new DMSImage( new Equirect2Ortho(ImageIn,3300) );

            //List<Point2D> vertices = new List<Point2D>();
            //vertices.Add(new Point2D(384, 526));
            //vertices.Add(new Point2D(736, 176));
            //vertices.Add(new Point2D(816, 830));
            //ImageOut = new DMSImage(new SuperSampler(new Equirect2Ortho(new FundDomain(vertices), 3300), 3));

            //ImageOut = new DMSImage(new StretchRadius(ImageIn, 2));

            //ImageOut = new DMSImage(
            //               new SuperSampler(
            //                   new Droste( ImageIn,
            //                               new Point2D(500, 1500),
            //                               1654,
            //                               4000,
            //                               new Size(15000, 15000),
            //                               new Point2D(7500, 7500),
            //                               1.07,
            //                               Color.Black),
            //                   3 ) );

            //ImageOut = new Palette(new DMSImage(args[1]), ImageIn);
            //new Stars(5000, args[0], 0.004).Save("Stars.bmp");

            // ImageOut = new DMSImage(new CubeFace(ImageIn));

            #if false //octahedron
            Mosaicker finalmosaic = new Mosaicker(1500, 1500, 3, 2, 60);
            finalmosaic.AddRenderer(new OctahedronUnit(new Size(1500, 1500), ImageIn, Point3D.ZAxis, Point3D.XAxis), 0, 0);
            finalmosaic.AddRenderer(new OctahedronUnit(new Size(1500, 1500), ImageIn, -Point3D.ZAxis, Point3D.XAxis), 0, 1);
            finalmosaic.AddRenderer(new OctahedronUnit(new Size(1500, 1500), ImageIn, Point3D.YAxis, Point3D.XAxis), 1, 0);
            finalmosaic.AddRenderer(new OctahedronUnit(new Size(1500, 1500), ImageIn, -Point3D.YAxis, Point3D.XAxis), 1, 1);
            finalmosaic.AddRenderer(new OctahedronUnit(new Size(1500, 1500), ImageIn, Point3D.XAxis, Point3D.YAxis), 2, 0);
            finalmosaic.AddRenderer(new OctahedronUnit(new Size(1500, 1500), ImageIn, -Point3D.XAxis, Point3D.YAxis), 2, 1);
            ImageOut = new DMSImage(finalmosaic);
            #endif

            //DMSImage ImageOut = new DMSImage(new Stereographic2Equirectangular(ImageIn, 1500));

            //DMSImage ImageOut = new DMSImage(new UnwrapMatroshka(ImageIn));

            #if false //draw net
            //drawnet
            Net net = new Net(args[0]);
            filenameout = args[0].Substring(0,args[0].Length-4) + ".png";
            DMSImage ImageOut = new DMSImage(new SuperSampler(new DrawNet(net),3));
            #endif
            ImageOut.Save(filenameout);
        }
Beispiel #13
0
 public InvNetMap( System.Drawing.Size size, DMSImage source, Color Background, Net net, RectangleF Window )
     : base(size, source, Background)
 {
     m_Window = Window;
     m_Net = net;
 }