/***************************************************/ public static void RenderMeshes(BHG.PolySurface polySurface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { List <BHG.ISurface> surfaces = polySurface.Surfaces; for (int i = 0; i < surfaces.Count; i++) { pipeline.DrawBrepShaded(RHG.Brep.CreateFromSurface((RHG.Surface)surfaces[i].IToRhino()), material); } }
public static bool TryJoin(Brep b1, Brep b2, out Brep result) { List <Curve> c1 = CurveUtils.Join(b1.GetExternalEdges()); List <Curve> c2 = CurveUtils.Join(b2.GetExternalEdges()); List <Curve> nakedEdges = new List <Curve>(); List <Curve> overlappedEdges = new List <Curve>(); List <Point> pts = new List <Point>(); List <Curve> updatedN = new List <Curve>(); List <Curve> updatedI = new List <Curve>(); for (int i = 0; i < c1.Count; i++) { for (int j = 0; j < c2.Count; j++) { if (Intersect.CurveCurve(c1[i], c2[j], 0.001, out pts, out overlappedEdges, out nakedEdges)) { updatedN.AddRange(nakedEdges); updatedN.AddRange(overlappedEdges); } } } if (updatedN.Count > 0) { Group <Brep> polySurface = new Group <Brep>(); if (b1 is PolySurface) { polySurface.AddRange((b1 as PolySurface).Surfaces); } else { polySurface.Add(b1); } if (b2 is PolySurface) { polySurface.AddRange((b2 as PolySurface).Surfaces); } else { polySurface.Add(b2); } result = new PolySurface(polySurface); result.GetExternalEdges().AddRange(updatedN); result.GetInternalEdges().AddRange(updatedI); return(true); } else { result = null; return(false); } }
public static global::Topologic.Topology TopologyByGeometry(BH.oM.Geometry.IGeometry geometry, double tolerance = 0.0001) { BH.oM.Geometry.Point bhomPoint = geometry as BH.oM.Geometry.Point; if (bhomPoint != null) { return(Create.VertexByPoint(bhomPoint)); } // Handle polyline and polycurve first BH.oM.Geometry.Polyline bhomPolyline = geometry as BH.oM.Geometry.Polyline; if (bhomPolyline != null) { if (bhomPolyline.ControlPoints.Count < 2) { throw new Exception("An invalid polyline with fewer than 2 control points is given."); } else if (bhomPolyline.ControlPoints.Count == 2) { BH.oM.Geometry.Line bhomLine = BH.Engine.Geometry.Create.Line(bhomPolyline.ControlPoints[0], bhomPolyline.ControlPoints[1]); return(Create.EdgeByLine(bhomLine)); } else { return(Create.WireByPolyLine(bhomPolyline)); } } BH.oM.Geometry.PolyCurve bhomPolyCurve = geometry as BH.oM.Geometry.PolyCurve; if (bhomPolyCurve != null) { if (bhomPolyCurve.Curves.Count == 0) { throw new Exception("An invalid polycurve with no curve is given."); } else if (bhomPolyCurve.Curves.Count == 1) { BH.oM.Geometry.ICurve bhomACurve = bhomPolyCurve.Curves[0]; return(Create.EdgeByCurve(bhomACurve)); } else { return(Create.WireByPolyCurve(bhomPolyCurve)); } } // Then curve BH.oM.Geometry.ICurve bhomCurve = geometry as BH.oM.Geometry.ICurve; if (bhomCurve != null) { return(Create.EdgeByCurve(bhomCurve)); } // Do polysurface first. BH.oM.Geometry.PolySurface bhomPolySurface = geometry as BH.oM.Geometry.PolySurface; if (bhomPolySurface != null) { return(Create.ShellByPolySurface(bhomPolySurface, tolerance)); } // Then surface BH.oM.Geometry.ISurface bhomSurface = geometry as BH.oM.Geometry.ISurface; if (bhomSurface != null) { return(Create.FaceBySurface(bhomSurface)); } BH.oM.Geometry.ISolid bhomSolid = geometry as BH.oM.Geometry.ISolid; if (bhomSolid != null) { return(Create.CellBySolid(bhomSolid, tolerance)); } BH.oM.Geometry.BoundingBox bhomBoundingBox = geometry as BH.oM.Geometry.BoundingBox; if (bhomBoundingBox != null) { return(Create.CellByBoundingBox(bhomBoundingBox)); } BH.oM.Geometry.CompositeGeometry bhomCompositeGeometry = geometry as BH.oM.Geometry.CompositeGeometry; if (bhomCompositeGeometry != null) { return(Create.ClusterByCompositeGeometry(bhomCompositeGeometry, tolerance)); } BH.oM.Geometry.Mesh bhomMesh = geometry as BH.oM.Geometry.Mesh; if (bhomMesh != null) { return(Create.TopologyByMesh(bhomMesh)); } throw new NotImplementedException("This BHoM geometry is not yet supported."); }
/***************************************************/ public static RHG.Brep ToRhino(this BHG.PolySurface polySurface) { return(polySurface.Surfaces.ToRhino()); }
/***************************************************/ public static void RenderWires(BHG.PolySurface polySurface, Rhino.Display.DisplayPipeline pipeline, Color bhColour) { polySurface.Surfaces.ForEach(srf => pipeline.DrawSurface((RHG.Surface)srf.IToRhino(), bhColour, 2)); }