public Engine.Surface.Canvas GetVectorFieldSketch() { t_vectorFieldSketch = new Surface.Canvas(Width, Height, Engine.Colors.White); for (int x = 0; x < t_cells.GetLength(0); x++) { for (int y = 0; y < t_cells.GetLength(1); y++) { PressureGridCell gc = t_cells[x, y]; Engine.Point pStart = new Point((x * gc.Width) - (gc.Width / 2), (y * gc.Height) - (gc.Height / 2)); Engine.Calc.Vector shortV = new Calc.Vector(0, 0); shortV += gc.Pressure; shortV.SetMagnitude(gc.Width / 2); Engine.Point pEnd = new Point(pStart.X + (int)shortV.X, pStart.Y + (int)shortV.Y); Engine.Tools.Drawing.DrawLine(t_vectorFieldSketch, pStart, pEnd, Engine.Colors.Black); } } return(t_vectorFieldSketch); }
private void SetField() { t_field = new List <List <Engine.Calc.Vector> >(); for (int i = 0; i < t_imageSource.Width; i++) { t_field.Add(new List <Engine.Calc.Vector>()); } double[] lums = new double[t_imageSource.Height * t_imageSource.Width]; int[] reds = new int[t_imageSource.Height * t_imageSource.Width]; int[] greens = new int[t_imageSource.Height * t_imageSource.Width]; int[] blues = new int[t_imageSource.Height * t_imageSource.Width]; int offset = 0; for (int y = 0; y < t_imageSource.Height; y++) { for (int x = 0; x < t_imageSource.Width; x++) { Engine.Color.Cell c = t_imageSource.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnNeutralGray); c.InArray(ref blues, ref greens, ref reds, offset); offset++; } } Engine.EngineCppLibrary.Luminance s_luminance = (Engine.EngineCppLibrary.Luminance)Marshal.GetDelegateForFunctionPointer( Engine.EngineCppLibrary.Pointer_luminance, typeof(Engine.EngineCppLibrary.Luminance)); s_luminance(t_imageSource.Height * t_imageSource.Width, blues, greens, reds, lums); offset = 0; for (int y = 0; y < t_imageSource.Height; y++) { for (int x = 0; x < t_imageSource.Width; x++) { double lum = lums[offset]; /* * surrounding cell config * 0 1 2 * * 7 x 3 * * 6 5 4 * */ double[] localLums = new double[8]; localLums[0] = GetLum(lums, x - 1, y - 1); localLums[1] = GetLum(lums, x, y - 1); localLums[2] = GetLum(lums, x + 1, y - 1); localLums[3] = GetLum(lums, x + 1, y); localLums[4] = GetLum(lums, x + 1, y + 1); localLums[5] = GetLum(lums, x, y + 1); localLums[6] = GetLum(lums, x - 1, y + 1); localLums[7] = GetLum(lums, x - 1, y); if (t_invertLuminance) { lum = 255 - lum; localLums[0] = 255 - localLums[0]; localLums[1] = 255 - localLums[1]; localLums[2] = 255 - localLums[2]; localLums[3] = 255 - localLums[3]; localLums[4] = 255 - localLums[4]; localLums[5] = 255 - localLums[5]; localLums[6] = 255 - localLums[6]; localLums[7] = 255 - localLums[7]; } double[] lumDiffs = new double[8]; for (int i = 0; i < lumDiffs.Length; i++) { lumDiffs[i] = lum - localLums[i]; } Engine.Calc.Vector[] vs = new Calc.Vector[lumDiffs.Length]; vs[0] = new Engine.Calc.Vector(-1, -1); vs[1] = new Engine.Calc.Vector(0, -1); vs[2] = new Engine.Calc.Vector(1, -1); vs[3] = new Engine.Calc.Vector(1, 0); vs[4] = new Engine.Calc.Vector(1, 1); vs[5] = new Engine.Calc.Vector(0, 1); vs[6] = new Engine.Calc.Vector(-1, 1); vs[7] = new Engine.Calc.Vector(-1, 0); Engine.Calc.Vector v_this = new Engine.Calc.Vector(0, 0); for (int i = 0; i < vs.Length; i++) { vs[i].SetMagnitude(lumDiffs[i]); v_this += vs[i]; } //v_this.Normalize(Calc.CalculationStyles.Accord); t_field[x].Add(v_this); offset++; } } }