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 void LoadVisualization(DataProfile dataProfile, DataProfile.SubProfile subProfile, IDataSourceReader dataSrcReader, DataSourceInfo dataSrcInfo) { renderFrame = true; renderingThread.Start(); controlStatus = ControlStatus.Loading; rContext.LoadingLayer.SetProgress(0); rContext.LoadingLayer.SetText("Loading... DEM Geometry"); rContext.LoadingLayer.Visible = true; Render(); // load data from dlg into database database = new RasterDatabase.RasterDatabase(); object filteredData = subProfile.Filter.FilterData(dataSrcReader); if (filteredData is byte[]) { DataLayer dataLayer = new DataLayer("DEM", 8, "byte"); dataLayer.AddArea(new ByteArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution), new RectangleF(0, 0, 1, 1), (byte[])filteredData, dataSrcReader.Info.Resolution)); database.AddLayer(dataLayer); } else if (filteredData is float[]) { DataLayer dataLayer = new DataLayer("DEM", 32, "float"); dataLayer.AddArea(new FloatArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution), new RectangleF(0, 0, 1, 1), (float[])filteredData, dataSrcReader.Info.Resolution)); database.AddLayer(dataLayer); } // load data source(s) DataSourceItem item = new DataSourceItem(dataSrcInfo.BppType, (Bitmap)PreviewRasterizer.DrawRotatedBandPreview(dataSrcInfo.Bands, 64, dataSrcInfo)); heightDataSrcs.Add(item); // load diffuse sources // grey-scale for height GreyScaleDEMSampler srcImgSampler = new GreyScaleDEMSampler(); Bitmap srcImg = srcImgSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]); item = new DataSourceItem("Height", srcImg); item.DEMSampler = srcImgSampler; //(Bitmap)PreviewRasterizer.DrawRotatedBandPreview(new DataSourceInfo.DataBandInfo[] { new DataSourceInfo.DataBandInfo("Source", srcImg) }, //64, null)); diffuseDataSrcs.Add(item); // load colour image if possible as other source (i.e the original if an RGB img) if (dataSrcReader.Info.SupportsRGB()) { item = new DataSourceItem("SourceRGB", SourceDataDiffuseSampler.SampleRGBDiffuseMap((GDALReader)dataSrcReader, new Size(64, 64))); diffuseDataSrcs.Add(item); reader = (GDALReader)dataSrcReader; } // height band range HeightBandRange hbr = new HeightBandRange(); hbr.AddBand(0, Color.DarkGreen); hbr.AddBand(0.25f, Color.Blue); hbr.AddBand(0.4f, Color.DarkGreen); hbr.AddBand(0.5f, Color.Green); hbr.AddBand(0.8f, Color.Gray); hbr.AddBand(1, Color.White); HeightBandDEMSampler hBandSampler = new HeightBandDEMSampler(hbr); item = new DataSourceItem("HeightBands", hBandSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0])); item.DEMSampler = hBandSampler; diffuseDataSrcs.Add(item); // load database into visualization dem = new DigitalElevationMap(database.Area.Size, database, rContext.DevIf, (GDALReader)dataSrcReader/*, * hBandSampler.GenerateBitmap(new Size(512, 512), * database.Layers[0].Areas[0])*/ ); rContext.SetDEM(dem); // setup geometry layers geometryLayers.Add(new GeometryVisLayer("Diffuse", item.Thumbnail, true)); geometryLayers.Add(new GeometryVisLayer("Overlay Grid", null, true)); rContext.DevIf.LocalSettings["GeometryVisLayer.Diffuse"] = geometryLayers[0]; rContext.DevIf.LocalSettings["GeometryVisLayer.Overlay"] = geometryLayers[1]; // now load default texture SetDiffuseSource(0); rContext.LoadingLayer.SetProgress(100); Render(); Thread.Sleep(500); rContext.LoadingLayer.Visible = false; controlStatus = ControlStatus.Idle; Render(); }