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 override Bitmap GenerateBitmap(Size size, DataArea area) { SizeF scale = new SizeF(area.Area.Width / size.Width, area.Area.Height / size.Height); PointF startPos = area.Area.Location; PointF pos = startPos; Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); BitmapData data = bitmap.LockBits(new Rectangle(0, 0, size.Width, size.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { Bitmap32bitARGBPixel* pixels = (Bitmap32bitARGBPixel*)data.Scan0; if (area.Data is byte[]) { for (int y = 0; y < size.Height; y++) { pos.X = startPos.X; for (int x = 0; x < size.Width; x++) { // take sample byte value = (byte)area[(int)pos.X, (int)pos.Y]; //bitmap.SetPixel(x, y, GetPixel((int)pos.X, (int)pos.Y, value)); SetPixel((int)pos.X, (int)pos.Y, value, pixels); pos.X += scale.Width; pixels++; } pos.Y += scale.Height; } } else if (area.Data is float[]) { for (int y = 0; y < size.Height; y++) { pos.X = startPos.X; for (int x = 0; x < size.Width; x++) { // take sample float rawValue = (float)area[(int)pos.X, (int)pos.Y]; float value = rawValue / area.MaxDataValue; //bitmap.SetPixel(x, y, Color.FromArgb(255, value, value, value)); SetPixel((int)pos.X, (int)pos.Y, value, pixels); pos.X += scale.Width; pixels++; } pos.Y += scale.Height; } } } bitmap.UnlockBits(data); return bitmap; }
public override bool Equals(object obj) { if (obj.GetType() != GetType()) { return(base.Equals(obj)); } DataArea rect = (DataArea)obj; return(rect.area == area && rect.texCoords == texCoords); }
public void AddArea(DataArea area) { areas.Add(area); // re-calc layer area if (layerArea.Size == Size.Empty || area.Area.Contains(layerArea)) { // expand layer area layerArea = Rectangle.Union(layerArea, area.Area); pixelCount += (ulong)(area.Area.Width * area.Area.Height); } }
public override Bitmap GenerateBitmap(Size size, DataArea area) { SizeF scale = new SizeF(area.Area.Width / size.Width, area.Area.Height / size.Height); PointF startPos = area.Area.Location; PointF pos = startPos; Bitmap bitmap = new Bitmap(size.Width, size.Height); if (area.Data is byte[]) { for (int y = 0; y < size.Height; y++) { pos.X = startPos.X; for (int x = 0; x < size.Width; x++) { // take sample byte value = (byte)area[(int)pos.X, (int)pos.Y]; // TODO: Use unmanaged direct access bitmap.SetPixel(x, y, Color.FromArgb(255, value, value, value)); pos.X += scale.Width; } pos.Y += scale.Height; } } else if (area.Data is float[]) { for (int y = 0; y < size.Height; y++) { pos.X = startPos.X; for (int x = 0; x < size.Width; x++) { // take sample float rawValue = (float)area[(int)pos.X, (int)pos.Y]; if (rawValue > 0) { byte value = (byte)((rawValue / area.MaxDataValue) * 255); // TODO: Use unmanaged direct access bitmap.SetPixel(x, y, Color.FromArgb(255, value, value, value)); } pos.X += scale.Width; } pos.Y += scale.Height; } } return bitmap; }
public override Texture GenerateTexture(Size size, DataArea area, Device gDevice) { Texture texture = new Texture(gDevice, size.Width, size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); lock (this) { ftAreaTemp = area; 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); if (area.Data is byte[]) TextureLoader.FillTexture(texture, FillTextureByte); else if (area.Data is float[]) TextureLoader.FillTexture(texture, FillTextureFloat); } return texture; }
public abstract Texture GenerateTexture(Size size, DataArea area, Device gDevice);
public abstract Bitmap GenerateBitmap(Size size, DataArea area);
public MultiSampleRasterSampler(DataArea dataSource, int sampleSize, int numSamples) : base(dataSource, sampleSize) { halfSampleSz = sampleSize / 2; halfSampleSzF = 1f / numSamples; }
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; } }