protected RhinoList <Rectangle3d> generateNetRects(Vector3d widthHeightDepthVect, out Point3d bottomRightmostPoint, double thickness = 0) { RhinoList <Rectangle3d> rectList = new RhinoList <Rectangle3d>(); double xDist = widthHeightDepthVect.X; double yDist = widthHeightDepthVect.Y; double zDist = widthHeightDepthVect.Z; // Add thickness for fingering gaps Point3d origin1 = ORIGIN + new Vector3d(xDist + thickness, 0, 0); Point3d origin2 = origin1 + new Vector3d(yDist + thickness, 0, 0); Point3d origin3 = origin2 + new Vector3d(xDist + thickness, 0, 0); // Line 4 rectangles X, Y, X, Y; all Z tall Rectangle3d rect0 = MakeRect(ORIGIN, xDist, zDist, margin: BIRCH_CM); Rectangle3d rect1 = MakeRect(origin1, yDist, zDist, margin: BIRCH_CM); Rectangle3d rect2 = MakeRect(origin2, xDist, zDist, margin: BIRCH_CM); Rectangle3d rect3 = MakeRect(origin3, yDist, zDist, margin: BIRCH_CM); rectList.Add(rect0); rectList.Add(rect1); rectList.Add(rect2); rectList.Add(rect3); // Set the bottomRightmost point so caller function can keep drawing // where we leave off bottomRightmostPoint = origin3 + new Vector3d(rect3.Width, 0, 0); return(rectList); }
/// <summary> /// This function selects breps /// </summary> /// /// public static bool XSelectBreps(string message, out RhinoList <Brep> breps) { breps = new RhinoList <Brep>(); int i; var gc = new GetObject(); gc.SetCommandPrompt("Select some Breps"); gc.EnablePreSelect(true, true); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gc.GetMultiple(1, 0); //we do our double check to make sure the user selected something if (gc.CommandResult() != Result.Success) { return(false); } for (i = 0; i < gc.ObjectCount; i++) { var brep = gc.Object(i).Brep(); if (null != brep) { breps.Add(brep); } } return(true); }
public RhinoList <Guid> CommitIntoRhinoDocument() { RhinoList <Guid> newGuids = new RhinoList <Guid>(Objects.Count); foreach (var content in this.Objects.AttributedGeometries) { var geom = content.Geometry; var attr = content.Attributes; if (geom is IGH_BakeAwareData) { Guid guid; (geom as IGH_BakeAwareData).BakeGeometry(RhinoDoc.ActiveDoc, attr, out guid); if (!guid.Equals(Guid.Empty)) { newGuids.Add(guid); } } else { throw new ApplicationException("UnexpectedObjectException. Please report this error to [email protected]"); } } return(newGuids); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType selFilter = Rhino.DocObjects.ObjectType.Point; Rhino.DocObjects.ObjRef[] pointObjRefs; Result getPointsResults = RhinoGet.GetMultipleObjects("Select circuit component endpoints", false, selFilter, out pointObjRefs); if (getPointsResults == Result.Success) { RhinoList <Point> circuitPoints = new RhinoList <Point>(); foreach (Rhino.DocObjects.ObjRef objRef in pointObjRefs) { circuitPoints.Add(objRef.Point()); } RhinoList <Line> conduitLines = autoroute(circuitPoints); foreach (Line conduitLine in conduitLines) { doc.Objects.AddLine(conduitLine); } doc.Views.Redraw(); return(Result.Success); } return(Result.Failure); }
public RhinoList <Guid> AddPoints(IEnumerable <Point3f> points, ObjectAttributes attributes) { RhinoList <Guid> list = new RhinoList <Guid>(InferLengthOrGuess(points)); foreach (var p in points) { var id = AddPoint(p, attributes); if (!id.Equals(Guid.Empty)) { list.Add(id); } } return(list); }
private RhinoList <Line> naiveGreedyRoute(RhinoList <Point> points) { RhinoList <Line> conduitLines = new RhinoList <Line>(); for (int i = 0; i < points.Count; i++) { for (int j = i + 1; j < points.Count; j++) { Point3d fromPoint, toPoint; fromPoint = points[i].Location; toPoint = points[j].Location; conduitLines.Add(new Line(fromPoint, toPoint)); } } return(conduitLines); }
protected RhinoList <Rectangle3d> generatePolyRects(Polyline charCurve, double depth, out Point3d bottomRightmostPoint, double thickness = 0) { RhinoList <double> sectionDistances = new RhinoList <double>(); Line[] sectionSegments = charCurve.GetSegments(); foreach (Line segment in sectionSegments) { sectionDistances.Add(segment.Length); } // Add origin points, accounting for thickness RhinoList <Point3d> origins = new RhinoList <Point3d>(); Point3d currOrigin = ORIGIN; // Loop invariant: CURR_ORIGIN be safely added and incremented foreach (double distance in sectionDistances) { origins.Add(currOrigin); currOrigin += new Vector3d(distance + thickness, 0, 0); } RhinoList <Rectangle3d> rectList = new RhinoList <Rectangle3d>(); Rectangle3d currRect; int i; for (i = 0; i < origins.Count; i++) { currRect = MakeRect(origins[i], sectionDistances[i], depth, margin: thickness); rectList.Add(currRect); } bottomRightmostPoint = origins.Last + new Vector3d(sectionDistances[i - 1], 0, 0); return(rectList); }
/// <summary> /// Splits (divides) the curve at a series of specified parameters. /// The parameter must be in the interior of the curve's domain. /// </summary> /// <param name="t"> /// Parameters to split the curve at in the interval returned by Domain(). /// </param> /// <returns> /// Multiple curves on success, null on failure. /// </returns> public Curve[] Split(IEnumerable<double> t) { Interval domain = Domain; RhinoList<double> parameters = new RhinoList<double>(t); parameters.Add(domain.Min); parameters.Add(domain.Max); parameters.Sort(); RhinoList<Curve> rc = new RhinoList<Curve>(); for (int i = 0; i < parameters.Count - 1; i++) { double start = parameters[i]; double end = parameters[i + 1]; if ((end - start) > RhinoMath.ZeroTolerance) { Curve trimcurve = Trim(start, end); if (trimcurve != null) rc.Add(trimcurve); } } return rc.Count == 0 ? null : rc.ToArray(); }
/// <summary> /// Gets a collection of perpendicular frames along the curve. Perpendicular frames /// are also known as 'Zero-twisting frames' and they minimize rotation from one frame to the next. /// </summary> /// <param name="parameters">A collection of <i>strictly increasing</i> curve parameters to place perpendicular frames on.</param> /// <returns>An array of perpendicular frames on success or null on failure.</returns> /// <exception cref="InvalidOperationException">Thrown when the curve parameters are not increasing.</exception> public Plane[] GetPerpendicularFrames(IEnumerable<double> parameters) { RhinoList<double> ts = new RhinoList<double>(); double t0 = double.MinValue; foreach (double t in parameters) { if (t <= t0) throw new InvalidOperationException("Curve parameters must be strictly increasing"); ts.Add(t); t0 = t; } // looks like we need at least two parameters to have this function make sense if (ts.Count < 2) return null; double[] _parameters = ts.ToArray(); int count = _parameters.Length; Plane[] frames = new Plane[count]; IntPtr pConstCurve = ConstPointer(); int rc_count = UnsafeNativeMethods.RHC_RhinoGet1RailFrames(pConstCurve, count, _parameters, frames); if (rc_count == count) return frames; if (rc_count > 0) { Plane[] rc = new Plane[rc_count]; Array.Copy(frames, rc, rc_count); return rc; } return null; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { int i, j; var gc = new GetObject(); gc.SetCommandPrompt("Select some Breps"); gc.EnablePreSelect(true, true); gc.GeometryFilter = ObjectType.Brep; gc.GetMultiple(1, 0); if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } RhinoList <Brep> breps = new RhinoList <Brep>(); for (i = 0; i < gc.ObjectCount; i++) { var brep = gc.Object(i).Brep(); if (null != brep) { breps.Add(brep); } var format = string.Format("F{0}", doc.DistanceDisplayPrecision); var brepinfo = string.Format("Brep {0} has {1} face(s) and total surface of {2} square {3}", i.ToString(), brep.Faces.Count, brep.GetArea().ToString(format), doc.ModelUnitSystem.ToString() ); for (j = 0; j < brep.Faces.Count; j++) { AreaMassProperties brepfacemass = AreaMassProperties.Compute(brep.Faces[j]); double brepfaceearea = brepfacemass.Area; var brepfaceinfo = string.Format("Brepface {0} belongs to brep {1} and has a surface of {2} square {3}", j.ToString(), i.ToString(), brepfaceearea.ToString(format), doc.ModelUnitSystem.ToString() ); var brepfacedomain = string.Format(" and its Domain is U:{0} to {1} and V: {2} to {3}", brep.Faces[j].Domain(0).T0.ToString(format), brep.Faces[j].Domain(0).T1.ToString(format), // Domain(0) means U, start at T0, end at T1 brep.Faces[j].Domain(1).T0.ToString(format), brep.Faces[j].Domain(1).T1.ToString(format) // Domain(1) means V ); RhinoApp.WriteLine(brepfaceinfo + brepfacedomain); } RhinoApp.WriteLine(brepinfo); } //if the breps are not joined, they will be joined with the function below. Brep[] joinedbreps = Brep.JoinBreps(breps, doc.ModelAbsoluteTolerance); for (i = 0; i < joinedbreps.Length; i++) // we use the .Length instead of .Count because we have a <Standard> array from Rhino. { doc.Objects.AddBrep(joinedbreps[i]); } doc.Views.Redraw(); RhinoApp.WriteLine("The user selected {0} brep(s) successfully, and they have been joined.", breps.Count.ToString()); return(Result.Success); }