public static Curve BrepNakedEdge(List <Brep> breps) { Brep brep = Brep.JoinBreps(breps, 1)[0]; brep.JoinNakedEdges(1); var crv = Curve.JoinCurves(brep.DuplicateNakedEdgeCurves(true, false), 1)[0]; return(crv); }
public Brep GetExtrusion(Brep brep, Vector3d vector, double tolerance) { // Curve curve = Curve.JoinCurves(planar.Curves3D, tolerance)[0]; List <Brep> extrudes = new List <Brep>(); Curve[] nakedEdge = brep.DuplicateNakedEdgeCurves(true, false); foreach (Curve c in nakedEdge) { Brep b = Surface.CreateExtrusion(c, vector).ToBrep(); extrudes.Add(b); } return(Brep.JoinBreps(extrudes, tolerance)[0]); }
/// <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) { Brep B = new Brep(); double D = 0; double K = 0; if (!DA.GetData(0, ref B)) { return; } if (!DA.GetData(1, ref D)) { return; } if (!DA.GetData(2, ref K)) { return; } Curve[] C = B.DuplicateNakedEdgeCurves(true, true); C = Curve.JoinCurves(C); wShapeCollection Shapes = new wShapeCollection(); foreach (Curve Crv in C) { Shapes.Shapes.Add(new wShape(new RhCrvToWindCrv().ToPiecewiseBezier(Crv, D, K))); } BoundingBox X = B.GetBoundingBox(true); wPoint O = new wPoint(X.Center.X, X.Center.Y, X.Center.Z); wPlane Pln = new wPlane().XYPlane(); Pln.Origin = O; Shapes.Boundary = new wRectangle(Pln, X.Diagonal.X, X.Diagonal.Y); Shapes.Type = "PolyCurveGroup"; Shapes.Graphics = new wGraphic().BlackFill(); wObject WindObject = new wObject(Shapes, "Hoopoe", Shapes.Type); DA.SetData(0, WindObject); }
/// <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) { Brep brep = null; if (!DA.GetData(0, ref brep)) { return; } Curve[] edges = brep.DuplicateNakedEdgeCurves(true, true); Curve[] curves = Curve.JoinCurves(edges); Shape shape = new Shape(curves.ToList()); Graphic graphic = Graphics.FillBlack; if (DA.GetData(1, ref graphic)) { shape.Graphic = new Graphic(graphic); } ; DA.SetData(0, shape); }
public bool subdivideBlocks(urbanModel model, int minPlotDepth, int maxPlotWidth) { //check dimensions, find shorter dim, validate if it needs to be subdivided, (if minPLotDepth can be achieved, depth > minPlotDepth * 2) //if so subdivide halfway, then into smaller plots based on maxPlot width foreach (block itBlock in model.blocks) { Brep itSrf = itBlock.blockSrf; // to get itBlock surface as Brep (use class or object outside this class urbSim, by accessing from and assigning to fields / properties / attributes) itBlock.plots = new List <plot>(); //so this is where plots are linked to block; plots assigned to block object, not to model object Curve[] blockBorderCrvs = itSrf.DuplicateNakedEdgeCurves(true, false); //border curves of each itBlock List <Curve> splitLines = new List <Curve>(); itSrf.Faces[0].SetDomain(0, new Interval(0, 1)); //reparameterise surface U and V, so domains 0 - 1 itSrf.Faces[0].SetDomain(1, new Interval(0, 1)); Point3d pt1 = itSrf.Faces[0].PointAt(0, 0); Point3d pt2 = itSrf.Faces[0].PointAt(0, 1); Point3d pt3 = itSrf.Faces[0].PointAt(1, 1); Point3d pt4 = itSrf.Faces[0].PointAt(1, 0); double length = pt1.DistanceTo(pt2); double width = pt1.DistanceTo(pt4); Point3d sdPt1 = new Point3d(); Point3d sdPt2 = new Point3d(); if (length > width) { if (width > (minPlotDepth * 2)) //suitable for subdivision { //create a subdividing line sdPt1 = itSrf.Faces[0].PointAt(0.5, 0); // sdPt2 = itSrf.Faces[0].PointAt(0.5, 1); } } else //if width is wider { if (length > (minPlotDepth * 2)) { sdPt1 = itSrf.Faces[0].PointAt(0, 0.5); sdPt2 = itSrf.Faces[0].PointAt(1, 0.5); } } Line subDLine = new Line(sdPt1, sdPt2); Curve subDCrv = subDLine.ToNurbsCurve(); splitLines.Add(subDCrv); double crvLength = subDCrv.GetLength(); double noPlots = Math.Floor(crvLength / maxPlotWidth); for (int t = 0; t < noPlots; t++) { double tVal = t * 1 / noPlots; //t is 0, 0.2, 0.4 ... 1 Plane perpFrm; Point3d evalPt = subDCrv.PointAtNormalizedLength(tVal); subDCrv.PerpendicularFrameAt(tVal, out perpFrm); //inpCrv.PerpendicularFrameAt(t, out perpFrm) 'out perpFrm' assigns to the variable perpFrm Point3d ptPer2Up = Point3d.Add(evalPt, perpFrm.XAxis); Point3d ptPer2Down = Point3d.Add(evalPt, -perpFrm.XAxis); //Draw a line perpendicular Line ln1 = new Line(evalPt, ptPer2Up); Line ln2 = new Line(evalPt, ptPer2Down); Curve lnExt1 = ln1.ToNurbsCurve().ExtendByLine(CurveEnd.End, blockBorderCrvs); //lnExt extended to all border curves in inObst (4 boundaries plus new lnExt) Curve lnExt2 = ln2.ToNurbsCurve().ExtendByLine(CurveEnd.End, blockBorderCrvs); splitLines.Add(lnExt1); splitLines.Add(lnExt2); } Brep plotPolySurface = itSrf.Faces[0].Split(splitLines, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); //split face using 3D trimming curves foreach (BrepFace itBF in plotPolySurface.Faces) { Brep itPlot = itBF.DuplicateFace(false); // a collection of Brep faces itPlot.Faces.ShrinkFaces(); itBlock.plots.Add(new plot(itPlot, itBlock.type)); //plots assigned to block object as list of Breps // this syntax, for assigning to a list outside of this class and into urbSim.block.plots //itBlock.type takes integer value from 'block' object and assigns same value to 'plot' object //RhinoDoc.ActiveDoc.Objects.AddBrep(itPlot); } } return(true); }
public override Curve ToNurbsCurve() { return(Surface.DuplicateNakedEdgeCurves(true, false)[0]); }
/// <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) { double span = 0; List <VariableSection> vSect = new List <VariableSection>(); if (!DA.GetData(0, ref span)) { return; } if (!DA.GetDataList(1, vSect)) { return; } int N = vSect.Count; if (N < 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "VSect needs at least 2 inputs"); return; } Transform mirrorYZ = Transform.Mirror(Plane.WorldYZ); Transform mirrorXZ = Transform.Mirror(Plane.WorldZX); Point3d spPtA = new Point3d(-span * 0.5, 0, 0); Curve spCrv = new Line(spPtA, Plane.WorldXY.XAxis, span).ToNurbsCurve(); Curve spCrvHlf = new Line(spPtA, Plane.WorldXY.XAxis, span * 0.5).ToNurbsCurve(); //if (N < 2) { N = 3; } double[] spCrvDiv = spCrv.DivideByCount(N - 1, true); Plane[] spCrvPln = spCrv.GetPerpendicularFrames(spCrvDiv); for (int i = 0; i < spCrvPln.Length; i++) //reorient planes to align with z-axis { Plane pl = spCrvPln[i]; pl.Rotate(-Math.PI * 0.5, Plane.WorldXY.XAxis); spCrvPln[i] = pl; } List <Point3d> allPts = new List <Point3d>(); List <Curve> crvs = new List <Curve>(); int ptCnt = vSect[0].sctPts.Count; Point3d[,] crvPts = new Point3d[ptCnt, vSect.Count]; //for(int i = 0; i < vSect.Count; i++) { Point3d[] crvPt = new Point3d[vSect.Count]; } for (int i = 0; i < vSect.Count; i++) //moves and reorients points from input i indicates number section, j number curve/point in section { List <Point3d> sctPts = vSect[i].sctPts; Plane sctPln = vSect[i].sctPln; if (sctPts.Count != ptCnt) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Each section needs the same number of points"); return; } Transform reorient = Transform.PlaneToPlane(sctPln, spCrvPln[i]); //foreach (Point3d pt in sctPts) { pt.Transform(reorient); allPts.Add(pt); } //remove when workaround is figured out for (int j = 0; j < sctPts.Count; j++) //separate points to each "row" in a list of arrays { Point3d pt = sctPts[j]; pt.Transform(reorient); crvPts[j, i] = pt; } } int degree = 3; for (int i = 0; i < crvPts.GetLength(0); i++) //creates curves through points { Point3d[] aCrvPts = new Point3d[vSect.Count]; for (int j = 0; j < crvPts.GetLength(1); j++) { aCrvPts[j] = crvPts[i, j]; } Curve crv = Curve.CreateInterpolatedCurve(aCrvPts, degree); crvs.Add(crv); } List <Brep> faces = new List <Brep>(); Brep[] loftFace = Brep.CreateFromLoft(crvs, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); //Brep face1 = new Brep(); //foreach(Brep face in loftFace) { face1 = face.DuplicateBrep(); } Brep face1 = loftFace[0].DuplicateBrep(); Brep face2 = face1.DuplicateBrep(); face2.Transform(mirrorXZ); faces.Add(face1); faces.Add(face2); Curve[] naked1 = face1.DuplicateNakedEdgeCurves(true, false); Curve[] naked2 = face2.DuplicateNakedEdgeCurves(true, false); Curve[] loftCrv1 = new Curve[] { naked1[1], naked2[1] }; Curve[] loftCrv2 = new Curve[] { naked1[3], naked2[3] }; Brep[] face3 = Brep.CreateFromLoft(loftCrv1, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); Brep[] face4 = Brep.CreateFromLoft(loftCrv2, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); faces.Add(face3[0]); faces.Add(face4[0]); Brep[] beamBreps = Brep.JoinBreps(faces, DocumentTolerance()); Brep beam = beamBreps[0].CapPlanarHoles(DocumentTolerance()); int intersects = 0; int a = crvs.Count; for (int i = 0; i < (a - 1); i++) { for (int j = (i + 1); j < a; j++) { Rhino.Geometry.Intersect.CurveIntersections crvCheck = Rhino.Geometry.Intersect.Intersection.CurveCurve( crvs[i], crvs[j], DocumentTolerance(), 0.0); intersects += crvCheck.Count; } } if (intersects > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Beam volume is invalid."); return; } DA.SetDataList(0, spCrvPln); DA.SetDataList(1, crvPts); DA.SetDataList(2, crvs); DA.SetData(3, beam); DA.SetData(4, spCrv); }
public bool subdivideBlocks(UrbanModel model, int minPlotDepth, int maxPlotWidth) { foreach (block itBlock in model.blocks) { Brep itSrf = itBlock.blockSrf; itBlock.plot = new List <plot>(); Curve[] borderCrvs = itSrf.DuplicateNakedEdgeCurves(true, false); List <Curve> splitLines = new List <Curve>(); itSrf.Faces[0].SetDomain(0, new Interval(0, 1)); iitSrf.Faces[0].SetDomain(1, new Interval(0, 1)); Point3d pt1 = itSrf.Faces[0].PointAt(0, 0); Point3d pt2 = itSrf.Faces[0].PointAt(0, 1); Point3d pt3 = itSrf.Faces[0].PointAt(1, 1); Point3d pt4 = itSrf.Faces[0].PointAt(1, 0); double length = pt1.DistanceTo(pt2); double width = pt1.DistanceTo(pt4); Point3d sdPt1 = new Point3d(); Point3d sdPt2 = new Point3d(); if (length > width) { if (width > (minPlotDepth * 2)) { sdPt1 = itSrf.Surfaces[0].PointAt(0.5, 0); sdPt2 = itSrf.Surfaces[0].PointAt(0.5, 1); } else { if (length > (minPlotDepth * 2)) { sdPt1 = itSrf.Surfaces[0].PointAt(0, 0.5); sdPt2 = itSrf.Surfaces[0].PointAt(1, 0.5); } } Line subDline = new Line(sdPt1, sdPt2); Curve subDCrv = subDline.ToNurbsCurve(); splitLines.Add(subDCrv); double crvLength = subDCrv.GetLength(); double noPlots = Math.Floor(crvLength / maxPlotWidth); for (int t = 0; t < noPlots; t++) { double tVal = t * 1 / noPlots; Plane PerpFrm; Point3d evalPt = subDCrv.PointAtNormalizedLength(tVal); subDCrv.PerpendicularFrameAt(tVal, out PerpFrm); Point3d ptPer2Up = Point3d.Add(evalPt, PerpFrm.XAxis); Point3d ptPer2Down = Point3d.Add(evalPt, PerpFrm.XAxis); // draw a line perpindicular Line ln1 = new Line(evalPt, ptPer2Up); Line ln2 = new Line(evalPt, ptPer2Down); Curve lnExt1 = ln1.ToNurbsCurve().ExtendByLine(CurveEnd.End, borderCrvs); Curve lnExt2 = ln2.ToNurbsCurve().ExtendByLine(CurveEnd.End, borderCrvs); splitLines.Add(lnExt1); splitLines.Add(lnExt2); } Brep plotPolySrf = itSrf.Faces[0].Split(splitLines, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); foreach (BrepFace itBF in plotPolySrf.Faces) { Brep itPlot = itBF.DuplicateFace(false); itPlot.Faces.ShrinkFaces(); itBlock.plot.Add(new plot(itPlot, itBlock.type)); RhinoDoc.ActiveDoc.Objects.AddBrep(itPlot); } RhinoDoc.ActiveDoc.Views.Redraw(); } //check the dimensions //find the shorter dimensions //validate if should be subdivide //if so subdidivde half way //hten si=ubdivide into smaller plots based on minim plot width } return(true); }