当前位置: 首页>>代码示例>>C#>>正文


C# ILArray.SetValue方法代码示例

本文整理汇总了C#中ILArray.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ILArray.SetValue方法的具体用法?C# ILArray.SetValue怎么用?C# ILArray.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILArray的用法示例。


在下文中一共展示了ILArray.SetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateData

 public static ILArray<float> CreateData(int rX, int rY) {
     
     Bitmap heightmap = Resource1.saltlake;
     int x = Math.Min(heightmap.Size.Width,rX); 
     int y = Math.Min(heightmap.Size.Height,rY);
     ILArray<float> ret = new ILArray<float>(rX, rY); 
     for (int c = 0; c < x; c++) {
         for (int r = 0; r < y; r++) {
             Color val = heightmap.GetPixel(c,r);
             ret.SetValue(val.GetBrightness(),r,c); 
         }
     }
     float maxVal = (float)maxall(abs(ret)); 
     if (maxVal != 0)
         ret /= maxVal; 
     ret *= 50; 
     return ret; // ["0:2:end;0:2:end"]; 
 }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:18,代码来源:Form1.cs

示例2: CreateMap

 /// <summary>
 /// create colormap
 /// </summary>
 /// <param name="map">map specification</param>
 /// <param name="len">len of colormap</param>
 /// <returns>colormap (matrix with size [len,3])</returns>
 internal static ILArray<float> CreateMap(Colormaps map, int len) {
     ILArray<float> ret = null; 
     ILArray<double> retd; // helper var 
     int n; 
     switch (map) {
         case Colormaps.Autumn:
             ret = tosingle(horzcat(ones(len,1),linspace(0,1.0,len).T,zeros(len,1))); 
             break;
         case Colormaps.Bone:
             ret = CreateMap( Colormaps.Hot)[":;end:-1:0"]; 
             ret = (tosingle(repmat(linspace(0,1.0,len).T,1,3)*7.0) + ret)/8.0f;                        
             break;
         case Colormaps.Colorcube:
             throw new NotImplementedException("ILColormap: sorry, colorcube must be implemented!"); 
             break;
         case Colormaps.Cool:
             retd = horzcat(linspace(0,1.0,len).T,linspace(1.0,0.0,len).T,ones(len,1));
             ret = tosingle(retd); 
             break;
         case Colormaps.Copper:
             retd = linspace(0,1.0,len).T; 
             ret = ILArray<float>.empty(); 
             ret = tosingle(min(1.0,retd*1.25)); 
             ret[":;1"] = tosingle(retd*0.782); 
             ret[":;2"] = tosingle(retd*0.4975); 
             break;
         case Colormaps.Flag:
             retd = new double[,]{{1, 0, 0},{1, 1, 1},{0, 0, 1},{0, 0, 0}}; 
             retd = repmat(retd.T,(int)ceil((double)len/retd.Dimensions[1]),1); 
             ret = tosingle(retd[vector(0,len-1),null]); 
             break;
         case Colormaps.Gray:
             ret = tosingle(repmat(linspace(0,1.0,len).T,1,3)); 
             break;
         case Colormaps.Hot:
             n = (int)fix(len/8.0*3);
             retd = zeros(len,3); 
             ILArray<double> rng = vector(0,n-1); 
             retd[rng,0] = linspace (0,1.0,n); 
             retd[vector(n,len-1),0] = 1.0;
             retd[rng+n,1] = linspace (0,1.0,n); 
             retd[vector(2*n,len-1),1] = 1.0;
             rng = vector(len-2*n,len-1); 
             retd[rng,2] = linspace (0,1.0,rng.Length); 
             ret = tosingle(retd); 
             break;
         case Colormaps.Hsv:
             n = len / 6; 
             // red 
             ILArray<double> peak = 2.0-abs(linspace(2,-2,4*n)); 
             retd = zeros(len,3); 
             retd[vector(len - peak.Length,len-1),0] = peak;
             retd[vector(0  ,4*n-1),1] = peak;
             retd[vector(0  ,2*n-1),2] = peak[vector(2*n,4*n-1)];  
             retd[vector(len - 2*n,len-1),2] = peak[vector(0  ,2*n-1)];  
             retd[retd > 1] = 1; 
             ret = tosingle(retd); 
             break;
         case Colormaps.ILNumerics:
             ret = new ILArray<float>(len,3); 
             int tmp; 
             ILColorProvider cprov = new ILColorProvider(0.0f,0.5f,1.0f); 
             rng = linspace(ILColorProvider.MAXHUEVALUE,0.0,len);
             for (int i = 0; i < len; i++) {
                 tmp = cprov.H2RGB((float)rng[i]); 
                 ret.SetValue((float)(tmp>>16 & 255),i,0); 
                 ret.SetValue((float)(tmp>>8 & 255),i,1); 
                 ret.SetValue((float)(tmp & 255),i,2); 
             }
             ret /= 255.0f; 
             break; 
         case Colormaps.Jet:
             n = len / 8; 
             // red 
             peak = 1.5-abs(linspace(1.5,-1.5,6*n)); 
             retd = zeros(len,3); 
             retd[vector(0  ,5*n-1),0] = peak[vector(n,6*n-1)];
             retd[vector(n  ,7*n-1),1] = peak;
             retd[vector(3*n,8*n-1),2] = peak[vector(0,5*n-1)];  
             retd[retd > 1] = 1; 
             ret = tosingle(retd); 
             break;
         case Colormaps.Lines:
             retd = randn(len,3); 
             retd /= maxall(abs(retd)); 
             ret = tosingle(1.0-abs(retd)); 
             break;
         case Colormaps.Pink:
             ret = CreateMap(Colormaps.Hot,len); 
             ret = sqrt((repmat(tosingle(linspace(0,1.0,len).T),1,3)*2.0f + ret)/3.0f); 
             break;
         case Colormaps.Prism:
             retd = new double[,]{{1, 0, 0},{1, 0.5, 0},{1, 1, 0},{0, 1, 0},{0, 0, 1},{2/3.0, 0, 1}}; 
             retd = repmat(retd.T,(int)ceil((double)len/retd.Dimensions[1]),1); 
//.........这里部分代码省略.........
开发者ID:wdxa,项目名称:ILNumerics,代码行数:101,代码来源:ILColormap.cs

示例3: Map

        /// <summary>
        /// map all elements in A into final colors
        /// </summary>
        /// <param name="A">array with elements to map</param>
        /// <returns>colors as ILArray, the i-th row represents the color for the i-th element of A as RGB tripel.</returns>
        public ILArray<float> Map (ILArray<float> A) {
            ILArray<float> ret = new ILArray<float>(A.Dimensions.NumberOfElements,3); 
            float min, max;
            if (!A.GetLimits(out min, out max) || min == max) {
                // special case: all constant: eturn middle of colormap
                return ILMath.repmat(m_map[m_map.Length / 2, null], ret.Dimensions[0], 1);
            }

            float dist = (m_map.Dimensions[0]-1) / (A.MaxValue - min);
            for (int i = 0; i < ret.Dimensions[0]; i++) {
                double index = (double)(A.GetValue(i)-min)*dist;
                if (index >= m_map.Dimensions[0] - 1) {
                    ret[i, null] = m_map["end;:"];
                    continue;
                } else if (index < 0) {
                    ret[i, null] = m_map["0;:"];
                    continue;
                }
                int find = (int)Math.Floor(index); 
                if (find == index) { 
                    ret[i,null] = m_map[find,null];
                    continue; 
                }
                // interpolate
                index = index - find; 
                float r1 = m_map.GetValue(find,0);
                float g1 = m_map.GetValue(find,1); 
                float b1 = m_map.GetValue(find,2); 
                r1 = (float)(index*(m_map.GetValue(find+1,0)-r1)+r1); 
                g1 = (float)(index*(m_map.GetValue(find+1,1)-g1)+g1); 
                b1 = (float)(index*(m_map.GetValue(find+1,2)-b1)+b1); 
                ret.SetValue(r1,i,0); 
                ret.SetValue(g1,i,1); 
                ret.SetValue(b1,i,2); 
            }
            return ret; 
        }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:42,代码来源:ILColormap.cs

示例4: LoadSTL

            public static ILLitTriangles LoadSTL(ILPanel panel, string par1) {
                string[] lines; 
                // modify according the number format in the stl file! Here: 0.12345
                System.Globalization.NumberFormatInfo nfi =
                    new System.Globalization.CultureInfo("en-US").NumberFormat;
                if (String.IsNullOrEmpty(par1.Trim()) || !System.IO.File.Exists(par1)) {
                    par1 = Resource1.gear; 
                    lines = par1.Split('\n'); 
                } else {
                    lines = System.IO.File.ReadAllLines(par1);
                }
                #region parse and load vertices
                // predefine array (for performance)
                ILArray<float> vertexData = new ILArray<float>(6, (int)(lines.Length / 2.0));
                int count = 0;
                float NX = 0, NY = 0, NZ = 0;
                foreach (string line in lines) {
                    int start = line.IndexOf("vertex");
                    if (start >= 0) {
                        // vertex found
                        start += 6;
                        string[] valsS = line.Substring(start).Trim().Split(new char[] {' '},StringSplitOptions.RemoveEmptyEntries);
                        if (valsS != null && valsS.Length >= 3) {
                            float X, Y, Z;
                            // vertex is valid (may be..) 
                            X = float.Parse(valsS[0], nfi);
                            Y = float.Parse(valsS[1], nfi);
                            Z = float.Parse(valsS[2], nfi);
                            // store for later 
                            vertexData.SetValue(X, 0, count);
                            vertexData.SetValue(Y, 1, count);
                            vertexData.SetValue(Z, 2, count);
                            vertexData.SetValue(NX, 3, count);
                            vertexData.SetValue(NY, 4, count);
                            vertexData.SetValue(NZ, 5, count);
                            count++;
                        }
                    } else {
                        start = line.IndexOf("normal");
                        if (start >= 0) {
                            // normal entry found
                            start += 6;
                            string[] valsN = line.Substring(start).Trim().Split(' ');
                            if (valsN != null && valsN.Length == 3) {
                                // normal is valid, cache it
                                NX = float.Parse(valsN[0], nfi);
                                NY = float.Parse(valsN[1], nfi);
                                NZ = float.Parse(valsN[2], nfi);
                            }
                        }
                    }
                }
                // truncate temp array, remove trail not needed 
                vertexData = vertexData[":;0:" + (count - 1)];
                #endregion

                #region create + configure composite shape
                ILLitTriangles ret = new ILLitTriangles(
                        panel  // panel hosting the scene
                        , vertexData["0;:"] // X components
                        , vertexData["1;:"] // Y components 
                        , vertexData["2;:"]); // Z components
                ret.AutoNormals = false;
                for (int i = 0; i < ret.Vertices.Length; i++) {
                    ret.Vertices[i].Normal = new ILPoint3Df(
                                   vertexData.GetValue(3, i)
                                  , vertexData.GetValue(4, i)
                                  , vertexData.GetValue(5, i));
                    ret.Vertices[i].Color = Color.FromArgb(255, 100, 100, 100);
                    ret.Vertices[i].Alpha = 255;
                }
                #endregion
                return ret;
            }
开发者ID:wdxa,项目名称:ILNumerics,代码行数:74,代码来源:Form1.cs


注:本文中的ILArray.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。