示例#1
0
 def renderTemplate(self,tmpl,data,gm,taxis,zaxis):
   ## ok first basic template stuff, let's store the displays
   ## because we need to return actors for min/max/mean
   displays = tmpl.plot(self.canvas,data,gm,bg=self.bg)
   returned = {}
   for d in displays:
       if d is None:
         continue
       texts=d.backend.get("vtk_backend_text_actors",[])
       for t in texts:
         ## ok we had a text actor, let's see if it's min/max/mean
         txt = t.GetInput()
         s0=txt.split()[0]
         if s0 in ["Min","Max","Mean"]:
             returned["vtk_backend_%s_text_actor" % s0] = t
         else:
             returned["vtk_backend_%s_text_actor" % d.backend["vtk_backend_template_attribute"]] = t
       self.canvas.display_names.remove(d.name)
       del(vcs.elements["display"][d.name])
   ## Sometimes user passes "date" as an attribute to replace date
   if hasattr(data,"user_date"):
       taxis = cdms2.createAxis([cdtime.s2r(data.user_date,"days since 1900").value])
       taxis.designateTime()
       taxis.units="days since 1900"
       if zaxis is not None and zaxis.isTime():
           zaxis=taxis
   if taxis is not None:
     try:
       tstr = str(cdtime.reltime(taxis[0],taxis.units).tocomp(taxis.getCalendar()))
       #ok we have a time axis let's display the time
       crdate = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"crdate")
       crdate.string = tstr.split()[0].replace("-","/")
       crtime = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"crtime")
       crtime.string = tstr.split()[1]
       if not (None,None,None) in self._renderers.keys():
           ren = self.createRenderer()
           self.renWin.AddRenderer(ren)
           self.setLayer(ren,1)
           self._renderers[(None,None,None)]=ren
       else:
           ren = self._renderers[(None,None,None)]
       tt,to = crdate.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if crdate.priority>0:
           actors = vcs2vtk.genTextActor(ren,to=to,tt=tt)
           returned["vtk_backend_crdate_text_actor"]=actors[0]
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][crdate.name])
       tt,to = crtime.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if crtime.priority>0:
           actors = vcs2vtk.genTextActor(ren,to=to,tt=tt)
           returned["vtk_backend_crtime_text_actor"]=actors[0]
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][crtime.name])
     except:
         pass
   if zaxis is not None:
     try:
       # ok we have a zaxis to draw
       zname = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zname")
       zname.string=zaxis.id
       zvalue = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zvalue")
       if zaxis.isTime():
           zvalue.string = str(zaxis.asComponentTime()[0])
       else:
           zvalue.string= "%g" % zaxis[0]
       if not (None,None,None) in self._renderers.keys():
           ren = self.createRenderer()
           self.renWin.AddRenderer(ren)
           self.setLayer(ren,1)
           self._renderers[(None,None,None)]=ren
       else:
           ren = self._renderers[(None,None,None)]
       tt,to = zname.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zname.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zname.name])
       if hasattr(zaxis,"units"):
           zunits = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zunits")
           zunits.string=zaxis.units
           if zunits.priority>0:
               tt,to = zunits.name.split(":::")
               tt = vcs.elements["texttable"][tt]
               to = vcs.elements["textorientation"][to]
               vcs2vtk.genTextActor(ren,to=to,tt=tt)
               del(vcs.elements["texttable"][tt.name])
               del(vcs.elements["textorientation"][to.name])
               del(vcs.elements["textcombined"][zunits.name])
       tt,to = zvalue.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zvalue.priority>0:
           actors = vcs2vtk.genTextActor(ren,to=to,tt=tt)
           returned["vtk_backend_zvalue_text_actor"]=actors[0]
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zvalue.name])
     except:
         pass
   return returned
