Exemplo n.º 1
0
def cones(obj, **kwds):
    X_attr = kwds.get('X_attr', 'X')
    Y_attr = kwds.get('Y_attr', 'Y')
    pos_dist = kwds.get('dist', 'Distance')
    pos_az = kwds.get('az', 'Azimuth')
    circ_attr = kwds.get('circ_attr', 'Circonference')
    height_attr = kwds.get('height_attr', 'Haut')
    botHoup_attr = kwds.get('botHoup', 'BaseHoup')
    radiusHoup_prefix = kwds.get('radiusHoup_prefix', 'r_houp')
    radiusHoup = kwds.get('radiusHoup', None)
    wood = kwds.get('wood', True)
    rgb = kwds.get('rgb', None)
    spec_name = kwds.get('spec_name', 'houppier_mat')

    if not obj.__dict__.has_key("posX") and not obj.__dict__.has_key("posY"):
        try:
            r = obj.__dict__[pos_dist]
            a = obj.__dict__[pos_az]
            obj.posX = r * cos(radians(forest2geomAZ(a)))
            obj.posY = r * sin(radians(forest2geomAZ(a)))
        except KeyError:
            obj.posX = obj.__dict__[X_attr]
            obj.posY = obj.__dict__[Y_attr]

    ht = 100 * (obj.__dict__[height_attr] - obj.__dict__[botHoup_attr])

    rd_kz = [k for k in obj.__dict__.keys() if radiusHoup_prefix in k]
    radii = [obj.__dict__[k] for k in rd_kz]

    if radiusHoup:
        if radiusHoup == 'Max':
            cone_radius = 1.0 * max(radii)
        else:
            cone_radius = obj.__dict__[radiusHoup]
    else:
        cone_radius = 1.0 * sum(radii) / len(radii)
        #cone_radius = ht/2.
    h = pgl.Translated(
        pgl.Vector3(obj.posX, obj.posY, obj.__dict__[botHoup_attr] * 100),
        pgl.Cone(cone_radius, ht, 1, 12))
    tr = pgl.Translated(
        pgl.Vector3(obj.posX, obj.posY, 0),
        pgl.Cylinder(obj.__dict__[circ_attr] / (2 * pi),
                     obj.__dict__[botHoup_attr] * 100 + ht * 0.1))

    if rgb == None:
        s_h = pgl.Shape(h, stand_material(spec_name=spec_name))
    else:
        r, g, b = rgb
        s_h = pgl.Shape(h, stand_material(r, g, b, spec_name))

    s_tr = pgl.Shape(
        tr,
        stand_material(spec_name="trunk_mat"),
    )  # s_h.id*10 )

    if wood:
        return (s_h, s_tr)
    else:
        return (s_h, )
Exemplo n.º 2
0
def display(vertices, faces, color=None, view=True):
    """3D display of a polyhedron with PlantGL

    Args:
        vertices (list of tuples): list of 3D coordinates of polyhedron vertices
        faces (list of tuple): list of vertex indices defining the faces
        color: a (r,g,b) tuple defining color.
        If None (default), default PlantGL material is used.
        view (bool): should the shape be displayed ?

    Returns:
        a pgl shape
    """
    global display_enable
    if display_enable:
        if color is None:
            shape = pgl.Shape(pgl.FaceSet(pointList=vertices, indexList=faces))
        else:
            m = pgl.Material(pgl.Color3(*color))
            shape = pgl.Shape(pgl.FaceSet(pointList=vertices, indexList=faces),
                              m)
        if view:
            pgl.Viewer.display(shape)
    else:
        warnings.warn('PlantGL not installed: display is not enable!')
        shape = None
    return shape
