internal static global::Topologic.Shell ShellByMesh(Mesh bhomMesh) { List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (BH.oM.Geometry.Face bhomFace in bhomMesh.Faces) { List <Point> bhomControlPoints = new List <Point>(); Point p1 = bhomMesh.Vertices[bhomFace.A]; bhomControlPoints.Add(p1); Point p2 = bhomMesh.Vertices[bhomFace.B]; bhomControlPoints.Add(p2); Point p3 = bhomMesh.Vertices[bhomFace.C]; bhomControlPoints.Add(p3); Point p4 = null; if (bhomFace.D >= 0) { p4 = bhomMesh.Vertices[bhomFace.D]; bhomControlPoints.Add(p4); } bhomControlPoints.Add(p1); // close the wire Polyline bhomBoundary = new Polyline { ControlPoints = bhomControlPoints }; BH.oM.Geometry.PlanarSurface bhomPlanarSurface = new BH.oM.Geometry.PlanarSurface(bhomBoundary, null); global::Topologic.Face face = Create.FaceByPlanarSurface(bhomPlanarSurface); faces.Add(face); } return(global::Topologic.Shell.ByFaces(faces, 0.0001)); }
internal static global::Topologic.Shell ShellByPolySurface(PolySurface bhomPolySurface, double tolerance) { List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (ISurface bhomSurface in bhomPolySurface.Surfaces) { global::Topologic.Face face = Create.FaceBySurface(bhomSurface); faces.Add(face); } return(global::Topologic.Shell.ByFaces(faces, tolerance)); }
internal static global::Topologic.Cell CellByBoundaryRepresentation(BoundaryRepresentation bhomBoundaryRepresentation, double tolerance) { List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (ISurface bhomSurface in bhomBoundaryRepresentation.Surfaces) { global::Topologic.Face face = Create.FaceBySurface(bhomSurface); faces.Add(face); } return(global::Topologic.Cell.ByFaces(faces, tolerance)); }
public static Spatial.ISAMGeometry3D ToSAM(this Topology topology) { Vertex vertex = topology as Vertex; if (vertex != null) { return(Geometry.Topologic.Convert.ToSAM(vertex)); } Edge edge = topology as Edge; if (edge != null) { return(Geometry.Topologic.Convert.ToSAM(edge)); } Wire wire = topology as Wire; if (wire != null) { if (wire.IsClosed) { return(Geometry.Topologic.Convert.ToSAM_Polygon3D(wire)); } else { return(Geometry.Topologic.Convert.ToSAM(wire)); } } global::Topologic.Face face = topology as global::Topologic.Face; if (face != null) { return(Geometry.Topologic.Convert.ToSAM(face)); } Cell cell = topology as Cell; if (cell != null) { return(Geometry.Topologic.Convert.ToSAM(cell)); } Shell shell = topology as Shell; if (shell != null) { return(Geometry.Topologic.Convert.ToSAM(shell)); } return(null); }
internal static BH.oM.Geometry.PlanarSurface PlanarSurface(global::Topologic.Face face) { Polyline bhomExternalBoundary = Convert.Polyline(face.ExternalBoundary); List <ICurve> bhomInternalBoundaries = new List <ICurve>(); List <global::Topologic.Wire> internalBoundaries = face.InternalBoundaries; foreach (global::Topologic.Wire internalBoundary in internalBoundaries) { bhomInternalBoundaries.Add(Convert.Polyline(internalBoundary)); } BH.oM.Geometry.PlanarSurface planarSurface = new BH.oM.Geometry.PlanarSurface(bhomExternalBoundary, bhomInternalBoundaries); return(planarSurface); }
public static PlaneSurface ToRhino(PlanarSurface planarSurface, global::Topologic.Face face) { // From Topologic List <double> coefficients = planarSurface.Coefficients; double a = coefficients[0]; double b = coefficients[1]; double c = coefficients[2]; double d = coefficients[3]; Vertex faceCenterOfMass = face.CenterOfMass; Point3d ghFaceCenterOfMass = ToRhino(faceCenterOfMass); Plane ghPlane = new Plane(a, b, c, d); double occtXMin = planarSurface.XMin; double occtXMax = planarSurface.XMax; double occtAbsDeltaX = Math.Abs(occtXMax - occtXMin); double occtHalfDeltaX = occtAbsDeltaX / 2.0; double occtYMin = planarSurface.YMin; double occtYMax = planarSurface.YMax; double occtAbsDeltaY = Math.Abs(occtYMax - occtYMin); double occtHalfDeltaY = occtAbsDeltaY / 2.0; double ghXMin = occtXMin; // - occtHalfDeltaX - safetyMarginX; double ghXMax = occtXMax; // - occtHalfDeltaX + safetyMarginX; double ghYMin = occtYMin; // - occtHalfDeltaY - safetyMarginY; double ghYMax = occtYMax; // - occtHalfDeltaY + safetyMarginY; Interval xExtents = new Interval( ghXMin, ghXMax); Interval yExtents = new Interval( ghYMin, ghYMax); PlaneSurface ghPlaneSurface = new PlaneSurface(ghPlane, xExtents, yExtents); Point3d ghCentroid = AreaMassProperties.Compute(ghPlaneSurface).Centroid; Vector3d ghTranslationVector = ghFaceCenterOfMass - ghCentroid; ghPlaneSurface.Translate(ghTranslationVector); if (!ghPlaneSurface.IsValid) { throw new Exception("A valid surface cannot be created from this Face."); } return(ghPlaneSurface); }
public static Rhino.Geometry.Surface ToRhino(global::Topologic.Face face) { Object faceGeometry = face.BasicGeometry; // 1. Compute the base surface Based on https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_NurbsSurface_Create.htm global::Topologic.NurbsSurface nurbsSurface = faceGeometry as global::Topologic.NurbsSurface; if (nurbsSurface != null) { return(ToRhino_NurbsSurface(nurbsSurface)); } global::Topologic.PlanarSurface planarSurface = faceGeometry as global::Topologic.PlanarSurface; if (planarSurface != null) { PlaneSurface planeSurface = ToRhino(planarSurface, face); return(planeSurface); } throw new Exception("An invalid surface is created."); }
/// <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) { // Declare a variable for the input String global::Topologic.Face face = null; global::Topologic.Topology parentTopology = null; // Use the DA object to retrieve the data inside the first input parameter. // If the retieval fails (for example if there is no data) we need to abort. if (!DA.GetData(0, ref face)) { return; } if (!DA.GetData(1, ref parentTopology)) { return; } // If the retrieved data is Nothing, we need to abort. // We're also going to abort on a zero-length String. if (face == null) { return; } if (parentTopology == null) { return; } //if (data.Length == 0) { return; } // Convert the String to a character array. //char[] chars = data.ToCharArray(); IList <global::Topologic.Shell> adjacentShells = global::Topologic.Utilities.FaceUtility.AdjacentShells(face, parentTopology); // Use the DA object to assign a new String to the first output parameter. DA.SetDataList(0, adjacentShells); }
public static Topology ToTopologic(this Brep brep, double tolerance = Core.Tolerance.Distance) { if (brep == null) { return(null); } BrepFaceList ghBrepFaces = brep.Faces; List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (BrepFace ghBrepFace in ghBrepFaces) { global::Topologic.Face face = ghBrepFace.ToTopologic(); faces.Add(face); } if (faces.Count == 0) { return(null); } else if (faces.Count == 1) { return(faces[0]); } else { global::Topologic.Shell shell = global::Topologic.Shell.ByFaces(faces, tolerance); if (brep.IsSolid) { Cell cell = Cell.ByShell(shell); return(cell); } return(shell); } }
public static List <global::Topologic.Vertex> Vertices(global::Topologic.Face face) { return(face.Vertices); }
public static List <global::Topologic.Shell> Shells(global::Topologic.Face face) { return(face.Shells); }
public static List <global::Topologic.Face> AdjacentFaces(global::Topologic.Face face) { return(face.AdjacentFaces); }
public static global::Topologic.Vertex InternalVertex(global::Topologic.Face face, double tolerance = 0.0001) { return(global::Topologic.Utilities.FaceUtility.InternalVertex(face, tolerance)); }
internal static IGeometry BasicGeometry(global::Topologic.Face face) { return(PlanarSurface(face)); }
public static Brep ToRhino(global::Topologic.Face face, double tolerance = Core.Tolerance.Distance) { Rhino.Geometry.Surface ghSurface = ToRhino(face); double width = 0.0, height = 0.0; bool canGetSurfaceSize = ghSurface.GetSurfaceSize(out width, out height); if (!canGetSurfaceSize) { throw new Exception("Fails to get the surface size."); } double maxSize = Math.Max(width, height); double maxSizeAndMargin = maxSize + 2; ghSurface = ghSurface.Extend(IsoStatus.North, maxSizeAndMargin, true); ghSurface = ghSurface.Extend(IsoStatus.South, maxSizeAndMargin, true); ghSurface = ghSurface.Extend(IsoStatus.West, maxSizeAndMargin, true); ghSurface = ghSurface.Extend(IsoStatus.East, maxSizeAndMargin, true); List <GeometryBase> ghGeometryBases = new List <GeometryBase>(); IList <Edge> outerEdges = face.ExternalBoundary.Edges; List <Curve> ghCurves = new List <Curve>(); foreach (Edge edge in outerEdges) { Curve ghCurve3D = ToRhino(edge); ghGeometryBases.Add(ghCurve3D); ghCurves.Add(ghCurve3D); } Brep ghBrep2 = Brep.CreatePatch( ghGeometryBases, ghSurface, 20, 20, true, true, tolerance, 100.0, 1, new Boolean[] { true, true, true, true }, tolerance); BrepFace ghSurfaceAsBrepFace = ghSurface as BrepFace; if (ghBrep2 == null) { return(null); } IList <Wire> internalBoundaries = face.InternalBoundaries; if (internalBoundaries.Count == 0) { return(ghBrep2); } BrepFace ghBrepFace = ghBrep2.Faces[0]; List <Curve> ghInternalCurves = new List <Curve>(); foreach (Wire internalBoundary in internalBoundaries) { List <Curve> ghCurvesFromWireAsObjects = ToRhino(internalBoundary); foreach (Curve ghCurveFromWireAsObject in ghCurvesFromWireAsObjects) { Curve ghCurveFromWire = ghCurveFromWireAsObject as Curve; if (ghCurveFromWire != null) { Curve[] ghPulledCurveFromWire = ghCurveFromWire.PullToBrepFace(ghBrepFace, tolerance); ghInternalCurves.AddRange(ghPulledCurveFromWire); } } } Brep ghBrep3 = ghBrepFace.Split(ghInternalCurves, tolerance); return(ghBrep3.Faces.ExtractFace(0)); }
public static global::Topologic.Wire ExternalBoundary(global::Topologic.Face face) { return(face.ExternalBoundary); }
public static List <global::Topologic.Vertex> SharedVertices(global::Topologic.Face face, global::Topologic.Face otherFace) { return(face.SharedVertices(otherFace)); }
public static global::Topologic.Face TrimByWire(global::Topologic.Face face, global::Topologic.Wire wire, bool reverseWire) { return(global::Topologic.Utilities.FaceUtility.TrimByWire(face, wire, reverseWire)); }
public static bool TrySplit_Obsolete(this IEnumerable <Spatial.Shell> shells_In, out List <Spatial.Shell> shells_Out, out List <Topology> topologies, bool tryCellComplexByCells = true, double tolerance = Core.Tolerance.Distance) { shells_Out = null; topologies = null; if (shells_In == null) { return(false); } List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (Spatial.Shell shell in shells_In) { List <Face3D> face3Ds = shell?.Face3Ds; if (face3Ds == null || face3Ds.Count == 0) { continue; } foreach (Face3D face3D in face3Ds) { global::Topologic.Face face = Convert.ToTopologic(face3D); if (face != null) { faces.Add(face); } } } topologies = new List <Topology>(); List <Cell> cells = null; if (tryCellComplexByCells) { try { Cluster cluster = Cluster.ByTopologies(faces as IList <Topology>); Topology topology = cluster.SelfMerge(); if (topology.Cells != null && topology.Cells.Count != 0) { cells = topology.Cells?.ToList(); CellComplex cellComplex = null; try { cellComplex = CellComplex.ByCells(cells); } catch (Exception exception) { } if (cellComplex != null && cellComplex.Cells != null && cellComplex.Cells.Count != 0) { topologies.Add(cellComplex); cells = cellComplex.Cells?.ToList(); } else { topologies.Add(topology); } } } catch (Exception exception) { cells = null; } } if (cells == null) { try { CellComplex cellComplex = CellComplex.ByFaces(faces, tolerance); topologies.Add(cellComplex); cells = cellComplex.Cells?.ToList(); } catch (Exception exception) { cells = null; } } if (cells == null || cells.Count == 0) { return(false); } shells_Out = cells.ToSAM(); return(shells_Out != null); }
public static global::Topologic.Face ToTopologic(this BrepFace brepFace) { Rhino.Geometry.Surface ghSurface = brepFace?.UnderlyingSurface(); if (ghSurface == null) { return(null); } global::Topologic.Face untrimmedFace = ghSurface.ToTopologic(); BrepLoop ghOuterLoop = brepFace.OuterLoop; Wire outerWire = null; BrepLoopList ghLoops = brepFace.Loops; List <Wire> innerWires = new List <Wire>(); foreach (BrepLoop ghLoop in ghLoops) { BrepTrimList ghTrims = ghLoop.Trims; List <Edge> trimmingEdges = new List <Edge>(); foreach (BrepTrim ghTrim in ghTrims) { BrepEdge ghEdge = ghTrim.Edge; if (ghEdge == null) { continue; //throw new Exception("An invalid Rhino edge is encountered."); } Topology topology = ghEdge.DuplicateCurve().ToTopologic(); // Edge or Wire? Edge trimmingEdge = topology as Edge; if (trimmingEdge != null) { trimmingEdges.Add(trimmingEdge); } Wire partialTrimmingWire = topology as Wire; if (partialTrimmingWire != null) { IList <Edge> partialTrimmingEdges = partialTrimmingWire.Edges; trimmingEdges.AddRange(partialTrimmingEdges); } } Wire trimmingWire = Wire.ByEdges(trimmingEdges); if (ghLoop == ghOuterLoop) { outerWire = trimmingWire; } else { innerWires.Add(trimmingWire); } } global::Topologic.Face outerTrimmedFace = global::Topologic.Utilities.FaceUtility.TrimByWire(untrimmedFace, outerWire, true); global::Topologic.Face finalFace = outerTrimmedFace.AddInternalBoundaries(innerWires); return(finalFace); }
public static Face3D ToSAM(this global::Topologic.Face face) { if (face == null) { return(null); } Polygon3D polygon3D = null; Vector3D normal = new Vector3D(FaceUtility.NormalAtParameters(face, 0.5, 0.5)); if (normal != null) { polygon3D = Spatial.Create.Polygon3D(normal, face.ExternalBoundary.Vertices?.ToList().ConvertAll(x => x.ToSAM())); } if (polygon3D == null) { polygon3D = ToSAM_Polygon3D(face.ExternalBoundary); } if (polygon3D == null) { return(null); } List <Polygon3D> polygon3Ds = new List <Polygon3D>() { polygon3D }; IList <Wire> wires = face.InternalBoundaries; if (wires != null && wires.Count > 0) { foreach (Wire wire in wires) { polygon3D = null; if (normal != null) { polygon3D = Spatial.Create.Polygon3D(normal, wire.Vertices?.ToList().ConvertAll(x => x.ToSAM())); } if (polygon3D == null) { polygon3D = ToSAM_Polygon3D(wire); } if (polygon3D == null) { continue; } polygon3Ds.Add(polygon3D); } } Face3D result = Face3D.Create(polygon3Ds); return(result); }
internal static IGeometry BasicGeometry(global::Topologic.Topology topology) { if (topology == null) { return(null); } global::Topologic.Vertex vertex = topology as global::Topologic.Vertex; if (vertex != null) { return(Convert.BasicGeometry(vertex)); } global::Topologic.Edge edge = topology as global::Topologic.Edge; if (edge != null) { return(Convert.BasicGeometry(edge)); } global::Topologic.Wire wire = topology as global::Topologic.Wire; if (wire != null) { return(Convert.BasicGeometry(wire)); } global::Topologic.Face face = topology as global::Topologic.Face; if (face != null) { return(Convert.BasicGeometry(face)); } global::Topologic.Shell shell = topology as global::Topologic.Shell; if (shell != null) { return(Convert.BasicGeometry(shell)); } global::Topologic.Cell cell = topology as global::Topologic.Cell; if (cell != null) { return(Convert.BasicGeometry(cell)); } global::Topologic.CellComplex cellComplex = topology as global::Topologic.CellComplex; if (cellComplex != null) { return(Convert.BasicGeometry(cellComplex)); } global::Topologic.Cluster cluster = topology as global::Topologic.Cluster; if (cluster != null) { return(Convert.BasicGeometry(cluster)); } //global::Topologic.Aperture aperture = topology as global::Topologic.Aperture; //if (aperture != null) //{ // return Aperture.Convert.BasicGeometry(aperture); //} throw new NotImplementedException("Geometry for this shape is not supported yet"); }
public static List <Spatial.Shell> Shells(IEnumerable <Face3D> face3Ds, out List <Topology> topologies, bool tryCellComplexByCells = true, double tolerance = Tolerance.Distance) { topologies = null; if (face3Ds == null || face3Ds.Count() == 0) { return(null); } List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (Face3D face3D in face3Ds) { global::Topologic.Face face = Convert.ToTopologic(face3D); if (face == null) { continue; } faces.Add(face); } topologies = new List <Topology>(); List <Cell> cells = null; if (tryCellComplexByCells) { try { Cluster cluster = Cluster.ByTopologies(faces as IList <Topology>); Topology topology = cluster.SelfMerge(); if (topology.Cells != null && topology.Cells.Count != 0) { cells = topology.Cells?.ToList(); CellComplex cellComplex = null; try { cellComplex = CellComplex.ByCells(cells); } catch (Exception exception) { cellComplex = null; } if (cellComplex != null && cellComplex.Cells != null && cellComplex.Cells.Count != 0) { topologies.Add(cellComplex); cells = cellComplex.Cells?.ToList(); } else { topologies.Add(topology); } } } catch (Exception exception) { cells = null; } } if (cells == null) { try { CellComplex cellComplex = CellComplex.ByFaces(faces, tolerance); topologies.Add(cellComplex); cells = cellComplex.Cells?.ToList(); } catch (Exception exception) { cells = null; } } return(cells?.ToSAM()); }
public static List <global::Topologic.Wire> Wires(global::Topologic.Face face) { return(face.Wires); }
public static List <global::Topologic.Edge> SharedEdges(global::Topologic.Face face, global::Topologic.Face otherFace) { return(face.SharedEdges(otherFace)); }
public static global::Topologic.Face AddInternalBoundaries(global::Topologic.Face face, List <global::Topologic.Wire> internalBoundaries) { return(face.AddInternalBoundaries(internalBoundaries)); }
public static List <global::Topologic.Wire> InternalBoundaries(global::Topologic.Face face) { return(face.InternalBoundaries); }
public static global::Topologic.Face AddApertureDesign(global::Topologic.Face face, global::Topologic.Face apertureDesign, int numEdgeSamples) { return(face.AddApertureDesign(apertureDesign, numEdgeSamples)); }
public static List <object> ToRhino(this Topology topology, double tolerance = Core.Tolerance.Distance) { if (topology == null) { return(null); } List <Object> geometries = new List <Object>(); Vertex vertex = topology as Vertex; if (vertex != null) { geometries.Add(ToRhino(vertex)); return(geometries); } Edge edge = topology as Edge; if (edge != null) { geometries.Add(ToRhino(edge)); return(geometries); } Wire wire = topology as Wire; if (wire != null) { return(ToRhino(wire)?.Cast <object>().ToList()); } global::Topologic.Face face = topology as global::Topologic.Face; if (face != null) { geometries.Add(ToRhino(face, tolerance)); return(geometries); } Shell shell = topology as Shell; if (shell != null) { return(ToRhino_Breps(shell, tolerance)?.Cast <object>().ToList()); } Cell cell = topology as Cell; if (cell != null) { return(ToRhino_Breps(cell, tolerance)?.Cast <object>().ToList()); } CellComplex cellComplex = topology as CellComplex; if (cellComplex != null) { return(ToRhino_Breps((CellComplex)cellComplex, tolerance)?.Cast <object>().ToList()); } Cluster cluster = topology as Cluster; if (cluster != null) { return(ToRhino(cluster.SubTopologies, tolerance)); } Aperture aperture = topology as Aperture; if (aperture != null) { return(ToRhino(aperture.Topology, tolerance)); } throw new Exception("The type of the input topology is not recognized."); }
public static List <global::Topologic.Edge> Edges(global::Topologic.Face face) { return(face.Edges); }