示例#2
0
  def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
    self.numberOfPlotCalls+=1
    created = self.createRenWin(**kargs)
    if self.bg is None:
      if bg:
        self.bg= True
      else:
        self.bg= False
        if created:
          self.initialSize()
    if bg:
        self.renWin.SetOffScreenRendering(True)
        self.renWin.SetSize(self.canvas.bgX,self.canvas.bgY)
    #self.renWin.Render()
    #screenSize = self.renWin.GetScreenSize()
    if gtype in ["boxfill","meshfill","isoline","isofill","vector"]:
      data1 = self.trimData2D(data1) # Ok get only the last 2 dims
      data2 = self.trimData2D(data2)
    #elif vcs.isgraphicsmethod(vcs.elements[gtype][gname]):
      ## oneD
    #  data1 = self.trimData1D(data1)
    #  data2 = self.trimData1D(data2)
    if gtype == "text":
      tt,to = gname.split(":::")
      tt = vcs.elements["texttable"][tt]
      to = vcs.elements["textorientation"][to]
      gm=tt
    else:
      gm = vcs.elements[gtype][gname]
    tpl = vcs.elements["template"][template]

    if kargs.get("renderer",None) is None:
        if ( gtype in ["3d_scalar", "3d_vector"] ) and (self.renderer <> None):
            ren = self.renderer
        else:
            ren = vtk.vtkRenderer()
            r,g,b = self.canvas.backgroundcolor
            ren.SetBackground(r/255.,g/255.,b/255.)
            if not (vcs.issecondaryobject(gm) and gm.priority==0):
                self.renderer = ren
                self.renWin.AddRenderer(ren)
        #ren.SetPreserveDepthBuffer(True)
    else:
      ren = kargs["renderer"]

    if gtype in ["boxfill","meshfill","isofill","isoline"]:      
      self.plot2D(data1,data2,tpl,gm,ren)
    elif gtype in ["3d_scalar", "3d_vector"]:
      self.plot3D(data1,data2,tpl,gm,ren)
    elif gtype in ["text"]:
      if tt.priority!=0:
        self.setLayer(ren,tt.priority)
        vcs2vtk.genTextActor(ren,to=to,tt=tt)
    elif gtype=="line":
      if gm.priority!=0:
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepLine(self.renWin,ren,gm)
    elif gtype=="marker":
      if gm.priority!=0:
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepMarker(self.renWin,ren,gm)
    elif gtype=="fillarea":
      if gm.priority!=0:
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepFillarea(self.renWin,ren,gm)
    elif gtype=="oned":
      self.plot1D(data1,data2,tpl,gm,ren)
    elif gtype=="vector":
      self.plotVector(data1,data2,tpl,gm,ren)
    else:
      raise Exception,"Graphic type: '%s' not re-implemented yet" % gtype
    if not kargs.get("donotstoredisplay",False):
      self.renWin.Render()
示例#3
0
  def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
    self.numberOfPlotCalls+=1
    ## these are keyargs that can be reused later by the backend.
    returned = {}
    if self.bg is None:
      if bg:
        self.bg= True
      else:
        self.bg= False
    self.createRenWin(**kargs)
    if self.bg:
        self.renWin.SetOffScreenRendering(True)
        self.renWin.SetSize(self.canvas.bgX,self.canvas.bgY)
    self.cell_coordinates=kargs.get( 'cell_coordinates', None )
    self.canvas.initLogoDrawing()
    if gtype == "text":
      tt,to = gname.split(":::")
      tt = vcs.elements["texttable"][tt]
      to = vcs.elements["textorientation"][to]
      gm=tt
    else:
      gm = vcs.elements[gtype][gname]
    tpl = vcs.elements["template"][template]

    if kargs.get("renderer",None) is None:
        if ( gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"] ) and (self.renderer <> None):
            ren = self.renderer
        else:
            #ren = self.createRenderer()
            #if not (vcs.issecondaryobject(gm) and gm.priority==0):
            #    self.setLayer(ren,tpl.data.priority)
            #    self.renderer = ren
            #    self.renWin.AddRenderer(ren)
            pass
        #ren.SetPreserveDepthBuffer(True)
    else:
      ren = kargs["renderer"]

    vtk_backend_grid = kargs.get("vtk_backend_grid",None)
    vtk_backend_geo = kargs.get("vtk_backend_geo",None)

    pipeline = vcsvtk.createPipeline(gm, self)
    if pipeline is not None:
        returned.update(pipeline.plot(data1, data2, tpl, gm,
                                      vtk_backend_grid, vtk_backend_geo))
    elif gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"]:
      cdms_file = kargs.get( 'cdmsfile', None )
      cdms_var = kargs.get( 'cdmsvar', None )
      if not cdms_var is None:
          raise Exception()
      if not cdms_file is None:
          gm.addPlotAttribute( 'file', cdms_file )
          gm.addPlotAttribute( 'filename', cdms_file )
          gm.addPlotAttribute( 'url', cdms_file )
      returned.update(self.plot3D(data1,data2,tpl,gm,ren,**kargs))
    elif gtype in ["text"]:
      if tt.priority!=0:
        #if not (None,None,None) in self._renderers.keys():
        ren = self.createRenderer()
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,1)
        #    self._renderers[(None,None,None)]=ren
        #else:
        #    ren = self._renderers[(None,None,None)]
        returned["vtk_backend_text_actors"] = vcs2vtk.genTextActor(ren,to=to,tt=tt)
        self.setLayer(ren,tt.priority)
    elif gtype=="line":
      if gm.priority!=0:
        actors = vcs2vtk.prepLine(self.renWin,gm)
        returned["vtk_backend_line_actors"]=actors
        for act,geo in actors:
            ren = self.fitToViewport(act,gm.viewport,wc=gm.worldcoordinate,geo=geo,priority=gm.priority)
    elif gtype=="marker":
      if gm.priority!=0:
        actors = vcs2vtk.prepMarker(self.renWin,gm)
        returned["vtk_backend_marker_actors"]=actors
        for g,gs,pd,act,geo in actors:
            ren = self.fitToViewport(act,gm.viewport,wc=gm.worldcoordinate,geo=geo,priority=gm.priority)
            if pd is None and act.GetUserTransform():
              vcs2vtk.scaleMarkerGlyph(g, gs, pd, act)

    elif gtype=="fillarea":
      if gm.priority!=0:
        actors = vcs2vtk.prepFillarea(self.renWin,gm)
        returned["vtk_backend_fillarea_actors"]=actors
        for act,geo in actors:
            ren = self.fitToViewport(act,gm.viewport,wc=gm.worldcoordinate,geo=geo,priority=gm.priority)
    else:
      raise Exception,"Graphic type: '%s' not re-implemented yet" % gtype
    self.scaleLogo()
    if not kargs.get("donotstoredisplay",False) and kargs.get("render", True):
      self.renWin.Render()
    return returned