Exemplo n.º 3
0
    def build_scene(self,
                    leaf_material=None,
                    stem_material=None,
                    soil_material=None):
        if not leaf_material:
            leaf_material = pgl.Material(pgl.Color3(0, 180, 0))

        if not stem_material:
            stem_material = pgl.Material(pgl.Color3(0, 130, 0))
        if not soil_material:
            soil_material = pgl.Material(pgl.Color3(170, 85, 0))

        scene = pgl.Scene()
        for id, plant in self.plants.items():
            leaves = plant["leaves"]
            stems = plant["stems"]
            for lid, leaf in leaves.items():
                shape = pgl.Shape(leaf, leaf_material)
                shape.name = str(lid)
                scene.add(shape)
            if len(stems.pointList) > 0:
                shape = pgl.Shape(stems, stem_material)
                shape.name = str(id)
                scene.add(shape)
        if "soil" in self.soil:
            shape = pgl.Shape(self.soil["soil"], soil_material)
            scene.add(shape)

        self.scene = scene
Exemplo n.º 4
0
    def to_scene(self, conversion=1.0, name=None):
        r"""Create a PlantGL scene from a Ply dictionary.

        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:
        

        """
        import openalea.plantgl.all as pgl
        smb_class, args, kwargs = self.to_geom_args(conversion=conversion,
                                                    name=name)
        smb = smb_class(*args, **kwargs)
        if name is not None:
            smb.setName(name)
        if self.get('material', None) is not None:
            mat = pgl.Material(self['material'])
            shp = pgl.Shape(smb, mat)
        else:
            shp = pgl.Shape(smb)
        if name is not None:
            shp.setName(name)
        scn = pgl.Scene([shp])
        return scn
Exemplo n.º 5
0
def view_kdtree(kdtree, bbox=[[-1., 1.], [-1., 1.], [-1., 1.]], radius=0.05):
    import numpy as np

    scene = pgl.Scene()

    sphere = pgl.Sphere(radius, slices=16, stacks=16)

    silver = pgl.Material(ambient=(49, 49, 49),
                          diffuse=3.,
                          specular=(129, 129, 129),
                          shininess=0.4)
    gold = pgl.Material(ambient=(63, 50, 18),
                        diffuse=3.,
                        specular=(160, 141, 93),
                        shininess=0.4)

    if isinstance(kdtree, KDNode):
        dim = kdtree.axis
        plane_bbox = [b for i, b in enumerate(bbox) if i != dim]
        plane_points = []
        plane_points += [
            np.insert([plane_bbox[0][0], plane_bbox[1][0]], dim,
                      kdtree.pivot[dim])
        ]
        plane_points += [
            np.insert([plane_bbox[0][0], plane_bbox[1][1]], dim,
                      kdtree.pivot[dim])
        ]
        plane_points += [
            np.insert([plane_bbox[0][1], plane_bbox[1][1]], dim,
                      kdtree.pivot[dim])
        ]
        plane_points += [
            np.insert([plane_bbox[0][1], plane_bbox[1][0]], dim,
                      kdtree.pivot[dim])
        ]

        left_bbox = np.copy(bbox).astype(float)
        right_bbox = np.copy(bbox).astype(float)
        left_bbox[dim, 1] = kdtree.pivot[dim]
        right_bbox[dim, 0] = kdtree.pivot[dim]

        scene += pgl.Shape(pgl.Translated(kdtree.pivot, sphere), gold)
        scene += view_kdtree(kdtree.left_child, bbox=left_bbox, radius=radius)
        scene += view_kdtree(kdtree.right_child,
                             bbox=right_bbox,
                             radius=radius)
        # scene += pgl.Shape(pgl.Polyline(plane_points+[plane_points[0]],width=2),pgl.Material(ambient=(0,0,0)))
        scene += pgl.Shape(
            pgl.Polyline(plane_points + [plane_points[0]], width=2),
            pgl.Material(ambient=tuple(list(np.insert([0, 0], dim, 255)))))
        scene += pgl.Shape(pgl.FaceSet(plane_points, [range(4)]),
                           pgl.Material(ambient=(0, 0, 0), transparency=0.6))

    else:
        assert (type(kdtree) == list) or (isinstance(kdtree, np.ndarray))
        for p in kdtree:
            scene += pgl.Shape(pgl.Translated(p, sphere), silver)

    return scene
