示例#1
0
        private void DrawNormalVectors(Graphics graphics, Index[,] indices)
        {
            WireframeImage wireframeImage = WireframeImage;
            float          capSize        = wireframeImage.VectorCapSize;
            Color          normalsColor   = wireframeImage.NormalsColor;

            using (Pen pen = new Pen(normalsColor, wireframeImage.NormalVectorPenWidth)
            {
                CustomEndCap = new AdjustableArrowCap(capSize, capSize),
            })
            {
                int hCount = HCount;
                int uCount = indices.GetLength(0);
                int vCount = indices.GetLength(1);
                for (int h = 0; h < hCount; h++)
                {
                    for (int i = 0; i < uCount; i++)
                    {
                        for (int j = 0; j < vCount; j++)
                        {
                            Index          ix = indices[i, j];
                            WireframePoint w  = this[h, ix.I, ix.J];
                            if (w == null)
                            {
                                continue;
                            }
                            PointF originF    = w.OriginF;
                            PointF normalEndF = w.NormalEndF;
                            pen.Color = GetColor(w, wireframeImage.NormalsColor);
                            graphics.DrawLine(pen, originF.X, originF.Y, normalEndF.X, normalEndF.Y);
                        }
                    }
                }
            }
        }
示例#2
0
        public void CalculateColors(float min, float max)
        {
            WireframeImage wireframeImage = WireframeImage;
            int            hCount = HCount, uCount = UCount, vCount = VCount;

            Parallel.For(0, uCount, (i) =>
            {
                for (int j = 0; j < vCount; j++)
                {
                    for (int h = 0; h < hCount; h++)
                    {
                        WireframePoint point = this[h, i, j];
                        float value          = _values[h, i, j];
                        Color color;
                        if (double.IsNaN(value))
                        {
                            color = wireframeImage.SurfaceColor;
                        }
                        else if (double.IsNaN(min) || double.IsNaN(max))
                        {
                            color = wireframeImage.InvalidColor;
                        }
                        else
                        {
                            float delta = max - min;
                            float z     = delta > 0f ? (value - min) / delta : 0.5f;
                            color       = ColorUtilities.GetColor(z, wireframeImage.ColorGradient, wireframeImage.InverseGradient);
                        }
                        _colors[h, i, j] = color;
                    }
                }
            });
        }
示例#3
0
        // ----------------------------------------------------------------------------------------
        #region WireFrame

        public void CalculatePointsF(float length, Func <Single3, PointF> func)
        {
            int hCount = HCount, uCount = UCount, vCount = VCount;

            Parallel.For(0, uCount, (i) =>
            {
                for (int j = 0; j < vCount; j++)
                {
                    for (int h = 0; h < hCount; h++)
                    {
                        WireframePoint w = this[h, i, j];
                        if (w == null)
                        {
                            continue;
                        }
                        w.CalculatePointsF(length, func);
                    }
                }
            });
        }
示例#4
0
        private void DrawValues(Graphics graphics, Index[,] indices)
        {
            Font font = WireframeImage.DefaultFont;

            using (SolidBrush brush = new SolidBrush(Color.Black))
                using (StringFormat format = new StringFormat()
                {
                    Alignment = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                })
                {
                    int hCount = HCount;
                    int uCount = indices.GetLength(0);
                    int vCount = indices.GetLength(1);
                    //int frameIndex = ParentNode.Frames.IndexOf(this);
                    for (int h = 0; h < hCount; h++)
                    {
                        for (int i = 0; i < uCount; i++)
                        {
                            for (int j = 0; j < vCount; j++)
                            {
                                Index          ix = indices[i, j];
                                WireframePoint w  = this[h, ix.I, ix.J];
                                if (w == null)
                                {
                                    continue;
                                }
                                PointF originF = w.OriginF;
                                double value   = _values[h, ix.I, ix.J];
                                string text    = double.IsNaN(value) ? $"[{h}, {ix.I}, {ix.J}]" : $"{value:F2}";
                                graphics.DrawString(text, font, brush, originF.X, originF.Y, format);
                            }
                        }
                    }
                }
        }