示例#4
0
  def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
    self.numberOfPlotCalls+=1
    if self.bg is None:
      if bg:
        self.bg= True
      else:
        self.bg= False
    created = self.createRenWin(**kargs)
    if created:
        self.initialSize()
    if self.bg:
        self.renWin.SetOffScreenRendering(True)
        self.renWin.SetSize(self.canvas.bgX,self.canvas.bgY)
    self.cell_coordinates=kargs.get( 'cell_coordinates', None )
    #self.renWin.Render()
    #screenSize = self.renWin.GetScreenSize()
    if gtype in ["boxfill","meshfill","isoline","isofill","vector"]:
      data1 = self.trimData2D(data1) # Ok get only the last 2 dims
      if gtype!="meshfill":
        data2 = self.trimData2D(data2)
    #elif vcs.isgraphicsmethod(vcs.elements[gtype][gname]):
      ## oneD
    #  data1 = self.trimData1D(data1)
    #  data2 = self.trimData1D(data2)
    if gtype == "text":
      tt,to = gname.split(":::")
      tt = vcs.elements["texttable"][tt]
      to = vcs.elements["textorientation"][to]
      gm=tt
    else:
      gm = vcs.elements[gtype][gname]
    tpl = vcs.elements["template"][template]

    if kargs.get("renderer",None) is None:
        if ( gtype in ["3d_scalar", "3d_vector"] ) and (self.renderer <> None):
            ren = self.renderer
        else:
            ren = vtk.vtkRenderer()
            r,g,b = self.canvas.backgroundcolor
            ren.SetBackground(r/255.,g/255.,b/255.)
            if not (vcs.issecondaryobject(gm) and gm.priority==0):
                self.renderer = ren
                self.renWin.AddRenderer(ren)
        #ren.SetPreserveDepthBuffer(True)
    else:
      ren = kargs["renderer"]

    if gtype in ["boxfill","meshfill","isofill","isoline"]:      
      self.plot2D(data1,data2,tpl,gm)
    elif gtype in ["3d_scalar", "3d_vector"]:
      cdms_file = kargs.get( 'cdmsfile', None )
      cdms_var = kargs.get( 'cdmsvar', None )
      if not cdms_var is None:
          raise Exception()
      if not cdms_file is None:
          gm.addPlotAttribute( 'file', cdms_file )
          gm.addPlotAttribute( 'filename', cdms_file )
          gm.addPlotAttribute( 'url', cdms_file )
      self.plot3D(data1,data2,tpl,gm,ren,**kargs)
    elif gtype in ["text"]:
      if tt.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,tt.priority)
        vcs2vtk.genTextActor(ren,to=to,tt=tt)
    elif gtype=="line":
      if gm.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepLine(self.renWin,ren,gm)
    elif gtype=="marker":
      if gm.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepMarker(self.renWin,ren,gm)
    elif gtype=="fillarea":
      if gm.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepFillarea(self.renWin,ren,gm)
    elif gtype=="oned":
      self.renWin.AddRenderer(ren)
      self.plot1D(data1,data2,tpl,gm,ren)
    elif gtype=="vector":
      self.plotVector(data1,data2,tpl,gm)
    else:
      raise Exception,"Graphic type: '%s' not re-implemented yet" % gtype
    if not kargs.get("donotstoredisplay",False): 
      self.renWin.Render()
