如何在ILNumerics中进行手动着色?

时间:2014-07-02 08:25:07

标签: colors visualization ilnumerics colorbar color-mapping

我用ILNumerics制作了一些盒子(右图)。这个框对于每个框都有不同的属性,如左侧所示。

enter image description here

实际上,我想按照我的定义对盒子进行着色。颜色本身取决于" Delta Rho",其最大值= 1,最小值= -1。我也想显示颜色条。如何实现?任何人都有线索?

是的,这是我的代码:

private void createBlockBody(BlockBody BlockBody, ILScene scene, ILPlotCube plotCube)
    {
        ILArray<double> A = ILMath.rand(1, 20) * 4 + ILMath.vec(1, 20);
        plotCube.Add(new ILTriangles("tri")
        {
            Positions = new float[,] { 
            // front side
            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z},

            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},

            //back side
            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},

            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},

            //up
            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z  + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},

            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z  + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},

            //up
            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z  + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z},

            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z  + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},

            //right
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z},

            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X + (float) BlockBody.dx, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},


            //left
            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z}, 

            {(float) BlockBody.UpperLeftPoint.X,(float) BlockBody.UpperLeftPoint.Y, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz}, 
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z},
            {(float) BlockBody.UpperLeftPoint.X, (float) BlockBody.UpperLeftPoint.Y + (float) BlockBody.dy, (float) BlockBody.UpperLeftPoint.Z + (float) BlockBody.dz},
            },

            Colors = new float[,] { 
            // front side
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},

            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},

            //
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},

            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},

            //
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},

            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
            {(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},{(float) BlockBody.Rho,(float) BlockBody.Rho,(float) BlockBody.Rho},
        },
        });

        // configure the limits of the plot cube content (similar to zooming)
        plotCube.Limits.Set(
          new Vector3(0, 0, 1000),   // set the minimum X,Y,Z coordinate
          new Vector3(1000, 1000, 0));// set the maximum X,Y,Z coordinate

        // disable clipping at the plot cube edges
        plotCube.Plots.Clipping = null;
        SliceilPanel.Scene = scene;
        SliceilPanel.Refresh();
    }

1 个答案:

答案 0 :(得分:1)

得到了答案!

plotCube.Add(box);
var colormap = new ILColormap(Colormaps.Jet);
Vector4 key1 = colormap.Map((float)BlockBody.Rho, new Tuple<float, float>(-1, 1));
var test = key1.ToColor();
box.Color = test;