示例#5
0
        private void DrawRays(Graphics graphics, Index[,] indices)
        {
            WireframeImage wireframeImage = WireframeImage;
            int            hCount         = HCount;
            int            uCount         = indices.GetLength(0);
            int            vCount         = indices.GetLength(1);
            float          penWidth       = wireframeImage.RayPenWidth;
            float          capSize        = wireframeImage.RayCapSize;

            using (Pen mainPen = new Pen(Color.Black, penWidth))
                using (Pen endPen = new Pen(Color.Black, penWidth)
                {
                    CustomEndCap = new AdjustableArrowCap(capSize, capSize),
                })
                {
                    for (int i = 0; i < uCount; i++)
                    {
                        for (int j = 0; j < vCount; j++)
                        {
                            Index ix           = indices[i, j];
                            bool  isInvalid    = false;
                            bool  isReflection = false;
                            bool  isTir        = false;
                            for (int h = 0; h < hCount; h++)
                            {
                                WireframePoint w = this[h, ix.I, ix.J];
                                isInvalid    = isInvalid || !w.HasFlux;
                                isReflection = isReflection || w.IsReflection;
                                isTir        = isTir || w.IsTir;
                            }

                            Color rayColor;
                            if (isInvalid)
                            {
                                rayColor = wireframeImage.InvalidColor;
                            }
                            else if (isTir)
                            {
                                rayColor = wireframeImage.TirColor;
                            }
                            else if (isReflection)
                            {
                                rayColor = wireframeImage.ReflectionColor;
                            }
                            else
                            {
                                rayColor = wireframeImage.RefractionColor;
                            }
                            endPen.Color  = rayColor;
                            mainPen.Color = rayColor;

                            WireframePoint w2 = null;
                            bool           b  = true;
                            for (int h = hCount - 1; h >= 0; h--)
                            {
                                WireframePoint w1 = w2;
                                w2 = this[h, ix.I, ix.J];
                                if (w2 == null)
                                {
                                    continue;
                                }

                                PointF p2 = w2.OriginF;
                                if (b)
                                {
                                    PointF p3 = w2.RayEndF;
                                    graphics.DrawLine(endPen, p2.X, p2.Y, p3.X, p3.Y);
                                    b = false;
                                }
                                if (w1 == null)
                                {
                                    continue;
                                }
                                PointF p1 = w1.OriginF;
                                graphics.DrawLine(mainPen, p1.X, p1.Y, p2.X, p2.Y);
                            }
                        }
                    }
                }
        }
示例#6
0
        private void DrawSurfaceV(Graphics graphics, Index[,] indices, int h)
        {
            WireframeImage wireframeImage = WireframeImage;
            int            uCount = indices.GetLength(0), vCount = indices.GetLength(1);
            int            nu = uCount, nv = vCount;

            if (nv < 2)
            {
                return;
            }
            if (VPeriodic)
            {
                nv++;
            }
            bool  drawAxis = wireframeImage.ViewUVAxes;
            float capSize = wireframeImage.UVAxisCapSize;
            Font  axisFont = WireframeImage.DefaultFont;

            using (Pen surfacePen = new Pen(Color.Black, wireframeImage.SurfacePenWidth))
            {
                for (int i = 0; i < nu; i++)
                {
                    for (int j = 1; j < nv; j++)
                    {
                        Index          ix1 = indices[i, j - 1];
                        WireframePoint w1  = this[h, ix1.I, ix1.J];
                        if (w1 == null)
                        {
                            continue;
                        }
                        Index          ix2 = indices[i, j % vCount];
                        WireframePoint w2  = this[h, ix2.I, ix2.J];
                        if (w2 == null)
                        {
                            continue;
                        }
                        Color  c1 = w1.HasFlux ? _colors[h, ix1.I, ix1.J] : wireframeImage.InvalidColor;
                        Color  c2 = w2.HasFlux ? _colors[h, ix2.I, ix2.J] : wireframeImage.InvalidColor;
                        Color  c  = ColorUtilities.Mix(c1, c2);
                        PointF p1 = w1.OriginF;
                        PointF p2 = w2.OriginF;
                        surfacePen.Color = c;
                        graphics.DrawLine(surfacePen, p1.X, p1.Y, p2.X, p2.Y);
                    }
                }
            }
            if (drawAxis && nu > 1)
            {
                using (Pen axisPen = new Pen(wireframeImage.VAxisColor, wireframeImage.UVAxisPenWidth))
                {
                    int i = 0;
                    for (int j = 1; j < nv; j++)
                    {
                        Index          ix1 = indices[i, j - 1];
                        WireframePoint w1  = this[h, ix1.I, ix1.J];
                        if (w1 == null)
                        {
                            continue;
                        }
                        Index          ix2 = indices[i, j % vCount];
                        WireframePoint w2  = this[h, ix2.I, ix2.J];
                        if (w2 == null)
                        {
                            continue;
                        }
                        PointF p1 = w1.OriginF;
                        PointF p2 = w2.OriginF;
                        if (j == nv - 1)
                        {
                            axisPen.CustomEndCap = new AdjustableArrowCap(capSize, capSize);
                            DrawString(graphics, axisPen.Color, axisFont, p1, p2, "V", 16f);
                        }
                        graphics.DrawLine(axisPen, p1.X, p1.Y, p2.X, p2.Y);
                    }
                }
            }
        }
示例#7
0
 private Color GetColor(WireframePoint w1, Color color)
 {
     return(w1.HasFlux ? color : WireframeImage.InvalidColor);
 }