/// <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 <Point3d> inPoints = new List <Point3d>(); if (!DA.GetDataList <Point3d>(0, inPoints)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, Constants.Constants.INPUT_ERROR_MESSAGE); } else { List <double> inMasses = new List <double>(); DA.GetDataList <double>(1, inMasses); ValuesAllocator.MatchLists(inPoints, inMasses); Point3d point3D = new Point3d(0, 0, 0); List <double> distances = new List <double>(); double totalMass = 0; for (int i = 0; i < inPoints.Count; i++) { point3D = point3D + (inPoints[i] * inMasses[i]); totalMass += inMasses[i]; } Point3d center = point3D / totalMass; GH_Point ghCenter = new GH_Point(center); foreach (Point3d pt in inPoints) { distances.Add(ghCenter.Value.DistanceTo(pt)); } DA.SetData(0, ghCenter); DA.SetDataList(1, distances); } }
/// <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); List <Curve> inCurves = new List <Curve>(); bool canGetCrvs = DA.GetDataList <Curve>("Curves", inCurves); inputChecker.StopIfConversionIsFailed(canGetCrvs); List <Plane> inPlanes = new List <Plane>(); bool canGetPlanes = DA.GetDataList <Plane>("Planes", inPlanes); inputChecker.StopIfConversionIsFailed(canGetPlanes); ValuesAllocator.MatchLists(inCurves, inPlanes); List <Curve> orientedCurves = new List <Curve>(); for (int i = 0; i < inCurves.Count; i++) { if (inCurves[i].ClosedCurveOrientation(inPlanes[i]) == CurveOrientation.Clockwise) { inCurves[i].Reverse(); } orientedCurves.Add(inCurves[i]); } DA.SetDataList(0, orientedCurves); }
/// <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); }
/// <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); List <Curve> inCurves = new List <Curve>(); List <double> inThres = new List <double>(); bool succes = DA.GetDataList <Curve>(0, inCurves) && DA.GetDataList <double>(1, inThres); inputChecker.StopIfConversionIsFailed(succes); ValuesAllocator.MatchLists(inCurves, inThres); List <Curve> culledCrvs = CurveProcessor.CullShortCrv(inCurves, inThres); #region SendOutputsToCanvas DA.SetDataList(0, culledCrvs); #endregion }
/// <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 get Input From GH Canvas GH_Structure <GH_Curve> inCurves = new GH_Structure <GH_Curve>(); bool areCurvesOK = DA.GetDataTree(0, out inCurves); inputChecker.StopIfConversionIsFailed(areCurvesOK); GH_Structure <GH_Curve> ghCurves = new GH_Structure <GH_Curve>(); ghCurves = inCurves.Duplicate(); ghCurves.Graft(GH_GraftMode.GraftAll); ghCurves.Simplify(GH_SimplificationMode.CollapseAllOverlaps); GH_Structure <GH_Number> inDistances = new GH_Structure <GH_Number>(); bool areDistancesOk = DA.GetDataTree(1, out inDistances); inputChecker.StopIfConversionIsFailed(areDistancesOk); GH_Structure <GH_Number> ghDistances = new GH_Structure <GH_Number>(); ghDistances = ValuesAllocator.NumsDSFromCurves(ghCurves, inDistances, ghDistances); GH_Structure <GH_Plane> inPlanes = new GH_Structure <GH_Plane>(); bool arePlanesOk = DA.GetDataTree(2, out inPlanes); inputChecker.StopIfConversionIsFailed(arePlanesOk); GH_Structure <GH_Plane> ghPlanes = new GH_Structure <GH_Plane>(); ghPlanes = ValuesAllocator.PlanesDSFromCurves(ghCurves, inPlanes, ghPlanes); GH_Structure <GH_Integer> inCorners = new GH_Structure <GH_Integer>(); bool areCornerssOk = DA.GetDataTree(3, out inCorners); inputChecker.StopIfConversionIsFailed(areCornerssOk); GH_Structure <GH_Integer> ghCorners = new GH_Structure <GH_Integer>(); ghCorners = ValuesAllocator.IntegerDSFromCurves(ghCurves, inCorners, ghCorners); #endregion GH_Structure <GH_Curve> ghCurveOffset = new GH_Structure <GH_Curve>(); double docTollerance = DocumentTolerance(); int pathIndex = 0; foreach (GH_Path ghPath in ghCurves.Paths) { for (int i = 0; i < ghCurves.get_Branch(ghPath).Count; i++) { CurveOffsetCornerStyle cornerStyle = CurveOffsetCornerStyle.None; int cornerStyleInInt = ghCorners.get_DataItem(ghPath, i).Value; GetCornerStyleFromInt(ref cornerStyleInInt, ref cornerStyle); Curve crv = ghCurves.get_DataItem(ghPath, i).Value; Plane plane = ghPlanes.get_DataItem(ghPath, i).Value; double dist = ghDistances.get_DataItem(ghPath, i).Value; List <Curve> resultingCurves = new List <Curve>(); resultingCurves.AddRange(crv.Offset(plane, dist, docTollerance, cornerStyle)); resultingCurves.AddRange(crv.Offset(plane, dist *= -1, docTollerance, cornerStyle)); foreach (Curve resultingCrv in resultingCurves) { GH_Curve ghResultingCrv = null; if (GH_Convert.ToGHCurve(resultingCrv, GH_Conversion.Both, ref ghResultingCrv)) { ghCurveOffset.Append(ghResultingCrv, ghPath); } } } pathIndex++; } DA.SetDataTree(0, ghCurveOffset); }
/// <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 GetInputsFromCanvas List <Point3d> inPts = new List <Point3d>(); bool canGetPts = DA.GetDataList(0, inPts); inputChecker.StopIfConversionIsFailed(canGetPts); List <Plane> inPlanes = new List <Plane>(); bool canGetPlns = DA.GetDataList(1, inPlanes); inputChecker.StopIfConversionIsFailed(canGetPlns); ValuesAllocator.MatchLists(inPts, inPlanes); List <double> inRange = new List <double>(); bool canGetRange = DA.GetDataList(2, inRange); inputChecker.StopIfConversionIsFailed(canGetRange); ValuesAllocator.MatchLists(inPts, inRange); List <int> inDensity = new List <int>(); bool canGetDensity = DA.GetDataList(3, inDensity); inputChecker.StopIfConversionIsFailed(canGetDensity); ValuesAllocator.MatchLists(inPts, inDensity); Color inFirstColor = new Color(); bool canGetFirstCol = DA.GetData(4, ref inFirstColor); inputChecker.StopIfConversionIsFailed(canGetFirstCol); Color inSecondColor = new Color(); bool canGetSecondColor = DA.GetData(5, ref inSecondColor); inputChecker.StopIfConversionIsFailed(canGetSecondColor); #endregion List <Circle> crvsOut = new List <Circle>(); List <Color> crvsColor = new List <Color>(); for (int i = 0; i < inPts.Count; i++) { Plane refPlane = inPlanes[i]; double maxRad = inRange[i]; int density = inDensity[i] > 0 ? inDensity[i] : 1; double distance = maxRad / density; double counter = distance; while (counter < maxRad) { crvsOut.Add(new Circle(refPlane, inPts[i], counter)); Color color = ColorRemapper.RemappedColor(ref inFirstColor, ref inSecondColor, maxRad, distance, counter); crvsColor.Add(color); counter += distance; } } #region SendOutputsToCanvas DA.SetDataList(0, crvsOut); DA.SetDataList(1, crvsColor); #endregion }
/// <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 GetInpuFromCanvas Surface inBaseSrf = null; bool canGetSurface = DA.GetData(0, ref inBaseSrf); inputChecker.StopIfConversionIsFailed(canGetSurface); inBaseSrf.SetDomain(0, new Interval(0.0, 1.0)); inBaseSrf.SetDomain(1, new Interval(0.0, 1.0)); List <double> inData = new List <double>(); bool canGetData = DA.GetDataList(1, inData); inputChecker.StopIfConversionIsFailed(canGetData); List <Point3d> inBasePts = new List <Point3d>(); bool canConvertPts = DA.GetDataList(2, inBasePts); inputChecker.StopIfConversionIsFailed(canConvertPts); ValuesAllocator.MatchLists(inData, inBasePts); Color inFirstColor = new Color(); if (!DA.GetData(3, ref inFirstColor)) { return; } Color inSecondColor = new Color(); if (!DA.GetData(4, ref inSecondColor)) { return; } #endregion int lastValueIndex = inData.Count - 1; List <double> sortedData = new List <double>(inData); sortedData.Sort(); double refStartDomain = sortedData[0]; double refEndDomain = sortedData[lastValueIndex]; List <Line> histogramLines = new List <Line>(); List <Color> histogramColors = new List <Color>(); for (int i = 0; i < inData.Count; i++) { Point3d inPt = inBasePts[i]; double uDir = 0.0; double vDir = 0.0; if (!inBaseSrf.ClosestPoint(inPt, out uDir, out vDir)) { return; } Plane basePlane = new Plane(); if (!inBaseSrf.FrameAt(uDir, vDir, out basePlane)) { return; } double dataVal = inData[i]; Line line = new Line(basePlane.Origin, basePlane.ZAxis, dataVal); histogramLines.Add(line); Color color = ColorRemapper.RemappedColor(ref inFirstColor, ref inSecondColor, refEndDomain, refStartDomain, dataVal); histogramColors.Add(color); } #region SetOutput DA.SetDataList(0, histogramLines); DA.SetDataList(1, histogramColors); #endregion }
/// <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 AssignInput Curve inCrv = null; bool canGetCrv = DA.GetData(0, ref inCrv); inputChecker.StopIfConversionIsFailed(canGetCrv); inCrv.Domain = new Interval(0, 1); List <double> inData = new List <double>(); bool canGetData = DA.GetDataList(1, inData); inputChecker.StopIfConversionIsFailed(canGetData); List <double> inDataOptional = new List <double>(); bool canGetDataOptional = DA.GetDataList(2, inDataOptional); inputChecker.StopIfConversionIsFailed(canGetDataOptional); if (inDataOptional.Count == 0) { EqualCurveSubD(inData, inDataOptional); } ValuesAllocator.MatchLists(inData, inDataOptional); Color inFirstColor = new Color(); if (!DA.GetData(3, ref inFirstColor)) { return; } Color inSecondColor = new Color(); if (!DA.GetData(4, ref inSecondColor)) { return; } List <double> inRotationAngles = new List <double>(); DA.GetDataList(5, inRotationAngles); ValuesAllocator.MatchLists(inData, inRotationAngles); #endregion int lastValueIndex = inData.Count - 1; List <double> sortedData = new List <double>(inData); sortedData.Sort(); double refStartDomain = sortedData[0]; double refEndDomain = sortedData[lastValueIndex]; List <Line> histogramLines = new List <Line>(); List <Color> histogramColors = new List <Color>(); for (int i = 0; i < inData.Count; i++) { Plane pFrame; double tValue = inDataOptional[i]; inCrv.PerpendicularFrameAt(tValue, out pFrame); double angle_rad = inRotationAngles[i]; if (_useDegrees) { angle_rad = RhinoMath.ToRadians(angle_rad); } pFrame.Rotate(angle_rad, pFrame.ZAxis); double dataVal = inData[i]; Line line = new Line(pFrame.Origin, pFrame.YAxis, dataVal); histogramLines.Add(line); Color color = ColorRemapper.RemappedColor(ref inFirstColor, ref inSecondColor, refEndDomain, refStartDomain, dataVal); histogramColors.Add(color); } #region SetOutput DA.SetDataList(0, histogramLines); DA.SetDataList(1, histogramColors); #endregion }
/// <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(0, inCurves); inputChecker.StopIfConversionIsFailed(canGetCurves); List <int> inClosingTypes = new List <int>(); bool canGetClosingType = DA.GetDataList(1, inClosingTypes); inputChecker.StopIfConversionIsFailed(canGetClosingType); ValuesAllocator.MatchLists(inCurves, inClosingTypes); List <double> inTollerances = new List <double>(); bool canGetTollerances = DA.GetDataList(2, inTollerances); inputChecker.StopIfConversionIsFailed(canGetTollerances); ValuesAllocator.MatchLists(inCurves, inTollerances); #endregion List <Point3d> endPoints = new List <Point3d>(); List <Curve> closedCurves = new List <Curve>(); List <bool> closingResults = new List <bool>(); for (int i = 0; i < inCurves.Count; i++) { Curve crv = inCurves[i]; if (crv.IsClosed) { closedCurves.Add(crv); closingResults.Add(true); } else { if (inClosingTypes[i] <= 0) { CurveProcessor.CloseCrvAddingLine(inTollerances, endPoints, closedCurves, closingResults, i, crv); } else if (inClosingTypes[i] >= 1) { bool success = crv.MakeClosed(inTollerances[i]); if (!success) { List <Point3d> endPts = CurveProcessor.GetEndPtsFromOpenCurve(crv); endPoints.AddRange(endPts); closedCurves.Add(null); } else { closedCurves.Add(crv); } closingResults.Add(success); } //TODO: Add blend option for the future } } DA.SetDataList(0, endPoints); DA.SetDataList(1, closedCurves); DA.SetDataList(2, closingResults); }
/// <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 GetIputFromCanvas GH_Structure <GH_Brep> inGhBreps = new GH_Structure <GH_Brep>(); bool areBrepsOk = DA.GetDataTree(0, out inGhBreps); inputChecker.StopIfConversionIsFailed(areBrepsOk); inGhBreps.Graft(GH_GraftMode.GraftAll); inGhBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps); GH_Structure <GH_Number> inGhDistances = new GH_Structure <GH_Number>(); bool areDistancesOk = DA.GetDataTree(1, out inGhDistances); inputChecker.StopIfConversionIsFailed(areDistancesOk); GH_Structure <GH_Number> ghDistances = new GH_Structure <GH_Number>(); ghDistances = ValuesAllocator.NumbersDSFromBreps(inGhBreps, inGhDistances, ghDistances); GH_Structure <GH_Boolean> inGhBothSides = new GH_Structure <GH_Boolean>(); bool areBoolBothSidesOk = DA.GetDataTree(2, out inGhBothSides); inputChecker.StopIfConversionIsFailed(areBoolBothSidesOk); GH_Structure <GH_Boolean> ghBothSides = new GH_Structure <GH_Boolean>(); ghBothSides = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhBothSides, ghBothSides); GH_Structure <GH_Boolean> inGhFlipNormals = new GH_Structure <GH_Boolean>(); bool areBoolFlipNormalsOk = DA.GetDataTree(3, out inGhFlipNormals); inputChecker.StopIfConversionIsFailed(areBoolFlipNormalsOk); GH_Structure <GH_Boolean> ghFlipNormals = new GH_Structure <GH_Boolean>(); ghFlipNormals = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhFlipNormals, ghFlipNormals); bool useParallel = false; DA.GetData <bool>(4, ref useParallel); double docTollerance = DocumentTolerance(); #endregion GH_Structure <GH_Brep> ghSolidBreps = new GH_Structure <GH_Brep>(); if (useParallel) { this.Message = Constants.Constants.PARALLEL_MESSAGE; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING); int processorCount = Environment.ProcessorCount - 1; //WORK IN PARALLEL ConcurrentDictionary <GH_Path, Brep> solidBrepsPA = new ConcurrentDictionary <GH_Path, Brep>(); Parallel.ForEach(inGhBreps.Paths, new ParallelOptions { MaxDegreeOfParallelism = processorCount }, path => { Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value; bool flipTheNormal = ghFlipNormals.get_DataItem(path, 0).Value; bool bothSide = ghBothSides.get_DataItem(path, 0).Value; double distance = ghDistances.get_DataItem(path, 0).Value; if (flipTheNormal) { distance *= -1; } foreach (var brepFace in brepToSolidify.Faces) { solidBrepsPA[path] = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true); } }); foreach (KeyValuePair <GH_Path, Brep> keyValueBrep in solidBrepsPA) { GH_Brep ghBrep = null; if (GH_Convert.ToGHBrep(keyValueBrep.Value, GH_Conversion.Both, ref ghBrep)) { ghSolidBreps.Append(ghBrep, keyValueBrep.Key); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Conversion Failed"); return; } } }//End Parallel Computation else { this.Message = Constants.Constants.SERIAL_MESSAGE; foreach (GH_Path path in inGhBreps.Paths) { Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value; bool flipTheNormal = ghFlipNormals.get_DataItem(path, 0).Value; bool bothSide = ghBothSides.get_DataItem(path, 0).Value; double distance = ghDistances.get_DataItem(path, 0).Value; if (flipTheNormal) { distance *= -1; } foreach (var brepFace in brepToSolidify.Faces) { Brep solidBrep = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true); GH_Brep ghBrep = null; if (GH_Convert.ToGHBrep(solidBrep, GH_Conversion.Both, ref ghBrep)) { ghSolidBreps.Append(ghBrep, path); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Conversion Failed"); return; } } } }//End Serial Computation #region SendDataToCanvas ghSolidBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps); DA.SetDataTree(0, ghSolidBreps); #endregion }//end SolveInstance