public static void SetColorByHeight(vtkPolyData data, Rectangle rect) { double zmin = data.GetPoint(0)[2]; double zmax = zmin; for (int i = 0; i < rect.Width * rect.Height; i++) { double z = data.GetPoint(i)[2]; if (z < zmin) { zmin = z; } if (z > zmax) { zmax = z; } } //Console.WriteLine("Zmin:" + zmin + " Zmax:" + zmax); vtkColorTransferFunction colorFunction = vtkColorTransferFunction.New(); colorFunction.AddRGBPoint(zmin, 0, 0, 1); colorFunction.AddRGBPoint(zmax, 1, 0, 0); //Console.WriteLine("Color:" + colorFunction.GetColor(0)[0] + " " // + colorFunction.GetColor(0)[1] + " " // + colorFunction.GetColor(0)[2]); for (int i = 0; i < rect.Width * rect.Height; i++) { double z = data.GetPoint(i)[2]; double[] c = colorFunction.GetColor(z); data.GetPointData().GetScalars().SetTuple3(i, c[0] * 255, c[1] * 255, c[2] * 255); } data.Modified(); }