private void AddDataSource(IDataSource2D <double> field, Guid guid) { double minT, maxT; //if (colorMapControl.PaletteType == PaletteType.FromMaxMin) //{ // minT = colorMapControl.MinValue; // maxT = colorMapControl.MaxValue; //} //else //{ MathHelper.GetMaxMin(field.Data, out maxT, out minT); //colorMapControl.MinValue = minT; //colorMapControl.MaxValue = maxT; //} double k = 1.0 / (maxT - minT); List <Vertex.PositionColored> vertices = new List <Vertex.PositionColored>(); double altitude = layerHelper.GetNewAltitude(); for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { float x = (float)field.Grid[i, j].X; float y = (float)field.Grid[i, j].Y; LatLonAlt position = LatLonAlt.CreateUsingDegrees(y, x, altitude); Vector3F vec = new Vector3F(position.GetVector()); System.Windows.Media.Color color = palette.GetColor((field.Data[i, j] - minT) * k); vertices.Add(new Vertex.PositionColored(vec, Color.FromArgb(opacity, color.R, color.G, color.B).ToArgb())); } } MeshGraphicsObject <Vertex.PositionColored, ushort> mesh = new MeshGraphicsObject <Vertex.PositionColored, ushort>( GraphicsBufferUsage.Static, GraphicsBufferUsage.Static, vertices.Count, vertices.Count * 6, true); Material material = new Material { AmbientColor = Color.White, DiffuseColor = Color.White, SpecularColor = Color.White }; int id = mesh.Materials.Add(material); mesh.Vertices.AddData(vertices.ToArray()); for (int i = 0; i < field.Width - 1; i++) { for (int j = 0; j < field.Height - 1; j++) { mesh.Indices.AddData( (ushort)(i * field.Height + j), (ushort)(i * field.Height + j + 1), (ushort)((i + 1) * field.Height + j), PrimitiveType.TriangleList, id); mesh.Indices.AddData( (ushort)(i * field.Height + j + 1), (ushort)((i + 1) * field.Height + j + 1), (ushort)((i + 1) * field.Height + j), PrimitiveType.TriangleList, id); } } mesh.RenderState.Lighting.Enabled = false; mesh.RenderState.Alpha.Enabled = true; mesh.RenderState.Alpha.AlphaTestEnable = true; mesh.RenderState.Alpha.SourceBlend = Blend.BothInvSourceAlpha; mesh.RenderState.Alpha.DestinationBlend = Blend.BothInvSourceAlpha; mesh.RenderState.Cull.Enabled = false; meshLayers.Add(new MeshLayer { LayerAltitude = altitude, Mesh = mesh, Guid = guid, IsVisible = true, ScalarField = field }); }