예제 #1
0
def gh_surface_decomposition(surface_guid, accuracy_value, point_guids, curve_guids):

	if point_guids == [None]:
		point_guids = []
	if curve_guids == [None]:
		curve_guids = []

	outer_boundary, inner_boundaries, polyline_features, point_features = surface_discrete_mapping(surface_guid, accuracy_value, crv_guids = curve_guids, pt_guids = point_guids)
	tri_mesh = boundary_triangulation(outer_boundary, inner_boundaries, polyline_features, point_features)
	decomposition = SkeletonDecomposition.from_mesh(tri_mesh)
	quad_mesh = decomposition.decomposition_mesh(point_features)
	RhinoSurface.from_guid(surface_guid).mesh_uv_to_xyz(quad_mesh)
	return quad_mesh
예제 #2
0
def gh_surface_skeleton(surface_guid, accuracy_value, point_guids, curve_guids):

	if point_guids == [None]:
		point_guids = []
	if curve_guids == [None]:
		curve_guids = []

	outer_boundary, inner_boundaries, polyline_features, point_features = surface_discrete_mapping(surface_guid, accuracy_value, crv_guids = curve_guids, pt_guids = point_guids)
	tri_mesh = boundary_triangulation(outer_boundary, inner_boundaries, polyline_features, point_features)
	skeleton = Skeleton.from_mesh(tri_mesh)
	branches = skeleton.branches()
	polylines = [rs.AddPolyline(RhinoSurface.from_guid(surface_guid).polyline_uv_to_xyz([point[:2] for point in branch])) for branch in branches]
	return polylines
from compas_singular.algorithms import SkeletonDecomposition

from compas_plotters.meshplotter import MeshPlotter

# read input data
filepath = 'data/01_decomposition.json'
with open(filepath, 'r') as fp:
    data = json.load(fp)

# get outer boundary polyline, inner boundary polylines, polyline features and point features
outer_boundary, inner_boundaries, polyline_features, point_features = data

# Delaunay triangulation of the surface formed by the planar polylines using the points as Delaunay vertices
mesh = boundary_triangulation(outer_boundary,
                              inner_boundaries,
                              polyline_features,
                              point_features,
                              src='numpy')

# start instance for skeleton-based decomposition
decomposition = SkeletonDecomposition.from_mesh(mesh)

# # build decomposition mesh
mesh = decomposition.decomposition_mesh(point_features)

# plot decomposition mesh
plotter = MeshPlotter(mesh, figsize=(5, 5))
plotter.draw_edges()
plotter.draw_vertices()
plotter.draw_faces()
plotter.show()
예제 #4
0
    def from_surface_and_features(cls,
                                  discretisation,
                                  target_edge_length,
                                  surf_guid,
                                  curve_guids=[],
                                  point_guids=[],
                                  delaunay=None):
        """Get a pattern object from a NURBS surface with optional point and curve features on the surface.
        The pattern is aligned to the surface boundaries and curve features.
        The pattern contains a pole singularity at the feature points. Pole singularities are a specific type of singularity.

        Parameters
        ----------
        discretisation : float
            The surface boundary and curve feature discretisation length.
            Values between 1% and 5% of the length of the diagonal of the bounding box are recommended.
        target_edge_length : float
            The edge target length for densification.
        surf_guid : str
            A Rhino surface guid.
        curves : list of str, optional
            A list of Rhino curve guids.
        points : list of str, optional
            A list of Rhino point guids.

        Returns
        -------
        Pattern
            A Pattern object.

        References
        ----------
        Based on [1]_ and [2]_.

        .. [1] Oval et al. *Feature-based topology finding of patterns for shell structures*. Automation in Construction, 2019.
               Available at: https://www.researchgate.net/publication/331064073_Feature-based_Topology_Finding_of_Patterns_for_Shell_Structures.
        .. [2] Oval. *Topology finding of patterns for structural design*. PhD thesis, Unversite Paris-Est, 2019.
               Available at: https://www.researchgate.net/publication/340096530_Topology_Finding_of_Patterns_for_Structural_Design.

        """
        from compas_singular.rhino import RhinoSurface

        AddInterpCrvOnSrfUV = compas_rhino.rs.AddInterpCrvOnSrfUV
        compas_rhino.rs.EnableRedraw(False)
        surface = RhinoSurface.from_guid(surf_guid)
        result = surface.discrete_mapping(discretisation,
                                          crv_guids=curve_guids,
                                          pt_guids=point_guids)
        outer_boundary, inner_boundaries, polyline_features, point_features = result
        trimesh = boundary_triangulation(*result, delaunay=delaunay)
        decomposition = SkeletonDecomposition.from_mesh(trimesh)
        coarsemesh = decomposition.decomposition_mesh(point_features)
        gkey_vertex = {
            geometric_key(coarsemesh.vertex_coordinates(vertex)): vertex
            for vertex in coarsemesh.vertices()
        }
        edge_curve = {}
        for polyline in decomposition.polylines:
            a = geometric_key(polyline[0])
            b = geometric_key(polyline[-1])
            u = gkey_vertex[a]
            v = gkey_vertex[b]
            points = [point[:2] for point in polyline]
            curve = AddInterpCrvOnSrfUV(surf_guid, points)
            edge_curve[u, v] = curve
        coarsemesh.collect_strips()
        coarsemesh.set_strips_density_target(target_edge_length)
        coarsemesh.densification(edges_to_curves=edge_curve)
        compas_rhino.delete_objects(edge_curve.values(), purge=True)
        densemesh = coarsemesh.get_quad_mesh()
        compas_rhino.rs.EnableRedraw(True)
        compas_rhino.rs.Redraw()
        return cls.from_vertices_and_faces(*densemesh.to_vertices_and_faces())
