Exemplo n.º 1
0
 /// <summary>
 /// Initialize graphics objects
 /// </summary>
 /// <param name="drawArgs"></param>
 public override void Initialize(MFW3D.DrawArgs drawArgs)
 {
     base.Initialize(drawArgs);
     lastUpdatelat = lastUpdatelon = MFW3D.Angle.Zero;
     lastUpdatealt = 0.0;
     m_needsupdate = true;
     Image         = new System.Drawing.Bitmap(Directory.GetParent(Application.ExecutablePath) + "\\Plugins\\Flickr\\flickr.ico");
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method updates the Icons to reflect only those in view
        /// </summary>
        /// <param name="drawArgs"></param>
        public override void Update(MFW3D.DrawArgs drawArgs)
        {
            base.Update(drawArgs);

            double distance = MFW3D.World.ApproxAngularDistance(drawArgs.WorldCamera.Latitude,
                                                                drawArgs.WorldCamera.Longitude, this.lastUpdatelat, this.lastUpdatelon).Degrees;
            double altchange = Math.Abs(this.lastUpdatealt - drawArgs.WorldCamera.Altitude);


            if (distance > 10 || altchange < 10000.0 || m_needsupdate)
            {
                this.lastUpdatelon = drawArgs.WorldCamera.Longitude;
                this.lastUpdatelat = drawArgs.WorldCamera.Latitude;
                this.lastUpdatealt = drawArgs.WorldCamera.Altitude;
                this.m_needsupdate = false;

                double viewNorth = drawArgs.WorldCamera.Latitude.Degrees + drawArgs.WorldCamera.TrueViewRange.Degrees * 0.5;
                double viewSouth = drawArgs.WorldCamera.Latitude.Degrees - drawArgs.WorldCamera.TrueViewRange.Degrees * 0.5;
                double viewWest  = drawArgs.WorldCamera.Longitude.Degrees - drawArgs.WorldCamera.TrueViewRange.Degrees * 0.5;
                double viewEast  = drawArgs.WorldCamera.Longitude.Degrees + drawArgs.WorldCamera.TrueViewRange.Degrees * 0.5;



                //Need lock on the folder
                lock (this)
                {
                    //TODO: Implement temporary caching and redownload on request
                    PhotoCollection allPhotos = GetPhotoCollection(viewWest, viewSouth,
                                                                   viewEast, viewNorth);

                    this.RemoveAll();
                    foreach (Photo photo in allPhotos)
                    {
                        double photolat          = Convert.ToDouble(photo.Latitude);
                        double photolon          = Convert.ToDouble(photo.Longitude);
                        MFW3D.Renderable.Icon ic = new MFW3D.Renderable.Icon(photo.Title, photolat
                                                                             , photolon);
                        ic.Image  = Image;
                        ic.Width  = 16;
                        ic.Height = 16;
                        //ic.MinimumDisplayDistance = 100000;
                        //WorldWind.Renderable.ScreenOverlay overlay
                        //= new WorldWind.Renderable.ScreenOverlay(ic.Name,0.0f,0.0f,photo.ThumbnailUrl);
                        //ic.AddOverlay(overlay);
                        ic.isSelectable = true;
                        ic.Description  = "<img src=\"" + photo.ThumbnailUrl + "\"/><br>" +
                                          photo.License + "<br>" +
                                          photo.DateTaken;
                        double distanceToIcon = Vector3.Length(ic.Position - drawArgs.WorldCamera.Position);

                        //If Camera is far render as icon
                        //if(ic.MinimumDisplayDistance < distanceToIcon)
                        this.Add(ic);
                        //if Camera is near render as textured polygon

                        /*
                         * else
                         * {
                         *  Point3d[] lineends = new Point3d[2];
                         *  lineends[0].X = photolon - 0.1;
                         *  lineends[0].Y = photolat - 0.1;
                         *  lineends[0].Z = 1000;
                         *  lineends[1].X = photolon + 0.1;
                         *  lineends[1].Y = photolat + 0.1;
                         *  lineends[1].Z = 1000;
                         *
                         *  WorldWind.LineFeature line = new LineFeature(photo.Title,
                         *      m_world,lineends,photo.ThumbnailUrl);
                         *  line.AltitudeMode = AltitudeMode.RelativeToGround;
                         *  line.DistanceAboveSurface = 0;
                         *  line.Extrude = true;
                         *
                         *  this.Add(line);
                         * }
                         */

                        //Console.WriteLine("Photos title is " + photo.Title + photo.Latitude + photo.Longitude);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Update(DrawArgs drawArgs)
        {
            try
            {
                double centerLatitude  = 0.5 * (m_geographicBoundingBox.North + m_geographicBoundingBox.South);
                double centerLongitude = 0.5 * (m_geographicBoundingBox.West + m_geographicBoundingBox.East);
                double tileSize        = m_geographicBoundingBox.North - m_geographicBoundingBox.South;

                if (!m_Initialized)
                {
                    if (drawArgs.WorldCamera.ViewRange * 0.5f < Angle.FromDegrees(ShapeTileArgs.TileDrawDistance * tileSize) &&
                        MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude),
                                                     drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) < Angle.FromDegrees(ShapeTileArgs.TileSpreadFactor * tileSize * 1.25f) &&
                        drawArgs.WorldCamera.ViewFrustum.Intersects(BoundingBox)
                        )
                    {
                        Initialize(drawArgs);
                    }
                }

                if (m_Initialized)
                {
                    if (m_LastUpdate < m_parentProjectedLayer.LastUpdate)
                    {
                        UpdateImageLayers(drawArgs);
                    }

                    if (m_NwImageLayer != null)
                    {
                        m_NwImageLayer.Update(drawArgs);
                    }
                    if (m_NeImageLayer != null)
                    {
                        m_NeImageLayer.Update(drawArgs);
                    }
                    if (m_SwImageLayer != null)
                    {
                        m_SwImageLayer.Update(drawArgs);
                    }
                    if (m_SeImageLayer != null)
                    {
                        m_SeImageLayer.Update(drawArgs);
                    }

                    if (
                        drawArgs.WorldCamera.ViewRange < Angle.FromDegrees(ShapeTileArgs.TileDrawDistance * tileSize) &&
                        MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude),
                                                     drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) < Angle.FromDegrees(ShapeTileArgs.TileSpreadFactor * tileSize) &&
                        drawArgs.WorldCamera.ViewFrustum.Intersects(BoundingBox)
                        )
                    {
                        if (m_NorthEastChild == null && m_NorthWestChild == null && m_SouthEastChild == null && m_SouthWestChild == null)
                        {
                            ComputeChildren(drawArgs);
                        }
                        else
                        {
                            if (m_NorthEastChild != null)
                            {
                                m_NorthEastChild.Update(drawArgs);
                            }

                            if (m_NorthWestChild != null)
                            {
                                m_NorthWestChild.Update(drawArgs);
                            }

                            if (m_SouthEastChild != null)
                            {
                                m_SouthEastChild.Update(drawArgs);
                            }

                            if (m_SouthWestChild != null)
                            {
                                m_SouthWestChild.Update(drawArgs);
                            }
                        }
                    }
                    else
                    {
                        if (m_NorthWestChild != null)
                        {
                            m_NorthWestChild.Dispose();
                            m_NorthWestChild = null;
                        }

                        if (m_NorthEastChild != null)
                        {
                            m_NorthEastChild.Dispose();
                            m_NorthEastChild = null;
                        }

                        if (m_SouthEastChild != null)
                        {
                            m_SouthEastChild.Dispose();
                            m_SouthEastChild = null;
                        }

                        if (m_SouthWestChild != null)
                        {
                            m_SouthWestChild.Dispose();
                            m_SouthWestChild = null;
                        }
                    }
                }

                if (m_Initialized)
                {
                    if (drawArgs.WorldCamera.ViewRange > Angle.FromDegrees(ShapeTileArgs.TileDrawDistance * tileSize * 1.5f) ||
                        MathEngine.SphericalDistance(Angle.FromDegrees(centerLatitude), Angle.FromDegrees(centerLongitude), drawArgs.WorldCamera.Latitude, drawArgs.WorldCamera.Longitude) > Angle.FromDegrees(ShapeTileArgs.TileSpreadFactor * tileSize * 1.5f))
                    {
                        if (this.Level != 0)
                        {
                            //{
                            Dispose();
                        }
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Exemplo n.º 4
0
        private void UpdateImageLayers(DrawArgs drawArgs)
        {
            try
            {
                m_LastUpdate = System.DateTime.Now;

                if (m_NwImageLayer != null)
                {
                    m_NwImageLayer.Dispose();
                }

                if (m_NeImageLayer != null)
                {
                    m_NeImageLayer.Dispose();
                }

                if (m_SwImageLayer != null)
                {
                    m_SwImageLayer.Dispose();
                }

                if (m_SeImageLayer != null)
                {
                    m_SeImageLayer.Dispose();
                }

                double centerLatitude  = 0.5 * (m_geographicBoundingBox.North + m_geographicBoundingBox.South);
                double centerLongitude = 0.5 * (m_geographicBoundingBox.West + m_geographicBoundingBox.East);

                m_NwImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, m_geographicBoundingBox.West, centerLongitude, drawArgs,
                                                  String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                null, //ShapeTile.CachePath,
                                                                "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                Level + 1,
                                                                2 * Row + 1,
                                                                2 * Col));

                m_NeImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, centerLongitude, m_geographicBoundingBox.East, drawArgs,
                                                  String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                null, //ShapeTile.CachePath,
                                                                "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                Level + 1,
                                                                2 * Row + 1,
                                                                2 * Col + 1));

                m_SwImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, m_geographicBoundingBox.West, centerLongitude, drawArgs,
                                                  String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                null, //ShapeTile.CachePath,
                                                                "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                Level + 1,
                                                                2 * Row,
                                                                2 * Col));

                m_SeImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, centerLongitude, m_geographicBoundingBox.East, drawArgs,
                                                  String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                null, //ShapeTile.CachePath,
                                                                "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                Level + 1,
                                                                2 * Row,
                                                                2 * Col + 1));

                if (m_NwImageLayer != null)
                {
                    m_NwImageLayer.Initialize(drawArgs);
                }
                if (m_NeImageLayer != null)
                {
                    m_NeImageLayer.Initialize(drawArgs);
                }
                if (m_SwImageLayer != null)
                {
                    m_SwImageLayer.Initialize(drawArgs);
                }
                if (m_SeImageLayer != null)
                {
                    m_SeImageLayer.Initialize(drawArgs);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Exemplo n.º 5
0
        private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath)
        {
            Bitmap   b = null;
            Graphics g = null;

            Renderable.ImageLayer imageLayer = null;
            GeographicBoundingBox geoBB      = new GeographicBoundingBox(north, south, west, east);
            int numberPolygonsInTile         = 0;

            FileInfo imageFile = new FileInfo(imagePath);

            if (!m_parentProjectedLayer.EnableCaching ||
                !imageFile.Exists
                )
            {
                if (m_parentProjectedLayer.LineStrings != null)
                {
                    for (int i = 0; i < m_parentProjectedLayer.LineStrings.Length; i++)
                    {
                        if (!m_parentProjectedLayer.LineStrings[i].Visible)
                        {
                            continue;
                        }

                        GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox();

                        if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                        {
                            continue;
                        }
                        else
                        {
                            if (b == null)
                            {
                                b = new Bitmap(
                                    m_parentProjectedLayer.TileSize.Width,
                                    m_parentProjectedLayer.TileSize.Height,
                                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            }

                            if (g == null)
                            {
                                g = Graphics.FromImage(b);
                            }

                            drawLineString(
                                m_parentProjectedLayer.LineStrings[i],
                                g,
                                geoBB,
                                b.Size
                                );

                            numberPolygonsInTile++;
                        }
                    }
                }

                if (m_parentProjectedLayer.Polygons != null)
                {
                    for (int i = 0; i < m_parentProjectedLayer.Polygons.Length; i++)
                    {
                        if (!m_parentProjectedLayer.Polygons[i].Visible)
                        {
                            continue;
                        }

                        GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox();

                        if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                        {
                            continue;
                        }
                        else
                        {
                            if (b == null)
                            {
                                b = new Bitmap(
                                    m_parentProjectedLayer.TileSize.Width,
                                    m_parentProjectedLayer.TileSize.Height,
                                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            }

                            if (g == null)
                            {
                                g = Graphics.FromImage(b);
                            }
                            drawPolygon(
                                m_parentProjectedLayer.Polygons[i],
                                g,
                                geoBB,
                                b.Size);

                            numberPolygonsInTile++;
                        }
                    }
                }
            }

            if (b != null)
            {
                System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0,
                                                                                     b.Width, b.Height),
                                                                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                                       System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                bool isBlank = true;
                unsafe
                {
                    int *srcPointer = (int *)srcInfo.Scan0;
                    for (int i = 0; i < b.Height; i++)
                    {
                        for (int j = 0; j < b.Width; j++)
                        {
                            int color = *srcPointer++;

                            if (((color >> 24) & 0xff) > 0)
                            {
                                isBlank = false;
                                break;
                            }
                        }

                        srcPointer += (srcInfo.Stride >> 2) - b.Width;
                    }
                }

                b.UnlockBits(srcInfo);
                if (isBlank)
                {
                    numberPolygonsInTile = 0;
                }
            }

            //	if(!m_parentProjectedLayer.EnableCaching)
            //	{
            string id = System.DateTime.Now.Ticks.ToString();

            if (b != null && numberPolygonsInTile > 0)
            {
                MemoryStream ms = new MemoryStream();
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                //must copy original stream into new stream, if not, error occurs, not sure why
                m_ImageStream = new MemoryStream(ms.GetBuffer());

                imageLayer = new MFW3D.Renderable.ImageLayer(
                    id,
                    m_parentProjectedLayer.World,
                    0,
                    m_ImageStream,
                    System.Drawing.Color.Black.ToArgb(),
                    (float)south,
                    (float)north,
                    (float)west,
                    (float)east,
                    1.0f                            //(float)m_parentProjectedLayer.Opacity / 255.0f
                    ,
                    m_parentProjectedLayer.World.TerrainAccessor);

                ms.Close();
            }

            /*	}
             *      else if(imageFile.Exists || numberPolygonsInTile > 0)
             *      {
             *              string id = System.DateTime.Now.Ticks.ToString();
             *
             *              if(b != null)
             *              {
             *                      MemoryStream ms = new MemoryStream();
             *                      b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
             *                      if(!imageFile.Directory.Exists)
             *                              imageFile.Directory.Create();
             *
             *                      //must copy original stream into new stream, if not, error occurs, not sure why
             *                      m_ImageStream = new MemoryStream(ms.GetBuffer());
             *                      ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName);
             *
             *                      ms.Close();
             *              }
             *
             *              imageLayer = new WorldWind.Renderable.ImageLayer(
             *                      id,
             *                      m_parentProjectedLayer.World,
             *                      0,
             *                      imageFile.FullName,
             *                      //System.Drawing.Color.Black.ToArgb(),
             *                      (float)south,
             *                      (float)north,
             *                      (float)west,
             *                      (float)east,
             *                      1.0f,//(float)m_parentProjectedLayer.Opacity / 255.0f,
             *                      m_parentProjectedLayer.World.TerrainAccessor);
             *
             *              imageLayer.TransparentColor = System.Drawing.Color.Black.ToArgb();
             *      }
             */
            if (b != null)
            {
                b.Dispose();
            }
            if (g != null)
            {
                g.Dispose();
            }

            b = null;
            g = null;

            //might not be necessary
            //GC.Collect();

            return(imageLayer);
        }
Exemplo n.º 6
0
 public override bool PerformSelectionAction(DrawArgs drawArgs)
 {
     return(false);
 }
Exemplo n.º 7
0
        private void RenderShaders(DrawArgs drawArgs, DynamicCloudFrame frame)
        {
            if (m_effect == null)
            {
                drawArgs.device.DeviceReset += new EventHandler(device_DeviceReset);
                device_DeviceReset(drawArgs.device, null);
            }

            Surface currentRenderTarget = drawArgs.device.GetRenderTarget(0);

            drawArgs.device.SetRenderTarget(0, s1);
            drawArgs.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0);

            drawArgs.device.RenderState.CullMode           = Cull.None;
            drawArgs.device.VertexFormat                   = CustomVertex.PositionTextured.Format;
            drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Add;
            drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;

            m_effect.Technique = "VSClouds";
            m_effect.SetValue("World", drawArgs.device.Transform.World);
            m_effect.SetValue("View", drawArgs.device.Transform.View);
            m_effect.SetValue("Projection", drawArgs.device.Transform.Projection);
            m_effect.SetValue("Tex0", frame.Texture);
            m_effect.SetValue("RenderMap", m_surface1);
            m_effect.SetValue("FullResMap", m_surface1);

            //	drawArgs.device.Indices = m_indexBuffer;
            //	drawArgs.device.SetStreamSource(0, m_vertexBuffer, 0);

            int numPasses = m_effect.Begin(0);

            for (int i = 0; i < numPasses; i++)
            {
                m_effect.BeginPass(i);
                drawArgs.device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0,
                                                          frame.Vertices.Length, frame.Indices.Length / 3, frame.Indices, true, frame.Vertices);

                //	drawArgs.device.DrawIndexedPrimitives(
                //		PrimitiveType.TriangleList,
                //		0,
                //		0,
                //		frame.Vertices.Length,
                //		0,
                //		frame.Indices.Length / 3);

                m_effect.EndPass();
            }

            m_effect.End();

            float pixelSizeX = -1.0f / (drawArgs.screenWidth / 2.0f);
            float pixelSizeY = 1.0f / (drawArgs.screenHeight / 2.0f);

            m_effect.SetValue("pixelSize", new Vector4(pixelSizeX, pixelSizeY, 1.0f, 1.0f));
            m_effect.SetValue("ExposureLevel", m_exposureLevel);

            drawArgs.device.Transform.World = drawArgs.WorldCamera.WorldMatrix;

            drawArgs.device.SetRenderTarget(0, s2);

            drawArgs.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0);
            m_effect.Technique = "ScaleBuffer";

            m_effect.SetValue("RenderMap", m_surface2);
            numPasses = m_effect.Begin(0);
            for (int i = 0; i < numPasses; i++)
            {
                m_effect.BeginPass(i);
                drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, m_transformedVertices);
                m_effect.EndPass();
            }
            m_effect.End();

            drawArgs.device.SetRenderTarget(0, s3);
            drawArgs.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0);
            m_effect.Technique = "GaussY";

            Vector4[] vSampleOffsets = new Vector4[16];
            float[]   fSampleOffsets = new float[16];
            Vector4[] vSampleWeights = new Vector4[16];

            CreateTexCoordNTexelWeights(
                drawArgs.screenWidth / 4,
                ref fSampleOffsets,
                ref vSampleWeights,
                7.0f,
                1.5f);

            for (int i = 0; i < 16; i++)
            {
                vSampleOffsets[i] = new Vector4(0.0f, fSampleOffsets[i], 0, 0);
            }

            m_effect.SetValue("TexelWeight", vSampleWeights);
            m_effect.SetValue("vertTapOffs", vSampleOffsets);

            numPasses = m_effect.Begin(0);
            for (int i = 0; i < numPasses; i++)
            {
                m_effect.BeginPass(i);
                drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, m_transformedVertices);
                m_effect.EndPass();
            }
            m_effect.End();

            drawArgs.device.SetRenderTarget(0, s2);
            drawArgs.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0);
            m_effect.Technique = "GaussX";

            m_effect.SetValue("RenderMap", m_surface3);

            for (int i = 0; i < 16; i++)
            {
                vSampleOffsets[i] = new Vector4(fSampleOffsets[i], 0, 0, 0);
            }

            m_effect.SetValue("horzTapOffs", vSampleOffsets);

            numPasses = m_effect.Begin(0);
            for (int i = 0; i < numPasses; i++)
            {
                m_effect.BeginPass(i);
                drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, m_transformedVertices);
                m_effect.EndPass();
            }
            m_effect.End();

            drawArgs.device.SetRenderTarget(0, currentRenderTarget);
            m_effect.Technique = "Screenblit";
            m_effect.SetValue("RenderMap", m_surface1);

            numPasses = m_effect.Begin(0);
            for (int i = 0; i < numPasses; i++)
            {
                m_effect.BeginPass(i);
                drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, m_transformedVertices);
                m_effect.EndPass();
            }
            m_effect.End();
        }