Ejemplo n.º 1
0
        public MapSdk(string directory)
        {
            #region initialize props

            CollectionColorArea      = new CollectionAreaColor();
            CollectionColorMountains = new CollectionAreaColorMountains();

            CollectionAreaItems           = new CollectionAreaItems();
            CollectionAreaItemsCoasts     = new CollectionAreaTransitionItemCoast();
            CollectionAreaTransitionItems = new CollectionAreaTransitionItems();


            CollectionAreaTexture                = new CollectionAreaTexture();
            CollectionAreaTransitionTexture      = new CollectionAreaTransitionTexture();
            CollectionAreaTransitionCliffTexture = new CollectionAreaTransitionCliffTexture();

            #endregion

            #region initialize Factories

            Factories = new List <Factory>();

            FactoryColor = new FactoryColorArea(Path.Combine(directory, "color_area.txt"));

            Factories.Add(FactoryColor);

            FactoryCoast = new FactoryCoast(Path.Combine(directory, "color_coast.txt"));

            Factories.Add(FactoryCoast);

            FactoryMountains = new FactoryMountains(Path.Combine(directory, "color_mntn.txt"));

            Factories.Add(FactoryMountains);

            FactoryItems = new FactoryItems(Path.Combine(directory, "items.txt"));

            Factories.Add(FactoryItems);

            FactoryItemCoasts = new FactoryItemCoasts(Path.Combine(directory, "ite_tex_coast.txt"));

            Factories.Add(FactoryItemCoasts);

            FactorySmoothItems = new FactorySmoothItems(Path.Combine(directory, "items_smooth.txt"));

            Factories.Add(FactorySmoothItems);

            FactoryTextureArea = new FactoryTextureArea(Path.Combine(directory, "texture_area.txt"));

            Factories.Add(FactoryTextureArea);

            FactoryTextureSmooth = new FactoryTextureSmooth(Path.Combine(directory, "texture_smooth.txt"));

            Factories.Add(FactoryTextureSmooth);

            FactoryCliff = new FactoryCliff(Path.Combine(directory, "texture_cliff.txt"));

            Factories.Add(FactoryCliff);

            #endregion
        }
Ejemplo n.º 2
0
        public MapSdk()
        {
            #region initialize props

            CollectionColorArea      = new CollectionAreaColor();
            CollectionColorMountains = new CollectionAreaColorMountains();
            CollectionColorCoast     = new CollectionAreaColor();

            CollectionAreaItems           = new CollectionAreaItems();
            CollectionAreaItemsCoasts     = new CollectionAreaTransitionItemCoast();
            CollectionAreaTransitionItems = new CollectionAreaTransitionItems();


            CollectionAreaTexture                = new CollectionAreaTexture();
            CollectionAreaTransitionTexture      = new CollectionAreaTransitionTexture();
            CollectionAreaTransitionCliffTexture = new CollectionAreaTransitionCliffTexture();

            #endregion
        }
