public object FilterData(IDataSourceReader dataSrc) { if (dataSrc is GDALReader) { // get as many bands as available and average values GDALReader reader = (GDALReader)dataSrc; int[] avrData = new int[reader.Info.Resolution.Width * reader.Info.Resolution.Height]; byte[] tempData = new byte[reader.Info.Resolution.Width * reader.Info.Resolution.Height]; int numBands = reader.Info.Bands.Length; for (int band = 0; band < numBands; band++) { Band bandData = reader.GetRasterBand(band + 1); bandData.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height, tempData, reader.Info.Resolution.Width, reader.Info.Resolution.Height, 0, 0); // add to averages for (int i = 0; i < tempData.Length; i++) { avrData[i] += tempData[i]; } } // average data into final byte[] for (int i = 0; i < avrData.Length; i++) { tempData[i] = (byte)(avrData[i] / numBands); } return(tempData); } return(null); }
public void OpenExecuted() { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "Image files (*.tif)|*.tif|All Files (*.*)|*.*"; fileDialog.RestoreDirectory = true; if (fileDialog.ShowDialog() == true) { //CanvasView.Children.Clear(); gdalReader = new GDALReader(); gdalReader.Open(fileDialog.FileName); MapImage mapImage = gdalReader.GetMapImageInfo(); if (mapImages.Count == 0) { canvasBoundary = mapImage.ImageBoundary; mapImages.Add(mapImage); Init(); FitCanvas(); } else { if (!AddImage(mapImage)) { MessageBox.Show("좌표계가 없어 이미지를 추가 할 수 없습니다."); return; } } EventAggregator.ImageOpenEvent.Publish(mapImage); } }
public void RebuildDiffuseTextures(GDALReader reader) { SourceDataDiffuseSampler sampler = new SourceDataDiffuseSampler(); for (int i = 0; i < nodes.Length; i++) { tex[i] = sampler.GenerateTexture(new Size(256, 256), nodes[i].Rectangles[0], gDevice, reader); } }
/// <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()); }
public object FilterData(IDataSourceReader dataSrc) { if (dataSrc is GDALReader) { GDALReader reader = (GDALReader)dataSrc; Band redBand = reader.GetRasterBand(1); byte[] data = new byte[reader.Info.Resolution.Width * reader.Info.Resolution.Height]; redBand.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height, data, reader.Info.Resolution.Width, reader.Info.Resolution.Height, 0, 0); return(data); } return(null); }
public static GpuDemGeometry CreateGeometry(RasterDatabase.RasterDatabase rDatabase, Device gDevice, out float maxValue, GDALReader reader) { // create actual geometry - tesselated plane IndexBuffer geomPlaneIndices; PlaneHelper.CreateIndexBuffer(gDevice, 14, 14, out geomPlaneIndices); VertexBuffer geomPlaneVerts; PlaneHelper.CreateVertexBufferInside(gDevice, 16, 16, new Vector2(1, 1), out geomPlaneVerts); VertexBuffer geomPatchVerts; PlaneHelper.CreatePatchVertexBuffer(gDevice, 16, 16, new Vector2(1, 1), out geomPatchVerts); IndexBuffer geomPatchIndices; PlaneHelper.CreatePatchIndexBuffer(gDevice, 16, 16, out geomPatchIndices); // create cache of all depths RectangleGroupQuadTree rTree = rDatabase.ProduceLayerMipMap(0, 256); RectangleGroupQuadTree.GroupNode[][] dataNodes = new RectangleGroupQuadTree.GroupNode[rTree.Depth][]; for (int depth = 0; depth < rTree.Depth; depth++) { RectangleGroupQuadTree.GroupNode[] nodes; rTree.GetNodes(depth + 1, out nodes); dataNodes[depth] = nodes; } GpuDemGeometry geom = new GpuDemGeometry(new Vector3(), new Vector3(10, 0, 10), new Vector3(5, 0, 5), 16 * 16, 15 * 15 * 2, PrimitiveType.TriangleList, gDevice); geom.geomPlaneVerts = geomPlaneVerts; geom.geomPlaneIndices = geomPlaneIndices; geom.geomPatchIndices = geomPatchIndices; geom.geomPatchVerts = geomPatchVerts; geom.reader = reader; geom.dataNodes = dataNodes; geom.ViewUpdated(new Vector3()); maxValue = 1; return(geom); }
public static Bitmap SampleRGBDiffuseMap(GDALReader dataSrc, Size size) { // find bands to use int r, g, b; dataSrc.Info.GetRGABands(out r, out g, out b); Size nativeSz = dataSrc.Info.Resolution; Band rBand = dataSrc.GetRasterBand(r + 1); Band gBand = dataSrc.GetRasterBand(g + 1); Band bBand = dataSrc.GetRasterBand(b + 1); // Note: This *should* work byte[] rData = new byte[size.Width * size.Height]; byte[] gData = new byte[size.Width * size.Height]; byte[] bData = new byte[size.Width * size.Height]; rBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, rData, size.Width, size.Height, 0, 0); gBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, gData, size.Width, size.Height, 0, 0); bBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, bData, size.Width, size.Height, 0, 0); // combine channel samples into image Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb); BitmapData data = bitmap.LockBits(new Rectangle(new Point(), size), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); unsafe { // write data to each pixel Bitmap24bitRGBPixel *pixels = (Bitmap24bitRGBPixel *)data.Scan0; for (int i = 0; i < rData.Length; i++) { pixels->R = bData[i]; pixels->G = gData[i]; pixels->B = rData[i]; pixels++; } } bitmap.UnlockBits(data); return(bitmap); }
public object FilterData(IDataSourceReader dataSrc) { if (dataSrc is GDALReader) { GDALReader reader = (GDALReader)dataSrc; Band band = reader.GetRasterBand(1); float[] data = new float[reader.Info.Resolution.Width * reader.Info.Resolution.Height]; band.ReadRaster(0, 0, reader.Info.Resolution.Width, reader.Info.Resolution.Height, data, reader.Info.Resolution.Width, reader.Info.Resolution.Height, 0, 0); for (int i = 0; i < data.Length; i++) { if (data[i] < 0 || data[i] > 32000) { data[i] = 0; } } return(data); } return(null); }
public Texture GenerateTexture(Size size, DataArea area, Device gDevice, GDALReader dataSrc) { Texture texture = new Texture(gDevice, size.Width, size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); lock (this) { // find bands to use int r, g, b; dataSrc.Info.GetRGABands(out r, out g, out b); Size nativeSz = dataSrc.Info.Resolution; Band rBand = dataSrc.GetRasterBand(r + 1); Band gBand = dataSrc.GetRasterBand(g + 1); Band bBand = dataSrc.GetRasterBand(b + 1); // Note: This *should* work rData = new byte[nativeSz.Width * nativeSz.Height]; gData = new byte[nativeSz.Width * nativeSz.Height]; bData = new byte[nativeSz.Width * nativeSz.Height]; rBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, rData, nativeSz.Width, nativeSz.Height, 0, 0); gBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, gData, nativeSz.Width, nativeSz.Height, 0, 0); bBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, bData, nativeSz.Width, nativeSz.Height, 0, 0); ftScaleTemp = new SizeF(1, 1);// (float)area.Area.Width / area.DataSize.Width, (float)area.Area.Height / area.DataSize.Height); ftScaleTemp = new SizeF(ftScaleTemp.Width * area.Area.Width, ftScaleTemp.Height * area.Area.Height); ftShiftTemp = new Size(area.Area.Location); ftNativeSz = nativeSz; if (area.Data is byte[]) { TextureLoader.FillTexture(texture, FillTextureByte); } /*else if (area.Data is float[]) * TextureLoader.FillTexture(texture, FillTextureFloat);*/ } return(texture); }
public void OpenExecuted(object sender, ExecutedRoutedEventArgs e) { System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog(); //dlg.InitialDirectory = "c:\\"; fileDialog.Filter = "Image files (*.tif)|*.tif|All Files (*.*)|*.*"; fileDialog.RestoreDirectory = true; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ZoomFit(); CanvasViewer.Children.Clear(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); string filePath = fileDialog.FileName; gdalReader = new GDALReader(); gdalReader.FileName = filePath; gdalReader.Open(filePath); imageInfo = gdalReader.GetImageInfo(); canvasBoundary = imageInfo.ImageBoundary; Debug.WriteLine("GDALReader : " + stopwatch.Elapsed.TotalMilliseconds + " msec"); InitLoadImage(); Debug.WriteLine("BitmapImage : " + stopwatch.Elapsed.TotalMilliseconds + " msec"); FitToFrame(); EventAggregator.ImageOpenEvent.Publish(imageInfo); stopwatch.Stop(); Debug.WriteLine("Fit2Frame : " + stopwatch.Elapsed.TotalMilliseconds + " msec"); } }
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(); }
public void RebuildDiffuseTextures(GDALReader gdalReader) { //geom.RebuildDiffuseTextures(gdalReader); }
public Texture GenerateTexture(Size size, DataArea area, Device gDevice, GDALReader dataSrc) { Texture texture = new Texture(gDevice, size.Width, size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); lock (this) { // find bands to use int r, g, b; dataSrc.Info.GetRGABands(out r, out g, out b); Size nativeSz = dataSrc.Info.Resolution; Band rBand = dataSrc.GetRasterBand(r + 1); Band gBand = dataSrc.GetRasterBand(g + 1); Band bBand = dataSrc.GetRasterBand(b + 1); rData = new byte[nativeSz.Width * nativeSz.Height]; gData = new byte[nativeSz.Width * nativeSz.Height]; bData = new byte[nativeSz.Width * nativeSz.Height]; rBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, rData, nativeSz.Width, nativeSz.Height, 0, 0); gBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, gData, nativeSz.Width, nativeSz.Height, 0, 0); bBand.ReadRaster(0, 0, nativeSz.Width, nativeSz.Height, bData, nativeSz.Width, nativeSz.Height, 0, 0); /*ftScaleTemp = new SizeF(1, 1);// (float)area.Area.Width / area.DataSize.Width, (float)area.Area.Height / area.DataSize.Height); * ftScaleTemp = new SizeF(ftScaleTemp.Width * area.Area.Width, ftScaleTemp.Height * area.Area.Height); * ftShiftTemp = new Size(area.Area.Location); * ftNativeSz = nativeSz;*/ ftScaleTemp = new SizeF((float)area.Area.Width / size.Width, (float)area.Area.Height / size.Height); ftShiftTemp = new Size(area.Area.Location); if (area.Data is byte[]) { // to heights //TextureLoader.FillTexture(texture, FillTextureByteToHeights); // generate normal acc ftTexSz = size; //texStream = texture.LockRectangle(0, LockFlags.None); /*Texture normalTex = new Texture(gDevice, size.Width, size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); * TextureLoader.FillTexture(normalTex, FillTextureByteToNormalAcc);*/ heights = new float[size.Width * size.Height]; int index = 0; //SizeF nativeScale = new SizeF((float)nativeSz.Width / size.Width, (float)nativeSz.Height / size.Height); for (int y = 0; y < size.Height; y++) { int yNative = (int)(ftShiftTemp.Height + (y * ftScaleTemp.Width)); for (int x = 0; x < size.Width; x++) { int xNative = (int)(ftShiftTemp.Width + (x * ftScaleTemp.Width)); int indexNative = (yNative * nativeSz.Width) + xNative; float rValue = rData[indexNative] / 255f; float gValue = gData[indexNative] / 255f; float bValue = bData[indexNative] / 255f; heights[index++] = (rValue + gValue + bValue) / 3f; } } /*texture.UnlockRectangle(0); * texture.Dispose();*/ // calculate normals Vector3[] normals; GenerateMap(heights, size, out normals); // write to texture texStream = texture.LockRectangle(0, LockFlags.None); foreach (Vector3 normal in normals) { texStream.WriteByte((byte)(((normal.Z / 2) + 0.5f) * 255)); texStream.WriteByte((byte)(((-normal.Y / 2) + 0.5f) * 255)); texStream.WriteByte((byte)(((normal.X / 2) + 0.5f) * 255)); texStream.WriteByte(255); } /*foreach (float height in heights) * { * texStream.WriteByte(0); * texStream.WriteByte((byte)(height * 255)); * texStream.WriteByte(0); * texStream.WriteByte(255); * }*/ texture.UnlockRectangle(0); } return(texture); } }