internal static void Build(PointModel model, int nx, int ny, int nz, float radius, float minValue, float maxValue) { Random positionRandom = new Random(); Random colorRandom = new Random(); Vertex min = new Vertex(), max = new Vertex(); bool isInit = false; unsafe { for (long i = 0; i < model.PointCount; i++) { float x = minValue + ((float)positionRandom.NextDouble()) * (maxValue - minValue); float y = minValue + ((float)positionRandom.NextDouble()) * (maxValue - minValue); float z = minValue + ((float)positionRandom.NextDouble()) * (maxValue - minValue); if (!isInit) { min = new Vertex(x, y, z); max = new Vertex(x, y, z); isInit = true; } if (x < min.X) { min.X = x; } if (x > max.X) { max.X = x; } if (y < min.Y) { min.Y = y; } if (y > max.Y) { max.Y = y; } if (z < min.Z) { min.Z = z; } if (z > max.Z) { max.Z = z; } Vertex *positions = model.Positions; positions[i].X = x; positions[i].Y = y; positions[i].Z = z; ByteColor *colors = model.Colors; colors[i].red = (byte)colorRandom.Next(0, 256 / 2);// 256 / 2 is max color in byte. colors[i].green = (byte)colorRandom.Next(0, 256 / 2); colors[i].blue = (byte)colorRandom.Next(0, 256 / 2); } model.BoundingBox.MaxPosition = max; model.BoundingBox.MinPosition = min; } }
private static unsafe OrthoColorIndicatorBar CreateBar(ColorTemplate colorTemplate) { OrthoColorIndicatorBar bar = new OrthoColorIndicatorBar() { Name = "color indicator's bar" }; // initialize rectangles with gradient color. { int length = colorTemplate.Colors.Length; PointerScientificModel rectModel = new PointerScientificModel(length * 2, Enumerations.BeginMode.QuadStrip); Vertex *positions = rectModel.Positions; for (int i = 0; i < length; i++) { positions[i * 2].X = colorTemplate.Width * i / (length - 1); positions[i * 2].Y = 0; positions[i * 2].Z = 0; positions[i * 2 + 1].X = colorTemplate.Width * i / (length - 1); positions[i * 2 + 1].Y = colorTemplate.Height; positions[i * 2 + 1].Z = 0; } ByteColor *colors = rectModel.Colors; for (int i = 0; i < length; i++) { GLColor color = colorTemplate.Colors[i]; colors[i * 2].red = (byte)(color.R * byte.MaxValue / 2); colors[i * 2].green = (byte)(color.G * byte.MaxValue / 2); colors[i * 2].blue = (byte)(color.B * byte.MaxValue / 2); colors[i * 2 + 1].red = (byte)(color.R * byte.MaxValue / 2); colors[i * 2 + 1].green = (byte)(color.G * byte.MaxValue / 2); colors[i * 2 + 1].blue = (byte)(color.B * byte.MaxValue / 2); } bar.rectModel = rectModel; } // initialize two horizontal white lines. { int length = 4; PointerScientificModel horizontalLines = new PointerScientificModel(length, Enumerations.BeginMode.Lines); Vertex *positions = horizontalLines.Positions; positions[0].X = 0; positions[0].Y = 0; positions[0].Z = 0; positions[1].X = colorTemplate.Width; positions[1].Y = 0; positions[1].Z = 0; positions[2].X = 0; positions[2].Y = colorTemplate.Height; positions[2].Z = 0; positions[3].X = colorTemplate.Width; positions[3].Y = colorTemplate.Height; positions[3].Z = 0; ByteColor *colors = horizontalLines.Colors; for (int i = 0; i < length; i++) { colors[i].red = byte.MaxValue / 2; colors[i].green = byte.MaxValue / 2; colors[i].blue = byte.MaxValue / 2; } bar.horizontalLines = horizontalLines; } // initialize vertical lines. { int length = colorTemplate.Colors.Length; PointerScientificModel verticalLines = new PointerScientificModel(length * 2, Enumerations.BeginMode.Lines); Vertex *positions = verticalLines.Positions; for (int i = 0; i < length; i++) { positions[i * 2].X = colorTemplate.Width * i / (length - 1); positions[i * 2].Y = -9; positions[i * 2].Z = 0; positions[i * 2 + 1].X = colorTemplate.Width * i / (length - 1); positions[i * 2 + 1].Y = colorTemplate.Height; positions[i * 2 + 1].Z = 0; } ByteColor *colors = verticalLines.Colors; for (int i = 0; i < length * 2; i++) { colors[i].red = byte.MaxValue / 2; colors[i].green = byte.MaxValue / 2; colors[i].blue = byte.MaxValue / 2; } bar.verticalLines = verticalLines; } // initialize rectangles' scale effect so that it always padding to left, right and bottom with fixed value. { OrthoColorIndicatorBarEffect scaleEffect = new OrthoColorIndicatorBarEffect(); scaleEffect.colorTemplate = colorTemplate; bar.AddEffect(scaleEffect); bar.scaleEffect = scaleEffect; } return(bar); }