Exemplo n.º 6
0
def stand_box(domain):
    '''
    
    domain: 3D bounding box of the stand
    '''
    # list of points
    z_base = domain[0][2]
    z_top = domain[1][2]
    sides_points = [
        domain[0],  # coordinates of bottom right corner
        (domain[1][0], domain[0][1], z_base),
        (domain[1][0], domain[1][1],
         z_base),  # coordinates of bottom left corner
        (domain[0][0], domain[1][1], z_base),
        (domain[0][0], domain[0][1], z_top),  # coordinates of top right corner
        (domain[1][0], domain[0][1], z_top),
        (domain[1][0], domain[1][1], z_top),  # coordinates of top left corner
        (domain[0][0], domain[1][1], z_top)
    ]

    bottom_points = [
        domain[0],  # coordinates of bottom right corner
        (domain[1][0], domain[0][1], z_base),
        (domain[1][0], domain[1][1],
         z_base),  # coordinates of bottom left corner
        (domain[0][0], domain[1][1], z_base)
    ]

    # list of indices to make the quads of the sides from the points
    side_indices = [
        (0, 1, 5, 4),  #
        (1, 2, 6, 5),  # indices for 
        (2, 3, 7, 6),  # side faces
        (3, 0, 4, 7)
    ]  #

    # list of indices to make the quads of the bottom from the points
    bottom_indices = [(0, 1, 2, 3)]  # indices for bottom face

    # list of colors
    side_color = pgl.Color3(0, 0, 0)
    bottom_color = pgl.Color3(255, 255, 255)

    # construction of the geometry for the sides
    side_box = pgl.QuadSet(sides_points, side_indices)
    # construction of the geometry for the bottom
    bottom_box = pgl.QuadSet(bottom_points, bottom_indices)

    # create 2 shapes: 1 with side_color, 1 with bottom_color
    sides_shape = pgl.Shape(side_box, pgl.Material(side_color))
    bottom_shape = pgl.Shape(bottom_box, pgl.Material(bottom_color))

    scene = pgl.Scene()
    scene.add(sides_shape)
    scene.add(bottom_shape)

    return scene
Exemplo n.º 7
0
def test_scene():
    ds = pgl.Sphere()
    t = pgl.Tapered(1., 1., ds)
    t2 = pgl.Translated(0., 0., 1., ds)
    sc = pgl.Scene([
        pgl.Shape(t, pgl.Material((255, 0, 0))),
        pgl.Shape(t2, pgl.Material((0, 255, 0)))
    ])
    jsonconversion(sc)
Exemplo n.º 8
0
def pgl_scene(g, flip=False):
    geometry = g.property('geometry')
    scene = pgl.Scene()
    for id in geometry:
        if not flip:
            sh = pgl.Shape(geometry[id])
        else:
            sh = pgl.Shape(pgl.AxisRotated(pgl.Vector3(1, 0, 0), pi, geometry[id]))
        sh.id = id
        scene.add(sh)
    return scene
