Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="sceneManager"></param>
 /// <param name="layerParams"></param>
 public ObjectLayer(SceneManager sceneManager, LayerParams layerParams)
     : base(layerParams)
 {
     _sceneManager = sceneManager;
     _polygonList = new List<Polygon>();
     m_layerRegion = new BBOXF(256000, 256000, 256512, 256512);
 }
Esempio n. 2
0
 public void Extends(BBOXF 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);
 }
Esempio n. 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="sceneManager"></param>
 public ObjectLayer(SceneManager sceneManager, string layerName, Size cacheSize)
     : base(layerName,cacheSize)
 {
     _sceneManager = sceneManager;
     _polygonList = new List<Polygon>();
     //TODO: layer region should be updated according to the real region change
     m_layerRegion = new BBOXF(256000, 256000, 256512, 256512);
 }
Esempio n. 4
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;
        }
Esempio n. 5
0
        public Bitmap GetRegionByBitmap(BBOXF spatialRegion, Size size)
        {
            m_log.Info(string.Format("[Map Service]: Request region {0}", spatialRegion.ToString()));
            Bitmap regionBMP = new Bitmap(size.Width, size.Height);

            lock (m_imgCache)
            {
                // Get the area from image cache
                BBOX imgRegion = CRS.Cartes2Image(spatialRegion, m_imgCache.Size, m_layerRegion);
                Rectangle srcRect = imgRegion.ToRectangle();
                Rectangle destRect = new Rectangle(0,0,size.Width - 1, size.Height - 1);
                Graphics gfx = Graphics.FromImage((Image)regionBMP);
                gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
                gfx.DrawImage(m_imgCache, destRect, srcRect,  GraphicsUnit.Pixel);
                gfx.Dispose();
            }

            return regionBMP;
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
        public static PointF[] Cartes2Image(PointF[] cartesPoints, Size imgSize, BBOXF spatialRegion)
        {
            PointF[] imgPoints = new PointF[cartesPoints.Length];
            Matrix mat = new Matrix(3, 3);
            mat[0, 0] = 1.0 * imgSize.Width / (spatialRegion.Width); mat[0, 1] = 0; mat[0, 2] = -1.0 * imgSize.Width * spatialRegion.MinX / (spatialRegion.Width);
            mat[1, 0] = 0; mat[1, 1] = -1.0 * imgSize.Height / spatialRegion.Height; mat[1, 2] = 1.0 * spatialRegion.MaxY * imgSize.Height / spatialRegion.Height;
            mat[2, 0] = 0; mat[2, 1] = 0; mat[2, 2] = 1;

            for (int i = 0; i < cartesPoints.Length; i++)
            {
                Matrix cPt = new Matrix(3, 1);
                cPt[0, 0] = cartesPoints[i].X;
                cPt[1, 0] = cartesPoints[i].Y;
                cPt[2, 0] = 1;
                Matrix iPt = Matrix.MatMul(mat, cPt);
                imgPoints[i] = new PointF((float)iPt[0, 0], (float)iPt[1, 0]);
            }

            return imgPoints;
        }
Esempio n. 8
0
 Bitmap WMSGetMap(BBOXF bbox, int height, int width, String[] layers)
 {
     Bitmap compositeBMP = new Bitmap(width, height);
     Graphics gf = Graphics.FromImage(compositeBMP);
     for (int i = 0; i < layers.Length; i++)
     {
         Bitmap layerBatch = layerDict[layers[i]].GetRegionByBitmap(bbox, new Size(width, height));
         gf.CompositingQuality = CompositingQuality.GammaCorrected;
         gf.CompositingMode = CompositingMode.SourceOver;
         gf.DrawImage(layerBatch, new Rectangle(0,0,height,width));
         layerBatch.Dispose();
     }
     return compositeBMP;
 }
Esempio n. 9
0
        public string owsHandler(string request, string path, string param,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            switch (httpRequest.QueryString["SERVICE"])
            {
                case "WMS":
                    if (httpRequest.QueryString["REQUEST"] == "GetMap")
                    {
                        httpResponse.ContentType = "image/png";

                        //parse query string
                        string[] layers = httpRequest.QueryString["LAYERS"].Split(',');
                        BBOXF bbox = new BBOXF(httpRequest.QueryString["BBOX"]);
                        int height = Int32.Parse(httpRequest.QueryString["HEIGHT"]);
                        int width = Int32.Parse(httpRequest.QueryString["WIDTH"]);
                        string format = httpRequest.QueryString["FORMAT"];

                        //get queryImg
                        Bitmap queryImg = WMSGetMap(bbox, height, width, layers);
                        //convert bitmap to base64 string
                        System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        queryImg.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        queryImg.Dispose();
                        byte[] byteImage = stream.ToArray();
                        stream.Dispose();
                        return Convert.ToBase64String(byteImage);
                    }
                    else if (httpRequest.QueryString["REQUEST"] == "GetCapabilities")
                    {
                        httpResponse.ContentType = "text/xml";
                        string capDes = "";
                        TextReader textReader = new StreamReader("Capability.xml");
                        capDes = textReader.ReadToEnd();
                        textReader.Close();
                        return capDes;
                    }
                    else
                    {
                        return "Sorry, the request method is not supported by this service.";
                    }
                case "WFS":
                    if (httpRequest.QueryString["REQUEST"] == "GetFeature")
                    {
                        if ((httpRequest.QueryString["TypeName"] == "agent"))
                        {
                            switch (httpRequest.QueryString["FORMAT"])
                            {
                                case "text":
                                    return m_agentLayer.GetFeaturesByText();
                                case "xml":
                                    return m_agentLayer.GetFeaturesByXML();
                            }
                        }
                        else
                            return "Query String is not supported";
                    }
                    break;
                default:
                    return "Unsupport Service";
            }
            return "Unsupport Service";
        }
Esempio n. 10
0
        protected override void updateLayer()
        {
            agentList.Clear();
            foreach (Scene scene in _sceneManager.Scenes)
            {
                //update layer region
                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);
                }

                //update agent list
                List<ScenePresence> scenePresenceList = scene.GetAvatars();
                foreach (ScenePresence scenePresence in scenePresenceList)
                {
                    Vector3 cartesPos = new Vector3();
                    cartesPos.X = scenePresence.AbsolutePosition.X + scene.RegionInfo.RegionLocX * 256;
                    cartesPos.Y = scenePresence.AbsolutePosition.Y + scene.RegionInfo.RegionLocY * 256;
                    cartesPos.Z = scenePresence.AbsolutePosition.Z;
                    AgentInfo tempAgent = new AgentInfo();
                    tempAgent.position = cartesPos;
                    tempAgent.name = scenePresence.Name;
                    agentList.Add(scenePresence.UUID, tempAgent);
                }
            }
        }
