/// <summary> /// Add to the sequence of Transforms; Scale the entity over a period of time. /// </summary> /// <param name="scale">The scale to transition to.</param> /// <param name="duration">Time taken to reach the goal scale. (seconds)</param> /// <returns></returns> public Transformer ScaleTo(Vector2 size, float duration, Interpolation.InterpolationMethod interpolation) { ScaleTransform transform = ScaleTransform.Create(_entity, size, duration); transform.InterpolationMethod = interpolation; _transforms.Enqueue(transform); return this; }
/// <summary> /// gets a key value of defined time using interpolation method. /// </summary> /// <param name="t">defined time</param> /// <param name="mode">interpolation method</param> /// <returns>key value</returns> public float GetKeyFrame(float t, Interpolation mode) { int idx = -1; float s = 0.0f; if (Time != null && Time.Count > 0) idx = GetTimeIndex(t); else idx = GetIndex(t); if (idx >= Count) idx = Count - 1; switch (mode) { case Interpolation.Lerp: { if (idx < (Count - 1)) { if( Time != null && Time.Count > 0) s = (t - Time[idx]) / (Time[idx + 1] - Time[idx]); else s = (t - ((float)idx * step)) * (float)Count; return Table[idx] + ((Table[idx + 1] - Table[idx]) * s); } return Table[idx]; } default: { return Table[idx]; } } }
public Slider(PercentChanged onChanged, float current = 1, float min = 0, float max = 1) { _onChanged = onChanged; _valueToCurrent = new Interpolation(min, max, 0, 1);; _currentToValue = new Interpolation(0, 1, min, max); Current = _valueToCurrent.From(current); Size = new Size(150, 15f); }
public MouseZoomController(float minZoom = 0.01f, float maxZoom = 2, UpdateTime updateTime = UpdateTime.Sim) { _updateTime = updateTime; _minZoom = minZoom; _maxZoom = maxZoom; _wheelIndexToZoomValue = new Interpolation(_minWheel, _maxWheel, _minZoom, _maxZoom, Ease); CurrentZoom = _wheelIndexToZoomValue.From(_currentWheelIndex); Add(new MouseWheelBinding(ChangeWheelIndex)); }
public SoundTest() { const string soundFilePath = @"C:\docs\music\Daft Punk - Random Access Memories (2013) [320 Kbps]\CD\08 Get Lucky (Feat. Pharrell Williams).mp3"; var sound = Add(new SoundFx(soundFilePath)); sound.Play(); _lowpass = new LowPassFilter(); sound.Filters.Add(_lowpass); _lpInterp = new Interpolation(-500, 500, 10, 8000, Sine.EaseOut); _resInterp = new Interpolation(-1000, 1000, 0, .4f, Sine.EaseIn); Add(new MouseButtonBinding(MouseButton.Left, ApplyLowpass, StopLowpass)); }
public static void Test() { Interpolation ip = new Interpolation(10, Interpolation.Method.CSpline); double[] x = new double[10]; double[] y = new double[10]; for (int i = 0; i < 10; i++) { x[i] = i + 0.5 * Math.Sin(i); y[i] = i + Math.Cos(i * i); } ip.Initialize(x, y); using (StreamWriter sWriter = new StreamWriter("out.csv")) { for (double xi = x[0]; xi <= x[9]; xi += 0.01) { sWriter.WriteLine(xi + "," + ip.Evaluate(xi)); } } using (StreamReader sReader = new StreamReader("interpolate.csv")) using (StreamWriter sWriter = new StreamWriter("interpolateResult.csv")) { string[] xs = sReader.ReadLine().Split(','); string[] ys = sReader.ReadLine().Split(','); x = new double[xs.Length]; y = new double[ys.Length]; for (int i = 0; i < xs.Length; i++) x[i] = double.Parse(xs[i]); for (int i = 0; i < ys.Length; i++) y[i] = double.Parse(ys[i]); double[,] z = new double[x.Length, y.Length]; string[] zs; for (int i = 0; i < ys.Length; i++) { zs = sReader.ReadLine().Split(','); for (int j = 0; j < zs.Length; j++) z[j, i] = double.Parse(zs[j]); } SurfaceInterpolation ips = new SurfaceInterpolation((uint)x.Length, (uint)y.Length, Interpolation.Method.CSpline); ips.Initialize(x, y, z); double dx = (x[x.Length - 1] - x[0]) / 20d; double dy = (y[y.Length - 1] - y[0]) / 20d; for (int i = 0; i < 21; i++) { for (int j = 0; j < 21; j++) { sWriter.Write(ips.Evaluate(x[0] + dx * j, y[0] + dy * i) + ","); } sWriter.WriteLine(); } } }
public static double Interpolate(Interpolation interpolationToUse, double currentXVal, double startYVal, double endYVal, double beforeStartYVal = 0.0, double afterEndYVal = 0.0) { switch(interpolationToUse) { case Interpolation.LINEAR: return LinearlyInterpolate(currentXVal, startYVal, endYVal); case Interpolation.COSINE: return CosineInterpolate(currentXVal, startYVal, endYVal); case Interpolation.CUBIC: return CubicInterpolate(currentXVal, startYVal, endYVal, beforeStartYVal, afterEndYVal); default: return 0.0; } }
public EditorCameraController() { Add(new MouseWheelBinding(ChangeWheelIndex)); Add(new KeyBinding(Keys.W, () => ApplyForce(0, -1), true)); Add(new KeyBinding(Keys.S, () => ApplyForce(0, 1), true)); Add(new KeyBinding(Keys.A, () => ApplyForce(-1, 0), true)); Add(new KeyBinding(Keys.D, () => ApplyForce(1, 0), true)); Add(new UpdateComponent(Update, UpdateTime.Always)); _zoomToForce = new Interpolation(0, 10, .01f, 10f); Force = 1; MaxVelocity = 10; Inertia = .9f; Add(new StateRecorder("EditorCameraController", Save, Restore)); }
public SoundEmitter2D(SoundFx sound, Body body, float far, float close = 1, float panFactor = .3f) { Close = close; _panFactor = panFactor; Far = far; _range = far - close; _body = body; _sound = sound; _lowpass = new LowPassFilter(); _sound.Filters.Add(_lowpass); _interp = new Interpolation(0, 1, 0, 1, Quart.EaseIn); }
static void Main(string[] args) { System.Console.WriteLine("The problem of the algebraic interpolation."); Interpolation i = new Interpolation(); Function f = new EFunction(); float a = 0.4f; float b = 1; int m = 15; int n = 5; System.Console.Write("Function: "); f.Print(); System.Console.WriteLine("Segment: [{0}, {1}]", a, b); System.Console.WriteLine("Params: m = {0}, n = {1}", m, n); i.Func = f; i.Init(m, n, a, b); float fx; while (true) { System.Console.WriteLine("What method you wanna use? (0 - Lagrange, 1 - Newton)"); string val = System.Console.ReadLine(); System.Console.WriteLine("Input X"); float x = Convert.ToSingle(System.Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture); if (Convert.ToInt32(val) == 0) { fx = i.Calc(x, new LagrangeMethod()); } else { fx = i.Calc(x, new NewtonMethod()); } System.Console.WriteLine("Pn(x) = {0}", (double)fx); System.Console.WriteLine("efn(x) = {0}", Math.Abs((float)f.f(x) - (float)fx)); } System.Console.ReadKey(); }
/// <summary> /// Creates a new resized WriteableBitmap. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new WriteableBitmap that is a resized version of the input.</returns> public static WriteableBitmap Resize(this WriteableBitmap bmp, int width, int height, Interpolation interpolation) { using (var srcContext = bmp.GetBitmapContext(ReadWriteMode.ReadOnly)) { var pd = Resize(srcContext, srcContext.Width, srcContext.Height, width, height, interpolation); var result = BitmapFactory.New(width, height); using (var dstContext = result.GetBitmapContext()) { BitmapContext.BlockCopy(pd, 0, dstContext, 0, SizeOfArgb * pd.Length); } return(result); } }
protected override double CalculateAverageFrameTime() => Interpolation.Damp(AverageFrameTime, ElapsedFrameTime - SleptTime, 0.01, Math.Max(ElapsedFrameTime, 0) / 1000);
/// <summary> /// Texture 2D resize. /// </summary> /// <param name="source"></param> /// <param name="destSize"></param> /// <param name="interpMethod">Interpolation Method</param> /// <returns></returns> public static Texture2D ResizeTexture2D(this Texture2D source, Vector2 destSize, Interpolation interpMethod) { Color[] sourceColors = source.GetPixels(0); Vector2 sourceSize = new Vector2(source.width, source.height); float destWidth = destSize.x; float destHeight = destSize.y; Texture2D newTex = new Texture2D((int)destWidth, (int)destHeight, TextureFormat.RGBA32, false); int len = (int)destWidth * (int)destHeight; Color[] destColors = new Color[len]; if (interpMethod == Interpolation.Average) { Vector2 pixelSize = new Vector2(sourceSize.x / destWidth, sourceSize.y / destHeight); Vector2 center = new Vector2(); float x, y; int xFrom, xTo, yFrom, yTo; float gridCount; Color colorTemp; for (int i = 0; i < len; i++) { x = (float)i % destWidth; y = Mathf.Floor((float)i / destWidth); center.x = (x / destWidth) * sourceSize.x; center.y = (y / destHeight) * sourceSize.y; xFrom = (int)Mathf.Max(Mathf.Floor(center.x - (pixelSize.x * 0.5f)), 0); xTo = (int)Mathf.Min(Mathf.Ceil(center.x + (pixelSize.x * 0.5f)), sourceSize.x); yFrom = (int)Mathf.Max(Mathf.Floor(center.y - (pixelSize.y * 0.5f)), 0); yTo = (int)Mathf.Min(Mathf.Ceil(center.y + (pixelSize.y * 0.5f)), sourceSize.y); colorTemp = new Color(); gridCount = 0; for (int yy = yFrom; yy < yTo; yy++) { for (int xx = xFrom; xx < xTo; xx++) { colorTemp += sourceColors[(int)(((float)yy * sourceSize.x) + xx)]; gridCount++; } } // Average destColors[i] = colorTemp / (float)gridCount; } } else if (interpMethod == Interpolation.NearestNeighbor) { int width = (int)destWidth; int height = (int)destHeight; float coef_widthDestToSource = sourceSize.x / destSize.x; float coef_heigthDestToSource = sourceSize.y / destSize.y; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { destColors[x + y * width] = sourceColors[(int)(x * coef_widthDestToSource) + (int)(y * coef_heigthDestToSource) * (int)sourceSize.x]; } } } // IDW for adjacent 4 pixels else if (interpMethod == Interpolation.InverseDistanceWeighted) { int width = (int)destWidth; int height = (int)destHeight; float coef_widthDestToSource = sourceSize.x / destSize.x; float coef_heigthDestToSource = sourceSize.y / destSize.y; float sourceX, sourceY; /* * p_1 p_2 * p' * p_3 p_4 * */ float d1, d2, d3, d4; // distance for 4 adjacent pixels float w1, w2, w3, w4; // weight for 4 adjacent pixels for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { sourceX = x * coef_widthDestToSource; sourceY = y * coef_heigthDestToSource; d1 = Mathf.Sqrt(Mathf.Pow(sourceX - Mathf.Floor(sourceX), 2) + Mathf.Pow(sourceY - Mathf.Floor(sourceY), 2)); d2 = Mathf.Sqrt(Mathf.Pow(sourceX - Mathf.Ceil(sourceX), 2) + Mathf.Pow(sourceY - Mathf.Floor(sourceY), 2)); d3 = Mathf.Sqrt(Mathf.Pow(sourceX - Mathf.Floor(sourceX), 2) + Mathf.Pow(sourceY - Mathf.Ceil(sourceY), 2)); d4 = Mathf.Sqrt(Mathf.Pow(sourceX - Mathf.Ceil(sourceX), 2) + Mathf.Pow(sourceY - Mathf.Ceil(sourceY), 2)); // handle Border Exception //if (sourceX > sourceSize.x || sourceY > sourceSize.y) //{ // destColors[x + y * width] = sourceColors[(int)((int)sourceX + (int)sourceY * sourceSize.x)]; //} // handle Zero Division Exception // Note that Floor and Ceil contain Equality => Check d1 is enough. if (d1 == 0) { destColors[x + y * width] = sourceColors[(int)((int)sourceX + (int)sourceY * sourceSize.x)]; } else { w1 = 1 / d1; w2 = 1 / d2; w3 = 1 / d3; w4 = 1 / d4; destColors[x + y * width] = (sourceColors[(int)((int)sourceX + (int)sourceY * sourceSize.x)] * w1 + sourceColors[(int)((int)sourceX + 1 + (int)sourceY * sourceSize.x)] * w2 + sourceColors[(int)((int)sourceX + (int)(sourceY + 1) * sourceSize.x)] * w3 + sourceColors[(int)((int)sourceX + 1 + (int)(sourceY + 1) * sourceSize.x)] * w4) / (w1 + w2 + w3 + w4); } } } } newTex.SetPixels(destColors); newTex.Apply(); return(newTex); }
public static int[] Resize(int[] pixels, int widthSource, int heightSource, int width, int height, Interpolation interpolation) #endif { var pd = new int[width * height]; var xs = (float)widthSource / width; var ys = (float)heightSource / height; float fracx, fracy, ifracx, ifracy, sx, sy, l0, l1, rf, gf, bf; int c, x0, x1, y0, y1; byte c1a, c1r, c1g, c1b, c2a, c2r, c2g, c2b, c3a, c3r, c3g, c3b, c4a, c4r, c4g, c4b; byte a, r, g, b; // Nearest Neighbor if (interpolation == Interpolation.NearestNeighbor) { var srcIdx = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; pd[srcIdx++] = pixels[y0 * widthSource + x0]; } } } // Bilinear else if (interpolation == Interpolation.Bilinear) { var srcIdx = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; // Calculate coordinates of the 4 interpolation points fracx = sx - x0; fracy = sy - y0; ifracx = 1f - fracx; ifracy = 1f - fracy; x1 = x0 + 1; if (x1 >= widthSource) { x1 = x0; } y1 = y0 + 1; if (y1 >= heightSource) { y1 = y0; } // Read source color c = pixels[y0 * widthSource + x0]; c1a = (byte)(c >> 24); c1r = (byte)(c >> 16); c1g = (byte)(c >> 8); c1b = (byte)(c); c = pixels[y0 * widthSource + x1]; c2a = (byte)(c >> 24); c2r = (byte)(c >> 16); c2g = (byte)(c >> 8); c2b = (byte)(c); c = pixels[y1 * widthSource + x0]; c3a = (byte)(c >> 24); c3r = (byte)(c >> 16); c3g = (byte)(c >> 8); c3b = (byte)(c); c = pixels[y1 * widthSource + x1]; c4a = (byte)(c >> 24); c4r = (byte)(c >> 16); c4g = (byte)(c >> 8); c4b = (byte)(c); // Calculate colors // Alpha l0 = ifracx * c1a + fracx * c2a; l1 = ifracx * c3a + fracx * c4a; a = (byte)(ifracy * l0 + fracy * l1); // Red l0 = ifracx * c1r + fracx * c2r; l1 = ifracx * c3r + fracx * c4r; rf = ifracy * l0 + fracy * l1; // Green l0 = ifracx * c1g + fracx * c2g; l1 = ifracx * c3g + fracx * c4g; gf = ifracy * l0 + fracy * l1; // Blue l0 = ifracx * c1b + fracx * c2b; l1 = ifracx * c3b + fracx * c4b; bf = ifracy * l0 + fracy * l1; // Cast to byte r = (byte)rf; g = (byte)gf; b = (byte)bf; // Write destination pd[srcIdx++] = (a << 24) | (r << 16) | (g << 8) | b; } } } return(pd); }
/// <summary> /// Creates a new resized bitmap. /// </summary> /// <param name="srcContext">The source context.</param> /// <param name="widthSource">The width of the source pixels.</param> /// <param name="heightSource">The height of the source pixels.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new bitmap that is a resized version of the input.</returns> public static int[] Resize(BitmapContext srcContext, int widthSource, int heightSource, int width, int height, Interpolation interpolation) { return Resize(srcContext.Pixels, widthSource, heightSource, width, height, interpolation); }
public void TestColourInterpolatesInLinearSpace() { FillFlowContainer interpolatingLines = null; AddStep("load interpolated colours", () => { Child = new FillFlowContainer { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, AutoSizeAxes = Axes.Both, Direction = FillDirection.Vertical, Margin = new MarginPadding(20), Children = new Drawable[] { new SpriteText { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Text = "d3.interpolateRgb.gamma(2.2)(\"red\", \"blue\")" }, new SampleSpriteD3 { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Size = new Vector2(750f, 50f), }, new SpriteText { Margin = new MarginPadding { Top = 20f }, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Text = $"{nameof(ColourInfo)}.{nameof(ColourInfo.GradientHorizontal)}(Blue, Red)" }, new Box { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Size = new Vector2(750f, 50f), Colour = ColourInfo.GradientHorizontal(Color4.Red, Color4.Blue), }, new SpriteText { Margin = new MarginPadding { Top = 20f }, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Text = $"{nameof(Interpolation)}.{nameof(Interpolation.ValueAt)}(Red, Red) with 1px boxes", }, interpolatingLines = new FillFlowContainer { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, AutoSizeAxes = Axes.X, Height = 50f, ChildrenEnumerable = Enumerable.Range(0, 750).Select(i => new Box { Width = 1f, RelativeSizeAxes = Axes.Y, Colour = Interpolation.ValueAt(i, Color4.Red, Color4.Blue, 0, 750), }), }, } }; }); AddAssert("interpolation in linear space", () => { var middle = interpolatingLines.Children[interpolatingLines.Children.Count / 2]; return(middle.Colour.AverageColour.Linear == new Color4(0.5f, 0f, 0.5f, 1f)); }); }
private void CalculateInitialConfigurationData(IElement element, out double[][] tx_i) { double[] E; double[] ni; IReadOnlyList <double[]> shapeFunctions = Interpolation.EvaluateFunctionsAtGaussPoints(QuadratureForStiffness); IReadOnlyList <Matrix> shapeFunctionsDerivatives = Interpolation.EvaluateNaturalGradientsAtGaussPoints(QuadratureForStiffness); (Matrix[] ll1, Matrix[] J_0a) = JacobianShell8Calculations.Getll1AndJ_0a( QuadratureForStiffness, tk, shapeFunctions, shapeFunctionsDerivatives); //TODO J_0, J_0b etc. can be cached for not large scale models tx_i = new double[8][]; (tU, tUvec) = Shell8DirectionVectorUtilities.GetInitialDirectionVectorValues(oVn_i); double[][] oV1_i = new double[8][]; //tangent vector ''1'' initial configuration for (int j = 0; j < 8; j++) { tx_i[j] = new double[] { element.Nodes[j].X, element.Nodes[j].Y, element.Nodes[j].Z, }; oV1_i[j] = new double[3]; oV1_i[j][0] = tUvec[j][0]; oV1_i[j][1] = tUvec[j][1]; oV1_i[j][2] = tUvec[j][2]; } (Matrix[] J_0inv, double[] detJ_0) = JacobianShell8Calculations.GetJ_0invAndDetJ_0(J_0a, element.Nodes, oVn_i, nGaussPoints); for (int j = 0; j < nGaussPoints; j++) { double[] V3 = new double[3]; double V3_norm; double[] V1 = new double[3]; double V1_norm; for (int k = 0; k < 3; k++) { V3[k] = 0; V1[k] = 0; /* V2[k] = 0; */ } for (int k = 0; k < 8; k++) { for (int l = 0; l < 3; l++) { V3[l] += shapeFunctions[j][k] * oVn_i[k][l]; V1[l] += shapeFunctions[j][k] * oV1_i[k][l]; } } V3_norm = Math.Sqrt(V3[0] * V3[0] + V3[1] * V3[1] + V3[2] * V3[2]); V1_norm = Math.Sqrt(V1[0] * V1[0] + V1[1] * V1[1] + V1[2] * V1[2]); for (int l = 0; l < 3; l++) { V3[l] = V3[l] / V3_norm; V1[l] = V1[l] / V1_norm; } materialsAtGaussPoints[j].NormalVectorV3 = V3; materialsAtGaussPoints[j].TangentVectorV1 = V1; } integrationCoefficient = new double[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { integrationCoefficient[j] += QuadratureForStiffness.IntegrationPoints[j].Weight * detJ_0[j]; } }
public override void Draw(Action <TexturedVertex2D> vertexAction) { base.Draw(vertexAction); if (texture?.Available != true || points == null || points.Count == 0) { return; } shader.Bind(); texture.TextureGL.Bind(); Vector2 localInflationAmount = new Vector2(0, 1) * DrawInfo.MatrixInverse.ExtractScale().Xy; // We're dealing with a _large_ number of points, so we need to optimise the quadToDraw * drawInfo.Matrix multiplications below // for points that are going to be masked out anyway. This allows for higher resolution graphs at larger scales with virtually no performance loss. // Since the points are generated in the local coordinate space, we need to convert the screen space masking quad coordinates into the local coordinate space RectangleF localMaskingRectangle = (Quad.FromRectangle(GLWrapper.CurrentMaskingInfo.ScreenSpaceAABB) * DrawInfo.MatrixInverse).AABBFloat; float separation = drawSize.X / (points.Count - 1); for (int i = 0; i < points.Count - 1; i++) { float leftX = i * separation; float rightX = (i + 1) * separation; if (rightX < localMaskingRectangle.Left) { continue; } if (leftX > localMaskingRectangle.Right) { break; // X is always increasing } Color4 frequencyColour = baseColour; // colouring is applied in the order of interest to a viewer. frequencyColour = Interpolation.ValueAt(points[i].MidIntensity / midMax, frequencyColour, midColour, 0, 1); // high end (cymbal) can help find beat, so give it priority over mids. frequencyColour = Interpolation.ValueAt(points[i].HighIntensity / highMax, frequencyColour, highColour, 0, 1); // low end (bass drum) is generally the best visual aid for beat matching, so give it priority over high/mid. frequencyColour = Interpolation.ValueAt(points[i].LowIntensity / lowMax, frequencyColour, lowColour, 0, 1); ColourInfo finalColour = DrawColourInfo.Colour; finalColour.ApplyChild(frequencyColour); Quad quadToDraw; switch (channels) { default: case 2: { float height = drawSize.Y / 2; quadToDraw = new Quad( new Vector2(leftX, height - points[i].Amplitude[0] * height), new Vector2(rightX, height - points[i + 1].Amplitude[0] * height), new Vector2(leftX, height + points[i].Amplitude[1] * height), new Vector2(rightX, height + points[i + 1].Amplitude[1] * height) ); break; } case 1: { quadToDraw = new Quad( new Vector2(leftX, drawSize.Y - points[i].Amplitude[0] * drawSize.Y), new Vector2(rightX, drawSize.Y - points[i + 1].Amplitude[0] * drawSize.Y), new Vector2(leftX, drawSize.Y), new Vector2(rightX, drawSize.Y) ); break; } } quadToDraw *= DrawInfo.Matrix; if (quadToDraw.Size.X != 0 && quadToDraw.Size.Y != 0) { DrawQuad(texture, quadToDraw, finalColour, null, vertexBatch.AddAction, Vector2.Divide(localInflationAmount, quadToDraw.Size)); } } shader.Unbind(); }
private void updateColour() { Color4 newColour = Interpolation.ValueAt((float)rollingHits / rolling_hits_for_engaged_colour, colourIdle, colourEngaged, 0, 1); (MainPiece.Drawable as IHasAccentColour)?.FadeAccent(newColour, 100); }
public static Orthotope2Double Interpolate(Orthotope2Double orthotope1, Orthotope2Double orthotope2, Interpolation <double> interpolate, double fraction) { return(new Orthotope2Double(OrderedRanges.Interpolate(orthotope1.rangeX, orthotope2.rangeX, interpolate, fraction), OrderedRanges.Interpolate(orthotope1.rangeY, orthotope2.rangeY, interpolate, fraction))); }
//Get the height below the given vector public float GetLandingHeight(Vector3 playerPos) { return(Interpolation.CircularIn(GetAirborneDelta(playerPos)) * m_XScale); }
//Set the angle of the pipe to below the player when they are airborne //While airborne, the circular movement mod does not apply public void SetAngleToAirbornePos(Vector3 playerPos) { m_CurrentAngle = Mathf.Lerp(0, 90, Interpolation.CircularIn(GetAirborneDelta(playerPos))); }
public static void WarpPerspective(Mat src, Mat dst, Mat M, CvSize dsize, Interpolation flags = Interpolation.Linear, BorderType borderMode = BorderType.Constant, CvScalar? borderValue = null) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); if (M == null) throw new ArgumentNullException("M"); CvScalar _borderValue = borderValue.GetValueOrDefault(CvScalar.ScalarAll(0)); CppInvoke.cv_warpPerspective(src.CvPtr, dst.CvPtr, M.CvPtr, dsize, flags, borderMode, _borderValue); }
private double [] UpdateForces(IElement element) { IReadOnlyList <double[]> shapeFunctions = Interpolation.EvaluateFunctionsAtGaussPoints(QuadratureForStiffness); IReadOnlyList <Matrix> shapeFunctionsDerivatives = Interpolation.EvaluateNaturalGradientsAtGaussPoints(QuadratureForStiffness); (Matrix[] ll1, Matrix[] J_0a) = JacobianShell8Calculations.Getll1AndJ_0a(QuadratureForStiffness, tk, shapeFunctions, shapeFunctionsDerivatives); //BL11a etc. are not cached currently(declare here) (Matrix[] J_0inv, double[] detJ_0) = JacobianShell8Calculations.GetJ_0invAndDetJ_0(J_0a, element.Nodes, oVn_i, nGaussPoints); Matrix[] BL11a; BL11a = GetBL11a(J_0inv); Matrix[] BL12; BL12 = GetBL12(J_0inv); Matrix[] BL13; BL13 = GetBL13(shapeFunctionsDerivatives, tUvec, J_0a); Matrix[] BL; BL = new Matrix[nGaussPoints]; Matrix[] BL01plus1_2; BL01plus1_2 = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL[j] = Matrix.CreateZero(6, 40); BL01plus1_2[j] = Matrix.CreateZero(6, 9); } double[][] Fxk = new double [nGaussPoints + 1] []; for (int j = 0; j < nGaussPoints + 1; j++) { Fxk[j] = new double[40]; } Matrix ll2; ll2 = Matrix.CreateZero(24, 3); for (int j = 0; j < 8; j++) { for (int k = 0; k < 3; k++) { ll2[3 * j + 0, k] = tU[j][k]; ll2[3 * j + 1, k] = tU[j][3 + k]; ll2[3 * j + 2, k] = oVn_i[j][k]; } } Matrix[] l_circumflex; l_circumflex = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { l_circumflex[j] = Matrix.CreateZero(3, 3); } for (int j = 0; j < nGaussPoints; j++) { l_circumflex[j] = ll1[j] * ll2; } Matrix[] BL11b; BL11b = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL11b[j] = Matrix.CreateZero(9, 9); } for (int j = 0; j < nGaussPoints; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { BL11b[j][3 * k + l, 3 * k + m] = l_circumflex[j][l, m]; } //don;t change that } } } Matrix[] BL11; BL11 = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL11[j] = BL11a[j] * BL11b[j]; } Matrix[] BL1_2; BL1_2 = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL1_2[j] = BL11[j] * BL12[j]; for (int k = 0; k < 6; k++) { for (int l = 0; l < 9; l++) { BL01plus1_2[j][k, l] = BL1_2[j][k, l] + BL11a[j][k, l]; } } BL[j] = BL01plus1_2[j] * BL13[j]; } for (int j = 0; j < nGaussPoints; j++) { for (int k = 0; k < 40; k++) { Fxk[j][k] = 0; for (int m = 0; m < 6; m++) { Fxk[j][k] += BL[j][m, k] * materialsAtGaussPoints[j].Stresses[m]; } } } for (int k = 0; k < 40; k++) { Fxk[nGaussPoints][k] = 0; for (int j = 0; j < nGaussPoints; j++) { Fxk[nGaussPoints][k] += integrationCoefficient[j] * Fxk[j][k]; } } return(Fxk[nGaussPoints]); }
/// <summary> /// Creates a new resized bitmap. /// </summary> /// <param name="srcContext">The source context.</param> /// <param name="widthSource">The width of the source pixels.</param> /// <param name="heightSource">The height of the source pixels.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new bitmap that is a resized version of the input.</returns> public static int[] Resize(BitmapContext srcContext, int widthSource, int heightSource, int width, int height, Interpolation interpolation) { var pixels = srcContext.Pixels; var pd = new int[width * height]; var xs = (float)widthSource / width; var ys = (float)heightSource / height; float sx, sy; int x0; int y0; // Nearest Neighbor switch (interpolation) { case Interpolation.NearestNeighbor: { var srcIdx = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; pd[srcIdx++] = pixels[y0 * widthSource + x0]; } } } break; case Interpolation.Bilinear: { var srcIdx = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; // Calculate coordinates of the 4 interpolation points var fracx = sx - x0; var fracy = sy - y0; var ifracx = 1f - fracx; var ifracy = 1f - fracy; var x1 = x0 + 1; if (x1 >= widthSource) { x1 = x0; } var y1 = y0 + 1; if (y1 >= heightSource) { y1 = y0; } // Read source color var c = pixels[y0 * widthSource + x0]; var c1A = (byte)(c >> 24); var c1R = (byte)(c >> 16); var c1G = (byte)(c >> 8); var c1B = (byte)(c); c = pixels[y0 * widthSource + x1]; var c2A = (byte)(c >> 24); var c2R = (byte)(c >> 16); var c2G = (byte)(c >> 8); var c2B = (byte)(c); c = pixels[y1 * widthSource + x0]; var c3A = (byte)(c >> 24); var c3R = (byte)(c >> 16); var c3G = (byte)(c >> 8); var c3B = (byte)(c); c = pixels[y1 * widthSource + x1]; var c4A = (byte)(c >> 24); var c4R = (byte)(c >> 16); var c4G = (byte)(c >> 8); var c4B = (byte)(c); // Calculate colors // Alpha var l0 = ifracx * c1A + fracx * c2A; var l1 = ifracx * c3A + fracx * c4A; var a = (byte)(ifracy * l0 + fracy * l1); // Red l0 = ifracx * c1R * c1A + fracx * c2R * c2A; l1 = ifracx * c3R * c3A + fracx * c4R * c4A; var rf = ifracy * l0 + fracy * l1; // Green l0 = ifracx * c1G * c1A + fracx * c2G * c2A; l1 = ifracx * c3G * c3A + fracx * c4G * c4A; var gf = ifracy * l0 + fracy * l1; // Blue l0 = ifracx * c1B * c1A + fracx * c2B * c2A; l1 = ifracx * c3B * c3A + fracx * c4B * c4A; var bf = ifracy * l0 + fracy * l1; // Divide by alpha if (a > 0) { rf = rf / a; gf = gf / a; bf = bf / a; } // Cast to byte var r = (byte)rf; var g = (byte)gf; var b = (byte)bf; // Write destination pd[srcIdx++] = (a << 24) | (r << 16) | (g << 8) | b; } } } break; } return pd; }
private Matrix UpdateKmatrices(IElement element) { double[][] kck;// 1 per node and (one per Gauss point+1 for the addition) -->[GP][8 dofs_per_node*nodes] Matrix[] KNL; Matrix[] KL; double[][] BL01plus1_2tSPKvec; IReadOnlyList <double[]> shapeFunctions = Interpolation.EvaluateFunctionsAtGaussPoints(QuadratureForStiffness); IReadOnlyList <Matrix> shapeFunctionsDerivatives = Interpolation.EvaluateNaturalGradientsAtGaussPoints(QuadratureForStiffness); (Matrix[] ll1, Matrix[] J_0a) = JacobianShell8Calculations.Getll1AndJ_0a(QuadratureForStiffness, tk, shapeFunctions, shapeFunctionsDerivatives); (Matrix[] J_0inv, double[] detJ_0) = JacobianShell8Calculations.GetJ_0invAndDetJ_0(J_0a, element.Nodes, oVn_i, nGaussPoints); Matrix[] BNL1; BNL1 = GetBNL1(J_0inv); Matrix[] BL13; BL13 = GetBL13(shapeFunctionsDerivatives, tUvec, J_0a); //TODO: maybe cached from calcForces for problems of normal memory requirements double[][,] ck; ck = CalculateCk(J_0a, tU); // Matrix[] BL11a; //TODO: maybe cached from calcForces for problems of normal memory BL11a = GetBL11a(J_0inv); Matrix[] BL12; BL12 = GetBL12(J_0inv); // Matrix[] BL; //TODO: maybe cached from calcForces for problems of normal memory BL = new Matrix[nGaussPoints]; Matrix[] BL01plus1_2; BL01plus1_2 = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL[j] = Matrix.CreateZero(6, 40); BL01plus1_2[j] = Matrix.CreateZero(6, 9); } // var ll2 = Matrix.CreateZero(24, 3); for (int j = 0; j < 8; j++) { for (int k = 0; k < 3; k++) { ll2[3 * j + 0, k] = tU[j][k]; ll2[3 * j + 1, k] = tU[j][3 + k]; ll2[3 * j + 2, k] = oVn_i[j][k]; } } Matrix[] l_circumflex; l_circumflex = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { l_circumflex[j] = Matrix.CreateZero(3, 3); } for (int j = 0; j < nGaussPoints; j++) { l_circumflex[j] = ll1[j] * ll2; } Matrix[] BL11b; BL11b = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL11b[j] = Matrix.CreateZero(9, 9); } for (int j = 0; j < nGaussPoints; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { for (int m = 0; m < 3; m++) { BL11b[j][3 * k + l, 3 * k + m] = l_circumflex[j][l, m]; } } } } Matrix[] BL11; BL11 = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL11[j] = Matrix.CreateZero(6, 9); } for (int j = 0; j < nGaussPoints; j++) { BL11[j] = BL11a[j] * BL11b[j]; } Matrix[] BL1_2; BL1_2 = new Matrix[nGaussPoints]; for (int j = 0; j < nGaussPoints; j++) { BL1_2[j] = Matrix.CreateZero(6, 9); } for (int j = 0; j < nGaussPoints; j++) { BL1_2[j] = BL11[j] * BL12[j]; for (int k = 0; k < 6; k++) { for (int l = 0; l < 9; l++) { BL01plus1_2[j][k, l] = BL1_2[j][k, l] + BL11a[j][k, l]; } } BL[j] = BL01plus1_2[j] * BL13[j]; } KL = new Matrix[nGaussPoints + 1]; KNL = new Matrix[nGaussPoints + 1]; kck = new double[nGaussPoints + 1][]; BL01plus1_2tSPKvec = new double[nGaussPoints][]; for (int j = 0; j < nGaussPoints + 1; j++) { KL[j] = Matrix.CreateZero(40, 40); KNL[j] = Matrix.CreateZero(40, 40); } for (int j = 0; j < nGaussPoints; j++) { var SPK_circumflex = Matrix.CreateZero(9, 9); for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { SPK_circumflex[3 * k + l, 3 * k + l] = materialsAtGaussPoints[j].Stresses[l]; } SPK_circumflex[3 * k, 3 * k + 1] = materialsAtGaussPoints[j].Stresses[3]; SPK_circumflex[3 * k, 3 * k + 2] = materialsAtGaussPoints[j].Stresses[5]; SPK_circumflex[3 * k + 1, 3 * k + 2] = materialsAtGaussPoints[j].Stresses[4]; SPK_circumflex[3 * k + 1, 3 * k] = materialsAtGaussPoints[j].Stresses[3]; SPK_circumflex[3 * k + 2, 3 * k] = materialsAtGaussPoints[j].Stresses[5]; SPK_circumflex[3 * k + 2, 3 * k + 1] = materialsAtGaussPoints[j].Stresses[4]; } var BNL = BNL1[j] * BL13[j]; BL01plus1_2tSPKvec[j] = new double[9]; for (int k = 0; k < 9; k++) { for (int m = 0; m < 6; m++) { BL01plus1_2tSPKvec[j][k] += BL01plus1_2[j][m, k] * materialsAtGaussPoints[j].Stresses[m]; } } kck[j] = new double[8]; for (int k = 0; k < 8; k++) { for (int m = 0; m < 9; m++) { kck[j][k] += ck[j][k, m] * BL01plus1_2tSPKvec[j][m]; } } var ConsBL = Matrix.CreateZero(6, 40); for (int k = 0; k < 6; k++) { for (int l = 0; l < 40; l++) { for (int m = 0; m < 6; m++) { ConsBL[k, l] += materialsAtGaussPoints[j].ConstitutiveMatrix[k, m] * BL[j][m, l]; } } } var S_BNL = SPK_circumflex * BNL; KNL[j] = BNL.Transpose() * S_BNL; KL[j] = BL[j].Transpose() * ConsBL; } var Kt = Matrix.CreateZero(40, 40); for (int j = 0; j < nGaussPoints; j++) { for (int k = 0; k < 40; k++) { for (int l = 0; l < 40; l++) { Kt[k, l] += integrationCoefficient[j] * (KL[j][k, l] + KNL[j][k, l]); } } for (int l = 0; l < 8; l++) { Kt[5 * l + 3, 5 * l + 3] += integrationCoefficient[j] * kck[j][l]; Kt[5 * l + 4, 5 * l + 4] += integrationCoefficient[j] * kck[j][l]; } } return(Kt); }
private void AddAlphaInterpolation(GUIControl control) { Interpolation i = new Interpolation(); i.Time = TimeSpan.FromSeconds(2); i.elapsed = TimeSpan.Zero; i.from = control.BackgroundColor; i.to = Color.Orange * 0.6f; i.Compleate = false; this.interpolations.Add(i); i.UpdatedValue += x => control.BackgroundColor = x; Interpolation i1 = new Interpolation(); i1.Time = TimeSpan.FromSeconds(2); i1.elapsed = TimeSpan.Zero; i1.from = Color.Orange * 0.6f; i1.to = control.BackgroundColor; i1.Compleate = false; this.interpolations.Add(i); i1.UpdatedValue += x => control.BackgroundColor = x; control.FocusLost += (s, e) => { i.Compleate = true; this.interpolations.Add(i1); }; }
private void load(OsuColour colours) { InternalChildren = new Drawable[] { new FillFlowContainer { RelativeSizeAxes = Axes.Both, Direction = FillDirection.Vertical, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, Padding = new MarginPadding(20), Spacing = new Vector2(0, 10), Children = new Drawable[] { new OsuSpriteText { Margin = new MarginPadding { Vertical = 10 }, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, Font = OsuFont.GetFont(size: 20), Text = "Let's create an account!", }, usernameTextBox = new OsuTextBox { PlaceholderText = "username", RelativeSizeAxes = Axes.X, TabbableContentContainer = this }, usernameDescription = new ErrorTextFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y }, emailTextBox = new OsuTextBox { PlaceholderText = "email address", RelativeSizeAxes = Axes.X, TabbableContentContainer = this }, emailAddressDescription = new ErrorTextFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y }, passwordTextBox = new OsuPasswordTextBox { PlaceholderText = "password", RelativeSizeAxes = Axes.X, TabbableContentContainer = this, }, passwordDescription = new ErrorTextFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y }, new Container { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Children = new Drawable[] { registerShake = new ShakeContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Child = new SettingsButton { Text = "Register", Margin = new MarginPadding { Vertical = 20 }, Action = performRegistration } } } }, }, }, processingOverlay = new ProcessingOverlay { Alpha = 0 } }; textboxes = new[] { usernameTextBox, emailTextBox, passwordTextBox }; usernameDescription.AddText("This will be your public presence. No profanity, no impersonation. Avoid exposing your own personal details, too!"); emailAddressDescription.AddText("Will be used for notifications, account verification and in the case you forget your password. No spam, ever."); emailAddressDescription.AddText(" Make sure to get it right!", cp => cp.Font = cp.Font.With(Typeface.Exo, weight: FontWeight.Bold)); passwordDescription.AddText("At least "); characterCheckText = passwordDescription.AddText("8 characters long"); passwordDescription.AddText(". Choose something long but also something you will remember, like a line from your favourite song."); passwordTextBox.Current.ValueChanged += password => { characterCheckText.ForEach(s => s.Colour = password.NewValue.Length == 0 ? Color4.White : Interpolation.ValueAt(password.NewValue.Length, Color4.OrangeRed, Color4.YellowGreen, 0, 8, Easing.In)); }; }
public static int[] Resize(int[] pixels, int widthSource, int heightSource, int width, int height, Interpolation interpolation) #endif { var pd = new int[width * height]; var xs = (float)widthSource / width; var ys = (float)heightSource / height; float fracx, fracy, ifracx, ifracy, sx, sy, l0, l1, rf, gf, bf; int c, x0, x1, y0, y1; byte c1a, c1r, c1g, c1b, c2a, c2r, c2g, c2b, c3a, c3r, c3g, c3b, c4a, c4r, c4g, c4b; byte a, r, g, b; // Nearest Neighbor if (interpolation == Interpolation.NearestNeighbor) { var srcIdx = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; pd[srcIdx++] = pixels[y0 * widthSource + x0]; } } } // Bilinear else if (interpolation == Interpolation.Bilinear) { var srcIdx = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; // Calculate coordinates of the 4 interpolation points fracx = sx - x0; fracy = sy - y0; ifracx = 1f - fracx; ifracy = 1f - fracy; x1 = x0 + 1; if (x1 >= widthSource) { x1 = x0; } y1 = y0 + 1; if (y1 >= heightSource) { y1 = y0; } // Read source color c = pixels[y0 * widthSource + x0]; c1a = (byte)(c >> 24); c1r = (byte)(c >> 16); c1g = (byte)(c >> 8); c1b = (byte)(c); c = pixels[y0 * widthSource + x1]; c2a = (byte)(c >> 24); c2r = (byte)(c >> 16); c2g = (byte)(c >> 8); c2b = (byte)(c); c = pixels[y1 * widthSource + x0]; c3a = (byte)(c >> 24); c3r = (byte)(c >> 16); c3g = (byte)(c >> 8); c3b = (byte)(c); c = pixels[y1 * widthSource + x1]; c4a = (byte)(c >> 24); c4r = (byte)(c >> 16); c4g = (byte)(c >> 8); c4b = (byte)(c); // Calculate colors // Alpha l0 = ifracx * c1a + fracx * c2a; l1 = ifracx * c3a + fracx * c4a; a = (byte)(ifracy * l0 + fracy * l1); // Red l0 = ifracx * c1r + fracx * c2r; l1 = ifracx * c3r + fracx * c4r; rf = ifracy * l0 + fracy * l1; // Green l0 = ifracx * c1g + fracx * c2g; l1 = ifracx * c3g + fracx * c4g; gf = ifracy * l0 + fracy * l1; // Blue l0 = ifracx * c1b + fracx * c2b; l1 = ifracx * c3b + fracx * c4b; bf = ifracy * l0 + fracy * l1; // Cast to byte r = (byte)rf; g = (byte)gf; b = (byte)bf; // Write destination pd[srcIdx++] = (a << 24) | (r << 16) | (g << 8) | b; } } } return pd; }
public void GetHyperTransformSpectrum( ref DeconToolsV2.HornTransform.clsHornTransformResults[] marr_transformResults, double mostAbundantMW, short charge, ref float[] sumMZs, ref float[] sumIntensities, ref float[] mzs, ref float[] intensities) { var vectIndicesToConsider = new List <int>(); // go through all the transforms and find which ones have most abundant mass between current value and // x Daltons var numResults = marr_transformResults.Length; short maxCharge = 0; double massRange = 0; for (var transformNum = 0; transformNum < numResults; transformNum++) { var result = marr_transformResults[transformNum]; var massDiff = System.Math.Abs((result.MostIntenseMw - mostAbundantMW) / 1.003); var massDiffRound = (double)((int)(massDiff + 0.5)); if (massDiffRound > 3) { continue; } var toleranceDiff = System.Math.Abs(massDiff - massDiffRound * 1.003); if (toleranceDiff < System.Math.Max(0.2, result.FWHM * 5)) { // consider this peak for addition. vectIndicesToConsider.Add(transformNum); if (result.ChargeState > maxCharge) { maxCharge = (short)result.ChargeState; } if (result.MostIntenseMw - result.MonoMw > 2 * massRange) { massRange = 2 * (result.MostIntenseMw - result.MonoMw); } } } if (massRange < 8) { massRange = 8; } if (massRange > 16) { massRange = 16; } var minMZForOut = (mostAbundantMW - massRange / 2) / charge + 1.00727638; var maxMZForOut = (mostAbundantMW + massRange / 2) / charge + 1.00727638; const int numPointsForOut = 4 * 1024; var currentMZ = minMZForOut; var mzInterval = (maxMZForOut - minMZForOut) / numPointsForOut; sumMZs = new float[numPointsForOut]; sumIntensities = new float[numPointsForOut]; for (var ptNum = 0; ptNum < numPointsForOut; ptNum++) { sumMZs[ptNum] = (float)currentMZ; sumIntensities[ptNum] = 0; currentMZ += mzInterval; } var interp = new Interpolation(); var vectMz = new List <double>(); var vectIntensity = new List <double>(); var numPts = mzs.Length; for (var ptNum = 0; ptNum < numPts; ptNum++) { double mz = mzs[ptNum]; vectMz.Add(mz); double intense = intensities[ptNum]; vectIntensity.Add(intense); } interp.Spline(vectMz, vectIntensity, 0, 0); for (var index = 0; index < (int)vectIndicesToConsider.Count; index++) { var result = marr_transformResults[vectIndicesToConsider[index]]; currentMZ = ((minMZForOut - 1.00727638) * charge) / result.ChargeState + 1.00727638; for (var ptNum = 0; ptNum < numPointsForOut; ptNum++) { sumIntensities[ptNum] += (float)interp.Splint(vectMz, vectIntensity, currentMZ); currentMZ += (mzInterval * charge) / result.ChargeState; } } }
public IEnumerator Shoot(Player player) { Transform oldParent = player.transform.parent; Quaternion oldRot = player.transform.localRotation; DamageType resistance = player.health.Resistance; player.transform.position = Barrel.transform.position; player.transform.SetParent(Barrel.transform, true); player.transform.up = Barrel.transform.forward; player.LookTowards(Barrel.transform.forward); // Immune to all... player.health.Resistance = DamageType.BASIC | DamageType.EXPLOSIVE | DamageType.FIRE | DamageType.ICE | DamageType.LIGHTNING | DamageType.EARTH | DamageType.TRUE; player.CanWalk = false; player.CanMove = false; player.CanRotate = false; player.CanAttack = false; player.HideWeapon(); while (aligning) { yield return(null); } // Charge Animation { Vector3 startPos = Barrel.transform.position; Vector3 endPos = BarrelChargePos.position; float startTime = Time.time; while (Time.time < startTime + ChargeTime) { float t = (Time.time - startTime) / ChargeTime; t = Interpolation.BounceOut(t); Vector3 pos = Vector3.Lerp(startPos, endPos, t); player.transform.position = pos; yield return(null); } } player.LookTowards(Barrel.transform.forward); player.CanRotate = true; // Launch Animation { AudioManager.Instance.PlaySoundWithParent("cannon", ESoundChannel.SFX, gameObject); player.ShowWeapon(); Vector3 startPos = BarrelChargePos.position; float startTime = Time.time; while (Time.time < startTime + LeapTime) { float t = (Time.time - startTime) / LeapTime; Vector3 pos = Utility.BezierCurve(startPos, Peak.position, Target.position, t); player.transform.position = pos; player.rotation += Vector3.right * PlayerRotateSpeed * Time.deltaTime; yield return(null); } player.transform.position = Target.position; } if (DestoryObjectOnImpact && DestroyableObject) { StartCoroutine(MakeDestroyableObjectFall()); } Explosion(player.transform.position); AudioManager.Instance.PlaySoundWithParent("thud", ESoundChannel.SFX, player.gameObject); player.CanWalk = true; player.CanMove = true; player.CanAttack = true; player.transform.SetParent(oldParent, true); player.transform.localRotation = oldRot; player.health.Resistance = resistance; }
private static double GetTemperature(byte intensity) => Interpolation.Lerp(0, 1, intensity / 255f);
/// <summary> /// Process the filter on the specified image. /// </summary> /// /// <param name="sourceData">Source image data.</param> /// <param name="destinationData">Destination image data.</param> /// protected override unsafe void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData) { // get source image size int width = sourceData.Width; int height = sourceData.Height; int pixelSize = sourceData.PixelSize; int srcStride = sourceData.Stride; int dstOffset = destinationData.Offset; double xFactor = (double)width / newWidth; double yFactor = (double)height / newHeight; // do the job byte *src = (byte *)sourceData.ImageData.ToPointer(); byte *dst = (byte *)destinationData.ImageData.ToPointer(); // width and height decreased by 1 int ymax = height - 1; int xmax = width - 1; // check pixel format if (destinationData.PixelFormat == PixelFormat.Format8bppIndexed) { // grayscale for (int y = 0; y < newHeight; y++) { // Y coordinates double oy = (double)y * yFactor - 0.5; int oy1 = (int)oy; double dy = oy - (double)oy1; for (int x = 0; x < newWidth; x++, dst++) { // X coordinates double ox = (double)x * xFactor - 0.5f; int ox1 = (int)ox; double dx = ox - (double)ox1; // initial pixel value double g = 0; for (int n = -1; n < 3; n++) { // get Y cooefficient double k1 = Interpolation.BiCubicKernel(dy - (double)n); int oy2 = oy1 + n; if (oy2 < 0) { oy2 = 0; } if (oy2 > ymax) { oy2 = ymax; } for (int m = -1; m < 3; m++) { // get X cooefficient double k2 = k1 * Interpolation.BiCubicKernel((double)m - dx); int ox2 = ox1 + m; if (ox2 < 0) { ox2 = 0; } if (ox2 > xmax) { ox2 = xmax; } g += k2 * src[oy2 * srcStride + ox2]; } } *dst = (byte)Math.Max(0, Math.Min(255, g)); } dst += dstOffset; } } else if (pixelSize == 3) { // RGB for (int y = 0; y < newHeight; y++) { // Y coordinates double oy = (double)y * yFactor - 0.5f; int oy1 = (int)oy; double dy = oy - (double)oy1; for (int x = 0; x < newWidth; x++, dst += 3) { // X coordinates double ox = (double)x * xFactor - 0.5f; int ox1 = (int)ox; double dx = ox - (double)ox1; // initial pixel value double r = 0; double g = 0; double b = 0; for (int n = -1; n < 3; n++) { // get Y cooefficient double k1 = Interpolation.BiCubicKernel(dy - (double)n); int oy2 = oy1 + n; if (oy2 < 0) { oy2 = 0; } if (oy2 > ymax) { oy2 = ymax; } for (int m = -1; m < 3; m++) { // get X cooefficient double k2 = k1 * Interpolation.BiCubicKernel((double)m - dx); int ox2 = ox1 + m; if (ox2 < 0) { ox2 = 0; } if (ox2 > xmax) { ox2 = xmax; } // get pixel of original image byte *p = src + oy2 * srcStride + ox2 * 3; r += k2 * p[RGB.R]; g += k2 * p[RGB.G]; b += k2 * p[RGB.B]; } } dst[RGB.R] = (byte)Math.Max(0, Math.Min(255, r)); dst[RGB.G] = (byte)Math.Max(0, Math.Min(255, g)); dst[RGB.B] = (byte)Math.Max(0, Math.Min(255, b)); } dst += dstOffset; } } else if (pixelSize == 4) { // ARGB for (int y = 0; y < newHeight; y++) { // Y coordinates double oy = (double)y * yFactor - 0.5f; int oy1 = (int)oy; double dy = oy - (double)oy1; for (int x = 0; x < newWidth; x++, dst += 3) { // X coordinates double ox = (double)x * xFactor - 0.5f; int ox1 = (int)ox; double dx = ox - (double)ox1; // initial pixel value double a = 0; double r = 0; double g = 0; double b = 0; for (int n = -1; n < 3; n++) { // get Y cooefficient double k1 = Interpolation.BiCubicKernel(dy - (double)n); int oy2 = oy1 + n; if (oy2 < 0) { oy2 = 0; } if (oy2 > ymax) { oy2 = ymax; } for (int m = -1; m < 3; m++) { // get X cooefficient double k2 = k1 * Interpolation.BiCubicKernel((double)m - dx); int ox2 = ox1 + m; if (ox2 < 0) { ox2 = 0; } if (ox2 > xmax) { ox2 = xmax; } // get pixel of original image byte *p = src + oy2 * srcStride + ox2 * 3; a += k2 * p[RGB.A]; r += k2 * p[RGB.R]; g += k2 * p[RGB.G]; b += k2 * p[RGB.B]; } } dst[RGB.A] = (byte)Math.Max(0, Math.Min(255, a)); dst[RGB.R] = (byte)Math.Max(0, Math.Min(255, r)); dst[RGB.G] = (byte)Math.Max(0, Math.Min(255, g)); dst[RGB.B] = (byte)Math.Max(0, Math.Min(255, b)); } dst += dstOffset; } } else { throw new InvalidOperationException("Execution should never reach here."); } }
/// <summary> /// Resizes an image. /// </summary> /// <param name="src">input image.</param> /// <param name="dst">output image; it has the size dsize (when it is non-zero) or the size computed /// from src.size(), fx, and fy; the type of dst is the same as of src.</param> /// <param name="dsize">output image size; if it equals zero, it is computed as: /// dsize = Size(round(fx*src.cols), round(fy*src.rows)) /// Either dsize or both fx and fy must be non-zero.</param> /// <param name="fx">scale factor along the horizontal axis; when it equals 0, /// it is computed as: (double)dsize.width/src.cols</param> /// <param name="fy">scale factor along the vertical axis; when it equals 0, /// it is computed as: (double)dsize.height/src.rows</param> /// <param name="interpolation">interpolation method</param> public static void Resize(InputArray src, OutputArray dst, Size dsize, double fx = 0, double fy = 0, Interpolation interpolation = Interpolation.Linear) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.imgproc_resize(src.CvPtr, dst.CvPtr, dsize, fx, fy, (int)interpolation); dst.Fix(); }
/// <summary> /// Creates a new resized bitmap. /// </summary> /// <param name="srcContext">The source context.</param> /// <param name="widthSource">The width of the source pixels.</param> /// <param name="heightSource">The height of the source pixels.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new bitmap that is a resized version of the input.</returns> public static int[] Resize(BitmapContext srcContext, int widthSource, int heightSource, int width, int height, Interpolation interpolation) { return(Resize(srcContext.Pixels, widthSource, heightSource, width, height, interpolation)); }
/// <summary> /// 画像の透視変換を行います. /// </summary> /// <param name="src">入力画像</param> /// <param name="dst">サイズが dsize で src と同じタイプの出力画像</param> /// <param name="m">3x3 の変換行列</param> /// <param name="dsize">出力画像のサイズ</param> /// <param name="flags">補間手法</param> /// <param name="borderMode">ピクセル外挿手法. /// borderMode=BORDER_TRANSPARENT の場合,入力画像中の「はずれ値」に対応する /// 出力画像中のピクセルが,この関数では変更されないことを意味します</param> /// <param name="borderValue">定数境界モードで利用されるピクセル値.</param> #else /// <summary> /// Applies a perspective transformation to an image. /// </summary> /// <param name="src">input image.</param> /// <param name="dst">output image that has the size dsize and the same type as src.</param> /// <param name="m">3x3 transformation matrix.</param> /// <param name="dsize">size of the output image.</param> /// <param name="flags">combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) /// and the optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation (dst -> src).</param> /// <param name="borderMode">pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).</param> /// <param name="borderValue">value used in case of a constant border; by default, it equals 0.</param> #endif public static void WarpPerspective(InputArray src, OutputArray dst, float[,] m, Size dsize, Interpolation flags = Interpolation.Linear, BorderType borderMode = BorderType.Constant, Scalar? borderValue = null) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); if (m == null) throw new ArgumentNullException("m"); src.ThrowIfDisposed(); dst.ThrowIfDisposed(); CvScalar borderValue0 = borderValue.GetValueOrDefault(CvScalar.ScalarAll(0)); int mRow = m.GetLength(0); int mCol = m.GetLength(1); NativeMethods.imgproc_warpPerspective_MisArray( src.CvPtr, dst.CvPtr, m, mRow, mCol, dsize, (int)flags, (int)borderMode, borderValue0); dst.Fix(); }
public override Replay Generate() { // todo: add support for HT DT const double dash_speed = CatcherArea.Catcher.BASE_SPEED; const double movement_speed = dash_speed / 2; float lastPosition = 0.5f; double lastTime = 0; // Todo: Realistically this shouldn't be needed, but the first frame is skipped with the way replays are currently handled Replay.Frames.Add(new CatchReplayFrame(-100000, lastPosition)); void moveToNext(CatchHitObject h) { float positionChange = Math.Abs(lastPosition - h.X); double timeAvailable = h.StartTime - lastTime; //So we can either make it there without a dash or not. double speedRequired = positionChange / timeAvailable; bool dashRequired = speedRequired > movement_speed && h.StartTime != 0; // todo: get correct catcher size, based on difficulty CS. const float catcher_width_half = CatcherArea.CATCHER_SIZE / CatchPlayfield.BASE_WIDTH * 0.3f * 0.5f; if (lastPosition - catcher_width_half < h.X && lastPosition + catcher_width_half > h.X) { //we are already in the correct range. lastTime = h.StartTime; Replay.Frames.Add(new CatchReplayFrame(h.StartTime, lastPosition)); return; } if (h is BananaShower.Banana) { // auto bananas unrealistically warp to catch 100% combo. Replay.Frames.Add(new CatchReplayFrame(h.StartTime, h.X)); } else if (h.HyperDash) { Replay.Frames.Add(new CatchReplayFrame(h.StartTime - timeAvailable, lastPosition, ReplayButtonState.Right1)); Replay.Frames.Add(new CatchReplayFrame(h.StartTime, h.X)); } else if (dashRequired) { //we do a movement in two parts - the dash part then the normal part... double timeAtNormalSpeed = positionChange / movement_speed; double timeWeNeedToSave = timeAtNormalSpeed - timeAvailable; double timeAtDashSpeed = timeWeNeedToSave / 2; float midPosition = (float)Interpolation.Lerp(lastPosition, h.X, (float)timeAtDashSpeed / timeAvailable); //dash movement Replay.Frames.Add(new CatchReplayFrame(h.StartTime - timeAvailable + 1, lastPosition, ReplayButtonState.Left1)); Replay.Frames.Add(new CatchReplayFrame(h.StartTime - timeAvailable + timeAtDashSpeed, midPosition)); Replay.Frames.Add(new CatchReplayFrame(h.StartTime, h.X)); } else { double timeBefore = positionChange / movement_speed; Replay.Frames.Add(new CatchReplayFrame(h.StartTime - timeBefore, lastPosition, ReplayButtonState.Right1)); Replay.Frames.Add(new CatchReplayFrame(h.StartTime, h.X)); } lastTime = h.StartTime; lastPosition = h.X; } foreach (var obj in Beatmap.HitObjects) { switch (obj) { case Fruit _: moveToNext(obj); break; } foreach (var nestedObj in obj.NestedHitObjects.Cast <CatchHitObject>()) { switch (nestedObj) { case BananaShower.Banana _: case TinyDroplet _: case Droplet _: moveToNext(nestedObj); break; } } } return(Replay); }
public static extern void cvLogPolar(IntPtr src, IntPtr dst, CvPoint2D32f center, double M, Interpolation flags);
public static void Resize(Mat src, Mat dst, CvSize dsize, double fx = 0, double fy = 0, Interpolation interpolation = Interpolation.Linear) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); CppInvoke.cv_resize(src.CvPtr, dst.CvPtr, dsize, fx, fy, interpolation); }
public static extern void cvWarpPerspective(IntPtr src, IntPtr dst, IntPtr map_matrix, Interpolation flags, CvScalar fillval);
/// <summary> /// Creates a new resized WriteableBitmap. /// </summary> /// <param name="srcContext">The WriteableBitmap.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new WriteableBitmap that is a resized version of the input.</returns> public static WriteableBitmap Resize(this BitmapContext srcContext, int width, int height, Interpolation interpolation) { var pd = Resize(srcContext, srcContext.Width, srcContext.Height, width, height, interpolation); var result = BitmapFactory.New(width, height); BitmapContext.BlockCopy(pd, 0, srcContext, 0, SizeOfArgb * pd.Length); return result; }
/// <summary> /// Applies a perspective transformation to an image. /// </summary> /// <param name="m">3x3 transformation matrix.</param> /// <param name="dsize">size of the output image.</param> /// <param name="flags">combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) /// and the optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation (dst -> src).</param> /// <param name="borderMode">pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).</param> /// <param name="borderValue">value used in case of a constant border; by default, it equals 0.</param> /// <returns>output image that has the size dsize and the same type as src.</returns> public Mat WarpPerspective(Mat m, Size dsize, Interpolation flags = Interpolation.Linear, BorderType borderMode = BorderType.Constant, Scalar? borderValue = null) { var dst = new Mat(); Cv2.WarpPerspective(this, dst, m, dsize, flags, borderMode, borderValue); return dst; }
/// <summary> /// Add custom experiment design's condition parmeter name(string), code(int) and condition interpolation parameters /// </summary> /// <param name="paraname"></param> /// <param name="code"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="n"></param> /// <param name="method"></param> public void AddCondition(string paraname, int code, float start, float end, int n, Interpolation method) { Cond.Add(new SLKeyValuePair <string, int, SLInterpolation>(paraname, code, new SLInterpolation(start, end, n, method))); }
/// <summary> /// Creates a new resized bitmap. /// </summary> /// <param name="pixels">The source pixels.</param> /// <param name="widthSource">The width of the source pixels.</param> /// <param name="heightSource">The height of the source pixels.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new bitmap that is a resized version of the input.</returns> #if WPF public static int[] Resize(int *pixels, int widthSource, int heightSource, int width, int height, Interpolation interpolation)
/// <summary> /// Applies an affine transformation to an image. /// </summary> /// <param name="src">input image.</param> /// <param name="dst">output image that has the size dsize and the same type as src.</param> /// <param name="m">2x3 transformation matrix.</param> /// <param name="dsize">size of the output image.</param> /// <param name="flags">combination of interpolation methods and the optional flag /// WARP_INVERSE_MAP that means that M is the inverse transformation (dst -> src) .</param> /// <param name="borderMode">pixel extrapolation method; when borderMode=BORDER_TRANSPARENT, /// it means that the pixels in the destination image corresponding to the "outliers" /// in the source image are not modified by the function.</param> /// <param name="borderValue">value used in case of a constant border; by default, it is 0.</param> public static void WarpAffine(InputArray src, OutputArray dst, InputArray m, Size dsize, Interpolation flags = Interpolation.Linear, BorderType borderMode = BorderType.Constant, Scalar? borderValue = null) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); if (m == null) throw new ArgumentNullException("m"); src.ThrowIfDisposed(); dst.ThrowIfDisposed(); m.ThrowIfDisposed(); CvScalar borderValue0 = borderValue.GetValueOrDefault(CvScalar.ScalarAll(0)); NativeMethods.imgproc_warpAffine(src.CvPtr, dst.CvPtr, m.CvPtr, dsize, (int)flags, (int)borderMode, borderValue0); dst.Fix(); }
protected override void GenerateFrames() { if (Beatmap.HitObjects.Count == 0) { return; } float lastPosition = CatchPlayfield.CENTER_X; double lastTime = 0; void moveToNext(PalpableCatchHitObject h) { float positionChange = Math.Abs(lastPosition - h.EffectiveX); double timeAvailable = h.StartTime - lastTime; if (timeAvailable < 0) { return; } // So we can either make it there without a dash or not. // If positionChange is 0, we don't need to move, so speedRequired should also be 0 (could be NaN if timeAvailable is 0 too) // The case where positionChange > 0 and timeAvailable == 0 results in PositiveInfinity which provides expected beheaviour. double speedRequired = positionChange == 0 ? 0 : positionChange / timeAvailable; bool dashRequired = speedRequired > Catcher.BASE_WALK_SPEED; bool impossibleJump = speedRequired > Catcher.BASE_DASH_SPEED; // todo: get correct catcher size, based on difficulty CS. const float catcher_width_half = Catcher.BASE_SIZE * 0.3f * 0.5f; if (lastPosition - catcher_width_half < h.EffectiveX && lastPosition + catcher_width_half > h.EffectiveX) { // we are already in the correct range. lastTime = h.StartTime; addFrame(h.StartTime, lastPosition); return; } if (impossibleJump) { addFrame(h.StartTime, h.EffectiveX); } else if (h.HyperDash) { addFrame(h.StartTime - timeAvailable, lastPosition); addFrame(h.StartTime, h.EffectiveX); } else if (dashRequired) { // we do a movement in two parts - the dash part then the normal part... double timeAtNormalSpeed = positionChange / Catcher.BASE_WALK_SPEED; double timeWeNeedToSave = timeAtNormalSpeed - timeAvailable; double timeAtDashSpeed = timeWeNeedToSave / 2; float midPosition = (float)Interpolation.Lerp(lastPosition, h.EffectiveX, (float)timeAtDashSpeed / timeAvailable); // dash movement addFrame(h.StartTime - timeAvailable + 1, lastPosition, true); addFrame(h.StartTime - timeAvailable + timeAtDashSpeed, midPosition); addFrame(h.StartTime, h.EffectiveX); } else { double timeBefore = positionChange / Catcher.BASE_WALK_SPEED; addFrame(h.StartTime - timeBefore, lastPosition); addFrame(h.StartTime, h.EffectiveX); } lastTime = h.StartTime; lastPosition = h.EffectiveX; } foreach (var obj in Beatmap.HitObjects) { if (obj is PalpableCatchHitObject palpableObject) { moveToNext(palpableObject); } foreach (var nestedObj in obj.NestedHitObjects.Cast <CatchHitObject>()) { if (nestedObj is PalpableCatchHitObject palpableNestedObject) { moveToNext(palpableNestedObject); } } } }
/// <summary> /// Applies a generic geometrical transformation to an image. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image. It has the same size as map1 and the same type as src</param> /// <param name="map1">The first map of either (x,y) points or just x values having the type CV_16SC2, CV_32FC1, or CV_32FC2.</param> /// <param name="map2">The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map if map1 is (x,y) points), respectively.</param> /// <param name="interpolation">Interpolation method. The method INTER_AREA is not supported by this function.</param> /// <param name="borderMode">Pixel extrapolation method. When borderMode=BORDER_TRANSPARENT, /// it means that the pixels in the destination image that corresponds to the "outliers" in /// the source image are not modified by the function.</param> /// <param name="borderValue">Value used in case of a constant border. By default, it is 0.</param> public static void Remap(InputArray src, OutputArray dst, InputArray map1, InputArray map2, Interpolation interpolation = Interpolation.Linear, BorderType borderMode = BorderType.Constant, CvScalar? borderValue = null) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); if (map1 == null) throw new ArgumentNullException("map1"); if (map2 == null) throw new ArgumentNullException("map2"); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); map1.ThrowIfDisposed(); map2.ThrowIfDisposed(); CvScalar borderValue0 = borderValue.GetValueOrDefault(CvScalar.ScalarAll(0)); NativeMethods.imgproc_remap(src.CvPtr, dst.CvPtr, map1.CvPtr, map2.CvPtr, (int)interpolation, (int)borderMode, borderValue0); dst.Fix(); }
public HRegion Extract(HImage image) { // image.WriteImage("tiff", 0, "B:\\test-01-cropped.tif"); var imageWidth = image.GetWidth(); var imageHeight = image.GetHeight(); // image.GrayRangeRect(55, 55).WriteImage("tiff", 0, "B:\\test-00-GrayRangeRect.tif"); var houghRegion = HoughRegionExtractor.Extract(image); // image.PaintRegion(houghRegion, 200.0, "fill").WriteImage("tiff", 0, "B:\\test-02-houghRegion.tif"); var houghCenterRegion = houghRegion.HoughCircles(HoughExpectRadius, HoughPercent, 0); var center = houghCenterRegion.GetCenterPoint(); // image.PaintRegion(houghCenterRegion, 200.0, "fill").WriteImage("tiff", 0, "B:\\test-03-houghCenterRegion.tif"); var phiAngleStart = AngleStart / 180.0 * 3.1415926; var phiAngleEnd = AngleEnd / 180.0 * 3.1415926; var finalRadiuStart = RadiusStart > RadiusEnd ? RadiusStart : RadiusEnd; var finalRadiuEnd = RadiusStart > RadiusEnd ? RadiusEnd : RadiusStart; int width = (int)((Math.Abs(phiAngleStart - phiAngleEnd)) * finalRadiuStart); int height = (int)Math.Abs(RadiusStart - RadiusEnd); var transImage = image.PolarTransImageExt(center.Y, center.X, phiAngleStart, phiAngleEnd, RadiusStart, RadiusEnd, width, height, Interpolation.ToHalconString()); // transImage.WriteImage("tiff", 0, "B:\\test-04-transImage.tif"); var transRegion = TargetRegionExtractor.Extract(transImage); var finalRegion = transRegion.PolarTransRegionInv(center.Y, center.X, phiAngleStart, phiAngleEnd, RadiusStart, RadiusEnd, width, height, imageWidth, imageHeight, Interpolation.ToHalconString()); // image.PaintRegion(finalRegion, 200.0, "fill").WriteImage("tiff", 0, "B:\\test-04-transRegion.tif"); return(finalRegion); }
public static extern void cvResize(IntPtr src, IntPtr dst, Interpolation interpolation);
private double[] UpdateForces(IElement element) { //TODO: the gauss point loop should be the outer one // Matrices that are not currently cached are calculated here. Matrix ll2 = Matrix.CreateZero(8, 3); for (int m = 0; m < 8; m++) { for (int n = 0; n < 3; n++) { ll2[m, n] = tu_i[m][n]; } } IReadOnlyList <Matrix> shapeFunctionNaturalDerivatives; shapeFunctionNaturalDerivatives = Interpolation.EvaluateNaturalGradientsAtGaussPoints(QuadratureForStiffness); (Matrix[] J_0inv_hexa, double[] detJ_0) = JacobianHexa8Reverse.GetJ_0invHexaAndDetJ_0( shapeFunctionNaturalDerivatives, element.Nodes, nGaussPoints); Matrix[] BL13_hexa; BL13_hexa = GetBL13Hexa(shapeFunctionNaturalDerivatives); Matrix[] BL11a_hexa; // dimension number of gpoints Matrix[] BL12_hexa; Matrix[] BL01_hexa; BL11a_hexa = GetBL11a_hexa(J_0inv_hexa); BL12_hexa = GetBL12_hexa(J_0inv_hexa); BL01_hexa = GetBL01_hexa(J_0inv_hexa); //INITIALIZATION of MAtrixes that are currently not cached double[][] integrCoeff_Spkvec = new double[nGaussPoints][]; Matrix[] BL = new Matrix[nGaussPoints]; for (int gpoint = 0; gpoint < nGaussPoints; gpoint++) { integrCoeff_Spkvec[gpoint] = new double[6]; BL[gpoint] = Matrix.CreateZero(6, 24); } double[][] fxk1 = new double[nGaussPoints + 1][]; for (int npoint = 0; npoint < nGaussPoints + 1; npoint++) { fxk1[npoint] = new double[24]; } Matrix[] BL11 = new Matrix[nGaussPoints]; Matrix[] BL1112sun01_hexa = new Matrix[nGaussPoints]; for (int npoint = 0; npoint < nGaussPoints; npoint++) { BL11[npoint] = Matrix.CreateZero(6, 9); BL1112sun01_hexa[npoint] = Matrix.CreateZero(6, 9); } for (int npoint = 0; npoint < nGaussPoints; npoint++) { integrCoeff_Spkvec[npoint] = materialsAtGaussPoints[npoint].Stresses.Scale(integrationCoeffs[npoint]); // Matrix l_cyrcumflex = Matrix.CreateZero(3, 3); l_cyrcumflex = shapeFunctionNaturalDerivatives[npoint] * ll2; for (int m = 0; m < 6; m++) { for (int n = 0; n < 3; n++) { for (int p = 0; p < 3; p++) { BL11[npoint][m, n] += BL11a_hexa[npoint][m, p] * l_cyrcumflex[p, n]; BL11[npoint][m, 3 + n] += BL11a_hexa[npoint][m, 3 + p] * l_cyrcumflex[p, n]; BL11[npoint][m, 6 + n] += BL11a_hexa[npoint][m, 6 + p] * l_cyrcumflex[p, n]; } } } // BL1112sun01_hexa[npoint] = BL11[npoint] * BL12_hexa[npoint]; BL1112sun01_hexa[npoint].AddIntoThis(BL01_hexa[npoint]); // BL[npoint] = BL1112sun01_hexa[npoint] * BL13_hexa[npoint]; // fxk1[npoint] = BL[npoint].Multiply(integrCoeff_Spkvec[npoint], true); } for (int npoint = 0; npoint < nGaussPoints; npoint++) { fxk1[nGaussPoints].AddIntoThis(fxk1[npoint]); } return(fxk1[nGaussPoints]); }
/// <summary> /// Resizes an image. /// </summary> /// <param name="dsize">output image size; if it equals zero, it is computed as: /// dsize = Size(round(fx*src.cols), round(fy*src.rows)) /// Either dsize or both fx and fy must be non-zero.</param> /// <param name="fx">scale factor along the horizontal axis; when it equals 0, /// it is computed as: (double)dsize.width/src.cols</param> /// <param name="fy">scale factor along the vertical axis; when it equals 0, /// it is computed as: (double)dsize.height/src.rows</param> /// <param name="interpolation">interpolation method</param> /// <returns>output image; it has the size dsize (when it is non-zero) or the size computed /// from src.size(), fx, and fy; the type of dst is the same as of src.</returns> public Mat Resize(Size dsize, double fx = 0, double fy = 0, Interpolation interpolation = Interpolation.Linear) { var dst = new Mat(); Cv2.Resize(this, dst, dsize, fx, fy, interpolation); return dst; }
private Matrix UpdateKmatrices(IElement element) { Matrix k_element = Matrix.CreateZero(24, 24); // initialization of matrices that are not cached currently double[][] integrCoeff_Spkvec = new double[nGaussPoints][]; Matrix[] BL = new Matrix[nGaussPoints]; for (int gpoint = 0; gpoint < nGaussPoints; gpoint++) { integrCoeff_Spkvec[gpoint] = new double[6]; BL[gpoint] = Matrix.CreateZero(6, 24); } Matrix ll2 = Matrix.CreateZero(8, 3); for (int m = 0; m < 8; m++) { for (int n = 0; n < 3; n++) { ll2[m, n] = tu_i[m][n]; } } IReadOnlyList <Matrix> shapeFunctionNaturalDerivatives; shapeFunctionNaturalDerivatives = Interpolation.EvaluateNaturalGradientsAtGaussPoints(QuadratureForStiffness); (Matrix[] J_0inv_hexa, double[] detJ_0) = JacobianHexa8Reverse.GetJ_0invHexaAndDetJ_0( shapeFunctionNaturalDerivatives, element.Nodes, nGaussPoints); Matrix[] BL13_hexa; BL13_hexa = GetBL13Hexa(shapeFunctionNaturalDerivatives); Matrix[] BL11a_hexa; // dimension: gpoints Matrix[] BL12_hexa; Matrix[] BL01_hexa; BL11a_hexa = GetBL11a_hexa(J_0inv_hexa); BL12_hexa = GetBL12_hexa(J_0inv_hexa); BL01_hexa = GetBL01_hexa(J_0inv_hexa); Matrix[] BL11 = new Matrix[nGaussPoints]; Matrix[] BL1112sun01_hexa = new Matrix[nGaussPoints]; for (int npoint = 0; npoint < nGaussPoints; npoint++) { BL11[npoint] = Matrix.CreateZero(6, 9); BL1112sun01_hexa[npoint] = Matrix.CreateZero(6, 9); //TODO this may be unnescessary } for (int npoint = 0; npoint < nGaussPoints; npoint++) { // integrCoeff_Spkvec[npoint] = materialsAtGaussPoints[npoint].Stresses.Scale(integrationCoeffs[npoint]); // Matrix l_cyrcumflex = Matrix.CreateZero(3, 3); l_cyrcumflex = shapeFunctionNaturalDerivatives[npoint] * ll2; for (int m = 0; m < 6; m++) { for (int n = 0; n < 3; n++) { for (int p = 0; p < 3; p++) { BL11[npoint][m, n] += BL11a_hexa[npoint][m, p] * l_cyrcumflex[p, n]; BL11[npoint][m, 3 + n] += BL11a_hexa[npoint][m, 3 + p] * l_cyrcumflex[p, n]; BL11[npoint][m, 6 + n] += BL11a_hexa[npoint][m, 6 + p] * l_cyrcumflex[p, n]; } } } // BL1112sun01_hexa[npoint] = BL11[npoint] * BL12_hexa[npoint]; BL1112sun01_hexa[npoint].AddIntoThis(BL01_hexa[npoint]); // BL[npoint] = BL1112sun01_hexa[npoint] * BL13_hexa[npoint]; } // TODO: BL and above calculations can cached from calculate forces method Matrix[] BNL1_hexa; Matrix[] BNL_hexa; BNL1_hexa = GetBNL1_hexa(J_0inv_hexa); BNL_hexa = new Matrix[nGaussPoints]; for (int gpoint = 0; gpoint < nGaussPoints; gpoint++) { BNL_hexa[gpoint] = Matrix.CreateZero(9, 24); //todo this may be unnescessary BNL_hexa[gpoint] = BNL1_hexa[gpoint] * BL13_hexa[gpoint]; } Matrix[] integrCoeff_Spk = new Matrix[nGaussPoints]; for (int npoint = 0; npoint < nGaussPoints; npoint++) { integrCoeff_Spk[npoint] = Matrix.CreateZero(3, 3); } Matrix[] kl_ = new Matrix[nGaussPoints + 1]; Matrix[] knl_ = new Matrix[nGaussPoints + 1]; for (int npoint = 0; npoint < nGaussPoints + 1; npoint++) { kl_[npoint] = Matrix.CreateZero(24, 24); knl_[npoint] = Matrix.CreateZero(24, 24); } for (int npoint = 0; npoint < nGaussPoints; npoint++) { Matrix integrCoeff_SPK_epi_BNL_hexa = Matrix.CreateZero(9, 24); //TODO Matrix integrCoeff_cons_disp = Matrix.CreateZero(6, 6); //TODO Matrix integrCoeff_cons_disp_epi_BL = Matrix.CreateZero(6, 24); //TODO // integrCoeff_Spk[npoint][0, 0] = integrCoeff_Spkvec[npoint][0]; integrCoeff_Spk[npoint][0, 1] = integrCoeff_Spkvec[npoint][3]; integrCoeff_Spk[npoint][0, 2] = integrCoeff_Spkvec[npoint][5]; integrCoeff_Spk[npoint][1, 0] = integrCoeff_Spkvec[npoint][3]; integrCoeff_Spk[npoint][1, 1] = integrCoeff_Spkvec[npoint][1]; integrCoeff_Spk[npoint][1, 2] = integrCoeff_Spkvec[npoint][4]; integrCoeff_Spk[npoint][2, 0] = integrCoeff_Spkvec[npoint][5]; integrCoeff_Spk[npoint][2, 1] = integrCoeff_Spkvec[npoint][4]; integrCoeff_Spk[npoint][2, 2] = integrCoeff_Spkvec[npoint][2]; // IMatrixView consDisp = materialsAtGaussPoints[npoint].ConstitutiveMatrix; for (int m = 0; m < 6; m++) { for (int n = 0; n < 6; n++) { integrCoeff_cons_disp[m, n] = integrationCoeffs[npoint] * consDisp[m, n]; } } // integrCoeff_cons_disp_epi_BL = integrCoeff_cons_disp * BL[npoint]; // kl_[npoint] = BL[npoint].Transpose() * integrCoeff_cons_disp_epi_BL; // for (int m = 0; m < 3; m++) // 3x24 dimensions { for (int n = 0; n < 24; n++) { for (int p = 0; p < 3; p++) { integrCoeff_SPK_epi_BNL_hexa[m, n] += integrCoeff_Spk[npoint][m, p] * BNL_hexa[npoint][p, n]; integrCoeff_SPK_epi_BNL_hexa[3 + m, n] += integrCoeff_Spk[npoint][m, p] * BNL_hexa[npoint][3 + p, n]; integrCoeff_SPK_epi_BNL_hexa[6 + m, n] += integrCoeff_Spk[npoint][m, p] * BNL_hexa[npoint][6 + p, n]; } } } // knl_[npoint] = BNL_hexa[npoint].Transpose() * integrCoeff_SPK_epi_BNL_hexa; } // Add contributions of each gp on the total element stiffness matrix k_element for (int npoint = 0; npoint < nGaussPoints; npoint++) { for (int m = 0; m < 24; m++) { for (int n = 0; n < 24; n++) { kl_[nGaussPoints][m, n] += kl_[npoint][m, n]; knl_[nGaussPoints][m, n] += knl_[npoint][m, n]; } } } for (int m = 0; m < 24; m++) { for (int n = 0; n < 24; n++) { k_element[m, n] = kl_[nGaussPoints][m, n] + knl_[nGaussPoints][m, n]; } } return(k_element); }
/// <summary> /// Applies a generic geometrical transformation to an image. /// </summary> /// <param name="map1">The first map of either (x,y) points or just x values having the type CV_16SC2, CV_32FC1, or CV_32FC2.</param> /// <param name="map2">The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map if map1 is (x,y) points), respectively.</param> /// <param name="interpolation">Interpolation method. The method INTER_AREA is not supported by this function.</param> /// <param name="borderMode">Pixel extrapolation method. When borderMode=BORDER_TRANSPARENT, /// it means that the pixels in the destination image that corresponds to the "outliers" in /// the source image are not modified by the function.</param> /// <param name="borderValue">Value used in case of a constant border. By default, it is 0.</param> /// <returns>Destination image. It has the same size as map1 and the same type as src</returns> public Mat Remap(InputArray map1, InputArray map2, Interpolation interpolation = Interpolation.Linear, BorderType borderMode = BorderType.Constant, CvScalar? borderValue = null) { var dst = new Mat(); Cv2.Remap(this, dst, map1, map2, interpolation, borderMode, borderValue); return dst; }
/// <summary> /// Creates a new resized WriteableBitmap. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new WriteableBitmap that is a resized version of the input.</returns> public static WriteableBitmap Resize(this WriteableBitmap bmp, int width, int height, Interpolation interpolation) { // Init vars int ws = bmp.PixelWidth; int hs = bmp.PixelHeight; #if SILVERLIGHT var ps = bmp.Pixels; var result = new WriteableBitmap(width, height); var pd = result.Pixels; #else bmp.Lock(); var result = new WriteableBitmap(width, height, 96.0, 96.0, PixelFormats.Bgra32, null); result.Lock(); unsafe { var ps = (int *)bmp.BackBuffer; var pd = (int *)result.BackBuffer; #endif float xs = (float)ws / width; float ys = (float)hs / height; float fracx, fracy, ifracx, ifracy, sx, sy, l0, l1; int c, x0, x1, y0, y1; byte c1a, c1r, c1g, c1b, c2a, c2r, c2g, c2b, c3a, c3r, c3g, c3b, c4a, c4r, c4g, c4b; byte a = 0, r = 0, g = 0, b = 0; // Nearest Neighbor if (interpolation == Interpolation.NearestNeighbor) { int srcIdx = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; pd[srcIdx++] = ps[y0 * ws + x0]; } } } // Bilinear else if (interpolation == Interpolation.Bilinear) { int srcIdx = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { sx = x * xs; sy = y * ys; x0 = (int)sx; y0 = (int)sy; // Calculate coordinates of the 4 interpolation points fracx = sx - x0; fracy = sy - y0; ifracx = 1f - fracx; ifracy = 1f - fracy; x1 = x0 + 1; if (x1 >= ws) { x1 = x0; } y1 = y0 + 1; if (y1 >= hs) { y1 = y0; } // Read source color c = ps[y0 * ws + x0]; c1a = (byte)(c >> 24); c1r = (byte)(c >> 16); c1g = (byte)(c >> 8); c1b = (byte)(c); c = ps[y0 * ws + x1]; c2a = (byte)(c >> 24); c2r = (byte)(c >> 16); c2g = (byte)(c >> 8); c2b = (byte)(c); c = ps[y1 * ws + x0]; c3a = (byte)(c >> 24); c3r = (byte)(c >> 16); c3g = (byte)(c >> 8); c3b = (byte)(c); c = ps[y1 * ws + x1]; c4a = (byte)(c >> 24); c4r = (byte)(c >> 16); c4g = (byte)(c >> 8); c4b = (byte)(c); // Calculate colors // Alpha l0 = ifracx * c1a + fracx * c2a; l1 = ifracx * c3a + fracx * c4a; a = (byte)(ifracy * l0 + fracy * l1); if (a > 0) { // Red l0 = ifracx * c1r * c1a + fracx * c2r * c2a; l1 = ifracx * c3r * c3a + fracx * c4r * c4a; r = (byte)((ifracy * l0 + fracy * l1) / a); // Green l0 = ifracx * c1g * c1a + fracx * c2g * c2a; l1 = ifracx * c3g * c3a + fracx * c4g * c4a; g = (byte)((ifracy * l0 + fracy * l1) / a); // Blue l0 = ifracx * c1b * c1a + fracx * c2b * c2a; l1 = ifracx * c3b * c3a + fracx * c4b * c4a; b = (byte)((ifracy * l0 + fracy * l1) / a); } // Write destination pd[srcIdx++] = (a << 24) | (r << 16) | (g << 8) | b; } } } #if !SILVERLIGHT } result.AddDirtyRect(new Int32Rect(0, 0, width, height)); result.Unlock(); bmp.Unlock(); #endif return(result); }
/// <summary> /// Creates a new resized WriteableBitmap. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new WriteableBitmap that is a resized version of the input.</returns> public static WriteableBitmap Resize(this WriteableBitmap bmp, int width, int height, Interpolation interpolation) { using (var srcContext = bmp.GetBitmapContext()) { var pd = Resize(srcContext, srcContext.Width, srcContext.Height, width, height, interpolation); var result = BitmapFactory.New(width, height); using (var dstContext = result.GetBitmapContext()) { BitmapContext.BlockCopy(pd, 0, dstContext, 0, SizeOfArgb * pd.Length); } return result; } }
public NoiseGenerator(long seed, double persistence, int levels, int[] size, bool smooth, Interpolation interpolation) { this.seed = seed; if (persistence < 0.0 || persistence > 1.0) { throw new ArgumentOutOfRangeException(nameof(persistence)); } this.persistence = persistence; if (levels <= 0) { throw new ArgumentOutOfRangeException(nameof(levels)); } this.levels = levels; this.persistences = Enumerable.Range(0, this.levels) .Select(l => Math.Pow(persistence, l)) .ToArray(); this.scale = this.persistences.Sum(); this.smooth = smooth; if (size == null) { throw new ArgumentNullException(nameof(size)); } else if (size.Length == 0) { throw new ArgumentOutOfRangeException(nameof(size)); } this.size = Array.ConvertAll(size, s => s); this.dimensions = this.size.Length; this.levelSizes = new int[this.levels][]; for (var level = 0; level < this.levels; level++) { this.levelSizes[level] = new int[this.dimensions]; for (var i = 0; i < this.dimensions; i++) { this.levelSizes[level][i] = this.size[i] * (1 << level); } } this.interpolation = interpolation ?? throw new ArgumentNullException(nameof(interpolation)); this.levelsCache = new SplayTreeDictionary <long[], Array[]>(CacheKeyComparer.Instance); }
/// <summary> /// Creates a new resized bitmap. /// </summary> /// <param name="pixels">The source pixels.</param> /// <param name="widthSource">The width of the source pixels.</param> /// <param name="heightSource">The height of the source pixels.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new bitmap that is a resized version of the input.</returns> #if WPF public static int[] Resize(int* pixels, int widthSource, int heightSource, int width, int height, Interpolation interpolation)
public override Replay Generate() { // todo: add support for HT DT const double dash_speed = CatcherArea.Catcher.BASE_SPEED; const double movement_speed = dash_speed / 2; float lastPosition = 0.5f; double lastTime = 0; void moveToNext(CatchHitObject h) { float positionChange = Math.Abs(lastPosition - h.X); double timeAvailable = h.StartTime - lastTime; // So we can either make it there without a dash or not. // If positionChange is 0, we don't need to move, so speedRequired should also be 0 (could be NaN if timeAvailable is 0 too) // The case where positionChange > 0 and timeAvailable == 0 results in PositiveInfinity which provides expected beheaviour. double speedRequired = positionChange == 0 ? 0 : positionChange / timeAvailable; bool dashRequired = speedRequired > movement_speed; bool impossibleJump = speedRequired > movement_speed * 2; // todo: get correct catcher size, based on difficulty CS. const float catcher_width_half = CatcherArea.CATCHER_SIZE / CatchPlayfield.BASE_WIDTH * 0.3f * 0.5f; if (lastPosition - catcher_width_half < h.X && lastPosition + catcher_width_half > h.X) { //we are already in the correct range. lastTime = h.StartTime; addFrame(h.StartTime, lastPosition); return; } if (impossibleJump) { addFrame(h.StartTime, h.X); } else if (h.HyperDash) { addFrame(h.StartTime - timeAvailable, lastPosition); addFrame(h.StartTime, h.X); } else if (dashRequired) { //we do a movement in two parts - the dash part then the normal part... double timeAtNormalSpeed = positionChange / movement_speed; double timeWeNeedToSave = timeAtNormalSpeed - timeAvailable; double timeAtDashSpeed = timeWeNeedToSave / 2; float midPosition = (float)Interpolation.Lerp(lastPosition, h.X, (float)timeAtDashSpeed / timeAvailable); //dash movement addFrame(h.StartTime - timeAvailable + 1, lastPosition, true); addFrame(h.StartTime - timeAvailable + timeAtDashSpeed, midPosition); addFrame(h.StartTime, h.X); } else { double timeBefore = positionChange / movement_speed; addFrame(h.StartTime - timeBefore, lastPosition); addFrame(h.StartTime, h.X); } lastTime = h.StartTime; lastPosition = h.X; } foreach (var obj in Beatmap.HitObjects) { switch (obj) { case Fruit _: moveToNext(obj); break; } foreach (var nestedObj in obj.NestedHitObjects.Cast <CatchHitObject>()) { switch (nestedObj) { case Banana _: case TinyDroplet _: case Droplet _: case Fruit _: moveToNext(nestedObj); break; } } } return(Replay); }
/// <summary> /// Creates a new resized WriteableBitmap. /// </summary> /// <param name="bmp">The WriteableBitmap.</param> /// <param name="width">The new desired width.</param> /// <param name="height">The new desired height.</param> /// <param name="interpolation">The interpolation method that should be used.</param> /// <returns>A new WriteableBitmap that is a resized version of the input.</returns> public static WriteableBitmap Resize(this WriteableBitmap bmp, int width, int height, Interpolation interpolation) { // Init vars int ws = bmp.PixelWidth; int hs = bmp.PixelHeight; #if SILVERLIGHT var ps = bmp.Pixels; var result = new WriteableBitmap(width, height); var pd = result.Pixels; #else bmp.Lock(); var result = new WriteableBitmap(width, height, 96.0, 96.0, PixelFormats.Bgra32, null); result.Lock(); unsafe { var ps = (int*) bmp.BackBuffer; var pd = (int*) result.BackBuffer; #endif float xs = (float) ws/width; float ys = (float) hs/height; float fracx, fracy, ifracx, ifracy, sx, sy, l0, l1; int c, x0, x1, y0, y1; byte c1a, c1r, c1g, c1b, c2a, c2r, c2g, c2b, c3a, c3r, c3g, c3b, c4a, c4r, c4g, c4b; byte a = 0, r = 0, g = 0, b = 0; // Nearest Neighbor if (interpolation == Interpolation.NearestNeighbor) { int srcIdx = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { sx = x*xs; sy = y*ys; x0 = (int) sx; y0 = (int) sy; pd[srcIdx++] = ps[y0*ws + x0]; } } } // Bilinear else if (interpolation == Interpolation.Bilinear) { int srcIdx = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { sx = x*xs; sy = y*ys; x0 = (int) sx; y0 = (int) sy; // Calculate coordinates of the 4 interpolation points fracx = sx - x0; fracy = sy - y0; ifracx = 1f - fracx; ifracy = 1f - fracy; x1 = x0 + 1; if (x1 >= ws) x1 = x0; y1 = y0 + 1; if (y1 >= hs) y1 = y0; // Read source color c = ps[y0*ws + x0]; c1a = (byte) (c >> 24); c1r = (byte) (c >> 16); c1g = (byte) (c >> 8); c1b = (byte) (c); c = ps[y0*ws + x1]; c2a = (byte) (c >> 24); c2r = (byte) (c >> 16); c2g = (byte) (c >> 8); c2b = (byte) (c); c = ps[y1*ws + x0]; c3a = (byte) (c >> 24); c3r = (byte) (c >> 16); c3g = (byte) (c >> 8); c3b = (byte) (c); c = ps[y1*ws + x1]; c4a = (byte) (c >> 24); c4r = (byte) (c >> 16); c4g = (byte) (c >> 8); c4b = (byte) (c); // Calculate colors // Alpha l0 = ifracx*c1a + fracx*c2a; l1 = ifracx*c3a + fracx*c4a; a = (byte) (ifracy*l0 + fracy*l1); if (a > 0) { // Red l0 = ifracx*c1r*c1a + fracx*c2r*c2a; l1 = ifracx*c3r*c3a + fracx*c4r*c4a; r = (byte) ((ifracy*l0 + fracy*l1)/a); // Green l0 = ifracx*c1g*c1a + fracx*c2g*c2a; l1 = ifracx*c3g*c3a + fracx*c4g*c4a; g = (byte) ((ifracy*l0 + fracy*l1)/a); // Blue l0 = ifracx*c1b*c1a + fracx*c2b*c2a; l1 = ifracx*c3b*c3a + fracx*c4b*c4a; b = (byte) ((ifracy*l0 + fracy*l1)/a); } // Write destination pd[srcIdx++] = (a << 24) | (r << 16) | (g << 8) | b; } } } #if !SILVERLIGHT } result.AddDirtyRect(new Int32Rect(0, 0, width, height)); result.Unlock(); bmp.Unlock(); #endif return result; }
/// <summary> /// Creates a shade of colour for the triangles. /// </summary> /// <returns>The colour.</returns> protected virtual Color4 CreateTriangleShade() => Interpolation.ValueAt(RNG.NextSingle(), ColourDark, ColourLight, 0, 1);