示例#5
0
  def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
    self.numberOfPlotCalls+=1
    if self.bg is None:
      if bg:
        self.bg= True
      else:
        self.bg= False
    created = self.createRenWin(**kargs)
    if created:
        self.initialSize()
    if self.bg:
        self.renWin.SetOffScreenRendering(True)
        self.renWin.SetSize(self.canvas.bgX,self.canvas.bgY)
    self.cell_coordinates=kargs.get( 'cell_coordinates', None )
    #self.renWin.Render()
    #screenSize = self.renWin.GetScreenSize()
    if gtype == "text":
      tt,to = gname.split(":::")
      tt = vcs.elements["texttable"][tt]
      to = vcs.elements["textorientation"][to]
      gm=tt
    else:
      gm = vcs.elements[gtype][gname]
    tpl = vcs.elements["template"][template]

    if kargs.get("renderer",None) is None:
        if ( gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"] ) and (self.renderer <> None):
            ren = self.renderer
        else:
            ren = self.createRenderer()
            if not (vcs.issecondaryobject(gm) and gm.priority==0):
                self.setLayer(ren,tpl.data.priority)
                self.renderer = ren
                self.renWin.AddRenderer(ren)
        #ren.SetPreserveDepthBuffer(True)
    else:
      ren = kargs["renderer"]

    if gtype in ["boxfill","meshfill","isofill","isoline"]:
      self.plot2D(data1,data2,tpl,gm)
    elif gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"]:
      cdms_file = kargs.get( 'cdmsfile', None )
      cdms_var = kargs.get( 'cdmsvar', None )
      if not cdms_var is None:
          raise Exception()
      if not cdms_file is None:
          gm.addPlotAttribute( 'file', cdms_file )
          gm.addPlotAttribute( 'filename', cdms_file )
          gm.addPlotAttribute( 'url', cdms_file )
      self.plot3D(data1,data2,tpl,gm,ren,**kargs)
    elif gtype in ["text"]:
      if tt.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,tt.priority)
        vcs2vtk.genTextActor(ren,to=to,tt=tt)
    elif gtype=="line":
      if gm.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepLine(self.renWin,ren,gm)
    elif gtype=="marker":
      if gm.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepMarker(self.renWin,ren,gm)
    elif gtype=="fillarea":
      if gm.priority!=0:
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,gm.priority)
        vcs2vtk.prepFillarea(self.renWin,ren,gm)
    elif gtype=="1d":
      self.renWin.AddRenderer(ren)
      self.plot1D(data1,data2,tpl,gm,ren)
    elif gtype=="vector":
      self.plotVector(data1,data2,tpl,gm)
    else:
      raise Exception,"Graphic type: '%s' not re-implemented yet" % gtype
    if self.logo is None:
      self.createLogo()
    if self.renWin.GetSize()!=(0,0):
      self.scaleLogo()
    if not kargs.get("donotstoredisplay",False):
      self.renWin.Render()