Esempio n. 11
0
        protected override Bitmap generateCacheBitmap(BBOXF spatialRegion, Size cacheSize)
        {
            Bitmap mapImg = new Bitmap(cacheSize.Width, cacheSize.Height);
            Graphics gfx = Graphics.FromImage(mapImg);
            Pen pen = new Pen(Color.Red);
            Brush brush = Brushes.Red;

            // draw agent position on the map
            foreach (var agent in agentList.Values)
            {
                PointF[] cartesPoints = new PointF[1];
                PointF[] imgPoints = null;
                cartesPoints[0].X = agent.position.X; cartesPoints[0].Y = agent.position.Y;
                imgPoints = CRS.Cartes2Image(cartesPoints, cacheSize, spatialRegion);
                RectangleF rect = new RectangleF(imgPoints[0].X - 2, imgPoints[0].Y - 2, 20, 20);
                gfx.FillEllipse(brush, rect);
            }

            gfx.Dispose();
            pen.Dispose();
            return mapImg;
        }
Esempio n. 12
0
        protected override Bitmap generateCacheBitmap(BBOXF spatialRegion, Size cacheSize)
        {
            Bitmap mapImg = new Bitmap(cacheSize.Width, cacheSize.Height);
            Graphics gs = Graphics.FromImage(mapImg);
            Pen pen = new Pen(Color.Blue, 3);

            foreach (var polygon in _polygonList)
            {
                PointF[] cartesPoints = polygon.ToPointFArray();
                PointF[] imgPoints = CRS.Cartes2Image(cartesPoints, cacheSize, spatialRegion);
                gs.DrawPolygon(pen, imgPoints);
            }

            gs.Dispose();
            pen.Dispose();
            return mapImg;
        }
Esempio n. 13
0
 protected abstract Bitmap generateCacheBitmap(BBOXF spatialRegion, Size cacheSize);