Exemplo n.º 9
0
    def dart_display(self, radius=0.1, coef=0.8, add=False):
        import openalea.plantgl.all as pgl

        sphere = pgl.Sphere(radius,slices=16,stacks=16)
        coal = pgl.Material(ambient=(8,10,13),diffuse=3.,specular=(89,89,89),shininess=0.3)
        purple = pgl.Material(ambient=(72,28,72),diffuse=2.,specular=(89,89,89),shininess=0.3)
        green = pgl.Material(ambient=(0,88,9),diffuse=2.,specular=(89,89,89),shininess=0.3)
        blue = pgl.Material(ambient=(9,0,88),diffuse=2.,specular=(89,89,89),shininess=0.3)

        font = pgl.Font(size=10)

        s = pgl.Scene()

        dart_points = {}

        for dart in self.darts():
            dart_point = self.get_position(dart)
            dart_face_center = self.element_center(dart,2)
            dart_edge_center = self.element_center(dart,1)

            dart_face_point = dart_face_center + coef*(dart_point-dart_face_center)
            dart_face_edge_center = dart_face_center + coef*(dart_edge_center-dart_face_center)

            dart_edge_point = dart_face_edge_center + coef*(dart_face_point-dart_face_edge_center)
            dart_middle_edge_point = dart_face_edge_center + 0.33*(dart_edge_point-dart_face_edge_center)

            dart_points[dart] = [dart_edge_point,dart_middle_edge_point]

            s += pgl.Shape(pgl.Translated(dart_points[dart][0],sphere),coal)
            # s += pgl.Shape(pgl.Translated(np.mean(dart_points[dart],axis=0), pgl.Text(str(dart),fontstyle=font)), coal, id=dart)
            s += pgl.Shape(pgl.Polyline(dart_points[dart],width=2),coal)

        for dart in self.darts():
            alpha_0_points = []
            alpha_0_points += [dart_points[dart][1]]
            alpha_0_points += [dart_points[self.alpha(0,dart)][1]]
            s += pgl.Shape(pgl.Polyline(alpha_0_points,width=5),purple)

            alpha_1_points = []
            alpha_1_points += [0.66*dart_points[dart][0] + 0.33*dart_points[dart][1]]
            alpha_1_points += [0.66*dart_points[self.alpha(1,dart)][0] + 0.33*dart_points[self.alpha(1,dart)][1]]
            s += pgl.Shape(pgl.Polyline(alpha_1_points,width=5),green)

            alpha_2_points = []
            alpha_2_points += [0.33*dart_points[dart][0] + 0.66*dart_points[dart][1]]
            alpha_2_points += [0.33*dart_points[self.alpha(2,dart)][0] + 0.66*dart_points[self.alpha(2,dart)][1]]
            s += pgl.Shape(pgl.Polyline(alpha_2_points,width=5),blue)

        if add : 
            pgl.Viewer.add(s)
        else : 
            pgl.Viewer.display(s)
Exemplo n.º 10
0
 def representation(self):
    mat = pgl.Material('mblue',(0,0,200),transparency=0.8)
    mat2 = pgl.Material('mred',(200,0,0),transparency=0.8)
    if not self.maxvalue: self.maxvalue = max(self.values)
    if self.maxvalue <= 0: return pgl.Scene()
    sc = pgl.Scene()
    for i, v in enumerate(self.values):
        size = v/(2*self.maxvalue)
        if size > 1e-2:
          sc += pgl.Shape(pgl.Translated(self.getVoxelCenterFromId(i),pgl.Box(self.getVoxelSize()*size)),mat,i)
        else:
          sc += pgl.Shape(pgl.Translated(self.getVoxelCenterFromId(i),pgl.Box(self.getVoxelSize()*0.1)),mat2,i)
    return sc
Exemplo n.º 11
0
def mangoLeaf(length = 1, alpha=0, color = __niceGreen):
  x = array(arange(0.1,length,0.1))
  y = (-3/(length*5.)) * (x**2/length - x)
  cos = math.cos(math.radians(alpha/2.0))
  sin = math.sin(math.radians(alpha/2.0))
  list = []
  idxList = []
  for i in range(len(x)):
    list.append(pgl.Vector3(x[i],0,0))
    list.append(pgl.Vector3(x[i],y[i]*cos,y[i]*sin))
    list.append(pgl.Vector3(x[i],-y[i]*cos,y[i]*sin))
  list.append(pgl.Vector3(0,0,0))
  list.append(pgl.Vector3(length,0,0))
  for i in range(len(x) -1):
    idxList.append(pgl.Index(3*(i+1), 3*(i+1)+1, 3*i+1, 3*i ))
    idxList.append(pgl.Index(3*i+2, 3*(i+1)+2, 3*(i+1), 3*i ))
    #idxList.append(pgl.Index(3*i,3*i+1,3*(i+1)+1, 3*(i+1)))
    #idxList.append(pgl.Index(3*i,3*(i+1),3*(i+1)+2,3*i+2))

  idxList.append(pgl.Index(0, 1, len(list)-2 ))
  idxList.append(pgl.Index(2, 0, len(list)-2 ))
  idxList.append(pgl.Index(3*(len(x)-1)+1, 3*(len(x)-1), len(list)-1 ))
  idxList.append(pgl.Index(3*(len(x)-1), 3*(len(x)-1)+2, len(list)-1 ))
  #idxList.append(pgl.Index(len(list)-2, 1, 0))
  #idxList.append(pgl.Index(len(list)-2, 0, 2))
  #idxList.append(pgl.Index(len(list)-1, 3*(len(x)-1), 3*(len(x)-1)+1))
  #idxList.append(pgl.Index(len(list)-1, 3*(len(x)-1)+2, 3*(len(x)-1)))
  #p3r = pgl.Point3Array(list)
  #ir = pgl.IndexArray(idxList)
  fs = pgl.FaceSet(list,idxList)
  return pgl.Shape(fs, color)
