private int SvToArrayIndex(double sv, Range1d svRange, int numOfSvLinesInArray) { var idNorm = ((sv - svRange.Min) / svRange.Size); if (idNorm > 1) { Report.Warn("ProfileLookUpTable: Lookup intended to read out of patch size."); return(-1); } return((int)System.Math.Round(idNorm * (numOfSvLinesInArray - 1))); }
public static void GaussTest() { // sample normal distribution function from -10 to 10 var range = new Range1d(-10, 10); var sampleCount = 201; // uneven values with give symmetrical pdf var pdf = new double[sampleCount].SetByIndex(i => { var x = i / (sampleCount - 1.0); var p = range.Lerp(x); return(Fun.Gauss(p, 1.0)); }); // integrate sampled gauss distribution var stepSize = range.Size / (sampleCount - 1.0); var integral = pdf.Sum() * stepSize; // Gauss must integrate to 1.0 Assert.True(integral.ApproximateEquals(1.0, 1e-10)); }
//from point2d list get the range2d internal static Range2d FromPoint2dGetRange2D(List <Point2d> point2dList) { List <double> xCordList = new List <double>(); List <double> yCordList = new List <double>(); double xMax = 0, xMin = 0, yMax = 0, yMin = 0; for (int i = 0; i < point2dList.Count; i++) { xCordList.Add(point2dList[i].X); yCordList.Add(point2dList[i].Y); } xMax = xCordList.Max(); yMax = yCordList.Max(); xMin = xCordList.Min(); yMin = yCordList.Min(); Range1d x = new Range1d(xMin, xMax); Range1d y = new Range1d(yMin, yMax); Range2d xyRange = new Range2d(x, y); return(xyRange); }
public void RootsTest3(double step) { Test.Begin("cubic roots tests"); var range = new Range1d(-1.0, 1.0); double half = 0.5 * step; double epsilon = Fun.Cbrt(Constant <double> .PositiveTinyValue); Report.Value("epsilon", epsilon); var stats = Stats <bool> .ComputeMaxMean; var uniqueStats = Stats <bool> .ComputeMaxMean; var multipleStats = Stats <bool> .ComputeMaxMean; var residualStats = Stats <bool> .ComputeMaxMean; var uniqueHisto = new Histogram(-16, -8, 8); var multipleHisto = new Histogram(-16, 0, 16); var uniqueResidualStats = Stats <bool> .ComputeMaxMean; var multipleResidualStats = Stats <bool> .ComputeMaxMean; long multipleCount = 0; for (double x0 = range.Min; x0 < range.Max + half; x0 += step) { var p0 = new double[] { -x0, 1.0 }; for (double x1 = range.Min; x1 < range.Max + half; x1 += step) { var p1 = new double[] { -x1, 1.0 }; var p01 = Polynomial.Multiply(p0, p1); for (double x2 = range.Min; x2 < range.Max + half; x2 += step) { var p2 = new double[] { -x2, 1.0 }; var p012 = Polynomial.Multiply(p01, p2); var t = Triple.CreateAscending(x0, x1, x2); var exact = new double[] { t.E0, t.E1, t.E2 }; var roots = p012.RealRoots(); var multiple = CountDoubles(exact, 0.0001); if (multiple > 0) { ++multipleCount; } var rootCountsOk = exact.Length == roots.Length; Test.IsTrue(rootCountsOk, "wrong number of roots found"); if (!rootCountsOk) { using (Report.Job("problematic roots:")) { Report.Line("exact: [" + exact.Select(x => x.ToString()).Join(",") + "]"); Report.Line("roots: [" + roots.Select(x => x.ToString()).Join(",") + "]"); } continue; } for (int i = 0; i < 3; i++) { var err = (exact[i] - roots[i]).Abs(); Test.IsTrue(err < epsilon, "root differs significantly from exact value {0}", err); double res = p012.Evaluate(roots[i]).Abs(); stats.Add(err); residualStats.Add(res); if (multiple == 0) { uniqueStats.Add(err); uniqueHisto.AddLog10(err); uniqueResidualStats.Add(res); } else { multipleStats.Add(err); multipleHisto.AddLog10(err); multipleResidualStats.Add(res); } } } } } Report.Value("roots error", stats); Report.Value("unique roots error", uniqueStats); Report.Value("unique roots log error histogram", uniqueHisto); Report.Value("multiple roots error", multipleStats); Report.Value("multiple roots log error histogram", multipleHisto); Report.Value("residual error", residualStats); Report.Value("unique roots residual error", uniqueResidualStats); Report.Value("multiple residual error", multipleResidualStats); Test.End(); }
public DepthTestMode(DepthTestComparison comparison) { Comparison = comparison; Bounds = Range1d.Infinite; }
public DepthTestMode(DepthTestMode other, Range1d range) { Comparison = other.Comparison; Bounds = range; }
public DepthTestMode(DepthTestComparison comparison, Range1d range) { Comparison = comparison; Bounds = range; }
public void Write(Range1d x) { Write(x.Min); Write(x.Max); }
/// <summary> /// Loads XYZ and SvBR profile from file at SV position. /// Multiple reloads of SvBR data might be possible to adjust off indexing based on malformed data. /// </summary> /// <param name="handle">File handles for XYZ and SvBR data.</param> /// <param name="sv">Sv position to load data at.</param> /// <param name="svRange">SvRange of patch (needed to calculate index).</param> /// <returns>XYZ/SvBR profile</returns> private Pair <IEnumerable <V3d> > LookUpProfile(Pair <PatchFileHandle> handle, double sv, Range1d svRange) { // sv to array index var index = handle.E0.PatchTree.Info.QuadVertexSortOrder == PatchFileInfo.QuadVertexSortOrderType.RowMajor ? SvToArrayIndex(sv, svRange, handle.E0.FileLoader.NumOfRows) : SvToArrayIndex(sv, svRange, handle.E0.FileLoader.NumOfColumns); // Load SvBR data. If indexing was not exact keep reloading neighboring profiles var pntsSvbr = new V3d[0]; var localSv = sv - handle.E1.PatchTree.Info.Local2Global2d.M03; int increment = 0; do { // Load data pntsSvbr = LookUpProfile(handle.E1, index); // For some reason we couldn't load any more data..... if (pntsSvbr == null || pntsSvbr.IsEmpty()) { break; } // NaN line, try next one if (pntsSvbr.Where(p => !p.IsNaN).IsEmptyOrNull()) { if (increment == 0) { break; } else { index += increment; continue; } } var avgSv = pntsSvbr.Where(p => !p.IsNaN).Average(p => p.X); // Profile close enough? if (avgSv.ApproximateEquals(localSv, AvgGeomtrySize / 2)) { break; } else { // nope, indexing must be off, try next one if (increment == 0) { increment = (avgSv < localSv) ? 1 : -1; } // if increment flips, than me might have a bigger hole between lines than AvgGeoSize else if (increment != ((avgSv < localSv) ? 1 : -1)) { break; } index += increment; } } while (!pntsSvbr.IsEmptyOrNull()); // Load XYZ data var pntsXyz = LookUpProfile(handle.E0, index); return(Pair.Create( pntsXyz.Select(pt => handle.E0.PatchTree.Info.Local2Global.TransformPos(pt)), pntsSvbr.Select(pt => handle.E0.PatchTree.Info.Local2Global2d.TransformPos(pt)) )); }