public SimpleUIColorIndicator(IUILayoutParam param, ColorPalette colorPalette, GLColor textColor, float min, float max, float step) { this.bar = new SimpleUIColorIndicatorBar(param, colorPalette, min, max, step); float[] coords = colorPalette.Coords; float coordLength = coords[coords.Length - 1] - coords[0]; this.numbers = new SimpleUIPointSpriteStringElement[coords.Length]; const float posY = -1.0f; this.numbers[0] = new SimpleUIPointSpriteStringElement( param, (-100.0f).ToShortString(), new vec3(-0.5f, posY, 0), textColor, 20); for (int i = 1; i < coords.Length; i++) { float x = (coords[i] - coords[0]) / coordLength - 0.5f; if (i + 1 == coords.Length) { var number = new SimpleUIPointSpriteStringElement(param, (100.0f).ToShortString(), new vec3(x, posY, 0), textColor, 20); this.numbers[i] = number; } else { var number = new SimpleUIPointSpriteStringElement(param, (-100.0f + i * (100 - (-100)) / 5).ToShortString(), new vec3(x, posY, 0), textColor, 20); this.numbers[i] = number; } } }
public SimpleUIPointSpriteStringElement(IUILayoutParam param, string content, vec3 position, GLColor color = null, int fontSize = 32, int maxRowWidth = 256, FontResource fontResource = null) { IUILayout layout = this; layout.Param = param; this.element = new PointSpriteStringElement(content, position, color, fontSize, maxRowWidth, fontResource); }
public static GLColor MapToColor(GLColor[] colors, float[] coords, float value, float minValue, float maxValue) { if (colors.Length < 2) throw new ArgumentException("template colors size error"); float d = maxValue - minValue; if (d < 0.0f) throw new ArgumentException("fault value range"); if (value < minValue) value = minValue; if (value > maxValue) value = maxValue; if (d == 0.0d) return colors[0]; float dx = value - minValue; float x = dx / d; if (x <= 0.000000001d) return colors[0]; bool find = false; float x1 = 0.0f, x2 = 0.0f; GLColor y1 = colors[0], y2 = colors[1]; for (int i = 0; i < coords.Length - 1; i++) { x1 = coords[i]; x2 = coords[i + 1]; y1 = colors[i]; y2 = colors[i + 1]; if (x >= x1 && x <= x2) { find = true; break; } } if (!find) throw new ArgumentException("not found colors,template fault default not in[0,1] ?"); dx = x2 - x1; float kr = LineSlope(y2.R, y1.R, dx); float kg = LineSlope(y2.G, y1.G, dx); float kb = LineSlope(y2.B, y1.B, dx); float ka = LineSlope(y2.A, y1.A, dx); float r = y1.R + kr * (x - x1); float g = y1.G + kg * (x - x1); float b = y1.B + kb * (x - x1); float a = y1.A + ka * (x - x1); return new GLColor(r, g, b, a); }
public ThresholdMarker(ILineGraph graph, GLPoint location, GLSize size, GLColor color) { _graph = graph; _rectangle = new Rectangle(color, true, location, size); _rectangle.Origin = new GLPoint(_rectangle.Origin.X - size.Width / 2.0, _rectangle.Origin.Y - size.Height / 2.0); graph.Control.MouseMove += OnMouseMove; graph.Control.MouseDown += OnMouseDown; graph.Control.MouseUp += OnMouseUp; }
/// <summary> /// /// </summary> /// <param name="anchor">the edges of the viewport to which a SimpleUIRect is bound and determines how it is resized with its parent. /// <para>something like AnchorStyles.Left | AnchorStyles.Bottom.</para></param> /// <param name="margin">the space between viewport and SimpleRect.</param> /// <param name="size">Stores width when <see cref="OpenGLUIRect.Anchor"/>.Left & <see cref="OpenGLUIRect.Anchor"/>.Right is <see cref="OpenGLUIRect.Anchor"/>.None. /// <para> and height when <see cref="OpenGLUIRect.Anchor"/>.Top & <see cref="OpenGLUIRect.Anchor"/>.Bottom is <see cref="OpenGLUIRect.Anchor"/>.None.</para></param> /// <param name="zNear"></param> /// <param name="zFar"></param> /// <param name="rectColor">default color is red.</param> //public LegacySimpleUIRect(AnchorStyles anchor, Padding margin, System.Drawing.Size size, int zNear = -1000, int zFar = 1000, GLColor rectColor = null) public LegacySimpleUIRect(IUILayoutParam param, GLColor rectColor = null) { this.Param = param; if (rectColor == null) { this.RectColor = new GLColor(1, 0, 0, 1); } else { this.RectColor = rectColor; } }
/// <summary> /// /// </summary> /// <param name="anchor">the edges of the viewport to which a SimpleUIRect is bound and determines how it is resized with its parent. /// <para>something like AnchorStyles.Left | AnchorStyles.Bottom.</para></param> /// <param name="margin">the space between viewport and SimpleRect.</param> /// <param name="size">Stores width when <see cref="OpenGLUIRect.Anchor"/>.Left & <see cref="OpenGLUIRect.Anchor"/>.Right is <see cref="OpenGLUIRect.Anchor"/>.None. /// <para> and height when <see cref="OpenGLUIRect.Anchor"/>.Top & <see cref="OpenGLUIRect.Anchor"/>.Bottom is <see cref="OpenGLUIRect.Anchor"/>.None.</para></param> /// <param name="zNear"></param> /// <param name="zFar"></param> /// <param name="rectColor">default color is red.</param> public SimpleUIRect(IUILayoutParam param, GLColor rectColor = null) { IUILayout layout = this; layout.Param = param; if (rectColor == null) { this.rectColor = new vec3(0, 0, 1); } else { this.rectColor = new vec3(rectColor.R, rectColor.G, rectColor.B); } }
public ColorPalette(String paletteName, GLColor[] colors, float[] coords) { if (colors == null || colors == null || colors.Length < 2 || colors.Length < 2 || colors.Length != coords.Length) { throw new ArgumentNullException("ColorPalette", "ColorPalette define error"); } this.Colors = colors; this.Coords = coords; this.Name = paletteName; }
/// <summary> /// /// </summary> /// <param name="anchor">the edges of the viewport to which a SimpleUIRect is bound and determines how it is resized with its parent. /// <para>something like AnchorStyles.Left | AnchorStyles.Bottom.</para></param> /// <param name="margin">the space between viewport and SimpleRect.</param> /// <param name="size">Stores width when <see cref="OpenGLUIRect.Anchor"/>.Left & <see cref="OpenGLUIRect.Anchor"/>.Right is <see cref="OpenGLUIRect.Anchor"/>.None. /// <para> and height when <see cref="OpenGLUIRect.Anchor"/>.Top & <see cref="OpenGLUIRect.Anchor"/>.Bottom is <see cref="OpenGLUIRect.Anchor"/>.None.</para></param> /// <param name="zNear"></param> /// <param name="zFar"></param> /// <param name="rectColor">default color is red.</param> public SimpleUIAxis(IUILayoutParam param, GLColor rectColor = null, float radius = 0.3f, float axisLength = 10, int faceCount = 10) { // 把AxiesElement缩放到恰好放进此UI radius = radius / axisLength / 2; axisLength = 0.5f; this.axisElement = new AxisElement(radius, axisLength, faceCount); IUILayout layout = this; layout.Param = param; }
public static ColorPalette CreateRainbow() { GLColor[] colors = new GLColor[5]; float[] coords = new float[5]; coords[0] = 0.0f; colors[0] = System.Drawing.Color.FromArgb(255, 0, 22, 76); coords[1] = 0.25f; colors[1] = System.Drawing.Color.FromArgb(255, 0, 193, 136); coords[2] = 0.5f; colors[2] = System.Drawing.Color.FromArgb(255, 166, 255, 27); coords[3] = 0.75f; colors[3] = System.Drawing.Color.FromArgb(255, 255, 173, 0); coords[4] = 1.0f; colors[4] = System.Drawing.Color.FromArgb(255, 255, 8, 1); return new ColorPalette("Rainbow", colors, coords); }
public BoundingBox() { BoxColor = new GLColor(1, 1, 1, 1);// white color }
///// <summary> ///// 获取或设置此字符串的字体资源。 ///// </summary> //public FontResource Resource //{ // get { return this.resouce; } // set // { // if (value != this.resouce) // { // this.resouce = value; // InitTexture(this.content, this.FontSize, this.resouce); // } // } //} //public void UpdateProperties(string content, GLColor color, int fontSize, FontResource fontResource) //{ //} /// <summary> /// 用shader+VAO+组装的texture显示字符串 /// </summary> /// <param name="content">要显示的字符串</param> /// <param name="position">字符串的中心位置</param> /// <param name="color">文字颜色,默认为黑色</param> /// <param name="fontSize">字体大小,默认为32</param> /// <param name="fontResource">字体资源。默认的字体资源只支持ASCII码。</param> public PointSpriteStringElement( string content, vec3 position, GLColor color = null, int fontSize = 32, int maxRowWidth = 256, FontResource fontResource = null) { if (fontSize > 256) { throw new ArgumentException(); } this.content = content; this.position = position; if (color == null) { textColor = new vec3(0, 0, 0); } else { textColor = new vec3(color.R, color.G, color.B); } this.fontSize = fontSize; if (0 < maxRowWidth && maxRowWidth < 257) { this.maxRowWidth = maxRowWidth; } else { throw new ArgumentOutOfRangeException("max row width must between 0 and 257(not include 0 or 257)"); } if (fontResource == null) { this.resource = FontResource.Default; } else { this.resource = fontResource; } }
public SimpleHorizon() { fColor = GLColor.Yellow; }
private void InitVAO() { this.axisPrimitiveMode = DrawMode.QuadStrip; GLColor[] colors = this.ColorPalette.Colors; float[] coords = this.ColorPalette.Coords; this.numbers = new PointSpriteStringElement[coords.Length]; this.vertexCount = coords.Length * 2; this.vao = new uint[1]; float coordLength = coords[coords.Length - 1] - coords[0]; { GL.GenVertexArrays(1, vao); GL.BindVertexArray(vao[0]); // Create a vertex buffer for the vertex data. { UnmanagedArray <vec3> positionArray = new UnmanagedArray <vec3>(this.vertexCount); positionArray[0] = new vec3(-0.5f, -0.5f, 0); positionArray[1] = new vec3(-0.5f, 0.5f, 0); for (int i = 1; i < coords.Length; i++) { float x = (coords[i] - coords[0]) / coordLength - 0.5f; positionArray[i * 2 + 0] = new vec3(x, -0.5f, 0); positionArray[i * 2 + 1] = new vec3(x, 0.5f, 0); } uint[] ids = new uint[1]; GL.GenBuffers(1, ids); GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]); GL.BufferData(BufferTarget.ArrayBuffer, positionArray, BufferUsage.StaticDraw); GL.VertexAttribPointer(in_PositionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(in_PositionLocation); positionArray.Dispose(); } // Now do the same for the colour data. { UnmanagedArray <vec3> colorArray = new UnmanagedArray <vec3>(this.vertexCount); for (int i = 0; i < colors.Length; i++) { GLColor color = colors[i]; //TODO:试验成功后换vec4试试 colorArray[i * 2 + 0] = new vec3(color.R, color.G, color.B); //, color.A); colorArray[i * 2 + 1] = new vec3(color.R, color.G, color.B); //, color.A); } uint[] ids = new uint[1]; GL.GenBuffers(1, ids); GL.BindBuffer(BufferTarget.ArrayBuffer, ids[0]); GL.BufferData(BufferTarget.ArrayBuffer, colorArray, BufferUsage.StaticDraw); GL.VertexAttribPointer(in_ColorLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(in_ColorLocation); colorArray.Dispose(); } // Unbind the vertex array, we've finished specifying data for it. GL.BindVertexArray(0); } // prepare numbers { const float numberPosY = -0.6f; this.numbers[0] = new PointSpriteStringElement( this.Min.ToShortString(), new vec3(-0.5f, numberPosY, 0)); this.numbers[0].Initialize(); for (int i = 1; i < coords.Length; i++) { float x = (coords[i] - coords[0]) / coordLength - 0.5f; if (i + 1 == coords.Length) { this.numbers[i] = new PointSpriteStringElement( (this.Min + i * this.Step).ToShortString(), new vec3(x, numberPosY, 0)); } else { this.numbers[i] = new PointSpriteStringElement( this.Max.ToShortString(), new vec3(x, numberPosY, 0)); } this.numbers[i].Initialize(); } } }
/// <summary> /// 蛇形管道(井)+文字显示 /// </summary> /// <param name="srcWellPath"></param> /// <param name="pipeRadius"></param> /// <param name="pipeColor"></param> /// <param name="name"></param> /// <param name="position"></param> /// <param name="camera"></param> public Well(IScientificCamera camera, List <Vertex> srcWellPath, float pipeRadius, GLColor pipeColor, String name, GLColor textColor = null, int fontSize = 32, int maxRowWidth = 256) { if (srcWellPath == null || srcWellPath.Count < 2) { throw new ArgumentException("well path error"); } this.wellInitPath = srcWellPath; this.wellInitRadius = pipeRadius; this.wellPathInitMaxZ = wellInitPath[0].Z; this.wellPathInitMinZ = wellInitPath[this.wellInitPath.Count - 1].Z; this.wellPathMaxDisplayZ = this.wellPathInitMaxZ; this.wellName = name; this.wellPathColor = pipeColor; this.textColor = textColor; this.fontSize = fontSize; this.maxRowWidth = maxRowWidth; }
/// <summary> /// Draw color indicator on viewport as an UI. /// </summary> /// <param name="anchor">the edges of the viewport to which a SimpleUIColorIndicator is bound and determines how it is resized with its parent.</param> /// <param name="margin">the space between viewport and SimpleUIColorIndicator.</param> /// <param name="size">Stores width when <see cref="OpenGLUIRect.Anchor"/>.Left & <see cref="OpenGLUIRect.Anchor"/>.Right is <see cref="OpenGLUIRect.Anchor"/>.None. /// <para> and height when <see cref="OpenGLUIRect.Anchor"/>.Top & <see cref="OpenGLUIRect.Anchor"/>.Bottom is <see cref="OpenGLUIRect.Anchor"/>.None.</para></param> /// <param name="zNear"></param> /// <param name="zFar"></param> /// <param name="rectColor"></param> public SimpleUIColorIndicator(AnchorStyles anchor, Padding margin, System.Drawing.Size size, int zNear = -1000, int zFar = 1000, GLColor rectColor = null) : base(anchor, margin, size, zNear, zFar) { { this.colorBar = new ColorIndicatorBar() { Name = "color indicator's bar" }; var colorBarTransform = new SharpGL.SceneGraph.Effects.LinearTransformationEffect(); colorBar.AddEffect(colorBarTransform); base.AddChild(colorBar); this.colorBarTransform = colorBarTransform.LinearTransformation; } { this.colorNumber = new ColorIndicatorNumber() { Name = "color indicator's number" }; base.AddChild(colorNumber); } }
public SimpleUIColorIndicator(IUILayoutParam param, ColorPalette colorPalette, GLColor textColor, float min, float max, float step) { this.bar = new SimpleUIColorIndicatorBar(param, colorPalette, min, max, step); }
/// <summary> /// /// </summary> /// <param name="anchor">the edges of the viewport to which a SimpleUIRect is bound and determines how it is resized with its parent. /// <para>something like AnchorStyles.Left | AnchorStyles.Bottom.</para></param> /// <param name="margin">the space between viewport and SimpleRect.</param> /// <param name="size">Stores width when <see cref="OpenGLUIRect.Anchor"/>.Left & <see cref="OpenGLUIRect.Anchor"/>.Right is <see cref="OpenGLUIRect.Anchor"/>.None. /// <para> and height when <see cref="OpenGLUIRect.Anchor"/>.Top & <see cref="OpenGLUIRect.Anchor"/>.Bottom is <see cref="OpenGLUIRect.Anchor"/>.None.</para></param> /// <param name="zNear"></param> /// <param name="zFar"></param> /// <param name="rectColor">default color is red.</param> public SimpleUIRect(AnchorStyles anchor, Padding margin, System.Drawing.Size size, int zNear = -1000, int zFar = 1000, GLColor rectColor = null) { this.Anchor = anchor; this.Margin = margin; this.Size = size; this.zNear = zNear; this.zFar = zFar; if (rectColor == null) { this.RectColor = new GLColor(1, 0, 0, 1); } else { this.RectColor = new GLColor(1, 0, 0, 1); } this.RenderBound = true; }
private static bool GLColorsEqual(GLColor x, GLColor y) { return(x.A.Equals(y.A) && x.B.Equals(y.B) && x.G.Equals(y.G) && x.R.Equals(y.R) && ColorsEqual(x.ColorNET, y.ColorNET)); }
GLColor MapToColor(float value, GLColor[] colors, float[] coords, float minValue, float maxValue) { if (colors == null || colors.Length < 2) { throw new ArgumentNullException("colors", "colors' count must greater than 1."); } if (coords == null || coords.Length != colors.Length) { throw new ArgumentException("coords must have same count of elements with colors."); } float difference = maxValue - minValue; if (difference < 0.0f) { throw new ArgumentException("fault value range"); } if (difference == 0f) { return(colors[0]); } if (value <= minValue) { return(colors[0]); } if (value >= maxValue) { return(colors[colors.Length - 1]); } float progress = (value - minValue) / difference; int leftIndex = -1; for (int i = 1; i < coords.Length; i++) { if (progress < coords[i]) { leftIndex = i - 1; break; } } if (leftIndex == -1) { Debug.WriteLine("MapToColor: progress[{0}] not found between minValue[{1}] and maxValue[{2}]! Coords (should be in [0, 1]) are: [{3}]", progress, minValue, maxValue, ArrayHelper.PrintArray(coords)); return(colors[colors.Length - 1]); } float leftValue = minValue + difference * coords[leftIndex]; float rightValue = minValue + difference * coords[leftIndex + 1]; float blockWidth = rightValue - leftValue; GLColor leftColor = colors[leftIndex]; GLColor rightColor = colors[leftIndex + 1]; GLColor color = leftColor * ((value - leftValue) / blockWidth) + rightColor * ((rightValue - value) / blockWidth); return(color); }
public UIColorIndicator(AnchorStyles anchor, Padding margin, System.Drawing.Size size, int zNear = -1000, int zFar = 1000, GLColor rectColor = null) : base(anchor, margin, size, zNear, zFar, rectColor) { }
public static GLColor MapToColor(GLColor[] colors, float[] coords, float value, float minValue, float maxValue) { if (colors.Length < 2) { throw new ArgumentException("template colors size error"); } float d = maxValue - minValue; if (d < 0.0f) { throw new ArgumentException("fault value range"); } if (value < minValue) { value = minValue; } if (value > maxValue) { value = maxValue; } if (d == 0.0d) { return(colors[0]); } float dx = value - minValue; float x = dx / d; if (x <= 0.000000001d) { return(colors[0]); } bool find = false; float x1 = 0.0f, x2 = 0.0f; GLColor y1 = colors[0], y2 = colors[1]; for (int i = 0; i < coords.Length - 1; i++) { x1 = coords[i]; x2 = coords[i + 1]; y1 = colors[i]; y2 = colors[i + 1]; if (x >= x1 && x <= x2) { find = true; break; } } if (!find) { throw new ArgumentException("not found colors,template fault default not in[0,1] ?"); } dx = x2 - x1; float kr = LineSlope(y2.R, y1.R, dx); float kg = LineSlope(y2.G, y1.G, dx); float kb = LineSlope(y2.B, y1.B, dx); float ka = LineSlope(y2.A, y1.A, dx); float r = y1.R + kr * (x - x1); float g = y1.G + kg * (x - x1); float b = y1.B + kb * (x - x1); float a = y1.A + ka * (x - x1); return(new GLColor(r, g, b, a)); }
/// <summary> /// Specify a cuboid that marks a model's edges. /// </summary> public LegacyBoundingBox() { BoxColor = new GLColor(1, 1, 1, 1);// white color }
private static unsafe OrthoColorIndicatorBar CreateBar(ColorTemplate colorTemplate) { OrthoColorIndicatorBar bar = new OrthoColorIndicatorBar() { Name = "color indicator's bar" }; // initialize rectangles with gradient color. { int length = colorTemplate.Colors.Length; PointerScientificModel rectModel = new PointerScientificModel(length * 2, Enumerations.BeginMode.QuadStrip); Vertex *positions = rectModel.Positions; for (int i = 0; i < length; i++) { positions[i * 2].X = colorTemplate.Width * i / (length - 1); positions[i * 2].Y = 0; positions[i * 2].Z = 0; positions[i * 2 + 1].X = colorTemplate.Width * i / (length - 1); positions[i * 2 + 1].Y = colorTemplate.Height; positions[i * 2 + 1].Z = 0; } ByteColor *colors = rectModel.Colors; for (int i = 0; i < length; i++) { GLColor color = colorTemplate.Colors[i]; colors[i * 2].red = (byte)(color.R * byte.MaxValue / 2); colors[i * 2].green = (byte)(color.G * byte.MaxValue / 2); colors[i * 2].blue = (byte)(color.B * byte.MaxValue / 2); colors[i * 2 + 1].red = (byte)(color.R * byte.MaxValue / 2); colors[i * 2 + 1].green = (byte)(color.G * byte.MaxValue / 2); colors[i * 2 + 1].blue = (byte)(color.B * byte.MaxValue / 2); } bar.rectModel = rectModel; } // initialize two horizontal white lines. { int length = 4; PointerScientificModel horizontalLines = new PointerScientificModel(length, Enumerations.BeginMode.Lines); Vertex *positions = horizontalLines.Positions; positions[0].X = 0; positions[0].Y = 0; positions[0].Z = 0; positions[1].X = colorTemplate.Width; positions[1].Y = 0; positions[1].Z = 0; positions[2].X = 0; positions[2].Y = colorTemplate.Height; positions[2].Z = 0; positions[3].X = colorTemplate.Width; positions[3].Y = colorTemplate.Height; positions[3].Z = 0; ByteColor *colors = horizontalLines.Colors; for (int i = 0; i < length; i++) { colors[i].red = byte.MaxValue / 2; colors[i].green = byte.MaxValue / 2; colors[i].blue = byte.MaxValue / 2; } bar.horizontalLines = horizontalLines; } // initialize vertical lines. { int length = colorTemplate.Colors.Length; PointerScientificModel verticalLines = new PointerScientificModel(length * 2, Enumerations.BeginMode.Lines); Vertex *positions = verticalLines.Positions; for (int i = 0; i < length; i++) { positions[i * 2].X = colorTemplate.Width * i / (length - 1); positions[i * 2].Y = -9; positions[i * 2].Z = 0; positions[i * 2 + 1].X = colorTemplate.Width * i / (length - 1); positions[i * 2 + 1].Y = colorTemplate.Height; positions[i * 2 + 1].Z = 0; } ByteColor *colors = verticalLines.Colors; for (int i = 0; i < length * 2; i++) { colors[i].red = byte.MaxValue / 2; colors[i].green = byte.MaxValue / 2; colors[i].blue = byte.MaxValue / 2; } bar.verticalLines = verticalLines; } // initialize rectangles' scale effect so that it always padding to left, right and bottom with fixed value. { OrthoColorIndicatorBarEffect scaleEffect = new OrthoColorIndicatorBarEffect(); scaleEffect.colorTemplate = colorTemplate; bar.AddEffect(scaleEffect); bar.scaleEffect = scaleEffect; } return(bar); }