示例#6
0
 def renderTemplate(self,tmpl,data,gm,taxis,zaxis):
   tmpl.plot(self.canvas,data,gm,bg=self.bg)
   if taxis is not None:
       tstr = str(cdtime.reltime(taxis[0],taxis.units).tocomp(taxis.getCalendar()))
       #ok we have a time axis let's display the time
       crdate = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"crdate")
       crdate.string = tstr.split()[0].replace("-","/")
       crtime = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"crtime")
       crtime.string = tstr.split()[1]
       ren = self.createRenderer()
       self.renWin.AddRenderer(ren)
       self.setLayer(ren,1)
       tt,to = crdate.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if crdate.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][crdate.name])
       tt,to = crtime.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if crtime.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][crtime.name])
   if zaxis is not None:
       # ok we have a zaxis to draw
       zname = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zname")
       zname.string=zaxis.id
       zunits = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zunits")
       zunits.string=zaxis.units
       zvalue = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zvalue")
       if zaxis.isTime():
           zvalue.string = str(zaxis.asComponentTime()[0])
       else:
           zvalue.string= "%g" % zaxis[0]
       ren = self.createRenderer()
       self.setLayer(ren,1)
       self.renWin.AddRenderer(ren)
       tt,to = zname.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zname.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zname.name])
       tt,to = zunits.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zunits.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zunits.name])
       tt,to = zvalue.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zvalue.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zvalue.name])
示例#7
0
 def renderTemplate(self,tmpl,data,gm,taxis,zaxis):
   ## ok first basic template stuff, let's store the displays
   ## because we need to return actors for min/max/mean
   displays = tmpl.plot(self.canvas,data,gm,bg=self.bg)
   returned = {}
   for d in displays:
       if d is None:
         continue
       texts=d.backend.get("vtk_backend_text_actors",[])
       for t in texts:
         ## ok we had a text actor, let's see if it's min/max/mean
         txt = t.GetInput()
         s0=txt.split()[0]
         if s0 in ["Min","Max","Mean"]:
             returned["vtk_backend_%s_text_actor" % s0] = t
         else:
             returned["vtk_backend_%s_text_actor" % d.backend["vtk_backend_template_attribute"]] = t
       self.canvas.display_names.remove(d.name)
       del(vcs.elements["display"][d.name])
   if taxis is not None:
     try:
       tstr = str(cdtime.reltime(taxis[0],taxis.units).tocomp(taxis.getCalendar()))
       #ok we have a time axis let's display the time
       crdate = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"crdate")
       crdate.string = tstr.split()[0].replace("-","/")
       crtime = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"crtime")
       crtime.string = tstr.split()[1]
       if not (None,None,None) in self._renderers.keys():
           ren = self.createRenderer()
           self.renWin.AddRenderer(ren)
           self.setLayer(ren,1)
           self._renderers[(None,None,None)]=ren
       else:
           ren = self._renderers[(None,None,None)]
       tt,to = crdate.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if crdate.priority>0:
           actors = vcs2vtk.genTextActor(ren,to=to,tt=tt)
           returned["vtk_backend_crdate_text_actor"]=actors[0]
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][crdate.name])
       tt,to = crtime.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if crtime.priority>0:
           actors = vcs2vtk.genTextActor(ren,to=to,tt=tt)
           returned["vtk_backend_crtime_text_actor"]=actors[0]
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][crtime.name])
     except:
         pass
   if zaxis is not None:
     try:
       # ok we have a zaxis to draw
       zname = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zname")
       zname.string=zaxis.id
       zvalue = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zvalue")
       if zaxis.isTime():
           zvalue.string = str(zaxis.asComponentTime()[0])
       else:
           zvalue.string= "%g" % zaxis[0]
       if not (None,None,None) in self._renderers.keys():
           ren = self.createRenderer()
           self.renWin.AddRenderer(ren)
           self.setLayer(ren,1)
           self._renderers[(None,None,None)]=ren
       else:
           ren = self._renderers[(None,None,None)]
       tt,to = zname.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zname.priority>0:
           vcs2vtk.genTextActor(ren,to=to,tt=tt)
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zname.name])
       if hasattr(zaxis,"units"):
           zunits = vcs2vtk.applyAttributesFromVCStmpl(tmpl,"zunits")
           zunits.string=zaxis.units
           if zunits.priority>0:
               tt,to = zunits.name.split(":::")
               tt = vcs.elements["texttable"][tt]
               to = vcs.elements["textorientation"][to]
               vcs2vtk.genTextActor(ren,to=to,tt=tt)
               del(vcs.elements["texttable"][tt.name])
               del(vcs.elements["textorientation"][to.name])
               del(vcs.elements["textcombined"][zunits.name])
       tt,to = zvalue.name.split(":::")
       tt = vcs.elements["texttable"][tt]
       to = vcs.elements["textorientation"][to]
       if zvalue.priority>0:
           actors = vcs2vtk.genTextActor(ren,to=to,tt=tt)
           returned["vtk_backend_zvalue_text_actor"]=actors[0]
       del(vcs.elements["texttable"][tt.name])
       del(vcs.elements["textorientation"][to.name])
       del(vcs.elements["textcombined"][zvalue.name])
     except:
         pass
   return returned
