private static void Initialize2DUI(ScientificVisual3DControl scientificVisual3DControl)
        {
            SceneElement parent = scientificVisual3DControl.UIScene.SceneContainer;
            SimpleUIAxis uiAxis = new SimpleUIAxis(
                AnchorStyles.Left | AnchorStyles.Bottom,
                new Padding(10, 0, 0, 20), new Size(40, 40))
            {
                Name = "UI: Axis",
            };

            uiAxis.RectDirection = ERectDirection.XZ;
            parent.AddChild(uiAxis);
            scientificVisual3DControl.uiAxis = uiAxis;

            SimpleUIColorIndicator uiColorIndicator = new SimpleUIColorIndicator(
                AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right,
                new Padding(80, 0, 80, 40), new Size(100, 15))
            {
                Name = "UI: Color Indicator",
            };
            ColorIndicatorData rainbow = ColorIndicatorDataFactory.CreateRainbow();

            uiColorIndicator.Data = rainbow;
            parent.AddChild(uiColorIndicator);
            scientificVisual3DControl.uiColorIndicator = uiColorIndicator;
        }
        private unsafe void TryUpdate(ColorIndicatorData data)
        {
            if (data == null)
            {
                this.rectModel       = null;
                this.verticalLines   = null;
                this.horizontalLines = null;
                return;
            }

            if (data.LastModified == this.lastModified)
            {
                return;
            }

            // initialize rectangles with gradient color.
            GenerateRectangles(data);

            // initialize two horizontal white lines.
            GenerateHorizontalLines();

            // initialize vertical lines.
            GenerateVerticalLines(data);

            this.lastModified = data.LastModified;
        }
        unsafe private void GenerateVerticalLines(ColorIndicatorData data)
        {
            int blockCount = data.GetBlockCount();
            //int blockCount = data.BlockCount;
            int             segmentCount  = blockCount + 1;
            ScientificModel verticalLines = new ScientificModel(segmentCount * 2, Enumerations.BeginMode.Lines);

            float[] positions = verticalLines.Positions;
            for (int i = 0; i < segmentCount; i++)
            {
                if (i + 1 != segmentCount)
                {
                    if (data.MaxValue != data.MinValue)
                    {
                        positions[i * 2 * 3 + 0] = barWidth * (i * data.Step / (data.MaxValue - data.MinValue));
                    }
                    else
                    {
                        positions[i * 2 * 3 + 0] = barWidth * 0;
                    }
                }
                else
                {
                    positions[i * 2 * 3 + 0] = barWidth;
                }
                positions[i * 2 * 3 + 1]     = -9;
                positions[i * 2 * 3 + 2]     = 0;
                positions[i * 2 * 3 + 3 + 0] = positions[i * 2 * 3 + 0];
                positions[i * 2 * 3 + 3 + 1] = barHeight;
                positions[i * 2 * 3 + 3 + 2] = 0;
            }
            // move the vertical lines' center to (0, 0, 0)
            for (int i = 0; i < segmentCount * 2; i++)
            {
                positions[i * 3 + 0] -= barWidth / 2;
                positions[i * 3 + 1] -= barHeight / 2;
            }

            float[] colors = verticalLines.Colors;
            for (int i = 0; i < segmentCount * 2; i++)
            {
                colors[i * 3 + 0] = 1;
                colors[i * 3 + 1] = 1;
                colors[i * 3 + 2] = 1;
                //colors[i].red = byte.MaxValue / 2;
                //colors[i].green = byte.MaxValue / 2;
                //colors[i].blue = byte.MaxValue / 2;
            }

            this.verticalLines = verticalLines;
        }
        unsafe private void GenerateRectangles(ColorIndicatorData data)
        {
            int             rectCount = data.ColorPalette.Colors.Length;
            ScientificModel rectModel = new ScientificModel(rectCount * 2, Enumerations.BeginMode.QuadStrip);

            float[] positions = rectModel.Positions;
            for (int i = 0; i < rectCount; i++)
            {
                positions[i * 2 * 3 + 0]     = barWidth * data.ColorPalette.Coords[i];
                positions[i * 2 * 3 + 1]     = 0;
                positions[i * 2 * 3 + 2]     = 0;
                positions[i * 2 * 3 + 3 + 0] = positions[i * 2 * 3];
                positions[i * 2 * 3 + 3 + 1] = barHeight;
                positions[i * 2 * 3 + 3 + 2] = 0;
            }
            // move the rectangles' center to (0, 0, 0)
            for (int i = 0; i < rectCount * 2; i++)
            {
                positions[i * 3 + 0] -= barWidth / 2;
                positions[i * 3 + 1] -= barHeight / 2;
            }

            float[] colors = rectModel.Colors;
            for (int i = 0; i < rectCount; i++)
            {
                GLColor color = data.ColorPalette.Colors[i];
                colors[i * 2 * 3 + 0]     = (color.R);
                colors[i * 2 * 3 + 1]     = (color.G);
                colors[i * 2 * 3 + 2]     = (color.B);
                colors[i * 2 * 3 + 3 + 0] = (color.R);
                colors[i * 2 * 3 + 3 + 1] = (color.G);
                colors[i * 2 * 3 + 3 + 2] = (color.B);
            }

            this.rectModel = rectModel;
        }
Beispiel #5
0
        public void Render(OpenGL gl, RenderMode renderMode)
        {
            SimpleUIRectArgs lastArgs = this.CurrentArgs;

            if (lastArgs == null)
            {
                return;
            }
            ColorIndicatorData data = this.Data;

            if (data == null)
            {
                return;
            }

            int blockCount = data.GetBlockCount();

            if (blockCount <= 0)
            {
                return;
            }

            String formatStr = MinorFormatString(data.Step);

            GLColor[] colors     = data.ColorPalette.Colors;
            int       blockWidth = 0;

            if (data.MaxValue - data.MinValue == 0)
            {
                blockWidth = lastArgs.UIWidth;
            }
            else
            {
                blockWidth = (int)(lastArgs.UIWidth * (data.Step / (data.MaxValue - data.MinValue)));
            }
            //draw numbers
            for (int i = 0; i <= blockCount; i++)
            {
                string value = null;
                if (i == blockCount)
                {
                    if (!data.UseLogarithmic)
                    {
                        value = data.MaxValue.ToString(formatStr, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        value = Math.Pow(data.LogBase, data.MaxValue).ToString(formatStr, CultureInfo.InvariantCulture);
                    }
                }
                else
                {
                    float tickValue = data.MinValue + data.Step * i;
                    if (!data.UseLogarithmic)
                    {
                        value = tickValue.ToString(formatStr, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        value = Math.Pow(data.LogBase, tickValue).ToString(formatStr, CultureInfo.InvariantCulture);
                    }
                }
                double valueLength = 100.0 * value.Length / fontSize;
                double x           = 0;
                if (i == blockCount)
                {
                    x = -(double)lastArgs.UIWidth / 2 - lastArgs.left + lastArgs.UIWidth - valueLength / 2;
                }
                else
                {
                    x = -(double)lastArgs.UIWidth / 2 - lastArgs.left + i * blockWidth - valueLength / 2;
                }
                double y = -(double)lastArgs.UIHeight / 2 - lastArgs.bottom - 14;
                gl.DrawText((int)x, (int)y, 1, 1, 1, "Courier New", fontSize, value);
            }
        }