Exemplo n.º 12
0
def frame(matrix, scene, color=1):
    """ Add a frame to the scene.
    The frame is represented by the matrix.
    :param color: allow to distinguish between to identical frames.
    """
    if color == 1:
        r = pgl.Material(pgl.Color3(*(255, 0, 0)))
        g = pgl.Material(pgl.Color3(*(0, 255, 0)))
        b = pgl.Material(pgl.Color3(*(0, 0, 255)))
    else:
        r = pgl.Material(pgl.Color3(*(255, 0, 255)))
        g = pgl.Material(pgl.Color3(*(255, 255, 0)))
        b = pgl.Material(pgl.Color3(*(0, 0, 0)))

    cylinder = pgl.Cylinder(radius=0.005, height=1)
    #x = pgl.AxisRotated(Vector3(0,1,0), radians(90), cylinder)
    #y = pgl.AxisRotated(Vector3(1,0,0), radians(-90), cylinder)
    z = cylinder

    #geom_x = transform4(matrix, x)
    #scene.add(pgl.Shape(geom_x, r))
    #geom_y = transform4(matrix, y)
    #scene.add(pgl.Shape(geom_y, g))
    geom_z = transform4(matrix, z)
    scene.add(pgl.Shape(geom_z, b))
Exemplo n.º 13
0
 def centroid(vid):
     if is_iterable(geometries[vid]):
         bbc.process(pgl.Scene(geometries[vid]))
     else:
         bbc.process(pgl.Scene([pgl.Shape(geometries[vid])]))
     center = bbc.result.getCenter()
     centroids[vid] = center
Exemplo n.º 14
0
def leaf(**kwds):
    global __myLeaf
    if __myLeaf is None:
        __myLeaf = mangoLeaf(alpha=20)

    rp = rdm_pos((1, 1, 1))
    rx, ry, rz = rp.x, rp.y, rp.z
    az, el, rl = rdm_orientation()
    x = kwds.get('x', rx)
    y = kwds.get('y', ry)
    z = kwds.get('z', rz)
    delta = kwds.get('rotz', az)
    phi = kwds.get('roty', el)
    psi = kwds.get('rotx', rl)
    size = kwds.get('len', 10.0)
    color = kwds.get('color', __niceGreen)
    if not size:
        size = 10.0
        print "length is None, using 10 instead : small leaf"
    v = pgl.Vector3(x, y, z)
    #print "leaf size : ", size
    #sx = pgl.Vector3(4,1,1) * size/40.
    #scaled_geometry = pgl.Scaled(sx, pgl.Translated(pgl.Vector3(0.5,0,0), pgl.Disc(0.5, 6)) )
    sx = pgl.Vector3(1, 1, 1) * size / 10.

    scaled_geometry = pgl.Scaled(sx, __myLeaf.geometry)
    rotated_geometry = pgl.EulerRotated(delta, phi, psi, scaled_geometry)
    tr = pgl.Translated(v, rotated_geometry)
    return pgl.Shape(tr, color)