示例#8
0
  def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
    self.numberOfPlotCalls+=1
    ## these are keyargs that can be reused later by the backend.
    returned = {}
    if self.bg is None:
      if bg:
        self.bg= True
      else:
        self.bg= False
    self.createRenWin(**kargs)
    if self.bg:
        self.renWin.SetOffScreenRendering(True)
        self.renWin.SetSize(self.canvas.bgX,self.canvas.bgY)
    self.cell_coordinates=kargs.get( 'cell_coordinates', None )
    self.canvas.initLogoDrawing()
    if gtype == "text":
      tt,to = gname.split(":::")
      tt = vcs.elements["texttable"][tt]
      to = vcs.elements["textorientation"][to]
      gm=tt
    else:
      gm = vcs.elements[gtype][gname]
    tpl = vcs.elements["template"][template]

    if kargs.get("renderer",None) is None:
        if ( gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"] ) and (self.renderer <> None):
            ren = self.renderer
        else:
            #ren = self.createRenderer()
            #if not (vcs.issecondaryobject(gm) and gm.priority==0):
            #    self.setLayer(ren,tpl.data.priority)
            #    self.renderer = ren
            #    self.renWin.AddRenderer(ren)
            pass
        #ren.SetPreserveDepthBuffer(True)
    else:
      ren = kargs["renderer"]

    vtk_backend_grid = kargs.get("vtk_backend_grid",None)
    vtk_backend_geo = kargs.get("vtk_backend_geo",None)

    pipeline = vcsvtk.createPipeline(gm, self)
    if pipeline is not None:
        returned.update(pipeline.plot(data1, data2, tpl, gm,
                                      vtk_backend_grid, vtk_backend_geo))
    elif gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"]:
      cdms_file = kargs.get( 'cdmsfile', None )
      cdms_var = kargs.get( 'cdmsvar', None )
      if not cdms_var is None:
          raise Exception()
      if not cdms_file is None:
          gm.addPlotAttribute( 'file', cdms_file )
          gm.addPlotAttribute( 'filename', cdms_file )
          gm.addPlotAttribute( 'url', cdms_file )
      returned.update(self.plot3D(data1,data2,tpl,gm,ren,**kargs))
    elif gtype in ["text"]:
      if tt.priority!=0:
        #if not (None,None,None) in self._renderers.keys():
        ren = self.createRenderer()
        self.renWin.AddRenderer(ren)
        self.setLayer(ren,1)
        #    self._renderers[(None,None,None)]=ren
        #else:
        #    ren = self._renderers[(None,None,None)]
        returned["vtk_backend_text_actors"] = vcs2vtk.genTextActor(ren,to=to,tt=tt)
        self.setLayer(ren,tt.priority)
    elif gtype=="line":
      if gm.priority!=0:
        actors = vcs2vtk.prepLine(self.renWin,gm)
        returned["vtk_backend_line_actors"]=actors
        for act,geo in actors:
            ren = self.fitToViewport(act,gm.viewport,wc=gm.worldcoordinate,geo=geo,priority=gm.priority)
    elif gtype=="marker":
      if gm.priority!=0:
        actors = vcs2vtk.prepMarker(self.renWin,gm)
        returned["vtk_backend_marker_actors"]=actors
        for g,gs,pd,act,geo in actors:
            ren = self.fitToViewport(act,gm.viewport,wc=gm.worldcoordinate,geo=geo,priority=gm.priority)
            if pd is None and act.GetUserTransform():
              vcs2vtk.scaleMarkerGlyph(g, gs, pd, act)

    elif gtype=="fillarea":
      if gm.priority!=0:
        actors = vcs2vtk.prepFillarea(self.renWin,gm)
        returned["vtk_backend_fillarea_actors"]=actors
        for act,geo in actors:
            ren = self.fitToViewport(act,gm.viewport,wc=gm.worldcoordinate,geo=geo,priority=gm.priority)
    else:
      raise Exception,"Graphic type: '%s' not re-implemented yet" % gtype
    self.scaleLogo()
    if not kargs.get("donotstoredisplay",False) and kargs.get("render", True):
      self.renWin.Render()
    return returned