public void Paint(Painter p, Bilinear tx) { //in this version, I can't apply bilinear tx to current tx matrix using (VgPaintArgsPool.Borrow(p, out var paintArgs)) { paintArgs.PaintVisitHandler = (vxs, painterA) => { //use external painter handler //draw only outline with its fill-color. Drawing.Painter m_painter = painterA.P; Drawing.Color prevFillColor = m_painter.FillColor; m_painter.FillColor = m_painter.FillColor; using (VxsTemp.Borrow(out var v1)) { tx.TransformToVxs(vxs, v1); m_painter.Fill(v1); } m_painter.FillColor = prevFillColor; }; _vgVisElem.Paint(paintArgs); } }
private static Filter GetDemosaic(DcRawState state, int quality) { Filter demosaic; if (state.filters != 0 && state.document_mode == 0) { if (quality == 0) { demosaic = new Bilinear(state); } else if (quality == 1 || state.colors > 3) { Demosaic.PreInterpolate(state); throw new NotImplementedException(); //vng_interpolate(); } else if (quality == 2) { Demosaic.PreInterpolate(state); throw new NotImplementedException(); //ppg_interpolate(); } else { demosaic = new AHD(state); } } else { demosaic = new BasicDemosiac(state); } return(demosaic); }
public SuperChromaRes() { Passes = 1; Strength = 1.0f; Softness = 0.0f; Prescaler = true; upscaler = new Bilinear(); downscaler = new Bilinear(); }
public override void Update() { double[] sb = new double[4]; double[] sa = new double[4]; // Capacitors double c1 = component[0]; double c2 = component[1]; double c3 = component[2]; // Resistors double Ri = component[3]; // R-in double Ro = component[4]; // R-out double R2 = component[5]; // resistor in stack // Pot values, each side double T1 = component[6] * Parameters[P_TREBLE]; double T2 = component[6] * (1 - Parameters[P_TREBLE]); double B0 = component[8] * Parameters[P_BASS]; double M1 = component[7] * Parameters[P_MID]; // If fendermode = true then = 0 double M2 = (FenderMode) ? 0 : component[7] * (1 - Parameters[P_MID]); // numerator // s^0 sb[0] = Ro * 0; // s^1 sb[1] = Ro * (B0 * c1 + B0 * c2 + c1 * M1 + c2 * M1 + c3 * M1 + c1 * M2 + c2 * M2 + c1 * T1); // s^2 sb[2] = Ro * (B0 * c1 * c3 * M1 + B0 * c2 * c3 * M1 + c1 * c3 * M1 * M2 + c2 * c3 * M1 * M2 + B0 * c1 * c3 * R2 + c1 * c3 * M1 * R2 + c1 * c2 * M2 * R2 + c1 * c3 * M2 * R2 + c1 * c3 * M1 * T1 + c1 * c2 * M2 * T1 + c1 * (c2 + c3) * R2 * T1 + c1 * c3 * M1 * T2 + c1 * c2 * M2 * T2 + B0 * c1 * c2 * (R2 + T1 + T2) + c1 * c2 * M1 * (R2 + T1 + T2)); // s^3 sb[3] = Ro * (B0 * c1 * c2 * c3 * R2 * T1 + c1 * c2 * c3 * M2 * R2 * T1 + B0 * c1 * c2 * c3 * M1 * (R2 + T1 + T2) + c1 * c2 * c3 * M1 * M2 * (R2 + T1 + T2)); // denominator // s^0 sa[0] = B0 + M1 + M2 + Ro + T1; // s^1 sa[1] = (B0 * c3 * M1 + c3 * M1 * M2 + B0 * c3 * Ri + c3 * M1 * Ri + c1 * M2 * Ri + c2 * M2 * Ri + B0 * c3 * R2 + c3 * M1 * R2 + c2 * M2 * R2 + c3 * M1 * Ro + c1 * M2 * Ro + c2 * M2 * Ro + c1 * Ri * Ro + B0 * c1 * (Ri + Ro) + c1 * M1 * (Ri + Ro) + c3 * M1 * T1 + c2 * M2 * T1 + c1 * Ri * T1 + c2 * (Ri + R2) * (Ro + T1) + c3 * (Ri + R2) * (M2 + Ro + T1) + B0 * c2 * (Ri + R2 + Ro + T1) + c2 * M1 * (Ri + R2 + Ro + T1) + B0 * c1 * T2 + c1 * M1 * T2 + c1 * M2 * T2 + c1 * T1 * T2 + c1 * Ro * (T1 + T2)); // s^2 sa[2] = (B0 * c1 * c3 * M1 * Ri + c1 * c3 * M1 * M2 * Ri + B0 * c1 * c3 * Ri * R2 + c1 * c2 * M2 * Ri * R2 + B0 * c1 * c3 * M1 * Ro + c1 * c3 * M1 * M2 * Ro + B0 * c1 * c3 * Ri * Ro + B0 * c1 * c3 * R2 * Ro + c1 * c2 * M2 * R2 * Ro + c1 * c2 * M2 * Ri * T1 + B0 * c1 * c2 * (Ri + Ro) * (R2 + T1) + c1 * c2 * M1 * (Ri + Ro) * (R2 + T1) + c2 * c3 * M2 * Ri * (Ro + T1) + c2 * c3 * M2 * R2 * (Ro + T1) + B0 * c2 * c3 * (Ri + R2) * (Ro + T1) + B0 * c2 * c3 * M1 * (Ri + R2 + Ro + T1) + c2 * c3 * M1 * M2 * (Ri + R2 + Ro + T1) + B0 * c1 * c3 * M1 * T2 + c1 * c3 * M1 * M2 * T2 + B0 * c1 * c3 * Ri * T2 + c1 * c2 * M2 * Ri * T2 + B0 * c1 * c3 * R2 * T2 + c1 * c2 * M2 * R2 * T2 + c1 * c2 * M2 * T1 * T2 + B0 * c1 * c2 * (Ri + R2 + Ro + T1) * T2 + c1 * c2 * M1 * (Ri + R2 + Ro + T1) * T2 + c1 * (c2 + c3) * Ri * T1 * (R2 + T2) + c1 * c3 * M2 * R2 * (Ro + T2) + c1 * c3 * M2 * Ri * (R2 + Ro + T2) + c1 * c2 * M2 * Ro * (T1 + T2) + c1 * (c2 + c3) * Ri * Ro * (R2 + T1 + T2) + c1 * c3 * M1 * ((Ri + Ro) * (R2 + T1) + (Ri + R2 + Ro + T1) * T2) + c1 * (c2 + c3) * R2 * (T1 * T2 + Ro * (T1 + T2))); // s^3 sa[3] = (B0 * c1 * c2 * c3 * Ri * Ro * T1 + c1 * c2 * c3 * M2 * Ri * Ro * T1 + B0 * c1 * c2 * c3 * R2 * Ro * T1 + c1 * c2 * c3 * M2 * R2 * Ro * T1 + B0 * c1 * c2 * c3 * M1 * (Ri + Ro) * (R2 + T1) + c1 * c2 * c3 * M1 * M2 * (Ri + Ro) * (R2 + T1) + B0 * c1 * c2 * c3 * Ri * R2 * (Ro + T1) + c1 * c2 * c3 * M2 * Ri * R2 * (Ro + T1) + B0 * c1 * c2 * c3 * Ri * (Ro + T1) * T2 + c1 * c2 * c3 * M2 * Ri * (Ro + T1) * T2 + B0 * c1 * c2 * c3 * R2 * (Ro + T1) * T2 + c1 * c2 * c3 * M2 * R2 * (Ro + T1) * T2 + B0 * c1 * c2 * c3 * M1 * (Ri + R2 + Ro + T1) * T2 + c1 * c2 * c3 * M1 * M2 * (Ri + R2 + Ro + T1) * T2); //System.out.println("b: "+sb[0]+" + "+sb[1]+"s + "+sb[2]+"s^2 + "+sb[3]+"s^3"); //System.out.println("a: "+sa[0]+" + "+sa[1]+"s + "+sa[2]+"s^2 + "+sa[3]+"s^3"); double[] zb = new double[4]; double[] za = new double[4]; Bilinear.Transform(sb, sa, out zb, out za, Fs); this.B = zb; this.A = za; }
public override void Update() { double[] sb = { 4.545e5, 1.002e6 }; double[] sa = { 4.545e5, 2200 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, Fs); this.B = zb; this.A = za; }
public override void Update() { double[] sb = { 361.1423f, 0.4076f }; // 860hz ca double[] sa = { 5403.5f, 1f }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public static VertexStore TransformToVxs(this Bilinear bilinearTx, VertexStore src, VertexStore vxs) { int count = src.Count; VertexCmd cmd; double x, y; for (int i = 0; i < count; ++i) { cmd = src.GetVertex(i, out x, out y); bilinearTx.Transform(ref x, ref y); vxs.AddVertex(x, y, cmd); } return(vxs); }
private void _quadControl_ShapeUpdated(QuadWidgetControl sender, EventArgs arg) { //update shape of sprite //transform from original lionBounds to quadPolygon Quad2f quadCorners = _quadControl.GetQuadCorners(); _quadCorners[0] = quadCorners.left_top_x; _quadCorners[1] = quadCorners.left_top_y; _quadCorners[2] = quadCorners.right_top_x; _quadCorners[3] = quadCorners.right_top_y; _quadCorners[4] = quadCorners.right_bottom_x; _quadCorners[5] = quadCorners.right_bottom_y; _quadCorners[6] = quadCorners.left_bottom_x; _quadCorners[7] = quadCorners.left_bottom_y; //this is bilinear transformation if (_useBilinear) { Bilinear txBilinear = Bilinear.RectToQuad( _lionBounds.Left, _lionBounds.Top, _lionBounds.Right, _lionBounds.Bottom, _quadCorners); if (txBilinear.IsValid) { SpriteShape spriteShape = _mySprite.GetSpriteShape(); spriteShape.ResetTransform(); spriteShape.ApplyTransform(txBilinear); } } else { Perspective perspective = new Perspective( _lionBounds.Left, _lionBounds.Top, _lionBounds.Right, _lionBounds.Bottom, _quadCorners); if (perspective.IsValid) { SpriteShape spriteShape = _mySprite.GetSpriteShape(); spriteShape.ResetTransform(); spriteShape.ApplyTransform(perspective); } } }
public void Update() { var fRad = Fc * 2 * Math.PI; // prewarp // fRad = 2 / Ts * Math.Tan(fRad * Ts / 2); var w = 2 * Samplerate * Math.Tan(fRad * ts * 0.5); switch (Mode) { case FilterMode.LowPass: sb[0] = w * w; sb[1] = 0.0; sb[2] = 0.0; break; case FilterMode.HighPass: sb[0] = 0.0; sb[1] = 0.0; sb[2] = 1.0; break; case FilterMode.BandPass: sb[0] = 0.0; sb[1] = w / Q; sb[2] = 0.0; break; case FilterMode.Notch: sb[0] = w * w; // Can also choose another zero for interesting effects sb[1] = 0.0; sb[2] = 1.0; break; } sa[0] = w * w; sa[1] = w / Q; sa[2] = 1.0; Bilinear.StoZ2(sb, sa, zb, za, Samplerate); var gInv = 1.0 / za[0]; zb[0] *= gInv; zb[1] *= gInv; zb[2] *= gInv; za[0] = 1.0; za[1] *= gInv; za[2] *= gInv; }
public override void Update() { double R1 = 100e3 * (1 - parameters[P_GAIN]); double R2 = 8.2e3; double c1 = 0.068e-6; double[] sb = { 0, c1 *R2 }; double[] sa = { 1, c1 *(R1 + R2) }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { double R1 = 220e3; double R2 = 40e3; double c1 = 0.0022e-6; double c2 = 0.22e-6; double[] sb = { 1, (c1 * R1 + c2 * (R1 + R2)), c1 *c2 *R1 *R2 }; double[] sa = { 1, (c1 * R1 + c2 * R2), c1 *c2 *R1 *R2 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { double R1 = 100e3 * parameters[P_GAIN]; double R2 = 3.3e3; double c1 = 100e-12; double c2 = 0.047e-6; double[] sb = { 1, (c1 * R1 + c2 * (R1 + R2)), c1 *c2 *R1 *R2 }; double[] sa = { 1, (c1 * R1 + c2 * R2), c1 *c2 *R1 *R2 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { double c1 = 0.01e-6f; double r1 = 68e3f; double c2 = 250e-12f; double r2 = 1e6f; double[] sb = { 0, c1 *r2, 0 }; double[] sa = { 1, r2 *c2 + c1 * r1 + c1 * r2, r1 *r2 *c1 *c2 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double x = this.Parameters[P_PRES]; double C1 = 0.1e-6f; double R14 = 1e3f; double P = 2e3f * x; double[] b = { 1, C1 *P }; double[] a = { 1, C1 *(P + R14) }; double[] zb, za; Bilinear.Transform(b, a, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double c4 = 0.02e-6f; double c5 = 0.005e-6f; double r3 = 22e3f * P_USE_R3 + 100; double Rvol = 50e3f; double x = this.Parameters[P_GAIN]; double[] sb = { 0, -c4 * Rvol * x, c4 *Rvol *x *(-c5 * (Rvol + r3) + c5 * Rvol * x) }; double[] sa = { -1, (-c4 * Rvol - c5 * (Rvol + r3) + c5 * Rvol * x), -c4 * c5 * Rvol * (r3 - Rvol * (-1 + x) * x) }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double x = this.Parameters[P_VOL]; double C1 = 200e-9f; double C2 = 0.0002e-6f; double R2 = 100e3f * (1 - x); double R1 = 100e3f * x; //double R3 = 140e3f; double[] b = { 0, C1 *R1, C1 *C2 *R1 *R2 }; double[] a = { 1, (C1 * R1 + C1 * R2 + C2 * R2), C1 *C2 *R1 *R2 }; double[] zb, za; Bilinear.Transform(b, a, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double R1 = 560; double R2 = 47 + 10000 * parameters[P_RUETZ]; // ~ infinite resistance if ruetz = 1 // note, R2 can't go too big since it causes a massive DC offset spike. double C1 = 4.7e-6; double C2 = 2.2e-6; double Gain = 150e3 * parameters[P_GAIN]; double C3 = 100e-12; double[] sb = { 1.0f, (C1 * Gain + C2 * Gain + C3 * Gain + C1 * R1 + C2 * R2), (C1 * C2 * Gain * R1 + C1 * C3 * Gain * R1 + C1 * C2 * Gain * R2 + C2 * C3 * Gain * R2 + C1 * C2 * R1 * R2), (C1 * C2 * C3 * Gain * R1 * R2) }; double[] sa = { 1.0f, (C3 * Gain + C1 * R1 + C2 * R2), (C1 * C3 * Gain * R1 + C2 * C3 * Gain * R2 + C1 * C2 * R1 * R2), (C1 * C2 * C3 * Gain * R1 * R2) }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { var contour = parameters[P_CONTOUR]; if (contour < 0.02) { contour = 0.02; } double R1 = 100; double R2 = 33e3; double R3 = 33e3; double c1 = 0.1e-6; double c2 = 0.047e-6; double c3 = 0.22e-6; double c4 = 0.001e-6; double RO = 100e3; double P1 = 100e3 * contour; double P2 = 100e3 * (1 - contour); double b4 = (c1 * c2 * c3 * c4 * P1 * R2 * R3 * RO + c1 * c2 * c3 * c4 * P1 * P2 * (R2 + R3) * RO); double b3 = (c1 * c2 * c4 * P1 * R2 * R3 + c1 * c2 * c4 * P1 * P2 * (R2 + R3) + c1 * c2 * c3 * P1 * P2 * RO + c2 * c3 * c4 * R2 * R3 * RO + c1 * c3 * c4 * P1 * (R2 + R3) * RO + c2 * c3 * c4 * P2 * (R2 + R3) * RO); double b2 = (c1 * c2 * P1 * P2 + c2 * c4 * R2 * R3 + c1 * c4 * P1 * (R2 + R3) + c2 * c4 * P2 * (R2 + R3) + c1 * c3 * P1 * RO + c2 * c3 * P2 * RO + c3 * c4 * (R2 + R3) * RO); double b1 = (c1 * P1 + c2 * P2 + c4 * (R2 + R3) + c3 * RO); double b0 = 1; double a4 = c1 * c2 * c3 * c4 * (P1 * R1 * (R2 * R3 + P2 * (R2 + R3)) + (P1 * (P2 + R1) * R2 + R1 * R2 * R3 + P1 * (P2 + R1 + R2) * R3 + P2 * R1 * (R2 + R3)) * RO); double a3 = (c2 * c3 * c4 * (R1 * R2 * R3 + R2 * R3 * RO + R1 * (R2 + R3) * RO + P2 * (R2 + R3) * (R1 + RO)) + c1 * (c3 * c4 * (R2 + R3) * (R1 * RO + P1 * (R1 + RO)) + c2 * (c4 * (P2 * R1 + P1 * (P2 + R1)) * R2 + c4 * (R1 * (P2 + R2) + P1 * (P2 + R1 + R2)) * R3 + c3 * (R1 * (R2 * (R3 + RO) + P2 * (R2 + R3 + RO)) + P1 * ((R1 + R2) * (R3 + RO) + P2 * (R1 + R2 + R3 + RO)))))); double a2 = (c3 * c4 * (R2 + R3) * (R1 + RO) + c1 * (c2 * (R1 * (P2 + R2) + P1 * (P2 + R1 + R2)) + c4 * (P1 + R1) * (R2 + R3) + c3 * (R1 * (R2 + R3 + RO) + P1 * (R1 + R2 + R3 + RO))) + c2 * (c4 * (P2 + R1) * R2 + c4 * (P2 + R1 + R2) * R3 + c3 * ((R1 + R2) * (R3 + RO) + P2 * (R1 + R2 + R3 + RO)))); double a1 = (c3 * R1 + c1 * (P1 + R1) + c3 * R2 + c4 * R2 + c2 * (P2 + R1 + R2) + c3 * R3 + c4 * R3 + c3 * RO); double a0 = 1; double[] sb = { b0, b1, b2, b3, b4 }; double[] sa = { a0, a1, a2, a3, a4 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
void DrawingPanel_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Matrix4 mtx = Matrix4.CreateTranslation(-m_SVGPathBounds.Center.X, -m_SVGPathBounds.Center.Y); mtx.Scale(m_Scale, m_Scale, MatrixOrder.Append); mtx.Translate(m_x, m_y, MatrixOrder.Append); ITransform transform = null; if (rbBilinear.IsChecked) { Bilinear tr = new Bilinear( m_SVGPathScaledBounds.Left, m_SVGPathScaledBounds.Top, m_SVGPathScaledBounds.Right, m_SVGPathScaledBounds.Bottom, m_PolygonElement.Polygon); if (tr.IsValid) { transform = tr; } } else { Perspective tr = new Perspective( m_SVGPathScaledBounds.Left, m_SVGPathScaledBounds.Top, m_SVGPathScaledBounds.Right, m_SVGPathScaledBounds.Bottom, m_PolygonElement.Polygon); if (tr.IsValid() && Perspective.IsConvex(m_PolygonElement.Polygon)) { transform = tr; } } // GeometryTransformer transformer = null; if (transform != null) { transformer = new GeometryTransformer(transform); } // Render transformed SVG m_SVGPath.Render(e.Graphics, mtx, transformer); // Render transformed ellipse Point center = m_SVGPathScaledBounds.Center; EllipseGeometry FilledEllipse = new EllipseGeometry(center.X, center.Y, m_SVGPathScaledBounds.Width / 2, m_SVGPathScaledBounds.Height / 2, 200); GeometryStroke EllipseOutline = new GeometryStroke(FilledEllipse); EllipseOutline.Width = 3.0; Geometry TransformedFilledEllipse = FilledEllipse; Geometry TransformedEllipesOutline = EllipseOutline; if (transform != null) { TransformedFilledEllipse = new GeometryTransformer(FilledEllipse, transform); TransformedEllipesOutline = new GeometryTransformer(EllipseOutline, transform); } SmoothingMode saveSmoothingMode = e.Graphics.SmoothingMode; e.Graphics.SmoothingMode = SmoothingMode.None; { e.Graphics.FillGeometry(m_EllipseBrush, TransformedFilledEllipse); } e.Graphics.SmoothingMode = saveSmoothingMode; e.Graphics.FillGeometry(m_EllipsePen.Color, TransformedEllipesOutline); }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); IImageByte backBuffer = widgetsSubImage; if (!didInit) { didInit = true; OnInitialize(); } ImageBuffer image; if (backBuffer.BitDepth == 32) { image = new ImageBuffer(); image.Attach(backBuffer, new BlenderBGRA()); } else { if (backBuffer.BitDepth != 24) { throw new System.NotSupportedException(); } image = new ImageBuffer(); image.Attach(backBuffer, new BlenderBGR()); } ImageClippingProxy clippingProxy = new ImageClippingProxy(image); clippingProxy.clear(new ColorF(1, 1, 1)); g_rasterizer.SetVectorClipBox(0, 0, Width, Height); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); if (transformationTypeRadioButton.SelectedIndex == 0) { Bilinear tr = new Bilinear(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon()); if (tr.is_valid()) { //-------------------------- // Render transformed lion // foreach (var shape in lionShape.Shapes) { g_rasterizer.add_path(new VertexSourceApplyTransform(shape.VertexStorage, tr)); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, shape.Color); } //-------------------------- //-------------------------- // Render transformed ellipse // VertexSource.Ellipse ell = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5, (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5, 200); Stroke ell_stroke = new Stroke(ell); ell_stroke.width(3.0); VertexSourceApplyTransform trans_ell = new VertexSourceApplyTransform(ell, tr); VertexSourceApplyTransform trans_ell_stroke = new VertexSourceApplyTransform(ell_stroke, tr); g_rasterizer.add_path(trans_ell); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.5, 0.3, 0.0, 0.3)); g_rasterizer.add_path(trans_ell_stroke); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.0, 0.3, 0.2, 1.0)); } } else { Perspective tr = new Perspective(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon()); if (tr.is_valid()) { // Render transformed lion foreach (var shape in lionShape.Shapes) { VertexSourceApplyTransform trans = new VertexSourceApplyTransform(shape.VertexStorage, tr); g_rasterizer.reset(); g_rasterizer.add_path(trans); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, shape.Color); } // Render transformed ellipse VertexSource.Ellipse FilledEllipse = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5, (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5, 200); Stroke EllipseOutline = new Stroke(FilledEllipse); EllipseOutline.width(3.0); VertexSourceApplyTransform TransformedFilledEllipse = new VertexSourceApplyTransform(FilledEllipse, tr); VertexSourceApplyTransform TransformedEllipesOutline = new VertexSourceApplyTransform(EllipseOutline, tr); g_rasterizer.add_path(TransformedFilledEllipse); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.5, 0.3, 0.0, 0.3)); g_rasterizer.add_path(TransformedEllipesOutline); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0.0, 0.3, 0.2, 1.0)); } } //-------------------------- // Render the "quad" tool and controls g_rasterizer.add_path(quadPolygonControl); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(0, 0.3, 0.5, 0.6)); //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy); base.OnDraw(graphics2D); }
/// <summary> /// serialize coord-transform-chain to specific stream /// </summary> /// <param name="coordTx"></param> /// <param name="writer"></param> public static void Write(ICoordTransformer coordTx, System.IO.BinaryWriter writer) { //write transformation matrix to binary stream CoordTransformerKind txKind = coordTx.Kind; switch (txKind) { case CoordTransformerKind.Unknown: default: throw new System.NotSupportedException(); case CoordTransformerKind.Affine3x2: { Affine aff = (Affine)coordTx; writer.Write((ushort)txKind); //type AffineMat affMat = aff.GetInternalMat(); //write elements writer.Write(affMat.sx); writer.Write(affMat.shy); writer.Write(affMat.shx); writer.Write(affMat.sy); writer.Write(affMat.tx); writer.Write(affMat.ty); } break; case CoordTransformerKind.Bilinear: { Bilinear binTx = (Bilinear)coordTx; writer.Write((ushort)txKind); //write elements BilinearMat binMat = binTx.GetInternalElements(); writer.Write(binMat.rc00); writer.Write(binMat.rc01); writer.Write(binMat.rc10); writer.Write(binMat.rc11); writer.Write(binMat.rc20); writer.Write(binMat.rc21); writer.Write(binMat.rc30); writer.Write(binMat.rc31); } break; case CoordTransformerKind.Perspective: { Perspective perTx = (Perspective)coordTx; writer.Write((ushort)txKind); PerspectiveMat perMat = perTx.GetInternalElements(); writer.Write(perMat.sx); writer.Write(perMat.shx); writer.Write(perMat.w0); writer.Write(perMat.shy); writer.Write(perMat.sy); writer.Write(perMat.w1); writer.Write(perMat.tx); writer.Write(perMat.ty); writer.Write(perMat.w2); //sx, shy, w0, //shx, sy, w1, //tx, ty, w2; } break; case CoordTransformerKind.TransformChain: { CoordTransformationChain chainTx = (CoordTransformationChain)coordTx; writer.Write((ushort)txKind); //*** left, right Write(chainTx.Left, writer); Write(chainTx.Right, writer); } break; } }
public override void Draw(CanvasPainter p) { CanvasPainter painter = p; if (!didInit) { didInit = true; OnInitialize(); } //----------------------------------- painter.Clear(ColorRGBA.White); //IImageReaderWriter backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); //ChildImage image; //if (backBuffer.BitDepth == 32) //{ // image = new ChildImage(backBuffer, new PixelBlenderBGRA()); //} //else //{ // if (backBuffer.BitDepth != 24) // { // throw new System.NotSupportedException(); // } // image = new ChildImage(backBuffer, new PixelBlenderBGR()); //} //ClipProxyImage dest = new ClipProxyImage(image); //gx.Clear(ColorRGBA.White); //gx.SetClippingRect(new RectInt(0, 0, Width, Height)); //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear) { var bound = lionShape.Bounds; Bilinear txBilinear = Bilinear.RectToQuad(bound.Left, bound.Bottom, bound.Right, bound.Top, quadPolygonControl.GetInnerCoords()); if (txBilinear.IsValid) { painter.PaintSeries(txBilinear.TransformToVxs(lionShape.Path.Vxs), lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); RectD lionBound = lionShape.Bounds; Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); VertexStore trans_ell = txBilinear.TransformToVxs(ell.MakeVxs()); painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(trans_ell); //------------------------------------------------------------- //outline double prevStrokeWidth = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell); painter.StrokeWidth = prevStrokeWidth; } } else { var txPerspective = new Perspective( lionShape.Bounds, quadPolygonControl.GetInnerCoords()); if (txPerspective.IsValid) { painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Path.Vxs), lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); //-------------------------------------------------------------------------------------- //filled Ellipse //1. create original fill ellipse RectD lionBound = lionShape.Bounds; var filledEllipse = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); VertexStore transformedEll = txPerspective.TransformToVxs(filledEllipse.MakeVxs()); painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(transformedEll); //-------------------------------------------------------- var prevStrokeW = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(transformedEll); painter.StrokeWidth = prevStrokeW; } } //-------------------------- // Render the "quad" tool and controls painter.FillColor = ColorRGBA.Make(0f, 0.3f, 0.5f, 0.6f); painter.Fill(quadPolygonControl.MakeVxs()); }
public override void Draw(Painter p) { Painter painter = p; if (!_didInit) { _didInit = true; OnInitialize(); } //----------------------------------- painter.Clear(Drawing.Color.White); //lionFill.Render(painter); //IBitmapBlender backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); //ChildImage image; //if (backBuffer.BitDepth == 32) //{ // image = new ChildImage(backBuffer, new PixelBlenderBGRA()); //} //else //{ // if (backBuffer.BitDepth != 24) // { // throw new System.NotSupportedException(); // } // image = new ChildImage(backBuffer, new PixelBlenderBGR()); //} //ClipProxyImage dest = new ClipProxyImage(image); //gx.Clear(ColorRGBA.White); //gx.SetClippingRect(new RectInt(0, 0, Width, Height)); //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; //----------------------------------- RectD lionBound = _lionShape.Bounds; if (!_setQuadLion) { _quadPolygonControl.SetXN(0, lionBound.Left); _quadPolygonControl.SetYN(0, lionBound.Top); _quadPolygonControl.SetXN(1, lionBound.Right); _quadPolygonControl.SetYN(1, lionBound.Top); _quadPolygonControl.SetXN(2, lionBound.Right); _quadPolygonControl.SetYN(2, lionBound.Bottom); _quadPolygonControl.SetXN(3, lionBound.Left); _quadPolygonControl.SetYN(3, lionBound.Bottom); _setQuadLion = true; } // // //Bilinear txBilinear = Bilinear.RectToQuad(lionBound.Left, // lionBound.Bottom, // lionBound.Right, // lionBound.Top, // quadPolygonControl.GetInnerCoords()); //Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, // (lionBound.Bottom + lionBound.Top) * 0.5, // (lionBound.Right - lionBound.Left) * 0.5, // (lionBound.Top - lionBound.Bottom) * 0.5, // 200); //var v1 = new VertexStore(); //var trans_ell = new VertexStore(); //txBilinear.TransformToVxs(ell.MakeVxs(v1), trans_ell); ////ell.MakeVxs(v1); //painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f); //painter.Fill(trans_ell); ////outline //double prevStrokeWidth = painter.StrokeWidth; //painter.StrokeWidth = 3; //painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); //painter.Draw(trans_ell); //painter.StrokeWidth = prevStrokeWidth; if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear) { RectD bound = lionBound; //transform from original lionBounds to quadPolygon Bilinear txBilinear = Bilinear.RectToQuad( bound.Left, bound.Top, bound.Right, bound.Bottom, _quadPolygonControl.GetInnerCoords()); if (txBilinear.IsValid) { using (VxsTemp.Borrow(out var trans_ell_vxs)) using (VectorToolBox.Borrow(out Ellipse ellipse)) { _lionShape.Paint(painter, txBilinear); //transform before draw // ellipse.Set((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5); //ellipse=> transform coord with tx => fill to output ellipse.MakeVxs(txBilinear, trans_ell_vxs); painter.FillColor = _ellipseColor; painter.Fill(trans_ell_vxs); //------------------------------------------------------------- //outline double prevStrokeWidth = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell_vxs); painter.StrokeWidth = prevStrokeWidth; } } } else { RectD r = lionBound; //var txPerspective = new Perspective( // r.Left, r.Bottom, r.Right, r.Top, // quadPolygonControl.GetInnerCoords()); var txPerspective = new Perspective( r.Left, r.Top, r.Right, r.Bottom, _quadPolygonControl.GetInnerCoords()); if (txPerspective.IsValid) { //lionFill.Draw(p); //lionShape.Paint(p, txPerspective); //transform -> paint //painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Vxs, v1), // lionShape.Colors, // lionShape.PathIndexList, // lionShape.NumPaths); //-------------------------------------------------------------------------------------- //filled Ellipse //1. create original fill ellipse //RectD lionBound = lionShape.Bounds; using (VectorToolBox.Borrow(out Ellipse filledEllipse)) using (VxsTemp.Borrow(out var trans_ell_vxs)) { filledEllipse.Set((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); _lionShape.Paint(painter, txPerspective); //ellipse=> transform coord with tx => fill to output filledEllipse.MakeVxs(txPerspective, trans_ell_vxs); painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(trans_ell_vxs); //-------------------------------------------------------- double prevStrokeW = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell_vxs); painter.StrokeWidth = prevStrokeW; } } //} ////-------------------------- //// Render the "quad" tool and controls //painter.FillColor = ColorEx.Make(0f, 0.3f, 0.5f, 0.6f); //VectorToolBox.GetFreeVxs(out var v4); //painter.Fill(quadPolygonControl.MakeVxs(v4)); //VectorToolBox.ReleaseVxs(ref v4); } }
public static Tuple <double[], double[]> ComputeCoefficients(double fs, bool isHighpass, double cutoffHz, int order) { var T = 1.0 / fs; var warpedWc = 2 / T * Math.Tan(cutoffHz * 2 * Math.PI * T / 2); // don't go over nyquist, with 10 hz safety buffer if (warpedWc >= fs / 2 * 2 * Math.PI) { warpedWc = (fs - 10) / 2 * 2 * Math.PI; } double[] sa = null; double[] sb = new double[order + 1]; sb[0] = 1; Func <double, double> ScaleFreq = (power) => Math.Pow(1.0 / warpedWc, power); if (order == 1) { sa = new[] { 1.0, ScaleFreq(1) }; } else if (order == 2) { sa = new[] { 1.0, 1.4142 * ScaleFreq(1), 1 * ScaleFreq(2) }; } else if (order == 3) { sa = new[] { 1, 2 * ScaleFreq(1), 2 * ScaleFreq(2), 1 * ScaleFreq(3) }; } else if (order == 4) { sa = new[] { 1, 2.613 * ScaleFreq(1), 3.414 * ScaleFreq(2), 2.613 * ScaleFreq(3), 1 * ScaleFreq(4) }; } else if (order == 5) { sa = new[] { 1, 3.236 * ScaleFreq(1), 5.236 * ScaleFreq(2), 5.236 * ScaleFreq(3), 3.236 * ScaleFreq(4), 1 * ScaleFreq(5) }; } else if (order == 6) { sa = new[] { 1, 3.864 * ScaleFreq(1), 7.464 * ScaleFreq(2), 9.142 * ScaleFreq(3), 7.464 * ScaleFreq(4), 3.864 * ScaleFreq(5), 1 * ScaleFreq(6) }; } else { throw new Exception("Orders higher than 6 are not supported"); } if (isHighpass) { // When transforming to high pass, we replace all s with 1/s. // then we multiply both numerator and denominator with s^order. // Since the denom. of a butterworth filter is mirrored, we don't actually need to flip it // but when we flip the numerator, we end up with an s^Order, which also needs to be frequency scaled //Utils.ReverseInPlace(sa); Utils.ReverseInPlace(sb); sb[order] = sb[order] * ScaleFreq(order); } double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); return(Tuple.Create(zb, za)); }
public override void OnDraw() { IPixelFormat pixf; if (this.bpp() == 32) { pixf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); //pixf = new pixfmt_alpha_blend_rgba32(rbuf_window(), new blender_rgba32()); } else { if (bpp() != 24) { throw new System.NotSupportedException(); } pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); } FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(1, 1, 1)); g_rasterizer.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height()); if (m_trans_type.cur_item() == 0) { Bilinear <T> tr = new Bilinear <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon()); if (tr.IsValid()) { //-------------------------- // Render transformed lion // ConvTransform <T> trans = new ConvTransform <T>(g_path, tr); Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths); //-------------------------- //-------------------------- // Render transformed ellipse // VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5), g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5), 200); ConvStroke <T> ell_stroke = new ConvStroke <T>(ell); ell_stroke.Width = M.New <T>(3.0); ConvTransform <T> trans_ell = new ConvTransform <T>(ell, tr); ConvTransform <T> trans_ell_stroke = new ConvTransform <T>(ell_stroke, tr); g_rasterizer.AddPath(trans_ell); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3)); g_rasterizer.AddPath(trans_ell_stroke); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0)); } } else { Perspective <T> tr = new Perspective <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon()); if (tr.IsValid()) { // Render transformed lion ConvTransform <T> trans = new ConvTransform <T>(g_path, tr); Renderer <T> .RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths); // Render transformed ellipse VertexSource.Ellipse <T> FilledEllipse = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5), g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5), 200); ConvStroke <T> EllipseOutline = new ConvStroke <T>(FilledEllipse); EllipseOutline.Width = M.New <T>(3.0); ConvTransform <T> TransformedFilledEllipse = new ConvTransform <T>(FilledEllipse, tr); ConvTransform <T> TransformedEllipesOutline = new ConvTransform <T>(EllipseOutline, tr); g_rasterizer.AddPath(TransformedFilledEllipse); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3)); g_rasterizer.AddPath(TransformedEllipesOutline); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0)); } } //-------------------------- // Render the "quad" tool and controls g_rasterizer.AddPath(m_quad); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6)); //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy); base.OnDraw(); }