Exemple #1
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
Exemple #2
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)
Exemple #3
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)
Exemple #4
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
 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)))
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)
Exemple #7
0
    def __init__( self,  **keys ):
        """ Default constructor.
        
        Parameters:
            pos : Vector3 convertable
                the shared translation T of each point creating a surface,
            axis : Vector3 convertable
                the shared rotation axis A of each point around. Zero element for the rotation axis is OZ.
            roll : Vector3 convertable
                the shared "roll angle" R of each point creating a surface around axis,
            points : Vector3 convertable tuple
                the list of *ordered* points positions,

        """
        absolute_shapes.ATriangle._common_init( self, **keys )
        AIShape3D.__init__( self,  
                         geometry=pgl.FaceSet( self._points, self._indexes ),  **keys )
Exemple #8
0
 def pgl_surface_mesh(self,
                      grid_size=128,
                      grid_resolution=1,
                      potential_value=0.5,
                      color=[190, 205, 205],
                      transparency=0):
     points, triangles = self.surface_mesh(grid_size, grid_resolution,
                                           potential_value)
     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(
             pgl.Point3Array(points),
             pgl.Index3Array([[int(i) for i in tr] for tr in triangles])),
         mat)
     return s