Exemplo n.º 15
0
def genericLeaf(allo_length, allo_surf, **kwds):
  if kwds.has_key('surface'):
    surface = kwds['surface']
    length = math.sqrt(surface / (allo_length*allo_surf) )
  else:  
    length = kwds.get('length', 1)

  alpha = kwds.get('alpha', 0)
  color = kwds.get('color', __niceGreen)
  step = length/10.
  x = array(arange(step,length,step)) #begin and end are specific
  y = (-3.0*allo_length*allo_surf) * (x**2/length - x)
  cos = math.cos(math.radians(alpha/2.0))
  sin = math.sin(math.radians(alpha/2.0))
  list = []
  idxList = []
  for i in range(len(x)):
    list.append(pgl.Vector3(x[i],0,0))
    list.append(pgl.Vector3(x[i],y[i]*cos,y[i]*sin))
    list.append(pgl.Vector3(x[i],-y[i]*cos,y[i]*sin))
  list.append(pgl.Vector3(0,0,0))
  list.append(pgl.Vector3(length,0,0))
  for i in range(len(x) -1):
    idxList.append(pgl.Index(3*(i+1), 3*(i+1)+1, 3*i+1, 3*i ))
    idxList.append(pgl.Index(3*i+2, 3*(i+1)+2, 3*(i+1), 3*i ))

  idxList.append(pgl.Index(0, 1, len(list)-2 ))
  idxList.append(pgl.Index(2, 0, len(list)-2 ))
  idxList.append(pgl.Index(3*(len(x)-1)+1, 3*(len(x)-1), len(list)-1 ))
  idxList.append(pgl.Index(3*(len(x)-1), 3*(len(x)-1)+2, len(list)-1 ))
  p3r = pgl.Point3Array(list)
  ir = pgl.IndexArray(idxList)
  fs = pgl.FaceSet(p3r, ir)
  return pgl.Shape(fs, color)
Exemplo n.º 16
0
def mesh2shapes(scene):
    """ Convert all the meshes containing colors into independent shapes.

    """
    if isinstance(scene, pgl.Scene):
        scene = scene
    else:
        # Case caribu scene
        scene = scene.scene

    new_scene = pgl.Scene()
    for shape in scene:
        g = shape.geometry
        if isinstance(g, pgl.TriangleSet) and len(g.colorList) > 0:
            # convert the mesh into shapes with different colors
            pts = g.pointList
            indx = g.indexList
            colors = g.colorList
            for i, ind in enumerate(indx):
                new_geom = pgl.TriangleSet([], [])
                new_geom.indexList.append(pgl.Index3(0, 1, 2))
                for k in ind:
                    new_geom.pointList.append(pts[k])
                _shape = pgl.Shape(new_geom,
                                   pgl.Material(pgl.Color3(colors[i])))
                new_scene.add(_shape)
        else:
            new_scene.add(shape)
    return new_scene,
Exemplo n.º 17
0
def cvxHull(shape_list_or_scene, color=Green):
    """create a convex hull enveloppe

    :param Scene scene: a scene with shapes to process
    :param color color: a PGL Material to place on the convex hull
    :return: a PGL shape 

    ::

        scene = Scene()
        scene += shapes
        hull = cvxhull(scene, color=Material(0,255,0))
        scene += hull
        Viewer.display(hull)

    .. figure:: convex.png
        :width: 50%

        Example of convex hull enveloppe (of the leaves) added on top of a tree generated with pruning.lpy

    """

    group = pgl.Group([sh.geometry for sh in shape_list_or_scene])
    tglSet = pgl.fit('convexhull', group)
    hull = pgl.Shape(tglSet, color)
    return hull
Exemplo n.º 18
0
def disc( x,y,z, color=color( 30,10,140 ) ):
  v = pgl.Vector3( x, y, z )
  d = pgl.Disc( 0.4, 5 )
  azimuth, elevation, roll= rdm_orientation()
  rotated_geometry= pgl.EulerRotated(azimuth, elevation, roll, d)
  tr = pgl.Translated( v,rotated_geometry )
  return pgl.Shape( tr, color )
