示例#1
0
 def plot(self, index=None):
     from tests import plot_whiskers
     from pylab import cm
     cmap = lambda i: cm.spectral(i / float(len(self._paths)))
     if index is None:
         for i, p in enumerate(self._paths):
             plot_whiskers([e for e in p if e], color=cmap(i))
     else:
         p = list(self._paths)[index]
         plot_whiskers([e for e in p if e], color=cmap(index))
示例#2
0
 def plot(self, index = None):
   from tests import plot_whiskers
   from pylab import cm
   cmap = lambda i: cm.spectral( i/float(len(self._paths)) )
   if index is None:
     for i,p in enumerate(self._paths):
       plot_whiskers( [e for e in p if e], color = cmap(i) )
   else:
     p = list(self._paths)[index]
     plot_whiskers( [e for e in p if e], color = cmap(index) )
示例#3
0
 def update( self, newpaths, owner, stubs ):
   if 0:
     from pylab import plot, cla, show
     from tests import plot_whiskers
     cla()
     plot(owner.x,owner.y,'k',linewidth=3)
     plot_whiskers([e for e in p if e],marker='x')
     show()
   issame = lambda a,b: (a is not None) and (a==b) # true implies (b is not None) 
   br = stubs[owner]                     
   if br:
     didmerge = False
     l,m,r = br                               # Filter paths to make sure only new paths   
     for p in newpaths:
       if (not (l or r)) or issame(l,p[0]) or issame(r,p[-1]):  #   corresponding to `owner` are substituted
         self._merge( owner, p )
         didmerge = True
     if not didmerge:             # There was a break
       self._merge( owner, None ) # But there was no parent path found that sourced the break...
示例#4
0
 def update(self, newpaths, owner, stubs):
     if 0:
         from pylab import plot, cla, show
         from tests import plot_whiskers
         cla()
         plot(owner.x, owner.y, 'k', linewidth=3)
         plot_whiskers([e for e in p if e], marker='x')
         show()
     issame = lambda a, b: (a is not None) and (
         a == b)  # true implies (b is not None)
     br = stubs[owner]
     if br:
         didmerge = False
         l, m, r = br  # Filter paths to make sure only new paths
         for p in newpaths:
             if (not (l or r)) or issame(l, p[0]) or issame(
                     r,
                     p[-1]):  #   corresponding to `owner` are substituted
                 self._merge(owner, p)
                 didmerge = True
         if not didmerge:  # There was a break
             self._merge(
                 owner, None
             )  # But there was no parent path found that sourced the break...
示例#5
0
    def compute_pairwise_conflict_paths(a, b, prune):
        """ 
    a and b are each tuples of (whisker, hitindex), as returned from CollisionTable.next()  

    Returns a set of tuples.
    """
        bnda, bndb = trace_overlap(a, b)
        la, ma, ra = breakout(a[0], bnda)
        lb, mb, rb = breakout(b[0], bndb)
        ownership = {a[0]: (la, ma, ra), b[0]: (lb, mb, rb)}
        if not ma or not mb or prune(ma) or prune(mb):
            ownership = {a[0]: None, b[0]: None}
            pset = set()
            return pset, ownership

        pset = [[la, ma, ra], [la, ma, mb, rb], [lb, mb, ma, ra], [lb, mb, rb]]
        #prune
        for p in pset:
            for i, w in enumerate(p):
                if w and prune(w):
                    p[i] = None

        #transform to set of tuples
        pset = set([tuple(e) for e in pset])

        #0. Path's must have legititmate middle nodes.
        for p in list(pset):
            if len(p) == 3 and p[1] is None:
                pset.remove(p)
            elif len(p) == 4 and (p[1] is None or p[2] is None):
                pset.remove(p)

        #reduction
        hasfullpath = False
        # 1. Remove if can't get from left to right
        for p in list(pset):
            if p[0] is None and p[-1] is None:
                pset.discard(p)
            if p[0] is not None and p[-1] is not None:
                hasfullpath = True

        # 2. if only overlap, return composite of overlap
        if len(pset
               ) == 0:  #no endpoints - this happens for middle-only overlaps
            m = max((ma, mb), key=lambda w: w.scores.mean())
            ownership = {a[0]: (None, m, None), b[0]: (None, m, None)}
            #ownership = {a[0]:None, b[0]:None}
            pset = set(((None, m, None), ))  #return best scoring
            return pset, ownership

        # 3. if there is at least one path from left to right, remove paths that
        #    don't
        if hasfullpath:
            for p in list(pset):
                if p[0] is None or p[-1] is None:
                    pset.discard(p)
        else:
            # 4. if not, path's should not begin or end on merged middles
            for p in list(pset):
                if len(p) == 4 and (p[0] is None or p[-1] is None):
                    pset.discard(p)

        if 0:
            from tests import plot_whiskers
            from pylab import cm, clf, show
            cmap = lambda i: cm.spectral(i / float(len(pset)))
            for i, p in enumerate(pset):
                plot_whiskers([e for e in p if e], color=cmap(i))
            show()

        return pset, ownership
示例#6
0
  def compute_pairwise_conflict_paths( a, b, prune ):
    """ 
    a and b are each tuples of (whisker, hitindex), as returned from CollisionTable.next()  

    Returns a set of tuples.
    """
    bnda,bndb = trace_overlap(a,b)
    la,ma,ra = breakout(a[0],bnda)
    lb,mb,rb = breakout(b[0],bndb)
    ownership = {a[0]:(la,ma,ra), b[0]:(lb,mb,rb)}
    if not ma or not mb or prune(ma) or prune(mb):
      ownership = {a[0]:None, b[0]:None}
      pset = set()
      return pset, ownership

    pset =     [  [ la, ma,     ra ], 
                  [ la, ma, mb, rb ], 
                  [ lb, mb, ma, ra ], 
                  [ lb, mb,     rb ] ] 
    #prune
    for p in pset:
      for i,w in enumerate(p):
        if w and prune(w):
          p[i] = None

    #transform to set of tuples
    pset = set( [tuple(e) for e in pset] ) 

    #0. Path's must have legititmate middle nodes.
    for p in list(pset):
      if len(p)==3 and p[1] is None:
        pset.remove(p)
      elif len(p)==4 and ( p[1] is None or p[2] is None ):
        pset.remove(p)

    #reduction
    hasfullpath = False
    # 1. Remove if can't get from left to right
    for p in list(pset):
      if p[0] is None and p[-1] is None:
        pset.discard(p)
      if p[0] is not None and p[-1] is not None:
        hasfullpath = True

    # 2. if only overlap, return composite of overlap 
    if len(pset)==0: #no endpoints - this happens for middle-only overlaps
      m = max( (ma,mb), key = lambda w: w.scores.mean() )
      ownership = {a[0]:(None,m,None), b[0]:(None,m,None)}
      #ownership = {a[0]:None, b[0]:None}
      pset = set( ((None,m,None),) ) #return best scoring
      return pset, ownership

    # 3. if there is at least one path from left to right, remove paths that
    #    don't
    if hasfullpath:
      for p in list(pset):
        if p[0] is None or p[-1] is None:
          pset.discard(p)
    else:
      # 4. if not, path's should not begin or end on merged middles
      for p in list(pset):
        if len(p)==4 and ( p[0] is None or p[-1] is None ):
          pset.discard(p)
          
    if 0:
      from tests import plot_whiskers
      from pylab import cm, clf, show
      cmap = lambda i: cm.spectral( i/float(len(pset)) )
      for i,p in enumerate(pset):
        plot_whiskers([e for e in p if e], color = cmap(i))
      show()

    return pset,ownership