Exemplo n.º 1
0
    def draw_edges(self, edges=None, color=None):
        """Draw a selection of edges.

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

        Returns
        -------
        list of :class:`Rhino.Geometry.Line`

        """
        edges = edges or list(self.network.edges())
        edge_color = colordict(color, edges, default=self.color_edges)
        lines = []
        for edge in edges:
            start, end = self.network.edge_coordinates(*edge)
            lines.append({
                'start':
                start,
                'end':
                end,
                'color':
                edge_color[edge],
                'name':
                "{}.edge.{}-{}".format(self.network.name, *edge)
            })
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 2
0
    def draw_edges(self, edges=None, color=None):
        """Draw a selection of edges.

        Parameters
        ----------
        edges : list, optional
            A list of edges to draw.
            The default is ``None``, in which case all edges are drawn.
        color : str, tuple, dict
            The color specification for the edges.
            The default color is ``~VolMeshArtist.default_edgecolor``.

        Returns
        -------
        list of :class:`Rhino.Geometry.Line`
        """
        self.edge_color = color
        edges = edges or list(self.volmesh.edges())
        vertex_xyz = self.vertex_xyz
        lines = []
        for edge in edges:
            lines.append({
                'start':
                vertex_xyz[edge[0]],
                'end':
                vertex_xyz[edge[1]],
                'color':
                self.edge_color.get(edge, self.default_edgecolor),
                'name':
                "{}.edge.{}-{}".format(self.volmesh.name, *edge)
            })
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 3
0
    def draw_edges(self, edges=None, color=None):
        """Draw a selection of edges.

        Parameters
        ----------
        edges : list[tuple[hashable, hashable]], optional
            A list of edges to draw.
            The default is None, in which case all edges are drawn.
        color : tuple[int, int, int] or dict[tuple[hashable, hashable], tuple[int, int, int]], optional
            The color specification for the edges.
            The default color is the value of :attr:`NetworkArtist.default_edgecolor`.

        Returns
        -------
        list[:rhino:`Rhino.Geometry.Line`]

        """
        self.edge_color = color
        node_xyz = self.node_xyz
        edges = edges or list(self.network.edges())
        lines = []
        for edge in edges:
            lines.append({
                'start':
                node_xyz[edge[0]],
                'end':
                node_xyz[edge[1]],
                'color':
                self.edge_color.get(edge, self.default_edgecolor),
                'name':
                "{}.edge.{}-{}".format(self.network.name, *edge)
            })
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 4
0
    def draw(self):
        """Draw the line.

        Returns
        -------
        :class:`Rhino.Geometry.Line`
        """
        lines = [self._get_args(self.primitive)]
        return compas_ghpython.draw_lines(lines)[0]
Exemplo n.º 5
0
    def draw_axes(self):
        """Draw the frame's axes.

        Returns
        -------
        list of :class:`Rhino.Geometry.Line`
        """
        _, lines = self._get_args(self.primitive, self.scale,
                                  self.color_origin, self.color_xaxis,
                                  self.color_yaxis, self.color_zaxis)
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 6
0
    def draw(self):
        """Draw the line.

        Returns
        -------
        list of :class:`Rhino.Geometry.Line`

        """
        start = list(self.primitive.start)
        end = list(self.primitive.end)
        lines = [{'start': start, 'end': end}]
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 7
0
    def draw_collection(collection):
        """Draw the collection of lines.

        Parameters
        ----------
        collection : list of compas.geometry.Line
            A collection of ``Line`` objects.

        Returns
        -------
        list of :class:`Rhino.Geometry.Line`

        """
        lines = [LineArtist._get_args(primitive) for primitive in collection]
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 8
0
    def draw_edges(self, keys=None, color=None):
        """Draw a selection of edges.

        Parameters
        ----------
        keys : list
            A list of edge keys (as uv pairs) identifying which edges to draw.
            The default is ``None``, in which case all edges are drawn.
        color : str, tuple, dict
            The color specififcation for the edges.
            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 edges, provide a single color
            specification. Individual colors can be assigned using a dictionary
            of key-color pairs. Missing keys will be assigned the default face
            color (``self.defaults['edge.color']``).
            The default is ``None``, in which case all edges are assigned the
            default edge color.

        Notes
        -----
        All edges are named using the following template:
        ``"{}.edge.{}-{}".fromat(self.datastructure.name, u, v)``.
        This name is used afterwards to identify edges in the Rhino model.

        """
        keys = keys or list(self.datastructure.edges())
        colordict = color_to_colordict(color,
                                       keys,
                                       default=self.defaults.get('color.edge'),
                                       colorformat='rgb',
                                       normalize=False)
        lines = []
        for u, v in keys:
            start, end = self.datastructure.edge_coordinates(u, v)
            lines.append({
                'start':
                start,
                'end':
                end,
                'color':
                colordict[(u, v)],
                'name':
                "{}.edge.{}-{}".format(self.datastructure.name, u, v),
                'layer':
                self.datastructure.edge_attribute((u, v), 'layer')
            })
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 9
0
    def draw(self):
        """Draw the frame.

        Returns
        -------
        geometry : list

            * geometry[0] : :class:`Rhino.Geometry.Point`
            * geometry[1] : list of :class:`Rhino.Geometry.Line`

        """
        point, lines = self._get_args(self.primitive, self.scale,
                                      self.color_origin, self.color_xaxis,
                                      self.color_yaxis, self.color_zaxis)
        geometry = [None, None]
        geometry[0] = compas_ghpython.draw_points([point])
        geometry[1] = compas_ghpython.draw_lines(lines)
        return geometry
