コード例 #1
0
 private void drawLineString(LineString lineString, Graphics g, GeographicBoundingBox dstBB, Size imageSize)
 {
     using (Pen p = new Pen(lineString.Color, lineString.LineWidth))
     {
         g.DrawLines(p,
                     getScreenPoints(lineString.Coordinates, 0, lineString.Coordinates.Length, dstBB, imageSize));
     }
 }
コード例 #2
0
        public ProjectedVectorTile(
            GeographicBoundingBox geographicBoundingBox,
            ProjectedVectorRenderer parentLayer
            )
        {
            m_geographicBoundingBox = geographicBoundingBox;
            m_parentProjectedLayer  = parentLayer;

            BoundingBox = new BoundingBox((float)geographicBoundingBox.South, (float)geographicBoundingBox.North, (float)geographicBoundingBox.West, (float)geographicBoundingBox.East,
                                          (float)(parentLayer.World.EquatorialRadius + geographicBoundingBox.MinimumAltitude), (float)(parentLayer.World.EquatorialRadius + geographicBoundingBox.MaximumAltitude + 300000f));
        }
コード例 #3
0
        private void drawPolygon(Polygon polygon, Graphics g, GeographicBoundingBox dstBB, Size imageSize)
        {
            if (polygon.innerBoundaries != null && polygon.innerBoundaries.Length > 0)
            {
                if (polygon.Fill)
                {
                    using (SolidBrush brush = new SolidBrush(polygon.PolgonColor))
                    {
                        g.FillPolygon(brush, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if (polygon.Outline)
                {
                    using (Pen p = new Pen(polygon.OutlineColor, polygon.LineWidth))
                    {
                        g.DrawPolygon(p,
                                      getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if (polygon.Fill)
                {
                    using (SolidBrush brush = new SolidBrush(System.Drawing.Color.Black))
                    {
                        for (int i = 0; i < polygon.innerBoundaries.Length; i++)
                        {
                            g.FillPolygon(brush,
                                          getScreenPoints(polygon.innerBoundaries[i].Points, 0, polygon.innerBoundaries[i].Points.Length, dstBB, imageSize)
                                          );
                        }
                    }
                }
            }
            else
            {
                if (polygon.Fill)
                {
                    using (SolidBrush brush = new SolidBrush(polygon.PolgonColor))
                    {
                        g.FillPolygon(brush, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }

                if (polygon.Outline)
                {
                    using (Pen p = new Pen(polygon.OutlineColor, polygon.LineWidth))
                    {
                        g.DrawPolygon(p, getScreenPoints(polygon.outerBoundary.Points, 0, polygon.outerBoundary.Points.Length, dstBB, imageSize));
                    }
                }
            }
        }
コード例 #4
0
 public bool Intersects(GeographicBoundingBox boundingBox)
 {
     if (North <= boundingBox.South ||
         South >= boundingBox.North ||
         West >= boundingBox.East ||
         East <= boundingBox.West)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
コード例 #5
0
        /// <summary>
        /// Method to update polygon bounding box
        /// </summary>
        protected void CalcBoundingBox()
        {
            double minY = double.MaxValue;
            double maxY = double.MinValue;
            double minX = double.MaxValue;
            double maxX = double.MinValue;
            double minZ = double.MaxValue;
            double maxZ = double.MinValue;

            if (m_outerRing != null && m_outerRing.Points.Length > 0)
            {
                for (int i = 0; i < m_outerRing.Points.Length; i++)
                {
                    if (m_outerRing.Points[i].X < minX)
                    {
                        minX = m_outerRing.Points[i].X;
                    }
                    if (m_outerRing.Points[i].X > maxX)
                    {
                        maxX = m_outerRing.Points[i].X;
                    }

                    if (m_outerRing.Points[i].Y < minY)
                    {
                        minY = m_outerRing.Points[i].Y;
                    }
                    if (m_outerRing.Points[i].Y > maxY)
                    {
                        maxY = m_outerRing.Points[i].Y;
                    }

                    if (m_outerRing.Points[i].Z < minZ)
                    {
                        minZ = m_outerRing.Points[i].Z;
                    }
                    if (m_outerRing.Points[i].Z > maxZ)
                    {
                        maxZ = m_outerRing.Points[i].Z;
                    }
                }

                // set a uniform Z for all the points
                for (int i = 0; i < m_outerRing.Points.Length; i++)
                {
                    if (m_outerRing.Points[i].Z != maxZ)
                    {
                        m_outerRing.Points[i].Z = maxZ;
                    }
                }

                if (m_innerRings != null && m_innerRings.Length > 0)
                {
                    for (int n = 0; n < m_innerRings.Length; n++)
                    {
                        for (int i = 0; i < m_innerRings[n].Points.Length; i++)
                        {
                            if (m_innerRings[n].Points[i].Z != maxZ)
                            {
                                m_innerRings[n].Points[i].Z = maxZ;
                            }
                        }
                    }
                }
            }

            m_geographicBoundingBox = new GeographicBoundingBox(maxY, minY, minX, maxX, minZ, maxZ);

            minZ += m_world.EquatorialRadius;
            maxZ += m_world.EquatorialRadius;

            BoundingBox = new BoundingBox(
                (float)minY, (float)maxY, (float)minX, (float)maxX, (float)minZ, (float)maxZ);
        }
コード例 #6
0
        protected virtual void CreateMesh(GeographicBoundingBox geographicBoundingBox, int meshPointCount, ref CustomVertex.PositionColoredTextured[] vertices, ref short[] indices)
        {
            int    upperBound  = meshPointCount - 1;
            float  scaleFactor = (float)1 / upperBound;
            double latrange    = Math.Abs(geographicBoundingBox.North - geographicBoundingBox.South);
            double lonrange;

            if (geographicBoundingBox.West < geographicBoundingBox.East)
            {
                lonrange = geographicBoundingBox.East - geographicBoundingBox.West;
            }
            else
            {
                lonrange = 360.0f + geographicBoundingBox.East - geographicBoundingBox.West;
            }

            double layerRadius = m_parentProjectedLayer.World.EquatorialRadius;

            int opacityColor = System.Drawing.Color.FromArgb(
                //m_parentProjectedLayer.Opacity,
                0, 0, 0).ToArgb();

            vertices = new CustomVertex.PositionColoredTextured[meshPointCount * meshPointCount];
            for (int i = 0; i < meshPointCount; i++)
            {
                for (int j = 0; j < meshPointCount; j++)
                {
                    double height = 0;
                    if (m_parentProjectedLayer.World.TerrainAccessor != null)
                    {
                        height = m_verticalExaggeration * m_parentProjectedLayer.World.TerrainAccessor.GetElevationAt(
                            (double)geographicBoundingBox.North - scaleFactor * latrange * i,
                            (double)geographicBoundingBox.West + scaleFactor * lonrange * j,
                            (double)upperBound / latrange);
                    }

                    Vector3 pos = MathEngine.SphericalToCartesian(
                        geographicBoundingBox.North - scaleFactor * latrange * i,
                        geographicBoundingBox.West + scaleFactor * lonrange * j,
                        layerRadius + height);

                    vertices[i * meshPointCount + j].X = pos.X;
                    vertices[i * meshPointCount + j].Y = pos.Y;
                    vertices[i * meshPointCount + j].Z = pos.Z;

                    vertices[i * meshPointCount + j].Tu    = j * scaleFactor;
                    vertices[i * meshPointCount + j].Tv    = i * scaleFactor;
                    vertices[i * meshPointCount + j].Color = opacityColor;
                }
            }

            indices = new short[2 * upperBound * upperBound * 3];
            for (int i = 0; i < upperBound; i++)
            {
                for (int j = 0; j < upperBound; j++)
                {
                    indices[(2 * 3 * i * upperBound) + 6 * j]     = (short)(i * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 1] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 2] = (short)(i * meshPointCount + j + 1);

                    indices[(2 * 3 * i * upperBound) + 6 * j + 3] = (short)(i * meshPointCount + j + 1);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 4] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 5] = (short)((i + 1) * meshPointCount + j + 1);
                }
            }
        }
コード例 #7
0
        private System.Drawing.Point[] getScreenPoints(Point3d[] sourcePoints, int offset, int length, GeographicBoundingBox dstBB, Size dstImageSize)
        {
            double degreesPerPixelX = (dstBB.East - dstBB.West) / (double)dstImageSize.Width;
            double degreesPerPixelY = (dstBB.North - dstBB.South) / (double)dstImageSize.Height;

            ArrayList screenPointList = new ArrayList();

            for (int i = offset; i < offset + length; i++)
            {
                double screenX = (sourcePoints[i].X - dstBB.West) / degreesPerPixelX;
                double screenY = (dstBB.North - sourcePoints[i].Y) / degreesPerPixelY;

                if (screenPointList.Count > 0)
                {
                    Point v = (Point)screenPointList[screenPointList.Count - 1];
                    if (v.X == (int)screenX && v.Y == (int)screenY)
                    {
                        continue;
                    }
                }

                screenPointList.Add(new Point((int)screenX, (int)screenY));
            }

            if (screenPointList.Count <= 1)
            {
                return new Point[] { new Point(0, 0), new Point(0, 0) }
            }
            ;

            return((Point[])screenPointList.ToArray(typeof(Point)));
        }
コード例 #8
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);
        }