Ejemplo n.º 1
0
        /// <summary>
        /// create new color enumeration based on a specific colormap
        /// </summary>
        /// <param name="basemap"></param>
        public ILColorEnumerator(Colormaps basemap)
        {
            ILColormap cm = new ILColormap(basemap);

            m_colors = new List <Color>();
            for (int i = 0; i < cm.Length; i++)
            {
                m_colors.Add(cm.Map(i));
            }
            m_curPos = 0;
        }
Ejemplo n.º 2
0
 private void create(ILBaseArray data, Colormaps colormap) {
     ILArray<float> dataF = ILNumerics.BuiltInFunctions.ILMath.tosingle(data); 
     m_boxes = new ILLitBox3D[data.Dimensions[0],data.Dimensions[1]];
     float maxY = data.Dimensions[0] * (m_barLengthY + m_paddingY);
     // prepare coloring for top quads 
     ILColormap cmap = new ILColormap(colormap); 
     float minV,maxV,mult;
     dataF.GetLimits(out minV, out maxV);
     if (maxV > minV) {
         mult = (cmap.Length - 1) / (maxV - minV);
     } else {
         minV = 0; 
         mult = 0;
     }
     for (int r = 0; r < data.Dimensions[0]; r++) {
         for (int c = 0; c < data.Dimensions[1]; c++) {
             float val = dataF.GetValue(r, c);  
             ILPoint3Df max = new ILPoint3Df(
                 (float)(c * (m_paddingX + m_barLengthX) + m_barLengthX)
                 , (float)(maxY - r * (m_paddingY + m_barLengthY))
                 , val);
             ILPoint3Df min = new ILPoint3Df(
                 max.X - m_barLengthX
                 , max.Y - m_barLengthY
                 , 0);
             Color topColor = cmap.Map((double)(val - minV) * mult); 
             ILLitBox3D box = new ILLitBox3D(m_panel,min,max,m_barColor,topColor);
             box.GradientColor = m_barColorGradient;
             box.TopLabel.Color = topColor;
             box.TopLabel.Text = ""; 
             m_boxes[r, c] = box; 
             Add(box); 
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// update range for color bar, supply color provider
 /// </summary>
 /// <param name="minValue">min value</param>
 /// <param name="maxValue">max value</param>
 /// <param name="colorProvider">color provider (not implemented)</param>
 public void Update(float minValue, float maxValue, ILColormap colormap) {
     m_minValue = minValue; 
     m_maxValue = maxValue; 
     m_colormap = colormap; 
 }
Ejemplo n.º 4
0
 public ILColorBar(ILColormap colormap) : base() {
     base.BorderStyle = BorderStyle.FixedSingle; 
     Padding = new Padding(4); 
     StandardOrientation = TextOrientation.Vertical;
     m_orientation = TextOrientation.Vertical;
     Visible = true; 
     BackColor = SystemColors.Info; 
     m_colormap = colormap; 
 }
Ejemplo n.º 5
0
            public static ILArray<int> configureVertices(
                    ILArray<float> xVals, ILArray<float> yVals,
                    ILArray<float> zVals, ILColormap cmap, C4fN3fV3f[] Vertices, byte opacity) {
                int i = 0, x, y, y0 = zVals.Dimensions[0] - 1;
                float minZ, maxZ;
                if (!zVals.GetLimits(out minZ, out maxZ,false))
                    minZ = maxZ = 1.0f;
                x = 0;
                y = 0;
                ILArray<float> colors = (tosingle((zVals - minZ) / (maxZ - minZ)))[":"] * (cmap.Length - 1);
                colors[isnan(colors)] = 0;
                bool useXvals = (xVals != null && !xVals.IsEmpty);
                bool useYvals = (yVals != null && !yVals.IsEmpty);
                foreach (float a in zVals.Values) {
                    C4fN3fV3f v = Vertices[i];
                    v.Position = new ILPoint3Df(
                         (useXvals)? xVals.GetValue(y,x): x 
                        ,(useYvals)? yVals.GetValue(y,x): y0 - y
                        , a);
                    byte r, g, b;
                    cmap.Map(colors.GetValue(i), out r, out g, out b);
                    v.Color = Color.FromArgb(255, r, g, b);
                    v.Alpha = opacity; 
                    Vertices[i++] = v;
                    // set next position
                    if (++y >= zVals.Dimensions[0]) {
                        x++;
                        y = 0;
                    }
                }

                // create quad indices
                int numQuad = (zVals.Dimensions[0] - 1) * (zVals.Dimensions[1] - 1);
                x = 0; y = 0;
                ILArray<double> ret = zeros(4, numQuad);
                ILArray<double> mult = counter(0.0, 1.0, zVals.Dimensions.ToIntArray());
                mult = mult["0:" + (zVals.Dimensions[0] - 2), "0:" + (zVals.Dimensions[1] - 2)];
                mult = mult[":"].T; 

                ret["0;:"] = mult;
                ret["3;:"] = mult + 1;
                mult = mult + zVals.Dimensions.SequentialIndexDistance(1); 
                ret["2;:"] = mult + 1;
                ret["1;:"] = mult; 
                return toint32(ret); 
            }
Ejemplo n.º 6
0
        /// <summary>
        /// create new lit surface, provide data for X,Y and Z coordinates
        /// </summary>
        /// <param name="panel">the panel hosting the scene</param>
        /// <param name="X">X coordinates matrix, same size as Z or null</param>
        /// <param name="Y">Y coordinates matrix, same size as Z or null</param>
        /// <param name="Z">Z data matrix, at least 2 rows, 2 columns</param>
        /// <param name="colormap">colormap used for auto coloring the surface</param>
        public ILLitSurface(ILPanel panel, ILBaseArray X, ILBaseArray Y, ILBaseArray Z, ILColormap colormap)
            : base(panel) {
            if (Z == null || Z.Dimensions[0] < 2 || Z.Dimensions[1] < 2)
                throw new ArgumentException("invalid parameter size: Z");
            if (X == null || !X.Dimensions.IsSameSize(Z.Dimensions))
                throw new ArgumentException("invalid parameter size: X");
            if (Y == null || !Y.Dimensions.IsSameSize(Z.Dimensions))
                throw new ArgumentException("invalid parameter size: Y");
            m_quads = new ILLitQuads(panel, Z.Dimensions.NumberOfElements);
            m_quads.Label.Text = ""; 
            m_quads.Shading = ShadingStyles.Interpolate;
            Add(m_quads);
            m_colorMap = colormap;
            ZValues = Z; 
            XValues = X;
            YValues = Y;

            Invalidate();
        }
Ejemplo n.º 7
0
 protected override void CreateVertices() {
     ILColormap colormap = m_panel.Colormap; 
     if (m_vertices == null) {
         m_vertices = ILMemoryPool.Pool.New<float>(m_Vertcount*40); 
     }
     float val = 0.0f; 
     float minZ = m_globalClipping.ZMin, minC = (m_colors == null)? 0.0f : m_colors.MinValue; 
     float maxZ = m_globalClipping.ZMax; 
     bool useColorArray = !object.Equals(m_colors,null); 
     float a;
     if (useColorArray)
         a = colormap.Length / (m_colors.MaxValue - minC);
     else {
         if (maxZ - minZ != 0.0f)
             a = colormap.Length / (maxZ - minZ);
         else
             a = 0.0f;
     }
     int curVertPos = 0, curVecPos = 0; 
     if (m_shading == ShadingStyles.Interpolate) {
         #region shading interpolate
         for (int r = 0; r < m_rows; r++) {
             for (int c = 0; c < m_cols; c++) {
                 curVecPos = r + c * m_rows; 
                 val = m_sourceArray.GetValue(r,c);
                 // set color values 
                 if (useColorArray)
                     colormap.Map((m_colors.GetValue(curVecPos) - minC) * a, m_vertices, ref curVertPos);
                 else {
                     if (a != 0) {
                         colormap.Map((val - minZ) * a, m_vertices, ref curVertPos);
                     } else {
                         // plane: minz == maxz
                         colormap.Map(colormap.Length / 2, m_vertices, ref curVertPos);
                     }
                 }
                 m_vertices[curVertPos++] = m_opacity;
                 curVertPos += 3; 
                 m_vertices[curVertPos++] = m_xCoords[curVecPos]; 
                 m_vertices[curVertPos++] = m_yCoords[curVecPos]; 
                 m_vertices[curVertPos++] = val;
             }
         }
         #endregion
     } else if (m_shading == ShadingStyles.Flat) {
         #region shading flat
         /**  Consider a surface area like this: 
          * 
          *  8 - 9 -10 -11
          *  | / | / | / |
          *  4 - 5 - 6 - 7
          *  | / | / | / | 
          *  0 - 1 - 2 - 3
          * 
          *  The rectangle surrounded by 0-1-4-5 is than colored by the 
          *  vertex 5. This rectangle will be assembled by 2 triangles: 
          *  0-1-5 and 0-4-5. Therefore the color for both rectangles 
          *  is the same and must be stored in the vertex No.5. 
          *  The vertices can be assembled in natural order, beginning 
          *  with 0 and approching m_vertexCount-1. The color for flat 
          *  shading is averaged over the neighbor corners of each
          *  rectangle. In our Example the color stored in 5 is averaged 
          *  over the values of the vertices 0,1,4 and 5. The first row 
          *  and the first column are not used for the surface. However
          *  it may _be_ used for the wireframe grid if that is drawn with 
          *  interpolated colors (Wireframe.Color.IsEmpty). So we must 
          *  prepare the color for it -> here we just take the value itself.
          */
         // first row: no color average
         for (int c = 0; c < m_cols; c++) {
             val = m_sourceArray.GetValue(0,c);
             if (useColorArray)
                 colormap.Map((m_colors.GetValue(0,c) - minC) * a, m_vertices,ref curVertPos); 
             else 
                 colormap.Map((val - minZ) * a, m_vertices,ref curVertPos); 
             m_vertices[curVertPos++] = m_opacity;
             curVertPos += 3; 
             m_vertices[curVertPos++] = m_xCoords[m_rows*c]; 
             m_vertices[curVertPos++] = m_yCoords[m_rows*c]; 
             m_vertices[curVertPos++] = val;
         }
         for (int r = 1; r < m_rows; r++) {
             val = m_sourceArray.GetValue(r,0);
             if (useColorArray)
                 colormap.Map((m_colors.GetValue(r) - minC) * a, m_vertices,ref curVertPos); 
             else 
                 colormap.Map((val - minZ) * a, m_vertices,ref curVertPos); 
             m_vertices[curVertPos++] = m_opacity;
             curVertPos += 3; 
             m_vertices[curVertPos++] = m_xCoords[r]; 
             m_vertices[curVertPos++] = m_yCoords[r]; 
             m_vertices[curVertPos++] = val;
             // next columns: average color over precomputed corners
             for (int c = 1; c < m_cols; c++) {
                 curVecPos = r + c * m_rows; 
                 val = m_sourceArray.GetValue(r,c);
                 val += m_sourceArray.GetValue(r-1,c); 
                 val += m_sourceArray.GetValue(r,c-1); 
                 val += m_sourceArray.GetValue(r-1,c-1); 
                 val /= 4;
                 if (useColorArray)
                     colormap.Map((m_colors.GetValue(curVecPos) - minC) * a, m_vertices,ref curVertPos); 
                 else 
                     colormap.Map((val - minZ) * a, m_vertices,ref curVertPos); 
                 m_vertices[curVertPos++] = m_opacity; 
                 curVertPos += 3; 
                 m_vertices[curVertPos++] = m_xCoords[curVecPos]; 
                 m_vertices[curVertPos++] = m_yCoords[curVecPos]; 
                 m_vertices[curVertPos++] = m_sourceArray.GetValue(r,c); 
             }
         }
         #endregion
         m_oldColormap = colormap; 
     }
     #region create normals 
     // todo: depends on lighting enabled or not...! 
     // reset vertices pointer and start all over 
     curVertPos = 0; float nx,ny,nz;
     for (int r = 0; r < m_rows; r++) {
         for (int c = 0; c < m_cols; c++) {
             nx= m_vertices[curVertPos+7];
             ny= m_vertices[curVertPos+8];
             nz= m_vertices[curVertPos+9];
             if (c > 0) {
                 nx += m_vertices[curVertPos-3];
                 ny += m_vertices[curVertPos-2];
                 nz += m_vertices[curVertPos-1];
             }
             if (c < m_cols-1) { 
                 nx += m_vertices[curVertPos+17];
                 ny += m_vertices[curVertPos+18];
                 nz += m_vertices[curVertPos+19];
             }
             if (r > 0 && r < m_rows) {
                 nx += m_vertices[curVertPos-m_cols*10+10];
                 ny += m_vertices[curVertPos-m_cols*10+11];
                 nz += m_vertices[curVertPos-m_cols*10+12];
             }
             if (r < m_rows - 1) { 
                 nx += m_vertices[curVertPos+m_cols*10+10];
                 ny += m_vertices[curVertPos+m_cols*10+11];
                 nz += m_vertices[curVertPos+m_cols*10+12];
             }
             // normalize
             float len = (float)Math.Sqrt(nx*nx+ny*ny+nz*nz); 
             m_vertices[curVertPos+4] = nx / len; 
             m_vertices[curVertPos+5] = ny / len; 
             m_vertices[curVertPos+6] = nz / len; 
             curVertPos+=10; 
         }
     }
     #endregion
     m_oldShading = m_shading; 
     m_vertexReady = true;
 }
Ejemplo n.º 8
0
            internal static ILArray<double> CreateVertices(ILBaseArray dataInput 
                                            ,out ILArray<double> indices
                                            ,double beta, double scaling
                                            , ILColormap colormap) {
                // each arrow needs 4 vertices (indexed rendering)
                ILArray<double> data = todouble(dataInput);
                int numRows = data.Dimensions[0];
                int numCols = data.Dimensions[1];
                ILArray<double> ret = new ILArray<double>(4, numCols * numRows, 2);
                // prepare indices
                indices = repmat(new ILArray<double>(new double[] { 0, 2, 1, 2, 3, 2 }, 6, 1), 1, numCols * numRows);
                indices = indices + repmat(counter(0.0, 4.0, 1, numCols * numRows), 6, 1);
                indices = indices.Reshape(2, numRows * numCols * 3);
                // normalize incoming data to length 1.0 
                ILArray<double> l = sqrt(sum(data * data, 2));
                double maxL = (double)max(maxall(l),MachineParameterDouble.eps);
                l = (l / maxL)[":"].T * scaling;
                ILArray<double> alpha = atan2(data[":;:;1"], data[":;:;0"]);
                alpha = alpha[":"].T;
                ILArray<double> x = data[":;:;0"][":"].T * scaling;
                ILArray<double> y = data[":;:;1"][":"].T * scaling;
                ILArray<double> xO = repmat(linspace(1, numCols, numCols), numRows, 1)[":"].T;
                ILArray<double> yO = repmat(linspace(numRows, 1, numRows).T, 1, numCols)[":"].T;
                ret["0;:;0"] = xO - x;
                ret["1;:;0"] = xO + x - l / 2 * cos(alpha + beta);
                ret["2;:;0"] = xO + x;
                ret["3;:;0"] = xO + x - l / 2 * cos(alpha - beta);

                ret["0;:;1"] = yO - y;
                ret["1;:;1"] = yO + y - l / 2 * sin(alpha + beta);
                ret["2;:;1"] = yO + y;
                ret["3;:;1"] = yO + y - l / 2 * sin(alpha - beta);

                ret["0;0;2"] = 0.0;
                // prepare colors 
                ret[":;:;3:5"] = todouble(
                    repmat(colormap.Map
                            (tosingle(l) * colormap.Length).Reshape(1, l.Length, 3) * 255, 4, 1, 1));
                return ret.Reshape(4 * numRows * numCols, 6).T;
            }
Ejemplo n.º 9
0
 /// <summary>
 /// create new vector field (2D) plot 
 /// </summary>
 /// <param name="panel">panel hosting the scene</param>
 /// <param name="data">3d data array: :;:;0 - X coords of vectors, :;:;1 - Y coords</param>
 /// <param name="colormap">Colormap used for coloring, on null: Colormaps.ILNumerics is used as default</param>
 /// <param name="XLabels">labels for X axis, on null: auto labeling</param>
 /// <param name="YLabels">labels for Y axis, on null: auto labeling</param>
 public ILVectorField2D(ILPanel panel, ILBaseArray data
     , ILColormap colormap, ICollection<string> XLabels
     , ICollection<string> YLabels ) 
 : base (panel) {
     if (data == null || data.Dimensions[2] != 2 || data.IsEmpty) {
         throw new ILArgumentException("Invalid parameter: data");
     }
     m_data = data;
     m_xLabels = XLabels;
     m_yLabels = YLabels; 
     m_colormap = colormap;
     m_lines = new ILLines(m_panel,data.Dimensions[0]*data.Dimensions[1]*4);
     m_lines.Shading = ShadingStyles.Interpolate;
     m_lines.Properties.Width = 2;
     m_lines.Properties.Antialiasing = true;
     m_lines.Label.Text = "";
     ArrowHeadAngle = 10 * Math.PI / 180; 
     Invalidate(); 
     Add(m_lines);
 }