Exemplo n.º 1
0
 public void Extends(BBOX bbox)
 {
     MinX = Math.Min(MinX, bbox.MinX);
     MinY = Math.Min(MinY, bbox.MinY);
     MaxX = Math.Max(MaxX, bbox.MaxX);
     MaxY = Math.Max(MaxY, bbox.MaxY);
 }
Exemplo n.º 2
0
        /// <summary>
        ///  replace the specified region of source bitmap with part bitmap
        /// </summary>
        public static void Replace(Bitmap source, Bitmap part, BBOX region)
        {
            if (part.Height != region.Height || part.Width != region.Width)
                throw new SizeNotMatchException();

            for (int i = 0; i < region.Height; i++)
                for (int j = 0; j < region.Width; j++)
                {
                    Color color = part.GetPixel(j,i);
                    source.SetPixel(region.MinX + j, region.MinY + i, color);
                }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cartesBbox"></param>
        /// <param name="imgOrigin">the cartes coordinate of img origin</param>
        /// <param name="xRes">resolution of x-axis, defined as 1 pixel/spatial_width</param>
        /// <param name="yRes">resolution of y-axis, defined as 1 pixel/spatial_height</param>
        /// <returns></returns>
        public static BBOX Cartes2Image(BBOXF cartesBbox, Size imgSize, BBOXF  spatialRegion)
        {
            PointF[] points = new PointF[2];
            points[0] = new PointF(cartesBbox.MinX, cartesBbox.MinY);
            points[1] = new PointF(cartesBbox.MaxX, cartesBbox.MaxY);
            PointF[] imgPoints = Cartes2Image(points, imgSize, spatialRegion);

            BBOX imgBbox = new BBOX();
            imgBbox.MinX = (int)Math.Floor(imgPoints[0].X);
            imgBbox.MinY = (int)Math.Floor(imgPoints[1].Y);
            imgBbox.MaxX = (int)Math.Floor(imgPoints[1].X - ROUNDERROR);
            imgBbox.MaxY = (int)Math.Floor(imgPoints[0].Y - ROUNDERROR);

            return imgBbox;
        }
Exemplo n.º 4
0
        protected override Bitmap generateCacheBitmap(BBOXF spatialRegion, Size cacheSize)
        {
            foreach (Scene scene in _sceneManager.Scenes)
            {
                int x = ((int)scene.RegionInfo.RegionLocX) * 256;
                int y = ((int)scene.RegionInfo.RegionLocY) * 256;
                if (m_layerRegion == null)
                {
                    m_layerRegion = new BBOXF(x, y, x + 256, y + 256);
                }
                else
                {
                    BBOXF newBBox = new BBOXF(x, y, x + 256, y + 256);
                    m_layerRegion.Extends(newBBox);
                }
            }

            try
            {
                //TODO add resolution
                BBOX imgMapBBox = new BBOX(0, 0, (int)Math.Floor(m_layerRegion.Width - CRS.ROUNDERROR), (int)Math.Floor(m_layerRegion.Height - CRS.ROUNDERROR));
                Bitmap mapImg = new Bitmap(imgMapBBox.Width, imgMapBBox.Height);

                foreach (Scene scene in _sceneManager.Scenes)
                {
                    int x = (int)scene.RegionInfo.RegionLocX;
                    int y = (int)scene.RegionInfo.RegionLocY;

                    BBOX imgRegionBBox = CRS.Cartes2Image(new BBOXF(x * 256, y * 256, x * 256 + 256, y * 256 + 256),
                        mapImg.Size, m_layerRegion);
                    Bitmap regionImg = ImageToolBox.CreateBitmapFromMap(scene.Heightmap);
                    ImageToolBox.Replace(mapImg, regionImg, imgRegionBBox);
                }
                return mapImg;
            }
            catch (Exception e)
            {
                m_log.Info("Terrain generation failed!");
                m_log.Info("Exception is:" + e.ToString());
                return null;
            }
        }