Ejemplo n.º 1
0
 def display(self, color=[190, 205, 205], add=False, transparency=0):
     from openalea.plantgl.all import Scene, Shape, Material, FaceSet, Viewer
     from random import randint
     s = Scene()
     for facedart in self.elements(2):
         lastdart = facedart
         positions = []
         for dart in self.orderedorbit(facedart, [0, 1]):
             if self.alpha(0, dart) != lastdart:
                 positions.append(self.get_position(dart))
             lastdart = dart
         if color is None:
             mat = Material(
                 (randint(0, 255), randint(0, 255), randint(0, 255)),
                 transparency=transparency)
         else:
             mat = Material(tuple(color),
                            diffuse=0.25,
                            transparency=transparency)
         s.add(
             Shape(FaceSet(positions, [range(len(positions))]), mat,
                   facedart))
     if add:
         Viewer.add(s)
     else:
         Viewer.display(s)
Ejemplo n.º 2
0
    def display(self, degree = None, add = False, randomcolor = True):
        from openalea.plantgl.all import Scene, Shape, Material, FaceSet, Polyline, PointSet, Viewer
        from random import randint
        s = Scene()
        m = Material()
        if degree is None: degree = self.degree
        if degree >= 2:
            try:
                ccw = self.orientation()
            except ValueError:
                ccw = set()

            for fid in self.iterate_over_each_i_cell(2):
                if fid in ccw: ofid = self.alpha(0,fid)
                else: ofid = fid
                positions = []
                for dart, deg in self.orderedorbit_iter(ofid,[0,1]):
                    if deg != 1:
                        positions.append(self.get_position(dart))
                s.add(Shape(FaceSet(positions, [range(len(positions))]) , Material((randint(0,255),randint(0,255),randint(0,255))) if randomcolor else m))
        elif degree == 1:
            for eid in self.iterate_over_each_i_cell(1):
                s.add(Shape(Polyline([self.get_position(eid),self.get_position(self.alpha(0,eid))]) ,Material((randint(0,255),randint(0,255),randint(0,255))) ))
        elif degree == 0:
                s.add(Shape(PointSet([self.get_position(pid) for pid in self.iterate_over_each_i_cell(0)]) ,Material((randint(0,255),randint(0,255),randint(0,255))) ))
        
        
        if add : Viewer.add(s)
        else   : Viewer.display(s)
Ejemplo n.º 3
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
		"""
            from openalea.plantgl.all import Scene, Shape, Material, FaceSet, Viewer
            from random import randint
            s = Scene()
            for facedart in self.elements(2):
                lastfart = facedart
                positions = []
                for dart in self.oderedorbit(facedart, [0, 1]):
                    if self.alpha(0, dart) != lastfart:
                        positions.append(self.get_position(dart))
                    lastfart = dart
                if color is None:
                    mat = Material(
                        (randint(0, 255), randint(0, 255), randint(0, 255)))
                else:
                    mat = Material(tuple(color), diffuse=0.25)
                s.add(
                    Shape(FaceSet(positions, [range(len(positions))]), mat,
                          facedart))
            if add:
                Viewer.add(s)
            else:
                Viewer.display(s)
Ejemplo n.º 4
0
def color_MTG_Nitrogen(g, df, t, SCREENSHOT_DIRPATH):
    def color_map(N):
        if 0 <= N <= 0.5:  # TODO: organe senescent (prendre prop)
            vid_colors = [150, 100, 0]
        elif 0.5 < N < 5:  # Fvertes
            vid_colors = [int(255 - N * 51), int(255 - N * 20), 50]
        else:
            vid_colors = [0, 155, 0]
        return vid_colors

    def calculate_Total_Organic_Nitrogen(amino_acids, proteins, Nstruct):
        """Total amount of organic N (amino acids + proteins + Nstruct).

        :param float amino_acids: Amount of amino acids (µmol N)
        :param float proteins: Amount of proteins (µmol N)
        :param float Nstruct: Structural N mass (g)

        :return: Total amount of organic N (mg)
        :rtype: float
        """
        return (amino_acids + proteins) * 14E-3 + Nstruct * 1E3

    colors = {}

    groups_df = df.groupby(['plant', 'axis', 'metamer', 'organ', 'element'])
    for vid in g.components_at_scale(g.root, scale=5):
        pid = int(g.index(g.complex_at_scale(vid, scale=1)))
        axid = g.property('label')[g.complex_at_scale(vid, scale=2)]
        mid = int(g.index(g.complex_at_scale(vid, scale=3)))
        org = g.property('label')[g.complex_at_scale(vid, scale=4)]
        elid = g.property('label')[vid]
        id_map = (pid, axid, mid, org, elid)
        if id_map in groups_df.groups.keys():
            N = (g.property('proteins')[vid] *
                 14E-3) / groups_df.get_group(id_map)['mstruct'].iloc[0]
            # N = (calculate_Total_Organic_Nitrogen(g.property('amino_acids')[vid], g.property('proteins')[vid], g.property('Nstruct')[vid])) / g.property('mstruct')[vid]
            colors[vid] = color_map(N)
        else:
            g.property('geometry')[vid] = None

    # plantgl
    s = to_plantgl(g, colors=colors)[0]
    Viewer.add(s)
    Viewer.camera.setPosition(Vector3(83.883, 12.3239, 93.4706))
    Viewer.camera.lookAt(Vector3(0., 0, 50))
    Viewer.saveSnapshot(
        os.path.join(SCREENSHOT_DIRPATH, 'Day_{}.png'.format(t / 24 + 1)))
Ejemplo n.º 5
0
 def display(self, color = [205,205,205], add = False):
   from openalea.plantgl.all import Scene, Shape, Material, FaceSet, Viewer
   from random import randint
   s = Scene()
   for facedart in self.elements(2):
       lastdart = facedart
       positions = []
       for dart in self.orderedorbit(facedart,[0,1]):
           if self.alpha(0, dart) != lastdart:
               positions.append(self.get_position(dart))
           lastdart = dart
       if color is None:
           mat = Material((randint(0,255),randint(0,255),randint(0,255)))
       else:
           mat = Material(tuple(color),diffuse=0.25)
       s.add(Shape(FaceSet(positions, [range(len(positions))]) , mat ))
   if add : Viewer.add(s)
   else : Viewer.display(s)
Ejemplo n.º 6
0
 def dartdisplay(self, add = False, textsize = None):
       from openalea.plantgl.all import Viewer
       s = self.darts2pglscene(textsize)
       if add : Viewer.add(s)
       else : Viewer.display(s)