private static SortedDictionary <double, double> CreateInterpolatedAgeVector( double previousAge, double currentAge, double ageToCreateVectorFor, SortedDictionary <double, double> vector1, SortedDictionary <double, double> vector2) { SortedDictionary <double, double> interpolatedAgeVector = new SortedDictionary <double, double> (); foreach (double percentile in vector1.Keys) { double vector1Value = vector1[percentile]; double vector2Value = vector2[percentile]; interpolatedAgeVector[percentile] = Interpolator.Interpolate(previousAge, vector1Value, currentAge, vector2Value, ageToCreateVectorFor); } return(interpolatedAgeVector); }
/// <summary> /// Creates a sample sequence used to demonstrate scope features. /// </summary> private SampleSequence CreateDemoSampleSequence(double duration, int sampleRate, IInterpolator interpolator, int interpolatedSampleRate) { var values1 = FunctionValueGenerator.GenerateSineValuesForFrequency(1, sampleRate, duration, (x, y) => y); var values3 = FunctionValueGenerator.GenerateSineValuesForFrequency(3, sampleRate, duration, (x, y) => y / 2); var values = CollectionUtilities.Zip( objects => ((double)objects[0]) + ((double)objects[1]), values1, values3); if (interpolator != null) { values = interpolator.Interpolate(values, 0, duration, sampleRate, interpolatedSampleRate); sampleRate = interpolatedSampleRate; } // LogDeferredAccess shows us some details about how the values are accessed (see there). return(new SampleSequence(1f / sampleRate, values)); //return new SampleSequence(1/sampleFrequency, LogDeferredAccess(values)); }
internal void Interpolate() { var delta = Time.time - lastFixedTime; var t = delta / Time.fixedDeltaTime; interpolator.Interpolate(PreviousStateData, CurrentStateData, t); }
/// <summary> /// 将控件参数传递到参数对象中 /// </summary> protected override void CollectArguments() { base.CollectArguments(); //CurveAdjustProcessorArg actualArg = _arg as CurveAdjustProcessorArg; for (int i = 0; i < 256; i++) { _rgbs[i] = _interpolator.Interpolate((byte)i); } }
public void SetCoor(IInterpolator inter,double x, double y, double z) { this.inter = inter; this.X = x; this.Y = y; this.Z = z; this.W = inter.Interpolate(x, y,z,true)[0]; uxValue.Text = this.W.ToString(); OnChangedCoordinater(EventArgs.Empty); }
public override void InterpolateBetweenAndExecute(GenericInstruction otherInstruction, float thisRatio) { IInterpolator <ValueType> interpolator = InstructionManager.GetInterpolator(mValue.GetType(), mMember) as IInterpolator <ValueType>; ValueType interpolatedValue = interpolator.Interpolate(mValue, ((ValueType)otherInstruction.MemberValueAsObject), thisRatio); LateBinder <TargetType> .Instance.SetProperty <ValueType>(mTarget, mMember, interpolatedValue); }
public static CommandDelegate ChangeTo <T>(Ref <T> val, T endValue, IInterpolator <T> interpolator, double duration, CommandEase ease = null) where T : struct { CheckArgumentNonNull(val, "val"); CheckArgumentNonNull(interpolator, "interpolator"); T startValue = val.Value; return(Cmd.Sequence( Cmd.Do(delegate() { startValue = val.Value; }), Cmd.Duration(delegate(double t) { val.Value = interpolator.Interpolate(startValue, endValue, t); }, duration, ease) )); }
public void UpdateTime(float time) { if (frameIndex >= timeFrames.Count) { return; } for (int i = frameIndex; i < timeFrames.Count; i++) { var frame = timeFrames[i]; // Update only if interpolant is less than 1. // Otherwise, frame index must be the last one. if (frame.IsOverTime(time) && i < timeFrames.Count - 1) { // Advance to the next frame. frameIndex++; } else { if (i == timeFrames.Count - 1) { // Set frame index to the end to prevent further updates. frameIndex = timeFrames.Count; // Just invoke with the last key value. handler.Invoke(frame.GetValue.Invoke()); } else { // Calculate interpolant float interpolant = frame.GetInterpolant(time); // Notify the handler. var nextFrame = timeFrames[i + 1]; handler.Invoke(interpolator.Interpolate(frame.GetValue.Invoke(), nextFrame.GetValue.Invoke(), interpolant)); } break; } } }
public List<double[]> UpdatePredictedTableDeterministics(IInterpolator predic, int trend, string transform) { //"Measured","Trans","Trend","Predicted","Error","StdError" List<double[]> lists = new List<double[]>(); List<double> predictedValues = new List<double>(); List<double> observedValues = new List<double>(); List<double> error = new List<double>(); #region Checkvalues foreach (Feature fea1 in data.Features) { double[] value = predic.Interpolate(fea1.Coordinates[0].X, fea1.Coordinates[0].Y,fea1.Coordinates[0].Z, false); if (value[0].Equals(double.NaN)) break; fea1.DataRow["Predicted"] = value[0] ; fea1.DataRow["Error"] = Convert.ToDouble(fea1.DataRow["Predicted"]) - Convert.ToDouble(fea1.DataRow["Measured"]); predictedValues.Add(Convert.ToDouble(fea1.DataRow["Predicted"])); observedValues.Add(Convert.ToDouble(fea1.DataRow["Measured"])); error.Add(Convert.ToDouble(fea1.DataRow["Error"])); } #endregion lists.Add(observedValues.ToArray()); lists.Add(predictedValues.ToArray()); lists.Add(error.ToArray()); return lists; }
public List<double[]> UpdatePredictedTable(IInterpolator predic, int trend, string transform) { //"Measured","Trans","Trend","Predicted","Error","StdError" List<double[]> lists= new List<double[]>(); List<double> predictedValues = new List<double>(); List<double> observedValues = new List<double>(); List<double> error = new List<double>(); List<double> stdError = new List<double>(); #region Checkvalues foreach (Feature fea1 in data.Features) { double[] value = predic.Interpolate(fea1.Coordinates[0].X, fea1.Coordinates[0].Y, fea1.Coordinates[0].Z,false); if (!value[0].Equals(double.NaN) && !value[1].Equals(double.NaN)) { if (trend != 0) { if (transform == "None") { //used= (real or trans) - trend; //(real or trans)= (used or pred) + trend; fea1.DataRow["Predicted"] = value[0] + Convert.ToDouble(fea1.DataRow["Trend"]); fea1.DataRow["Error"] = Convert.ToDouble(fea1.DataRow["Predicted"]) - Convert.ToDouble(fea1.DataRow["Measured"]); fea1.DataRow["StdError"] = value[1]; } else { fea1.DataRow["Predicted"] = check.TransformInverse(transform, (value[0] + Convert.ToDouble(fea1.DataRow["Trend"]))); fea1.DataRow["Error"] = check.TransformInverse(transform, Convert.ToDouble(fea1.DataRow["Predicted"]) - Convert.ToDouble(fea1.DataRow["Measured"])); fea1.DataRow["StdError"] = check.TransformInverse(transform, value[1]); } } else { if (transform == "None") { //used= (real or trans) - trend; //(real or trans)= (used or pred) + trend; fea1.DataRow["Predicted"] = value[0]; ; fea1.DataRow["Error"] = Convert.ToDouble(fea1.DataRow["Predicted"]) - Convert.ToDouble(fea1.DataRow["Used"]); fea1.DataRow["StdError"] = value[1]; } else { fea1.DataRow["Predicted"] = check.TransformInverse(transform, (value[0])); fea1.DataRow["Error"] = check.TransformInverse(transform, Convert.ToDouble(fea1.DataRow["Predicted"]) - Convert.ToDouble(fea1.DataRow["Used"])); fea1.DataRow["StdError"] = check.TransformInverse(transform, value[1]); } } predictedValues.Add(Convert.ToDouble(fea1.DataRow["Predicted"])); observedValues.Add(Convert.ToDouble(fea1.DataRow["Measured"])); error.Add(Convert.ToDouble(fea1.DataRow["Error"])); stdError.Add(Convert.ToDouble(fea1.DataRow["StdError"])); } } #endregion lists.Add(observedValues.ToArray()); lists.Add(predictedValues.ToArray()); lists.Add(error.ToArray()); lists.Add(stdError.ToArray()); return lists; }
private float GetElevationAtPoint(IRasterFile mainRaster, RasterFileDictionary adjacentTiles, FileMetadata metadata, double lat, double lon, float lastElevation, IInterpolator interpolator) { float heightValue = 0; try { //const double epsilon = (Double.Epsilon * 100); float noData = metadata.NoDataValueFloat; double yPixel, xPixel, xInterpolationAmount, yInterpolationAmount; // pixel coordinates interpolated if (metadata.FileFormat.Registration == DEMFileRegistrationMode.Grid) { yPixel = Math.Sign(metadata.pixelSizeY) == 1 ? (metadata.DataEndLat - lat) / metadata.pixelSizeY : (lat - metadata.DataEndLat) / metadata.pixelSizeY; xPixel = (lon - metadata.DataStartLon) / metadata.pixelSizeX; // If at pixel center (ending by .5, .5), we are on the data point, so no need for adjacent raster checks xInterpolationAmount = (double)(xPixel) % 1d; yInterpolationAmount = (double)(yPixel) % 1d; } else { // In cell registration mode, the actual data point is at pixel center // If at pixel center (ending by .5, .5), we are on the data point, so no need for adjacent raster checks yPixel = Math.Sign(metadata.pixelSizeY) == 1 ? ((metadata.PhysicalEndLat + metadata.pixelSizeY / 2) - lat) / metadata.pixelSizeY : (lat - (metadata.PhysicalEndLat + metadata.pixelSizeY / 2)) / metadata.pixelSizeY; xPixel = (lon - (metadata.PhysicalStartLon + metadata.pixelSizeX / 2)) / metadata.pixelSizeX; xInterpolationAmount = Math.Abs((double)(xPixel) % 1d); yInterpolationAmount = Math.Abs((double)(yPixel) % 1d); } bool xOnDataPoint = Math.Abs(xInterpolationAmount) < EPSILON; bool yOnDataPoint = Math.Abs(yInterpolationAmount) < EPSILON; // If xOnGrid and yOnGrid, we are on a grid intersection, and that's all // TODO fix that // When cell registered, this true when interpolation is 0.5 / 0.5 // When grid registered, this is true if (xOnDataPoint && yOnDataPoint) { int x = (int)Math.Round(xPixel, 0); int y = (int)Math.Round(yPixel, 0); var tile = FindTile(metadata, adjacentTiles, x, y, out x, out y); heightValue = mainRaster.GetElevationAtPoint(tile, x, y); } else { int xCeiling = (int)Math.Ceiling(xPixel); int xFloor = (int)Math.Floor(xPixel); int yCeiling = (int)Math.Ceiling(yPixel); int yFloor = (int)Math.Floor(yPixel); // Get 4 grid nearest points (DEM grid corners) // If not yOnGrid and not xOnGrid we are on grid horizontal line // We need elevations for top, bottom, left and right grid points (along x axis and y axis) float northWest = GetElevationAtPoint(metadata, adjacentTiles, xFloor, yFloor, noData); float northEast = GetElevationAtPoint(metadata, adjacentTiles, xCeiling, yFloor, noData); float southWest = GetElevationAtPoint(metadata, adjacentTiles, xFloor, yCeiling, noData); float southEast = GetElevationAtPoint(metadata, adjacentTiles, xCeiling, yCeiling, noData); float avgHeight = GetAverageExceptForNoDataValue(noData, NO_DATA_OUT, southWest, southEast, northWest, northEast); if (northWest == noData) { northWest = avgHeight; } if (northEast == noData) { northEast = avgHeight; } if (southWest == noData) { southWest = avgHeight; } if (southEast == noData) { southEast = avgHeight; } heightValue = (float)interpolator.Interpolate(southWest, southEast, northWest, northEast, xInterpolationAmount, yInterpolationAmount); } if (heightValue == NO_DATA_OUT) { heightValue = lastElevation; } } catch (Exception e) { _logger?.LogError(e, $"Error while getting elevation data : {e.Message}{Environment.NewLine}{e.ToString()}"); throw; } return(heightValue); }
/// <summary> /// 将控件参数传递到参数对象中 /// </summary> protected override void CollectArguments() { if (_arg == null) { return; } CurveAdjustProcessorArg actualArg = _arg as CurveAdjustProcessorArg; IInterpolator interpolator = GetInterpolator(); if (curveControl.Channels == 3) { for (int i = 0; i < curveControl.Channels; i++) { interpolator.Clear(); CurveControl curve = curveControl;// curveControls[CA.ColorTransferMode.Rgb]; SortedList <int, int> cps = curve.ControlPoints[i]; for (int s = 0; s < cps.Count; s++) { interpolator.Add(cps.Keys[s], cps.Values[s]); } byte[] rgbMap = new byte[curveControl.Entries]; for (int j = 0; j < curveControl.Entries; j++) { rgbMap[j] = (byte)Utility.Clamp(interpolator.Interpolate((byte)j), 0, curveControl.Entries - 1); } if (i == 0) { actualArg.Red.Values = rgbMap; } else if (i == 1) { actualArg.Green.Values = rgbMap; } else if (i == 2) { actualArg.Blue.Values = rgbMap; } } actualArg.RGB.Values = null; } else { interpolator.Clear(); CurveControl curve = curveControl;// curveControls[CA.ColorTransferMode.Luminosity]; SortedList <int, int> cps = curve.ControlPoints[0]; for (int s = 0; s < cps.Count; s++) { interpolator.Add(cps.Keys[s], cps.Values[s]); } byte[] rgbMap = new byte[curveControl.Entries]; for (int j = 0; j < curveControl.Entries; j++) { rgbMap[j] = (byte)Utility.Clamp(interpolator.Interpolate((byte)j), 0, curveControl.Entries - 1); } actualArg.RGB.Values = rgbMap; actualArg.Red.Values = null; actualArg.Green.Values = null; actualArg.Blue.Values = null; } base.CollectArguments(); }
private ExpressionVariant EvaluateImpl(TimeSpan elapsed, ExpressionVariant currentValue, ref ExpressionEvaluationContext ctx) { if (elapsed < _delayTime) { if (_delayBehavior == AnimationDelayBehavior.SetInitialValueBeforeDelay) { return(ExpressionVariant.Create(GetKeyFrame(ref ctx, _keyFrames[0]))); } return(currentValue); } elapsed -= _delayTime; var iterationNumber = elapsed.Ticks / _duration.Ticks; if (_iterationBehavior == AnimationIterationBehavior.Count && iterationNumber >= _iterationCount) { return(ExpressionVariant.Create(GetKeyFrame(ref ctx, _keyFrames[_keyFrames.Length - 1]))); } var evenIterationNumber = iterationNumber % 2 == 0; elapsed = TimeSpan.FromTicks(elapsed.Ticks % _duration.Ticks); var reverse = _direction == PlaybackDirection.Alternate ? !evenIterationNumber : _direction == PlaybackDirection.AlternateReverse ? evenIterationNumber : _direction == PlaybackDirection.Reverse; var iterationProgress = elapsed.TotalSeconds / _duration.TotalSeconds; if (reverse) { iterationProgress = 1 - iterationProgress; } var left = new ServerKeyFrame <T> { Value = _startingValue }; var right = _keyFrames[_keyFrames.Length - 1]; for (var c = 0; c < _keyFrames.Length; c++) { var kf = _keyFrames[c]; if (kf.Key < iterationProgress) { // this is the last frame if (c == _keyFrames.Length - 1) { return(ExpressionVariant.Create(GetKeyFrame(ref ctx, kf))); } left = kf; right = _keyFrames[c + 1]; break; } } var keyProgress = Math.Max(0, Math.Min(1, (iterationProgress - left.Key) / (right.Key - left.Key))); var easedKeyProgress = (float)right.EasingFunction.Ease(keyProgress); if (float.IsNaN(easedKeyProgress) || float.IsInfinity(easedKeyProgress)) { return(currentValue); } return(ExpressionVariant.Create(_interpolator.Interpolate( GetKeyFrame(ref ctx, left), GetKeyFrame(ref ctx, right), easedKeyProgress ))); }