/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Curve> inCurves = new List <Curve>(); if (!DA.GetDataList(0, inCurves)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, Constants.Constants.INPUT_ERROR_MESSAGE); return; } double tolerance = Constants.Constants.STANDARD_TOLLERANCE; DA.GetData(1, ref tolerance); List <Curve> optimizedCurves = new List <Curve>(); foreach (var crv in inCurves) { SortedList <double, Point3d> separationPts = new SortedList <double, Point3d>(); crv.Domain = new Interval(0.0, 1.0); CurvesOptimizer.DeCasteljauCurvePts(crv, 0.0, 1.0, tolerance, separationPts); optimizedCurves.Add(new PolylineCurve(separationPts.Values)); } DA.SetDataList(0, optimizedCurves); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { InputChecker inputChecker = new InputChecker(this); #region GetDataFromCanvas List <Curve> inCurves = new List <Curve>(); bool canGetCurves = DA.GetDataList <Curve>(0, inCurves); inputChecker.StopIfConversionIsFailed(canGetCurves); List <int> inCurvesDegree = new List <int>(); bool canGetCrvDegrees = DA.GetDataList <int>(1, inCurvesDegree); inputChecker.StopIfConversionIsFailed(canGetCrvDegrees); ValuesAllocator.MatchLists(inCurves, inCurvesDegree); List <double> inRebuildFactors = new List <double>(); bool canGetFactors = DA.GetDataList <double>(2, inRebuildFactors); inputChecker.StopIfConversionIsFailed(canGetFactors); ValuesAllocator.MatchLists(inCurves, inRebuildFactors); List <bool> inPreserveTan = new List <bool>(); bool canGetPreserveTan = DA.GetDataList <bool>(3, inPreserveTan); inputChecker.StopIfConversionIsFailed(canGetPreserveTan); ValuesAllocator.MatchLists(inCurves, inPreserveTan); bool useParallel = false; DA.GetData <bool>(4, ref useParallel); #endregion Curve[] curves = inCurves.ToArray(); int[] curvesDegree = inCurvesDegree.ToArray(); double[] rebuildFactors = inRebuildFactors.ToArray(); bool[] preserveTan = inPreserveTan.ToArray(); ConcurrentDictionary <int, Curve> rebuildedCurves = new ConcurrentDictionary <int, Curve>(); if (!useParallel) { this.Message = Constants.Constants.SERIAL_MESSAGE; for (int i = 0; i < (int)curves.Length; i++) { CurvesOptimizer.RebuildProportionally(i, curves, curvesDegree, rebuildFactors, preserveTan, rebuildedCurves); } } else { this.Message = Constants.Constants.PARALLEL_MESSAGE; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING); int processorCount = Environment.ProcessorCount - 1;; Parallel.For(0, curves.Length, new ParallelOptions { MaxDegreeOfParallelism = processorCount }, i => CurvesOptimizer.RebuildProportionally(i, curves, curvesDegree, rebuildFactors, preserveTan, rebuildedCurves) ); } List <Curve> curves1 = new List <Curve>(); curves1.AddRange(rebuildedCurves.Values); DA.SetDataList(0, curves1); }