Exemplo n.º 19
0
def get_source_leaf_and_max_height(g,
                                   position='center',
                                   relative_height=2. / 3):
    tesselator = pgl.Tesselator()
    bbc = pgl.BBoxComputer(tesselator)
    leaves = get_leaves(g, label='LeafElement')
    centroids = g.property('centroid')
    geometries = g.property('geometry')
    targets = list(leaf for leaf in leaves if leaf in geometries.iterkeys())
    for vid in targets:
        if is_iterable(geometries[vid]):
            bbc.process(pgl.Scene(geometries[vid]))
        else:
            bbc.process(pgl.Scene([pgl.Shape(geometries[vid])]))
        center = bbc.result.getCenter()
        centroids[vid] = center
    zmax = max(centroids.items(), key=lambda x: x[1][2])[1][2]
    distances = {
        vid: pgl.norm(centroids[vid] - (0, 0, relative_height * zmax))
        for vid in centroids
    }
    if position == 'center':
        return min(distances.items(), key=lambda x: x[1])[0], zmax
    elif position == 'border':
        return max(distances.items(), key=lambda x: x[1])[0], zmax
Exemplo n.º 20
0
def oneScHullScene(scgroup,pointsbyshape):#aka hullscene
  """cree les cvxHull des groupes de scgroup"""
  sc = pgl.Scene()
  m = color(20,150,20, trans=True)
  for ids in scgroup:
    pts = ptUnion(pointsbyshape,ids)
    sc += pgl.Shape(pgl.fit('convexhull',pgl.Polyline(pts)),m)
  return sc
Exemplo n.º 21
0
def plot_spline_surface(ctrl_net, points):
    """
    Parameters
    ==========
      - ctrl_net : the net of control points (list of list)
      - points : a set of evaluated points (list of list)
    """
    scene = pgl.Scene()
    n = len(points)
    m = len(points[0])

    # Compute a mesh (i.e. TriangleSet) for the set of points
    pointList = [pt for rank in points for pt in rank]
    indexList = []

    for i in range(n - 1):
        for j in range(m - 1):
            ii = i * m + j
            i1 = (ii, ii + 1, ii + m)
            i2 = (ii + 1, ii + m + 1, ii + m)
            indexList.append(i1)
            indexList.append(i2)

    surf = pgl.Shape(pgl.TriangleSet(pointList, indexList),
                     appearance=pgl.Material((12, 125, 12)))
    scene.add(surf)

    # plot the control net
    n = len(ctrl_net)
    m = len(ctrl_net[0])
    for pts in ctrl_net:
        crv = pgl.Shape(geometry=pgl.Polyline(pts),
                        appearance=pgl.Material((125, 12, 12)))
        scene.add(crv)
        for pt in pts:
            scene.add(
                pgl.Shape(
                    pgl.Translated(pgl.Vector3(pt), pgl.Sphere(radius=0.1))))

    for i in range(m):
        pts = [ctrl_net[j][i] for j in range(n)]
        crv = pgl.Shape(geometry=pgl.Polyline(pts),
                        appearance=pgl.Material((12, 12, 125)))
        scene.add(crv)

    pgl.Viewer.display(scene)
def plotSkyTurtle():
  pgl.Viewer.start()
  sc = pgl.Scene()
  for i in range(len(elevations)):
    pos = pgl.Vector3(pgl.Vector3.Spherical(30,radians(azimuths[i]),radians(90-elevations[i])))
    sc += pgl.Shape(pgl.Translated(pos,pgl.Sphere(0.5)),pgl.Material(),i+1)
  pgl.Viewer.display(sc)
  return sc
Exemplo n.º 23
0
def display_leaves(g):
    green = pgl.Material(pgl.Color3(0, 150, 0))
    scene = pgl.Scene()
    for vid, geom in g.property('geometry').items():
        sh = pgl.Shape(geom, green)
        sh.id = vid
        scene.add(sh)
    pgl.Viewer.display(scene)
    return scene
Exemplo n.º 24
0
 def get_leaf_height(self, leaf_geom):
     from openalea.plantgl import all as pgl
     tesselator = pgl.Tesselator()
     bbc = pgl.BBoxComputer(tesselator)
     if self.is_iterable(leaf_geom):
         bbc.process(pgl.Scene(leaf_geom))
     else:
         bbc.process(pgl.Scene([pgl.Shape(leaf_geom)]))
     return bbc.result.getCenter()[2]
