예제 #1
0
파일: pca_rhino.py 프로젝트: tetov/ITA19
def draw_cloud(cloud, bbox, color, layer):
    points = [{'pos': xyz, 'color': color} for xyz in cloud]
    lines = []
    for a, b in pairwise(bbox[:4] + bbox[:1]):
        lines.append({'start': a, 'end': b, 'color': color})
    for a, b in pairwise(bbox[4:] + bbox[4:5]):
        lines.append({'start': a, 'end': b, 'color': color})
    for a, b in zip(bbox[:4], bbox[4:]):
        lines.append({'start': a, 'end': b, 'color': color})
    compas_rhino.draw_points(points, layer=layer, clear=True)
    compas_rhino.draw_lines(lines, layer=layer, clear=False)
예제 #2
0
def draw_frame(frame, layer):
    origin = list(frame.point)
    xaxis = list(frame.point + frame.xaxis)
    yaxis = list(frame.point + frame.yaxis)
    zaxis = list(frame.point + frame.zaxis)
    points = [{'pos': origin, 'color': (255, 255, 0)}]
    lines = [
        {'start': origin, 'end': xaxis, 'color': (255, 0, 0), 'arrow': 'end'},
        {'start': origin, 'end': yaxis, 'color': (0, 255, 0), 'arrow': 'end'},
        {'start': origin, 'end': zaxis, 'color': (0, 0, 255), 'arrow': 'end'}]
    compas_rhino.draw_points(points, layer=layer, clear=True)
    compas_rhino.draw_lines(lines, layer=layer, clear=False)
