Example #1
0
        public void Update(FEWorld world)
        {
            FieldValue fv         = world.GetFieldValue(ValueId);
            uint       quantityId = fv.QuantityId;
            uint       dim        = world.Dimension;

            uint ptCnt = 0;

            if (IsNsvDraw)
            {
                ptCnt = fv.GetPointCount();
                // あとで実装する
                throw new NotImplementedException();
            }
            else
            {
                ptCnt = world.GetCoordCount(quantityId);
            }
            System.Diagnostics.Debug.Assert(VertexArray.PointCount == ptCnt);

            if (!IsntDisplacementValue)
            {
                // 変位を伴う場合

                if (dim == 2 &&
                    (fv.Type == FieldValueType.Scalar || fv.Type == FieldValueType.ZScalar))
                {
                    // 垂直方向の変位として捉える

                    System.Diagnostics.Debug.Assert(VertexArray.Dimension == 3);
                    for (int coId = 0; coId < ptCnt; coId++)
                    {
                        double[]            coord = world.GetCoord(quantityId, coId);
                        FieldDerivativeType dt    = ValueDt;
                        double value = fv.GetShowValue(coId, 0, dt);
                        VertexArray.VertexCoordArray[coId * 3 + 0] = coord[0];
                        VertexArray.VertexCoordArray[coId * 3 + 1] = coord[1];
                        VertexArray.VertexCoordArray[coId * 3 + 2] = value;
                    }
                }
                else
                {
                    System.Diagnostics.Debug.Assert(VertexArray.Dimension == dim);
                    for (int coId = 0; coId < ptCnt; coId++)
                    {
                        double[]            coord = world.GetCoord(quantityId, coId);
                        FieldDerivativeType dt    = ValueDt;
                        for (int iDim = 0; iDim < dim; iDim++)
                        {
                            double value = fv.GetShowValue(coId, iDim, dt);
                            VertexArray.VertexCoordArray[coId * dim + iDim] = coord[iDim] + value;
                        }
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.Assert(VertexArray.Dimension == dim);
                for (int coId = 0; coId < ptCnt; coId++)
                {
                    double[] coord = world.GetCoord(quantityId, coId);
                    for (int iDim = 0; iDim < dim; iDim++)
                    {
                        VertexArray.VertexCoordArray[coId * dim + iDim] = coord[iDim];
                    }
                }
            }

            if (world.IsFieldValueId(ColorValueId))
            {
                FieldValue          colorfv = world.GetFieldValue(ColorValueId);
                FieldDerivativeType dt      = ColorValueDt;
                bool isBubble        = colorfv.IsBubble;
                uint colorQuantityId = colorfv.QuantityId;
                uint colorPtCnt      = world.GetCoordCount(colorQuantityId);
                if (!ColorMap.IsFixedMinMax)
                {
                    double min;
                    double max;

                    colorfv.GetMinMaxShowValue(out min, out max, 0, dt);
                    ColorMap.MinValue = min;
                    ColorMap.MaxValue = max;
                }

                if (!isBubble)
                {
                    // color is assigned to vertex
                    if (ColorArray == null)
                    {
                        ColorArray = new float[colorPtCnt * 4];
                    }
                    for (int coId = 0; coId < colorPtCnt; coId++)
                    {
                        double   value = colorfv.GetShowValue(coId, 0, dt);
                        double[] color = ColorMap.GetColor(value);
                        ColorArray[coId * 4]     = (float)color[0];
                        ColorArray[coId * 4 + 1] = (float)color[1];
                        ColorArray[coId * 4 + 2] = (float)color[2];
                        ColorArray[coId * 4 + 3] = 0.0f;
                    }
                }
                else
                {
                    // color is assigned to face
                    for (int idp = 0; idp < DrawParts.Count; idp++)
                    {
                        FaceFieldDrawPart dp = DrawParts[idp];
                        dp.SetColors(ColorValueId, dt, world, ColorMap);
                    }
                }
            }

            if (NormalArray != null)
            {
                MakeNormal();
            }


            if (UVArray != null)
            {
                for (int coId = 0; coId < ptCnt; coId++)
                {
                    double[] coord = world.GetCoord(quantityId, coId);
                    UVArray[coId * 2 + 0] = coord[0] * TexScale;
                    UVArray[coId * 2 + 1] = coord[1] * TexScale;
                }
            }
        }
Example #2
0
        public void Draw()
        {
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Disable(EnableCap.CullFace);
            GL.LineWidth(1);
            GL.Color3(0, 0, 0);

            int[] viewport = new int[4];
            GL.GetInteger(GetPName.Viewport, viewport);
            double asp = (viewport[2] + 1.0) / (viewport[3] + 1.0);

            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadIdentity();
            GL.Ortho(-asp, asp, -1, 1, -1, 1);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();
            GL.LoadIdentity();

            double intervalN = 17.0;
            uint   divC      = 20;

            GL.Scale(ScaleX, ScaleY, 1.0);
            GL.Translate(((asp - 0.05) / ScaleX - 9), ((1 - 0.05) / ScaleY - 11.5 * 1.7), 1.0);
            GL.Begin(PrimitiveType.Quads);
            for (int i = 0; i < divC; i++)
            {
                double   val0   = (ColorMap.MaxValue - ColorMap.MinValue) * (1.0 / divC) * (i + 0) + ColorMap.MinValue;
                double   val1   = (ColorMap.MaxValue - ColorMap.MinValue) * (1.0 / divC) * (i + 1) + ColorMap.MinValue;
                double[] color0 = ColorMap.GetColor(val0);
                double[] color1 = ColorMap.GetColor(val1);
                GL.Color3(color0);
                GL.Vertex2(-3, intervalN * (1.0 / divC) * i);
                GL.Vertex2(-0, intervalN * (1.0 / divC) * i);
                GL.Color3(color1);
                GL.Vertex2(-0, intervalN * (1.0 / divC) * (i + 1));
                GL.Vertex2(-3, intervalN * (1.0 / divC) * (i + 1));
            }
            GL.End();

            GL.Color3(0, 0, 0);
            GL.Translate(0, -0.5, 0);
            uint   divN   = 10;
            double maxAbs = Math.Abs(ColorMap.MaxValue) > Math.Abs(ColorMap.MinValue) ?
                            Math.Abs(ColorMap.MaxValue) : Math.Abs(ColorMap.MinValue);
            int    exp = (int)Math.Log10(maxAbs);
            double pow = Math.Pow(10.0, exp);

            for (int i = 0; i < divN + 1; i++)
            {
                double val = (ColorMap.MaxValue - ColorMap.MinValue) * i / divN + ColorMap.MinValue;
                string str = string.Format("{0,5:N2}", val / pow);
                OpenGLUtils.DrawString(str, FontSize);
                GL.Translate(0, +intervalN / divN, 0);
            }
            {
                string str = string.Format("[x10{0}{1}]", (exp >= 0 ? "+" : ""), exp);
                OpenGLUtils.DrawString(str, FontSize);
            }

            GL.MatrixMode(MatrixMode.Projection);
            GL.PopMatrix();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PopMatrix();
        }
Example #3
0
 public ColorMap(ColorMap src)
 {
     IsFixedMinMax = src.IsFixedMinMax;
     MinValue      = src.MinValue;
     MaxValue      = src.MaxValue;
 }