/// <summary>
        /// Initializes a new instance of the DigitalElevationMap class.
        /// </summary>
        /// <param name="mapSize">Size of the map</param>
        /// <param name="rDb"></param>
        /// <param name="devIf"></param>
        /// <param name="reader"></param>
        public DigitalElevationMap(Size mapSize, RasterDatabase.RasterDatabase rDb,
                                   DeviceInterface devIf, GDALReader reader)
            : base(new Vector3(-5f, -0.5f, -5f), new Vector3(5f, 1f, 5f))
        {
            this.mapSize = mapSize;
            maxDimension = mapSize.Width > mapSize.Height ? mapSize.Width : mapSize.Height;
            this.rDb = rDb;

            this.devIf = devIf;
            this.reader = reader;

            axisHelper = new Axis3DHelper(new Vector3(2.5f, 0.5f, 2.5f));
            rotAxisHelper = new RotationAxis3DHelper(new Vector3());
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            src = Bitmap.FromFile(@"f:\output.bmp");
            src2 = Bitmap.FromFile(@"C:\Users\Andrew\Pictures\sense.jpg");

            RasterDatabase db = new RasterDatabase();
            DataLayer layer;
            db.AddLayer(layer = new DataLayer("DiffuseMap", 32, "X8R8G8B8"));
            layer.AddArea(new DataArea(new Rectangle(0, 0, 960, 1200), new RectangleF(0, 0, 1, 1), src));
            layer.AddArea(new DataArea(new Rectangle(1000, 50, 501, 501), new RectangleF(0, 0, 1, 1), src2));

            tree = layer.BuildQuadTree(512);

            DrawDepth();
        }
        public static TextureMatrixLayer[] RenderDatabaseTree(RasterDatabase.RasterDatabase db, Device device)
        {
            // setup device
            device.RenderState.ZBufferEnable = false;
            device.Indices = null;
            device.VertexFormat = CustomVertex.TransformedTextured.Format;
            //device.Transform.World = Matrix.Identity;
            Surface rt0 = device.GetRenderTarget(0);

            // setup template quad
            CustomVertex.TransformedTextured[] tQuad = new CustomVertex.TransformedTextured[4];

            foreach(DataLayer layer in db.Layers)
            {
                RectangleGroupQuadTree tree = db.ProduceLayerMipMap(layer, 2048);
                Texture[][] textures = new Texture[tree.Depth][];
                for (int i = 1; i <= tree.Depth; i++)
                {
                    RectangleGroupQuadTree.GroupNode[] nodes;
                    tree.GetNodes(i, out nodes);
                    textures[i] = new Texture[nodes.Length];

                    // render each node to texture
                    int texIdx = 0;
                    foreach (RectangleGroupQuadTree.GroupNode node in nodes)
                    {
                        Texture texture = textures[i][texIdx++] = new Texture(device, node.NodeArea.Width,
                                                                              node.NodeArea.Height, 0,
                                                                              Usage.WriteOnly, Format.X8R8G8B8,
                                                                              Pool.Managed);
                        device.SetRenderTarget(0, texture.GetSurfaceLevel(0));

                        device.Clear(ClearFlags.Target, Color.Black, 1, 0);
                        device.BeginScene();

                        // draw each rectangle quad
                        foreach (DataArea area in node.Rectangles)
                        {
                            // setup quad
                            tQuad[0] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Top, 1, 1,
                                                                            area.TexCoords.Left, area.TexCoords.Top);
                            tQuad[1] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Top, 1, 1,
                                                                            area.TexCoords.Right, area.TexCoords.Top);
                            tQuad[2] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Bottom, 1, 1,
                                                                            area.TexCoords.Left, area.TexCoords.Bottom);
                            tQuad[3] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Bottom, 1, 1,
                                                                            area.TexCoords.Right, area.TexCoords.Bottom);

                            // render quad
                            device.SetTexture(0, (Texture)area.Data);
                            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, tQuad);
                        }
                        device.EndScene();
                    }
                }
            }

            device.SetRenderTarget(0, rt0);
            device.RenderState.ZBufferEnable = true;

            return null;
        }