/// <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); ret = tosingle(retd[vector(0, len - 1), null]); break; case Colormaps.Spring: retd = ones(len, 1); retd[":;1"] = linspace(0.0, 1.0, len); retd[":;2"] = linspace(1.0, 0.0, len); ret = tosingle(retd); break; case Colormaps.Summer: retd = linspace(0.0, 1.0, len).T; retd[":;1"] = 0.5 + retd / 2.0;; retd[":;2"] = ones(len, 1) * 0.4; ret = tosingle(retd); break; case Colormaps.White: ret = tosingle(ones(len, 3)); break; case Colormaps.Winter: retd = zeros(len, 1); retd[":;2"] = 0.5 + (1.0 - linspace(0.0, 1.0, len)) / 2.0; retd[":;1"] = linspace(0.0, 1.0, len); ret = tosingle(retd); break; } return(ret); }
/// <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); ret = tosingle(retd[vector(0,len-1),null]); break; case Colormaps.Spring: retd = ones(len,1); retd[":;1"] = linspace(0.0,1.0,len); retd[":;2"] = linspace(1.0,0.0,len); ret = tosingle(retd); break; case Colormaps.Summer: retd = linspace(0.0,1.0,len).T; retd[":;1"] = 0.5+retd/2.0;; retd[":;2"] = ones(len,1)*0.4; ret = tosingle(retd); break; case Colormaps.White: ret = tosingle(ones(len,3)); break; case Colormaps.Winter: retd = zeros(len,1); retd[":;2"] = 0.5+(1.0-linspace(0.0,1.0,len))/2.0; retd[":;1"] = linspace(0.0,1.0,len); ret = tosingle(retd); break; } return ret; }
protected void CreateVertices(object sender, EventArgs e) { VertexBuffer buffer = (VertexBuffer)sender; VERTEX_FORMAT[] vertices = (VERTEX_FORMAT[])buffer.Lock(0,0); float val = 0.0f; float minZ = m_globalClipping.ZMin; float maxZ = m_globalClipping.ZMax; float a = MAXHUEVALUE / (maxZ - minZ); float b = -minZ * a; int i=0; ILColorProvider colHelp = new ILColorProvider(0.0f,0.5f,1.0f); for (int r = 0; r < m_rows; r++) { for (int c = 0; c < m_cols; c++) { val = m_sourceArray.GetValue(c,r); vertices[i].X = c; vertices[i].Y = r; vertices[i].Z = val; vertices[i++].Color = colHelp.H2RGB(MAXHUEVALUE - val * a - b); } } #region create normals // Vector3 normal; i = 0; for (int r = 0; r < m_rows; r++) { for (int c = 0; c < m_cols; c++,i++) { normal = new Vector3(); if (c > 0 && c < m_cols) normal.Add(vertices[i-1].Position); if (c < m_cols-1) normal.Add(vertices[i+1].Position); if (r > 0 && r < m_rows) normal.Add(vertices[i-m_cols].Position); if (r < m_rows - 1) normal.Add(vertices[i+m_cols].Position); normal.Normalize(); vertices[i].Normal = normal; } } #endregion buffer.Unlock(); m_vertexReady = true; }