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; }
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; }