Exemplo n.º 10
0
    def draw(self, show_points=False, show_edges=False, show_face=True):
        """Draw the polygon.

        Parameters
        ----------
        show_points : bool, optional
            If True, draw the points of the polygon.
        show_edges : bool, optional
            If True, draw the edges of the polygon.
        show_face : bool, optional
            If True, draw the face of the polygon.

        Returns
        -------
        list[:rhino:`Rhino.Geometry.Point3d`, :rhino:`Rhino.Geometry.Line`, :rhino:`Rhino.Geometry.Mesh`]
            The Rhino points, lines and face.

        """
        _points = map(list, self.primitive.points)
        result = []
        if show_points:
            points = [{
                'pos': point,
                'color': self.color,
                'name': self.primitive.name
            } for point in _points]
            result += compas_ghpython.draw_points(points)
        if show_edges:
            lines = [{
                'start': list(a),
                'end': list(b),
                'color': self.color,
                'name': self.primitive.name
            } for a, b in self.primitive.lines]
            result += compas_ghpython.draw_lines(lines)
        if show_face:
            polygons = [{
                'points': _points,
                'color': self.color,
                'name': self.primitive.name
            }]
            result += compas_ghpython.draw_faces(polygons)
        return result
Exemplo n.º 11
0
    def draw_edges(self, keys=None, color=None):
        """Draw a selection of edges.

        Parameters
        ----------
        keys : list
            A list of edge keys (as uv pairs) identifying which edges to draw.
            The default is ``None``, in which case all edges are drawn.
        color : str, tuple, dict
            The color specififcation for the edges.
            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 edges, provide a single color specification.
            Individual colors can be assigned using a dictionary of key-color pairs.
            Missing keys will be assigned the default face color (``self.settings['color.edges']``).
            The default is ``None``, in which case all edges are assigned the default edge color.

        Returns
        -------
        list of :class:`Rhino.Geometry.Line`

        """
        edges = keys or list(self.volmesh.edges())
        colordict = color_to_colordict(color,
                                       edges,
                                       default=self.settings['color.edges'],
                                       colorformat='rgb',
                                       normalize=False)
        lines = []
        for edge in edges:
            start, end = self.volmesh.edge_coordinates(*edge)
            lines.append({
                'start':
                start,
                'end':
                end,
                'color':
                colordict[edge],
                'name':
                "{}.edge.{}-{}".format(self.volmesh.name, *edge)
            })
        return compas_ghpython.draw_lines(lines)
Exemplo n.º 12
0
    def draw(self):
        """Draw the frame.

        Returns
        -------
        geometry : list

            * geometry[0] : :class:`Rhino.Geometry.Point`
            * geometry[1] : list of :class:`Rhino.Geometry.Line`

        """
        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'
        }]
        geometry = [None, None]
        geometry[0] = compas_ghpython.draw_points(points)
        geometry[1] = compas_ghpython.draw_lines(lines)
        return geometry
Exemplo n.º 13
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 point of application of the vector.

        Returns
        -------
        list[:rhino:`Rhino.Geometry.Point3d`, :rhino:`Rhino.Geometry.Line`]
            The Rhino line and endpoints, if requested.

        """
        if not point:
            point = [0, 0, 0]
        start = Point(*point)
        end = start + self.primitive
        start = list(start)
        end = list(end)
        result = []
        if show_point:
            points = [{
                'pos': start,
                'color': self.color,
                'name': self.primitive.name
            }]
            result += compas_ghpython.draw_points(points)
        lines = [{
            'start': start,
            'end': end,
            'arrow': 'end',
            'color': self.color,
            'name': self.primitive.name
        }]
        result += compas_ghpython.draw_lines(lines)
        return result
Exemplo n.º 14
0
    def draw_collection(collection):
        """Draw the collections of frames.

        Parameters
        ----------
        collection : list of compas.geometry.Frame
            A collection of ``Frame`` objects.

        Returns
        -------
        geometry : list

            * geometry[0] : list of :class:`Rhino.Geometry.Point`
            * geometry[1] : list of :class:`Rhino.Geometry.Line`

        """
        args = [FrameArtist._get_args(primitive) for primitive in collection]
        points, lines = zip(*args)
        lines = itertools.chain(*lines)
        geometry = [None, None]
        geometry[0] = compas_ghpython.draw_points(points)
        geometry[1] = compas_ghpython.draw_lines(lines)
        return geometry