Exemplo n.º 25
0
    def _local2global(self, vid, matrix, color):
        g = self._graph
        geometry = g.vertex_property("geometry")
        colors = g.vertex_property("color")
        final_geometry = g.vertex_property("final_geometry")
        shape = geometry.get(vid)
        edge_type = g.edge_property("edge_type")

        if shape:
            if color:
                shape = pgl.Shape(transform4(matrix, shape), pgl.Material(color))
            else:
                shape = pgl.Shape(transform4(matrix, shape))
            shape.id = vid
            final_geometry[vid] = shape

        if color:
            colors[vid] = color
Exemplo n.º 26
0
 def display(self, color=(190, 205, 205), add=False):
     """
   Display the 2-cells of a 2-G-Map using the ordered orbit of its darts in PlantGL.
   For each face element, retrieve the position of its ordered face darts and add a FaceSet PlantGL object to the scene.
   Example : s += pgl.Shape(pgl.FaceSet( [[0,0,0],[1,0,0],[1,1,0],[0,1,0]], [[0,1,2,3]]) , pgl.Material((0,100,0))) # for a green square
   """
     s += pgl.Shape(
         pgl.FaceSet([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]],
                     [[0, 1, 2, 3]]), pgl.Material((0, 100, 0)))
Exemplo n.º 27
0
def simple_tree(height=2,
                crown_radius=1,
                n_leaves=500,
                leaf_area=0.1,
                inner=True):
    """return a simple tree scene"""
    leaves = random_leaves(n_leaves=n_leaves,
                           leaf_area=leaf_area,
                           crown_radius=crown_radius,
                           crown_center=(0, 0, height),
                           inner=inner)
    trunk = pgl.Cylinder(0.1, height)
    green = pgl.Material(pgl.Color3(0, 150, 0))
    brown = pgl.Material(pgl.Color3(100, 60, 10))
    scene = pgl.Scene()
    scene.add(pgl.Shape(trunk, brown))
    for leaf in leaves:
        scene.add(pgl.Shape(leaf, green))
    return scene
Exemplo n.º 28
0
def plot_spline_crv(ctrls, pts):
    """ 
    Parameters
    ==========
      - ctrl: control points
      - pts : evaluated points on the curve
    """

    scene = pgl.Scene()
    crvContols = pgl.Shape(geometry=pgl.Polyline(ctrls),
                           appearance=pgl.Material((12, 125, 12)))
    scene.add(crvContols)
    crv = pgl.Shape(geometry=pgl.Polyline(pts),
                    appearance=pgl.Material((125, 12, 12)))
    scene.add(crv)

    # To complete: Draw the control points and the line between each ones.

    pgl.Viewer.display(scene)
def mesh_display(points, triangles, color=[190,205,205], transparency=0, add=False):
    import openalea.plantgl.all as pgl
    if color is None:
        color = [np.random.randint(0,255) for i in xrange(3)] 
    mat = pgl.Material(tuple(color), diffuse=0.25, transparency=transparency)
    s = pgl.Scene()
    s += pgl.Shape(pgl.FaceSet(points, triangles), mat)
    if add : 
        pgl.Viewer.add(s)
    else : 
        pgl.Viewer.display(s)
Exemplo n.º 30
0
def arrow(x,y,z,length,az=0, el=0, radius=None, color=color(255,255,255),id=0):
  if radius==None:
    radius=length*0.05
  rad_az = math.radians(az)
  rad_el = math.pi/2 - math.radians(el)
  v = pgl.Vector3( x, y, z )
  c = pgl.Cylinder(radius, length*0.8, 10)
  con =pgl.Translated(pgl.Vector3(0,0,length*0.7), pgl.Cone(2*radius, length*0.3))
  arr = pgl.Group([c,con])
  dir_arr = pgl.EulerRotated(rad_az,rad_el,0,arr)
  tr_dir_arr = pgl.Translated(v,dir_arr)
  return pgl.Shape(tr_dir_arr, color, id)