public void Draw(Conv1D c) { // if (!dodraw) return; //Draw2Xsection(); return; drawlist.Add(c); Form df = this; int mar = 5; // y margin df.Show(); Graphics formGraphics = df.CreateGraphics(); // formGraphics.Clear(Conv2DColor.Green); Pen myPen = new Pen(col); myPen.Width *= 1; float ymax = c.Max(); // 1.5f; // c.Max() float ymin = -ymax * 0.5f; // c.Min() float rx = df.ClientSize.Width / (2 * drawRange); float ry = (df.ClientSize.Height - 2 * mar) / (ymax - ymin); float my = ymax + mar / ry; float ov = 0; for (float x = c.xlo; x <= c.xhi; x += c.xstep) { float v = c[x]; formGraphics.DrawLine(myPen, (x - c.xstep + drawRange) * rx, (my - ov) * ry, (x + drawRange) * rx, (my - v) * ry); ov = v; } myPen.Dispose(); formGraphics.Dispose(); // Draw2Xsection(); }
private void SetTexture(Effects effects, float[,] a, Conv1D c1d) { int M = a.GetLength(0); int N = a.GetLength(1); xwidth = c1d.xwidth; texture = new Texture2D(effects.graphicsDevice, N, M, 1, TextureUsage.Linear, SurfaceFormat.Single); texture.SetData <float>(Flatten(a)); //xlo = c1d.xlo; //xhi = c1d.xhi; //xstep = c1d.xstep; }
/// <summary>take a 1d conv and make it 2d by sweeping into a super-egg /// note: only +ve part of input conv will be used /// result will be array size K2xK2, with egg power p ///</summary> private float[,] Circle2D(int K2, double p, Conv1D c1d) { float[,] rv = new float[K2, K2]; for (int i = 0; i < K2; i++) { for (int j = 0; j < K2; j++) { if (i == (int)(K2 / 2) && j == (int)(K2 / 2)) { } float ii = Math.Abs(P(i, K2)); float jj = Math.Abs(P(j, K2)); float rr = (float)Math.Pow(Math.Pow(ii, p) + Math.Pow(jj, p), 1 / p); rv[i, j] = c1d[rr]; } } return(rv); }
/// <summary>convolve two 1d convolutions</summary> public static Conv1D operator *(Conv1D ca, Conv1D cb) { // conserve same spacing as ca int N = (int)Math.Round((ca.xwidth + cb.xwidth) / ca.xstep); Conv1D cc = new Conv1D(N, (ca.xwidth + cb.xwidth) / 2); float[] rv = cc.v; int i = 0; for (float rx = cc.xlo; rx <= cc.xhi; rx += cc.xstep) // rx position in output { for (float bx = cb.xlo; bx <= cb.xhi; bx += ca.xstep) // bx position in b { rv[i] += ca[rx - bx] * cb[bx]; } i++; } return(cc); }
public Lanczos(Form1 form1, int a, double LancW, double SQWidth, int K, Effects effects) : base(effects) { //toggle = !toggle; if (toggle) return MakeLanczosOld(a, K); if (K == 0) { K = 16; // default } int s = (int)Math.Ceiling(Math.Log(2 * a * K, 2)); int N = (int)Math.Round(Math.Pow(2, s)); // actual size of texture float LSQWidth = (float)(Math.Max(0.001f, SQWidth)); // K * 8; // K * 4; Lanc1D lanc = new Lanc1D(a, K * 20, (float)LancW); //lanc.SetRange((float)LancW); SQ1D sq = new SQ1D(LSQWidth); Conv1D lancsq = lanc * sq; SetTexture(effects, 64, lancsq); form1.Draw(lancsq); }
/// <summary>make a 2d convolution (with texture) from a 1d convolution (with array)</summary> public void SetTexture(Effects effects, int K, Conv1D c1d) { xwidth = c1d.xwidth; float[,] v2d = Circle2D(K, Form1.CircP, c1d); SetTexture(effects, v2d, c1d); }