Example #1
0
def show(scene, color=black, width=1, clearprevious=True):
    if clearprevious: clear()
    if isinstance(scene, pgl.PointSet):
        scene.width = width
        scene.colorList = pgl.Color4Array(full(len(scene.pointList), color, dtype=pgl.Color4))
    scenelist.append((scene.getId(), scene))
    update()
    def to_geom_args(self,
                     conversion=1.0,
                     name=None,
                     _as_obj=False):  # pragma: lpy
        r"""Get arguments for creating a PlantGL geometry.

        Args:
            conversion (float, optional): Conversion factor that should be
                applied to the vertices. Defaults to 1.0.
            name (str, optional): Name that should be given to the created
                PlantGL symbol. Defaults to None and is ignored.

        Returns:
            tuple: Class, arguments and keyword arguments for PlantGL geometry.

        """
        import openalea.plantgl.all as pgl
        kwargs = dict()
        # Add vertices
        obj_points = []
        obj_colors = []
        for v in self['vertices']:
            xarr = conversion * np.array([v[k] for k in ['x', 'y', 'z']])
            obj_points.append(
                pgl.Vector3(np.float64(xarr[0]), np.float64(xarr[1]),
                            np.float64(xarr[2])))
            c = [v.get(k, None) for k in ['red', 'green', 'blue']]
            if None not in c:
                cast_type = int
                obj_colors.append(
                    pgl.Color4(cast_type(c[0]), cast_type(c[1]),
                               cast_type(c[2]), cast_type(1)))
        points = pgl.Point3Array(obj_points)
        if obj_colors:
            colors = pgl.Color4Array(obj_colors)
            kwargs['colorList'] = colors
            kwargs['colorPerVertex'] = True
        # Add indices
        obj_indices = []
        index_class = pgl.Index
        array_class = pgl.IndexArray
        smb_class = pgl.FaceSet
        # index_class = pgl.Index3
        # array_class = pgl.Index3Array
        # smb_class = pgl.TriangleSet
        for f in self['faces']:
            if _as_obj:
                f_int = [int(_f['vertex_index']) for _f in f]
            else:
                f_int = [int(_f) for _f in f['vertex_index']]
            obj_indices.append(index_class(*f_int))
        indices = array_class(obj_indices)
        args = (points, indices)
        return smb_class, args, kwargs
Example #3
0
    def to_geom_args(self, conversion=1.0, name=None):
        r"""Get arguments for creating a PlantGL geometry.

        Args:
            conversion (float, optional): Conversion factor that should be
                applied to the vertices. Defaults to 1.0.
            name (str, optional): Name that should be given to the created
                PlantGL symbol. Defaults to None and is ignored.

        Returns:
            tuple: Class, arguments and keyword arguments for PlantGL geometry.

        """
        import openalea.plantgl.all as pgl
        kwargs = dict()
        # Add vertices
        obj_points = []
        for v in self['vertices']:
            xarr = conversion * np.array(v)
            obj_points.append(pgl.Vector3(xarr[0], xarr[1], xarr[2]))
        points = pgl.Point3Array(obj_points)
        # Add indices
        obj_indices = []
        nind = None
        index_class = pgl.Index3
        array_class = pgl.Index3Array
        smb_class = pgl.TriangleSet
        for f in self['faces']:
            if nind is None:
                nind = len(f)
                if nind == 3:
                    pass
                else:
                    raise ValueError(
                        "No PlantGL class for faces with %d vertices." % nind)
            else:
                if len(f) != nind:
                    raise ValueError("Faces do not all contain %d vertices." %
                                     nind)
            f_int = [int(_f) for _f in f]
            obj_indices.append(index_class(*f_int))
        indices = array_class(obj_indices)
        # Add colors
        if self['vertex_colors']:
            obj_colors = []
            for c in self['vertex_colors']:
                assert (len(c) == 3)
                obj_colors.append(pgl.Color4(c[0], c[1], c[2], 1))
            colors = pgl.Color4Array(obj_colors)
            kwargs['colorList'] = colors
            kwargs['colorPerVertex'] = True
        args = (points, indices)
        return smb_class, args, kwargs