private void SetPixelWithColorMap(Bitmap bmp, int x, int y, Byte val, ColorMapContainer colorMapper) { if (colorMapper == null) { bmp.SetPixel(x, y, val, val, val, (TransparentBlack && val == 0) ? 0 : 255); return; } float pixel_value = (float)val / 255; if (pixel_value != pixel_value) { // The above test is an unpleasant way of checking if // pixel_value is NaN, since ScriptSharp seems not to support // Float.IsNaN(). This case "can't happen" in C#, but due to // JavaScript's numerical model, it *can* in the transpiled // SDK. bmp.SetPixel(x, y, 0, 0, 0, 0); return; } Color pixel_color = colorMapper.FindClosestColor(pixel_value); bmp.SetPixel(x, y, (int)pixel_color.R, (int)pixel_color.G, (int)pixel_color.B, (TransparentBlack && val == 0) ? 0 : 255); }
private Bitmap GetBitmapInt(double min, double max, ScaleMap scale, int z, ColorMapContainer colorMapper) { int[] buf = (int[])DataBuffer; double factor = max - min; int stride = AxisSize[0]; int page = AxisSize[0] * AxisSize[1] * z; Bitmap bmp = Bitmap.Create(AxisSize[0], AxisSize[1]); for (int y = 0; y < AxisSize[1]; y++) { int indexY = ((AxisSize[1] - 1) - y); for (int x = 0; x < AxisSize[0]; x++) { if (color) { int datR = buf[(x + indexY * stride)]; int datG = buf[(x + indexY * stride) + page]; int datB = buf[(x + indexY * stride) + page * 2]; if (ContainsBlanks && (double)datR == BlankValue) { bmp.SetPixel(x, y, 0, 0, 0, 0); } else { int r = scale.Map(datR); int g = scale.Map(datG); int b = scale.Map(datB); bmp.SetPixel(x, y, r, g, b, 255); } } else { int dataValue = buf[x + indexY * stride + page]; if (ContainsBlanks && (double)dataValue == BlankValue) { bmp.SetPixel(x, y, 0, 0, 0, 0); } else { Byte val = scale.Map(dataValue); SetPixelWithColorMap(bmp, x, y, val, colorMapper); } } } } return(bmp); }
public override void RenderPart(RenderContext renderContext, int part, double opacity, bool combine) { if (RenderContext.UseGlVersion2 && dataset.WcsImage is FitsImage) { ColorMapContainer.BindColorMapTexture(PrepDevice, dataset.FitsProperties.ColorMapName); FitsShader.Min = (float)dataset.FitsProperties.LowerCut; FitsShader.Max = (float)dataset.FitsProperties.UpperCut; FitsShader.ContainsBlanks = dataset.FitsProperties.ContainsBlanks; FitsShader.BlankValue = (float)dataset.FitsProperties.BlankValue; FitsShader.BZero = (float)dataset.FitsProperties.BZero; FitsShader.BScale = (float)dataset.FitsProperties.BScale; FitsShader.ScaleType = (int)dataset.FitsProperties.ScaleType; FitsShader.TransparentBlack = dataset.FitsProperties.TransparentBlack; FitsShader.Use(renderContext, VertexBuffer, GetIndexBuffer(part, accomidation), texture2d, (float)opacity, false); } else { TileShader.Use(renderContext, VertexBuffer, GetIndexBuffer(part, accomidation), texture2d, (float)opacity, false); } renderContext.gl.drawElements(GL.TRIANGLES, TriangleCount * 3, GL.UNSIGNED_SHORT, 0); }
public Bitmap GetScaledBitmap(double min, double max, ScaleTypes scaleType, int z, string colorMapperName) { z = Math.Min(z, sizeZ); ScaleMap scale; lastScale = scaleType; lastBitmapMin = min; lastBitmapMax = max; lastBitmapZ = z; lastBitmapColorMapperName = colorMapperName; ColorMapContainer colorMapper = ColorMapContainer.FromNamedColormap(colorMapperName); switch (scaleType) { default: case ScaleTypes.Linear: scale = new ScaleLinear(min, max); break; case ScaleTypes.Log: scale = new ScaleLog(min, max); break; case ScaleTypes.Power: scale = new ScalePow(min, max); break; case ScaleTypes.SquareRoot: scale = new ScaleSqrt(min, max); break; case ScaleTypes.HistogramEqualization: scale = new HistogramEqualization(this, min, max); break; } try { switch (DataType) { case DataTypes.ByteT: return(GetBitmapByte(min, max, scale, lastBitmapZ, colorMapper)); case DataTypes.Int16T: return(GetBitmapShort(min, max, scale, lastBitmapZ, colorMapper)); case DataTypes.Int32T: return(GetBitmapInt(min, max, scale, lastBitmapZ, colorMapper)); case DataTypes.FloatT: return(GetBitmapFloat(min, max, scale, lastBitmapZ, colorMapper)); case DataTypes.DoubleT: return(GetBitmapDouble(min, max, scale, lastBitmapZ, colorMapper)); case DataTypes.None: default: return(Bitmap.Create(100, 100)); } } catch { return(Bitmap.Create(10, 10)); } }
public virtual void RenderPart(RenderContext renderContext, int part, double opacity, bool combine) { if (PrepDevice == null) { bool lighting = renderContext.Lighting && renderContext.SunPosition != null; foreach (RenderTriangle tri in RenderTriangleLists[part]) { tri.Opacity = opacity; if (lighting) { // tranform normal by WV Vector3d norm = tri.Normal.Copy(); renderContext.World.MultiplyVector(norm); norm.Normalize(); // Dot product from sun angle double light = Vector3d.Dot(norm, renderContext.SunPosition); if (light < 0) { light = 0; } else { light = Math.Min(1.0f, (light * 1)); } // set lighting tri.lighting = (float)light; } else { tri.lighting = 1.0f; } tri.Draw(renderContext.Device, renderContext.WVP); } } else { if (RenderContext.UseGlVersion2 && fitsImage != null) { ColorMapContainer.BindColorMapTexture(PrepDevice, dataset.FitsProperties.ColorMapName); FitsShader.Min = (float)dataset.FitsProperties.LowerCut; FitsShader.Max = (float)dataset.FitsProperties.UpperCut; FitsShader.ContainsBlanks = dataset.FitsProperties.ContainsBlanks; FitsShader.BlankValue = (float)dataset.FitsProperties.BlankValue; FitsShader.BZero = (float)dataset.FitsProperties.BZero; FitsShader.BScale = (float)dataset.FitsProperties.BScale; FitsShader.ScaleType = (int)dataset.FitsProperties.ScaleType; FitsShader.TransparentBlack = dataset.FitsProperties.TransparentBlack; FitsShader.Use(renderContext, VertexBuffer, GetIndexBuffer(part, accomidation), texture2d, (float)opacity, false, GlobalCenter); } else { TileShader.Use(renderContext, VertexBuffer, GetIndexBuffer(part, accomidation), texture2d, (float)opacity, false, GlobalCenter); } renderContext.gl.drawElements(GL.TRIANGLES, TriangleCount * 3, GL.UNSIGNED_SHORT, 0); } }