예제 #5
0
    def from_surface_and_features(cls,
                                  input_subdivision_spacing,
                                  mesh_edge_length,
                                  srf_guid,
                                  crv_guids=[],
                                  pt_guids=[],
                                  delaunay=None):
        """Get a pattern object from a NURBS surface with optional point and curve features on the surface.
        The pattern is aligned to the surface boundaries and curve features.
        The pattern contains a pole singularity at the feature points. Pole singularities are a specific type of singularity.

        Parameters
        ----------
        input_subdivision_spacing : float
            The surface boundary and curve feature subdivision spacing. Values between 0.01 and 0.05 of the length of the diagonal of the bounding box are recommended.
        mesh_edge_length : float
            The edge target length for densification.
        srf_guid : Rhino surface guid
            A Rhino surface guid.
        crv_guids : list, []
            Optional. A list of Rhino curve guids.
        pt_guids : list, []
            Optional. A list of Rhino point guids. WIP

        Returns
        -------
        Pattern
            A Pattern object.

        References
        ----------
        Based on [1]_ and [2]_.

        .. [1] Oval et al. *Feature-based topology finding of patterns for shell structures*. Automation in Construction, 2019.
               Available at: https://www.researchgate.net/publication/331064073_Feature-based_Topology_Finding_of_Patterns_for_Shell_Structures.
        .. [2] Oval. *Topology finding of patterns for structural design*. PhD thesis, Unversite Paris-Est, 2019.
               Available at: https://www.researchgate.net/publication/340096530_Topology_Finding_of_Patterns_for_Structural_Design.

        """
        outer_boundary, inner_boundaries, polyline_features, point_features = surface_discrete_mapping(
            srf_guid,
            input_subdivision_spacing,
            crv_guids=crv_guids,
            pt_guids=pt_guids)
        tri_mesh = boundary_triangulation(outer_boundary, inner_boundaries,
                                          polyline_features, point_features,
                                          delaunay)
        decomposition = SkeletonDecomposition.from_mesh(tri_mesh)
        coarse_mesh = decomposition.decomposition_mesh(point_features)
        polylines = decomposition.polylines
        nurbs_curves = {
            (geometric_key(polyline[0]), geometric_key(polyline[-1])):
            compas_rhino.rs.AddInterpCrvOnSrfUV(srf_guid,
                                                [pt[:2] for pt in polyline])
            for polyline in polylines
        }
        vkey_map = {
            geometric_key(coarse_mesh.vertex_coordinates(vkey)): vkey
            for vkey in coarse_mesh.vertices()
        }
        edges_to_curves = {
            tuple([vkey_map[gkey] for gkey in geom_key]): curve
            for geom_key, curve in nurbs_curves.items()
        }
        for edge, curve in edges_to_curves.items():
            polyline = [
                compas_rhino.rs.EvaluateCurve(
                    curve,
                    compas_rhino.rs.CurveParameter(curve,
                                                   float(t) / 99.0))
                for t in range(100)
            ]
            edges_to_curves[edge] = polyline
        coarse_mesh.collect_strips()
        coarse_mesh.set_strips_density_target(mesh_edge_length)
        coarse_mesh.densification(edges_to_curves=edges_to_curves)
        compas_rhino.rs.DeleteObjects(list(nurbs_curves.values()))
        dense_mesh = coarse_mesh.get_quad_mesh()
        vertices, faces = dense_mesh.to_vertices_and_faces()
        return cls.from_vertices_and_faces(vertices.values(), faces.values())