예제 #3
0
    def draw_vertices(self, vertices=None, color=None):
        """Draw a selection of vertices.

        Parameters
        ----------
        vertices : list, optional
            A selection of vertices to draw.
            Default is ``None``, in which case all vertices are drawn.
        color : tuple or dict of tuple, optional
            The color specification for the vertices.
            The default is the value of ``~MeshArtist.default_vertexcolor``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        self.vertex_color = color
        vertices = vertices or self.vertices
        vertex_xyz = self.vertex_xyz
        points = []
        for vertex in vertices:
            points.append({
                'pos': vertex_xyz[vertex],
                'name': "{}.vertex.{}".format(self.mesh.name, vertex),
                'color': self.vertex_color.get(vertex, self.default_vertexcolor)
            })
        guids = compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
        return guids
예제 #4
0
    def draw(self, show_points=False):
        """Draw the polyline.

        Parameters
        ----------
        show_points : bool, optional
            Default is ``False``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.
        """
        _points = map(list, self.primitive.points)
        guids = []
        if show_points:
            points = [{
                'pos': point,
                'color': self.color,
                'name': self.primitive.name
            } for point in _points]
            guids += compas_rhino.draw_points(points,
                                              layer=self.layer,
                                              clear=False,
                                              redraw=False)
        polylines = [{
            'points': _points,
            'color': self.color,
            'name': self.primitive.name
        }]
        guids = compas_rhino.draw_polylines(polylines,
                                            layer=self.layer,
                                            clear=False,
                                            redraw=False)
        return guids
예제 #5
0
    def draw_nodes(self, nodes=None, color=None):
        """Draw a selection of nodes.

        Parameters
        ----------
        nodes : list, optional
            A list of nodes to draw.
            Default is ``None``, in which case all nodes are drawn.
        color : tuple or dict of tuple, optional
            The color specification for the nodes.
            The default color is the value of ``~NetworkArtist.default_nodecolor``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.
        """
        self.node_color = color
        node_xyz = self.node_xyz
        nodes = nodes or self.nodes
        points = []
        for node in nodes:
            points.append({
                'pos':
                node_xyz[node],
                'name':
                "{}.node.{}".format(self.network.name, node),
                'color':
                self.node_color.get(node, self.default_nodecolor)
            })
        return compas_rhino.draw_points(points,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
예제 #6
0
    def draw_vertices(self, vertices=None, color=None):
        """Draw a selection of vertices.

        Parameters
        ----------
        vertices : list
            A selection of vertices to draw.
            Default is ``None``, in which case all vertices are drawn.
        color : tuple or dict of tuple, optional
            The color specififcation for the vertices.
            The default is white, ``(255, 255, 255)``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        vertices = vertices or list(self.mesh.vertices())
        vertex_xyz = self.vertex_xyz
        vertex_color = colordict(color, vertices, default=self.color_vertices)
        points = []
        for vertex in vertices:
            points.append({
                'pos': vertex_xyz[vertex],
                'name': "{}.vertex.{}".format(self.mesh.name, vertex),
                'color': vertex_color[vertex]
            })
        return compas_rhino.draw_points(points,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
예제 #7
0
    def draw(self):
        """Draw the polyhedron associated with the artist.

        Returns
        -------
        list
            The GUIDs of the objects created in Rhino.
        """
        vertices = [list(vertex) for vertex in self.shape.vertices]
        faces = self.shape.faces
        edges = self.shape.edges
        points = [{'pos': point, 'color': self.color} for point in vertices]
        lines = [{
            'start': vertices[i],
            'end': vertices[j],
            'color': self.color
        } for i, j in edges]
        polygons = [{
            'points': [vertices[index] for index in face],
            'color': self.color
        } for face in faces]
        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        guids += compas_rhino.draw_lines(lines,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        guids += compas_rhino.draw_faces(polygons,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self._guids = guids
        return guids
예제 #8
0
    def draw(self, show_points=False, show_edges=False, show_face=True):
        """Draw the polygon.

        Parameters
        ----------
        show_points : bool, optional
            Default is ``False``.
        show_edges : bool, optional
            Default is ``False``.
        show_face : bool, optional
            Default is ``True``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.
        """
        _points = map(list, self.primitive.points)
        guids = []
        if show_points:
            points = [{'pos': point, 'color': self.color, 'name': self.name} for point in _points]
            guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
        if show_edges:
            lines = [{'start': list(a), 'end': list(b), 'color': self.color, 'name': self.name} for a, b in self.primitive.lines]
            guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
        if show_face:
            polygons = [{'points': _points, 'color': self.color, 'name': self.name}]
            guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
        self._guids = guids
        return guids
예제 #9
0
    def draw(self, point=None, show_point=False):
        """Draw the vector.

        Parameters
        ----------
        point : [float, float, float] or :class:`compas.geometry.Point`, optional
            Point of application of the vector.
            Default is ``Point(0, 0, 0)``.
        show_point : bool, optional
            If True, draw the base point of the vector.

        Returns
        -------
        list[System.Guid]
            The GUIDs of the created Rhino objects.

        """
        if not point:
            point = [0, 0, 0]
        start = Point(*point)
        end = start + self.primitive
        start = list(start)
        end = list(end)
        guids = []
        if show_point:
            points = [{'pos': start, 'color': self.color, 'name': self.primitive.name}]
            guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
        lines = [{'start': start, 'end': end, 'arrow': 'end', 'color': self.color, 'name': self.primitive.name}]
        guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
        return guids
예제 #10
0
    def draw(self, show_point=False, show_normal=False):
        """Draw the circle.

        Parameters
        ----------
        show_point : bool, optional
            Default is ``False``.
        show_normal : bool, optional
            Default is ``False``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.
        """
        point = list(self.primitive.plane.point)
        normal = list(self.primitive.plane.normal)
        plane = point, normal
        radius = self.primitive.radius
        guids = []
        if show_point:
            points = [{'pos': point, 'color': self.color, 'name': self.primitive.name}]
            guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
        if show_normal:
            lines = [{'start': point, 'end': add_vectors(point, normal), 'arrow': 'end', 'color': self.color, 'name': self.primitive.name}]
            guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
        circles = [{'plane': plane, 'radius': radius, 'color': self.color, 'name': self.primitive.name}]
        guids += compas_rhino.draw_circles(circles, layer=self.layer, clear=False, redraw=False)
        return guids
예제 #11
0
    def draw_vertices(self, vertices=None, color=None):
        """Draw a selection of vertices.

        Parameters
        ----------
        vertices : list[int], optional
            A list of vertices to draw.
            Default is None, in which case all vertices are drawn.
        color : tuple[int, int, int] or dict[int, tuple[int, int, int]], optional
            The color of the vertices.
            The default color of the vertices is :attr:`VolMeshArtist.default_vertexcolor`.

        Returns
        -------
        list[System.Guid]
            The GUIDs of the created Rhino objects.

        """
        self.vertex_color = color
        vertices = vertices or list(self.volmesh.vertices())
        vertex_xyz = self.vertex_xyz
        points = []
        for vertex in vertices:
            points.append({
                'pos':
                vertex_xyz[vertex],
                'name':
                "{}.vertex.{}".format(self.volmesh.name, vertex),
                'color':
                self.vertex_color.get(vertex, self.default_vertexcolor)
            })
        return compas_rhino.draw_points(points,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
예제 #12
0
    def draw(self, show_points=False):
        """Draw the line.

        Parameters
        ----------
        show_points : bool, optional
            Show the start and end point.
            Default is ``False``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        start = list(self.primitive.start)
        end = list(self.primitive.end)
        guids = []
        if show_points:
            points = [
                {'pos': start, 'color': self.color, 'name': self.primitive.name},
                {'pos': end, 'color': self.color, 'name': self.primitive.name}
            ]
            guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
        lines = [{'start': start, 'end': end, 'color': self.color, 'name': self.primitive.name}]
        guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
        return guids
예제 #13
0
    def draw_nodes(self, nodes=None, color=None):
        """Draw a selection of nodes.

        Parameters
        ----------
        nodes : list[int], optional
            A list of nodes to draw.
            Default is None, in which case all nodes are drawn.
        color : tuple[int, int, int] or dict[int, tuple[int, int, int]], optional
            Color of the nodes.
            The default color is :attr:`NetworkArtist.default_nodecolor`.

        Returns
        -------
        list[System.Guid]
            The GUIDs of the created Rhino objects.

        """
        self.node_color = color
        node_xyz = self.node_xyz
        nodes = nodes or self.nodes
        points = []
        for node in nodes:
            points.append({
                'pos':
                node_xyz[node],
                'name':
                "{}.node.{}".format(self.network.name, node),
                'color':
                self.node_color.get(node, self.default_nodecolor)
            })
        return compas_rhino.draw_points(points,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
예제 #14
0
    def draw_nodes(self, nodes=None, color=None):
        """Draw a selection of nodes.

        Parameters
        ----------
        nodes : list, optional
            A list of nodes to draw.
            Default is ``None``, in which case all nodes are drawn.
        color : 3-tuple or dict of 3-tuples, optional
            The color specififcation for the nodes.
            The default color is ``(255, 255, 255)``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        node_xyz = self.node_xyz
        nodes = nodes or list(self.network.nodes())
        node_color = colordict(color, nodes, default=self.color_nodes)
        points = []
        for node in nodes:
            points.append({
                'pos': node_xyz[node],
                'name': "{}.node.{}".format(self.network.name, node),
                'color': node_color[node]
            })
        return compas_rhino.draw_points(points,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
예제 #15
0
    def draw_points(self, points, layer=None, clear_layer=False, redraw=False):
        """Draw a collection of points.

        Parameters
        ----------
        points : list of dict
            The points to draw.
        layer : str, optional
            The layer to draw the points in.
            Default is ``None``.
        clear_layer : bool, optional
            Clear the specified layer.
            Default is ``False``.
        redraw : bool, optional
            Redraw the Rhino view.
            Default is ``False``.

        Returns
        -------
        list of guid
            The GUIDs of the point objects.

        """
        layer = layer or self.layer
        return compas_rhino.draw_points(points,
                                        layer=layer,
                                        clear=clear_layer,
                                        redraw=redraw)
예제 #16
0
    def draw(self, u=10):
        """Draw the cone associated with the artist.

        Parameters
        ----------
        u : int, optional
            Number of faces in the "u" direction.
            Default is ``10``.

        Returns
        -------
        list
            The GUIDs of the objects created in Rhino.
        """
        vertices, faces = self.shape.to_vertices_and_faces(u=u)
        vertices = [list(vertex) for vertex in vertices]
        points = [{'pos': point, 'color': self.color} for point in vertices]
        polygons = [{
            'points': [vertices[index] for index in face],
            'color': self.color
        } for face in faces]
        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        guids += compas_rhino.draw_faces(polygons,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self._guids = guids
        return guids
예제 #17
0
 def draw_resultants(self, scale=1.0, eps=1e-3):
     """
     """
     layer = "{}::Resultants".format(self.layer) if self.layer else None
     scale = scale or self.settings['scale.force']
     eps = eps or self.settings['eps.force']
     color_compression = self.settings['color.force:compression']
     color_tension = self.settings['color.force:tension']
     eps2 = eps**2
     lines = []
     points = []
     for key in self.assembly.edges():
         u, v = key
         corners = self.assembly.edge_attribute(key, 'interface_points')
         forces = self.assembly.edge_attribute(key, 'interface_forces')
         if not forces:
             continue
         n = self.assembly.edge_attribute(key, 'interface_uvw')[2]
         cx, cy, cz = 0, 0, 0
         p = len(corners)
         R = 0
         for point, force in zip(corners, forces):
             c = force['c_np']
             t = force['c_nn']
             f = c - t
             cx += point[0] * f
             cy += point[1] * f
             cz += point[2] * f
             R += f
         if R**2 < eps2:
             continue
         cx = cx / R
         cy = cy / R
         cz = cz / R
         c = [cx, cy, cz]
         sp = add_vectors(c, scale_vector(n, R * scale))
         ep = add_vectors(c, scale_vector(n, -R * scale))
         if R < 0:
             color = color_tension
         else:
             color = color_compression
         lines.append({'start': sp, 'end': ep, 'color': color, 'name': "{0}.resultant.{1}-{2}".format(self.assembly.name, u, v)})
         points.append({'pos': c, 'color': color, 'name': "{0}.resultant.{1}-{2}".format(self.assembly.name, u, v)})
     compas_rhino.draw_lines(lines, layer=layer, clear=False, redraw=False)
     compas_rhino.draw_points(points, layer=layer, clear=False, redraw=False)
예제 #18
0
    def draw_collection(collection,
                        names=None,
                        colors=None,
                        layer=None,
                        clear=False,
                        add_to_group=False,
                        group_name=None):
        """Draw a collection of points.

        Parameters
        ----------
        collection : list of :class:`compas.geometry.Point`
            A collection of points.
        names : list of str, optional
            Individual names for the points.
        colors : color or list of color, optional
            A color specification for the points as a single color or a list of individual colors.
        layer : str, optional
            A layer path.
        clear : bool, optional
            Clear the layer before drawing.
        add_to_group : bool, optional
            Add the points to a group.
        group_name : str, optional
            Name of the group.

        Returns
        -------
        guids: list
            A list of GUIDs if the collection is not grouped.
        groupname: str
            The name of the group if the collection objects are grouped.

        """
        points = [{'pos': list(point)} for point in collection]
        if colors:
            if isinstance(colors[0], (int, float)):
                colors = iterable_like(collection, [colors], colors)
            else:
                colors = iterable_like(collection, colors, colors[0])
            for point, rgb in zip(points, colors):
                point['color'] = rgb
        if names:
            if isinstance(names, basestring):
                names = iterable_like(collection, [names], names)
            else:
                names = iterable_like(collection, names, names[0])
            for point, name in zip(points, names):
                point['name'] = name
        guids = compas_rhino.draw_points(points, layer=layer, clear=clear)
        if not add_to_group:
            return guids
        group = compas_rhino.rs.AddGroup(group_name)
        if group:
            compas_rhino.rs.AddObjectsToGroup(guids, group)
        return group
예제 #19
0
    def draw(self):
        """Draw the point.

        Returns
        -------
        guid: str
            The GUID of the created Rhino object.

        """
        points = [{'pos': list(self.primitive), 'color': self.color, 'name': self.name}]
        self.guids = compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
예제 #20
0
    def draw_nodes(self, keys=None, color=None):
        """Draw a selection of nodes.

        Parameters
        ----------
        keys : list
            A list of node keys identifying which nodes to draw.
            Default is ``None``, in which case all nodes are drawn.
        color : str, tuple, dict
            The color specififcation for the nodes.
            Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components.
            To apply the same color to all nodes, provide a single color specification.
            Individual colors can be assigned using a dictionary of key-color pairs.
            Missing keys will be assigned the default node color (``self.settings['color.nodes']``).
            The default is ``None``, in which case all nodes are assigned the default node color.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        Notes
        -----
        The nodes are named using the following template: ``"{network.name}.node.{id}"``.
        This name can be used afterwards to identify nodes in the Rhino model.

        """
        keys = keys or list(self.network.nodes())
        colordict = color_to_colordict(
            color,
            keys,
            default=self.settings.get('color.nodes'),
            colorformat='rgb',
            normalize=False)
        points = []
        for key in keys:
            points.append({
                'pos':
                self.network.node_coordinates(key),
                'name':
                "{}.node.{}".format(self.network.name, key),
                'color':
                colordict[key],
                'layer':
                self.network.node_attribute(key, 'layer', None)
            })

        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self.guids += guids
        return guids
예제 #21
0
    def draw(self, u=10, v=10, show_vertices=False, show_edges=False, show_faces=True, join_faces=True):
        """Draw the sphere associated with the artist.

        Parameters
        ----------
        u : int, optional
            Number of faces in the "u" direction.
            Default is ``10``.
        v : int, optional
            Number of faces in the "v" direction.
            Default is ``10``.
        show_vertices : bool, optional
            Default is ``False``.
        show_edges : bool, optional
            Default is ``False``.
        show_faces : bool, optional
            Default is ``True``.
        join_faces : bool, optional
            Default is ``True``.

        Returns
        -------
        list
            The GUIDs of the objects created in Rhino.
        """
        vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v)
        vertices = [list(vertex) for vertex in vertices]
        guids = []
        if show_vertices:
            points = [{'pos': point, 'color': self.color} for point in vertices]
            guids += compas_rhino.draw_points(points, layer=self.layer, clear=False, redraw=False)
        if show_edges:
            lines = []
            seen = set()
            for face in faces:
                for u, v in pairwise(face + face[:1]):
                    if (u, v) not in seen:
                        seen.add((u, v))
                        seen.add((v, u))
                        lines.append({'start': vertices[u], 'end': vertices[v], 'color': self.color})
            guids += compas_rhino.draw_lines(lines, layer=self.layer, clear=False, redraw=False)
        if show_faces:
            if join_faces:
                guid = compas_rhino.draw_mesh(vertices, faces, layer=self.layer, name=self.name, color=self.color, disjoint=True)
                guids.append(guid)
            else:
                polygons = [{'points': [vertices[index] for index in face], 'color': self.color} for face in faces]
                guids += compas_rhino.draw_faces(polygons, layer=self.layer, clear=False, redraw=False)
        self._guids = guids
        return guids
예제 #22
0
    def draw_collection(collection,
                        color=None,
                        layer=None,
                        clear=False,
                        group_collection=False,
                        group_name=None):
        """Draw a collection of points.

        Parameters
        ----------
        collection: list of compas.geometry.Point
            A collection of ``Point`` objects.
        color: tuple or list of tuple (optional)
            Color specification of the points.
            If one RGB color is provided, it will be applied to all points.
            If a list of RGB colors is provided, these colors are applied to the corresponding points.
            A list of colors should have the same length as the collection, with one color per item.
            Default value is ``None`` in which case the default point color of the artist is used.
        layer: str (optional)
            The layer in which the objects of the collection should be created.
            Default is ``None``, in which case the default layer setting of the artist is used.
        clear: bool (optional)
            Clear the layer before drawing.
            Default is ``False``.
        group_collection: bool (optional)
            Flag for grouping the objects of the collection.
            Default is ``False``.
        group_name: str (optional).
            The name of the group.
            Default is ``None``.

        Returns
        -------
        guids: list
            A list of GUIDs if the collection is not grouped.
        groupname: str
            The name of the group if the collection objects are grouped.

        """
        points = []
        colors = list_like(collection, color)
        for point, rgb in zip(collection, colors):
            points.append({'pos': list(point), 'color': rgb})
        guids = compas_rhino.draw_points(points, layer=layer, clear=clear)
        if not group_collection:
            return guids
        group = compas_rhino.rs.AddGroup(group_name)
        if group:
            compas_rhino.rs.AddObjectsToGroup(guids, group)
        return group
예제 #23
0
    def draw_vertices(self, keys=None, color=None):
        """Draw a selection of vertices.

        Parameters
        ----------
        keys : list
            A list of vertex keys identifying which vertices to draw.
            Default is ``None``, in which case all vertices are drawn.
        color : str, tuple, dict
            The color specififcation for the vertices.
            Colors should be specified in the form of a string (hex colors) or
            as a tuple of RGB components.
            To apply the same color to all vertices, provide a single color
            specification. Individual colors can be assigned using a dictionary
            of key-color pairs. Missing keys will be assigned the default vertex
            color (``self.defaults['color.vertex']``).
            The default is ``None``, in which case all vertices are assigned the
            default vertex color.

        Notes
        -----
        The vertices are named using the following template:
        ``"{}.vertex.{}".format(self.datastructure.name], key)``.
        This name is used afterwards to identify vertices in the Rhino model.

        """
        keys = keys or list(self.datastructure.vertices())
        colordict = color_to_colordict(
            color,
            keys,
            default=self.defaults.get('color.vertex'),
            colorformat='rgb',
            normalize=False)
        points = []
        for key in keys:
            points.append({
                'pos':
                self.datastructure.vertex_coordinates(key),
                'name':
                self.datastructure.vertex_name(key),
                'color':
                colordict[key],
                'layer':
                self.datastructure.get_vertex_attribute(key, 'layer', None)
            })
        return compas_rhino.draw_points(points,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
예제 #24
0
    def draw(self):
        """Draw the frame.

        Returns
        -------
        guids: list
            The GUIDs of the created Rhino objects.

        """
        points = []
        lines = []
        origin = list(self.primitive.point)
        x = list(self.primitive.point +
                 self.primitive.xaxis.scaled(self.scale))
        y = list(self.primitive.point +
                 self.primitive.yaxis.scaled(self.scale))
        z = list(self.primitive.point +
                 self.primitive.zaxis.scaled(self.scale))
        points = [{'pos': origin, 'color': self.color_origin}]
        lines = [{
            'start': origin,
            'end': x,
            'color': self.color_xaxis,
            'arrow': 'end'
        }, {
            'start': origin,
            'end': y,
            'color': self.color_yaxis,
            'arrow': 'end'
        }, {
            'start': origin,
            'end': z,
            'color': self.color_zaxis,
            'arrow': 'end'
        }]
        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        guids += compas_rhino.draw_lines(lines,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self.guids = guids
        return guids
예제 #25
0
    def draw(self):
        """Draw the point.

        Returns
        -------
        guid: str
            The GUID of the created Rhino object.

        """
        points = [{
            'pos': list(self.primitive),
            'color': self.settings['color.point']
        }]
        guids = compas_rhino.draw_points(points,
                                         layer=self.settings['layer'],
                                         clear=False)
        if guids:
            return guids[0]
예제 #26
0
    def draw(self):
        """Draw the frame.

        Returns
        -------
        list[System.Guid]
            The GUIDs of the created Rhino objects.

        """
        points = []
        lines = []
        origin = list(self.primitive.point)
        X = list(self.primitive.point +
                 self.primitive.xaxis.scaled(self.scale))
        Y = list(self.primitive.point +
                 self.primitive.yaxis.scaled(self.scale))
        Z = list(self.primitive.point +
                 self.primitive.zaxis.scaled(self.scale))
        points = [{'pos': origin, 'color': self.color_origin}]
        lines = [{
            'start': origin,
            'end': X,
            'color': self.color_xaxis,
            'arrow': 'end'
        }, {
            'start': origin,
            'end': Y,
            'color': self.color_yaxis,
            'arrow': 'end'
        }, {
            'start': origin,
            'end': Z,
            'color': self.color_zaxis,
            'arrow': 'end'
        }]
        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        guids += compas_rhino.draw_lines(lines,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        return guids
예제 #27
0
    def draw_vertices(self, keys=None, color=None):
        """Draw a selection of vertices.

        Parameters
        ----------
        keys : list
            A list of vertex keys identifying which vertices to draw.
            Default is ``None``, in which case all vertices are drawn.
        color : str, tuple, dict
            The color specififcation for the vertices.
            Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components.
            To apply the same color to all vertices, provide a single color specification.
            Individual colors can be assigned using a dictionary of key-color pairs.
            Missing keys will be assigned the default vertex color (``self.settings['color.vertices']``).
            The default is ``None``, in which case all vertices are assigned the default vertex color.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        vertices = keys or list(self.mesh.vertices())
        vertex_color = color_to_colordict(
            color,
            vertices,
            default=self.settings['color.vertices'],
            colorformat='rgb',
            normalize=False)
        points = []
        for vertex in vertices:
            points.append({
                'pos': self.mesh.vertex_coordinates(vertex),
                'name': "{}.vertex.{}".format(self.mesh.name, vertex),
                'color': vertex_color[vertex]
            })

        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self.guid_vertex = zip(guids, vertices)
        return guids
예제 #28
0
    def draw(self):
        """Draw the point.

        Returns
        -------
        list[System.Guid]
            The GUIDs of the created Rhino objects.

        """
        points = [{
            'pos': list(self.primitive),
            'color': self.color,
            'name': self.primitive.name
        }]
        guids = compas_rhino.draw_points(points,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        return guids
예제 #29
0
파일: artist.py 프로젝트: mpopescu/compas
    def draw_points(self, points, layer=None, clear_layer=False, redraw=False):
        """Draw a collection of points.

        Parameters
        ----------
        points : list of dict
            The points to draw.
        layer : str, optional
            The layer to draw the points in.
            Default is ``None``, in which case the current layer is used.
        clear_layer : bool, optional
            Clear the specified layer.
            Default is ``False``.
        redraw : bool, optional
            Redraw the Rhino view.
            Default is ``False``.

        Returns
        -------
        list of guid
            The GUIDs of the point objects.

        Notes
        -----
        The attributes required for drawing a point are stored in a dictionary per point.
        The dictionary has the following structure:

        .. code-block:: none

            {
                'pos'   : point,
                'name'  : str,         # optional
                'color' : rgb or hex,  # optional
                'layer' : str          # optional, defaults to the value of the parameter ``layer``.
            }

        """
        layer = layer or self.layer
        return compas_rhino.draw_points(points,
                                        layer=layer,
                                        clear=clear_layer,
                                        redraw=redraw)
예제 #30
0
    def draw(self):
        """Draw the frame.

        Returns
        -------
        guids: list
            The GUIDs of the created Rhino objects.

        """
        points = []
        lines = []
        origin = list(self.primitive.point)
        x = (self.primitive.point + self.primitive.xaxis)
        y = (self.primitive.point + self.primitive.yaxis)
        z = (self.primitive.point + self.primitive.zaxis)
        points = [{'pos': origin, 'color': self.settings['color.origin']}]
        lines = [{
            'start': origin,
            'end': x,
            'color': self.settings['color.xaxis'],
            'arrow': 'end'
        }, {
            'start': origin,
            'end': y,
            'color': self.settings['color.yaxis'],
            'arrow': 'end'
        }, {
            'start': origin,
            'end': z,
            'color': self.settings['color.zaxis'],
            'arrow': 'end'
        }]
        guids = compas_rhino.draw_points(points,
                                         layer=self.settings['layer'],
                                         clear=True)
        guids += compas_rhino.draw_lines(lines,
                                         layer=self.settings['layer'],
                                         clear=False)
        return guids