Ejemplo n.º 3
0
        ///// <summary>
        ///// Just cache the bmp in ram
        ///// </summary>
        ///// <param name="location"></param>
        ///// <param name="altitude"> </param>
        //private void Cache(string location, bool altitude)
        //{
        //    using (var bitmap = new Bitmap(location))
        //    {

        //            BitmapColors = new Color[bitmap.Width*bitmap.Height];
        //            BitmapColors.Initialize();

        //             Lock the bitmap's bits.
        //            var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

        //            lock the bitmap bits
        //            BitmapData bmpData;

        //            bmpData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

        //             Get the address of the first line.
        //            var ptr = bmpData.Scan0;

        //             Declare an array to hold the bytes of the bitmap.
        //            var bytes = bmpData.Stride*bitmap.Height;
        //            var rgbValues = new byte[bytes];


        //             Copy the RGB values into the array.
        //            Marshal.Copy(ptr, rgbValues, 0, bytes);

        //            var stride = bmpData.Stride;

        //            for (var coulmn = bmpData.Height - 1; coulmn >= 0; coulmn--)
        //            {
        //                for (var row = 0; row < bmpData.Width; row++)
        //                {
        //                    BitmapColors[(coulmn * (bmpData.Width)) + row] = Color.FromRgb((rgbValues[(coulmn * stride) + (row * 3) + 2]),
        //                                                               rgbValues[(coulmn*stride) + (row*3) + 1],
        //                                                               rgbValues[(coulmn*stride) + (row*3)]);
        //                }
        //            }
        //    }
        //}


        /// <summary>
        ///
        /// </summary>
        /// <param name="collectionAreaColor"></param>
        /// <param name="location"></param>
        /// <exception>
        ///   <cref>ExecutionEngineException</cref>
        /// </exception>
        /// <returns></returns>
        public static AreaColor[] ProduceMap(CollectionAreaColor collectionAreaColor, string location)
        {
            AreaColor[] areaColors = null;
            using (var bitmap = new Bitmap(location))
            {
                areaColors = new AreaColor[bitmap.Width * bitmap.Height];

                // Lock the bitmap's bits.
                var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

                //lock the bitmap bits
                BitmapData bmpData;

                bmpData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

                // Get the address of the first line.
                var ptr = bmpData.Scan0;

                // Declare an array to hold the bytes of the bitmap.
                var bytes     = bmpData.Stride * bitmap.Height;
                var rgbValues = new byte[bytes];

                var list = new List <String>();
                // Copy the RGB values into the array.
                Marshal.Copy(ptr, rgbValues, 0, bytes);

                var stride = bmpData.Stride;

                for (var coulmn = bmpData.Height - 1; coulmn >= 0; coulmn--)
                {
                    for (var row = 0; row < bmpData.Width; row++)
                    {
                        areaColors[(coulmn * (bmpData.Width)) + row] =
                            collectionAreaColor.FindByByteArray(new[]
                        {
                            rgbValues[(coulmn * stride) + (row * 3) + 2],
                            rgbValues[(coulmn * stride) + (row * 3) + 1],
                            rgbValues[(coulmn * stride) + (row * 3)]
                        });

                        if (areaColors[(coulmn * (bmpData.Width)) + row] != null)
                        {
                            continue;
                        }

                        var str = "Color =" +
                                  System.Windows.Media.Color.FromRgb(
                            rgbValues[(coulmn * stride) + (row * 3) + 2],
                            rgbValues[(coulmn * stride) + (row * 3) + 1],
                            rgbValues[(coulmn * stride) + (row * 3)])
                                  + " not found.";

                        if (!list.Contains(str))
                        {
                            list.Add(str);
                        }
                    }
                }

                if (list.Count > 0)
                {
                    var message = list.Aggregate("", (current, str) => current + (str + '\n'));
                    throw new Exception(message);
                }
            }

            return(areaColors);
        }
Ejemplo n.º 4
0
        public static AreaColor[] ColorsFromBitmap(CollectionAreaColor collectionAreaColor, string originalLocation, int XMax, int YMax)
        {
            var original = new Bitmap(originalLocation);

            if (original.Height != YMax || original.Width != XMax)
            {
                throw new Exception("Terrain Bitmap has wrong dimentions");
            }
            var areaColors = new AreaColor[original.Height * original.Width];
            var list       = new List <string>();

            using (original)
            {
                unsafe
                {
                    //lock the original bitmap in memory
                    BitmapData originalData = original.LockBits(
                        new Rectangle(0, 0, original.Width, original.Height),
                        ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);


                    //set the number of bytes per pixel
                    const int pixelSize = 3;


                    for (int y = originalData.Height - 1; y >= 0; y--)
                    {
                        //get the data from the original image
                        byte *oRow = (byte *)originalData.Scan0 + (y * originalData.Stride);

                        for (int x = 0; x < originalData.Width; x++)
                        {
                            var red   = oRow[x * pixelSize + 2];
                            var green = oRow[x * pixelSize + 1];
                            var blue  = oRow[x * pixelSize];

                            var area =
                                collectionAreaColor.FindByByteArray(new[]
                            {
                                red,
                                green,
                                blue
                            });
                            areaColors[(y * (originalData.Width)) + x] = area;
                            if (area != null)
                            {
                                continue;
                            }


                            var str = "Color =" +
                                      System.Windows.Media.Color.FromRgb(
                                red,
                                green,
                                blue)
                                      + " not found.";

                            if (!list.Contains(str))
                            {
                                list.Add(str);
                            }
                        }
                    }

                    original.UnlockBits(originalData);
                }
                if (list.Count > 0)
                {
                    var message = list.Aggregate("", (current, str) => current + (str + '\n'));
                    throw new Exception(message);
                }
                return(areaColors);
            }
        }
 public FactoryColorArea(string location) : base(location)
 {
     Areas = new CollectionAreaColor();
 }