当前位置: 首页>>代码示例>>Python>>正文


Python GeomUtils.strokeNormalizeSpacing方法代码示例

本文整理汇总了Python中Utils.GeomUtils.strokeNormalizeSpacing方法的典型用法代码示例。如果您正苦于以下问题:Python GeomUtils.strokeNormalizeSpacing方法的具体用法?Python GeomUtils.strokeNormalizeSpacing怎么用?Python GeomUtils.strokeNormalizeSpacing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Utils.GeomUtils的用法示例。


在下文中一共展示了GeomUtils.strokeNormalizeSpacing方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onStrokeAdded

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
    def onStrokeAdded(self, stroke):
        "Tags 1's and 0's as letters (TextAnnotation)"
        closedDistRatio = 0.22
        circularityThresh_0 = 0.80
        circularityThresh_1 = 0.20
        strokeLen = max(GeomUtils.strokeLength(stroke), 1)
        normDist = max(3, strokeLen / 5)
        head, tail = stroke.Points[0], stroke.Points[-1]

        endDist = GeomUtils.pointDistance(head.X, head.Y, tail.X, tail.Y)
        #If the endpoints are 1/thresh apart, actually close the thing
        isClosedShape = GeomUtils.pointDistanceSquared(head.X, head.Y, tail.X, tail.Y) \
                        < (strokeLen * closedDistRatio) ** 2

        if isClosedShape: #Close the shape back up
            s_norm = GeomUtils.strokeNormalizeSpacing( Stroke(stroke.Points + [stroke.Points[0]]) , normDist ) 
        else:
            s_norm = GeomUtils.strokeNormalizeSpacing( stroke , normDist ) 
        curvatures = GeomUtils.strokeGetPointsCurvature(s_norm)
        circularity = GeomUtils.strokeCircularity( s_norm ) 

        if isClosedShape and circularity > circularityThresh_0:
            height = stroke.BoundTopLeft.Y - stroke.BoundBottomRight.Y
            oAnnotation = TextAnnotation("0", height)
            l_logger.debug("Annotating %s with %s" % ( stroke, oAnnotation))
            BoardSingleton().AnnotateStrokes( [stroke],  oAnnotation)
            l_logger.debug(" Afterward: %s.annotations is %s" % ( stroke, stroke.Annotations))

        elif len(stroke.Points) >= 2 \
            and max(curvatures) < 0.5 \
            and circularity < circularityThresh_1:
                if stroke.Points[0].X < stroke.Points[-1].X + strokeLen / 2.0 \
                and stroke.Points[0].X > stroke.Points[-1].X - strokeLen / 2.0:
                    height = stroke.BoundTopLeft.Y - stroke.BoundBottomRight.Y
                    oneAnnotation = TextAnnotation("1", height)
                    l_logger.debug("Annotating %s with %s" % ( stroke, oneAnnotation.text))
                    BoardSingleton().AnnotateStrokes( [stroke],  oneAnnotation)
                    l_logger.debug(" Afterward: %s.annotations is %s" % ( stroke, stroke.Annotations))
                elif stroke.Points[0].Y < stroke.Points[-1].Y + strokeLen / 2.0 \
                and stroke.Points[0].Y > stroke.Points[-1].Y - strokeLen / 2.0:
                    width = stroke.BoundBottomRight.X - stroke.BoundTopLeft.X 
                    dashAnnotation = TextAnnotation("-", width * 1.5) #Treat the dash's (boosted) width as its scale 
                    l_logger.debug("Annotating %s with %s" % ( stroke, dashAnnotation.text))
                    BoardSingleton().AnnotateStrokes( [stroke],  dashAnnotation)
        else:
            if not isClosedShape:
                l_logger.debug("0: Not a closed shape")
            if not (circularity > circularityThresh_0):
                l_logger.debug("0: Not circular enough: %s" % (circularity))
            if not len(stroke.Points) >= 2:
                l_logger.debug("1: Not enough points")
            if not (circularity < circularityThresh_1):
                l_logger.debug("1: Too circular")
            if not (max(curvatures) < 0.5):
                l_logger.debug("1: Max curvature too big %s" % max(curvatures))
            if not ( stroke.Points[0].X < stroke.Points[-1].X + strokeLen / 3 \
               and   stroke.Points[0].X > stroke.Points[-1].X - strokeLen / 3):
                l_logger.debug("1: Not vertical enough: \nX1 %s, \nX2 %s, \nLen %s" % (stroke.Points[0].X, stroke.Points[-1].X, strokeLen))
开发者ID:loserpenguin15,项目名称:UCSBsketch,代码行数:60,代码来源:TextObserver.py

示例2: _scoreStroke

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
def _scoreStroke(stroke, template, sample_size = None):
    
    if sample_size is None:
        sample_size = len(template)
        
    sNorm = GeomUtils.strokeNormalizeSpacing(stroke, len(template))
    centr = GeomUtils.centroid(sNorm.Points)
    numPoints = len(sNorm.Points)
    
    point_vect = []
    templ_vect = []

    numPoints = len(template)
    if len(template) == len(sNorm.Points):
        for idx in range(0, numPoints, numPoints/sample_size ):
            templ_vect.append(template[idx].X)
            templ_vect.append(template[idx].Y)
            
            p = sNorm.Points[idx]
            point_vect.append(p.X - centr.X)
            point_vect.append(p.Y - centr.Y)
       
        angularDist = GeomUtils.vectorDistance(point_vect, templ_vect)
    else:
        angularDist = math.pi
    return angularDist
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:28,代码来源:Template.py

示例3: SaveTemplate

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
 def SaveTemplate(self, numSamples = TEMPLATE_SAMPLE):
     if len(self.StrokeList) > 0:
         last_stroke = self.StrokeList[-1]
         template_name = str(len(self.StrokeList))
         sNorm = GeomUtils.strokeNormalizeSpacing(last_stroke, numSamples)
         centroid = GeomUtils.centroid(sNorm.Points)
         sNorm = sNorm.translate(-1*centroid.X, -1 * centroid.Y)
         storeTemplate(sNorm, tag=template_name)
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:10,代码来源:TkTemplateInput.py

示例4: refreshTuringMachines

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
    def refreshTuringMachines(self):
        labelEdgeMatchingThresh = 2000 # how many times greater than the median we'll match edges

        labelEdgeMatches = {} # { label : {edge, distance} }

        for tmAnno in set(self.tmMap.keys()):
            BoardSingleton().RemoveAnnotation(tmAnno)
            del(self.tmMap[tmAnno])

        for textAnno in self.labelMap.keys():
            labelTL, labelBR = GeomUtils.strokelistBoundingBox(textAnno.Strokes)
            #Midpoint of the labe's bounding box
            labelCenterPt = Point ( (labelTL.X + labelBR.X) / 2.0, (labelTL.Y + labelBR.Y) / 2.0) 

            labelMatchDict = labelEdgeMatches.setdefault(textAnno, {}) 

            for graphAnno in self.graphMap:
                #Match edges to labels
                for edgeAnno in graphAnno.edge_set:
                    edgeLabelPoints = GeomUtils.strokeNormalizeSpacing(edgeAnno.tailstroke, 19).Points #Midpoint in the arrow-stroke
                    for elp in edgeLabelPoints:
                        dist = GeomUtils.pointDistanceSquared(elp.X, elp.Y, labelCenterPt.X, labelCenterPt.Y)
                        #labelMatchDict['allmatches'].append({'anno': edgeAnno, 'dist': dist})
                        if 'bestmatch' not in labelMatchDict or dist < labelMatchDict['bestmatch'][1]:
                            labelMatchDict['bestmatch'] = (edgeAnno, dist)

        #labelEdgeMatches contains each label paired with its best edge
        
        #Have each edge claim a label
        edge2LabelMatching = {}
        for textAnno, matchDict in labelEdgeMatches.items():
            if 'bestmatch' in matchDict: # and matchDict['bestmatch'][1] < labelEdgeMatchingThresh:
                edgeLabelList = edge2LabelMatching.setdefault(matchDict['bestmatch'][0], [])
                edgeLabelList.append(textAnno)
            else:
                tm_logger.debug("TextAnno %s not matched to an edge" % (textAnno.text))

        #Make the associations and add the turing machine annotation
        for graphAnno, tmAnno in self.graphMap.items():
            assocSet = set([graphAnno])
            shouldAddAnno = False
            if tmAnno == None:
                shouldAddAnno = True
                tmAnno = TuringMachineAnnotation(state_graph_anno = graphAnno)

            for edgeAnno in graphAnno.edge_set:
                if edge2LabelMatching.get(edgeAnno, None) is not None:
                    assocLabelsList = edge2LabelMatching[edgeAnno]
                    for label in assocLabelsList:
                        assocSet.add(label)
                        tmAnno.assocLabel2Edge(label, edgeAnno)

            if shouldAddAnno:
                BoardSingleton().AnnotateStrokes(tmAnno.getAssociatedStrokes(), tmAnno)
                self.tmMap[tmAnno] = assocSet
            else:
                BoardSingleton().UpdateAnnotation(tmAnno, new_strokes = tmAnno.getAssociatedStrokes())
                self.tmMap[tmAnno] = assocSet
开发者ID:loserpenguin15,项目名称:UCSBsketch,代码行数:60,代码来源:TuringMachineObserver.py

示例5: onStrokeAdded

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
    def onStrokeAdded( self, stroke ):
        "Watches for Strokes that look like an arrow to Annotate"
        ep1 = stroke.Points[0]
        ep2 = stroke.Points[-1]
        isArrowHead = False
        GeomUtils.ellipseAxisRatio(stroke)

        #Match single-stroke arrows
        tip, tail = _isSingleStrokeArrow(stroke)
        if tip is None or tail is None:
            revpts = list(stroke.Points)
            revpts.reverse()
            tip, tail = _isSingleStrokeArrow(Stroke(revpts))
        
        if  tip is not None and tail is not None:
            isArrowHead = False
            anno = ArrowAnnotation( tip, tail )
            BoardSingleton().AnnotateStrokes( [stroke],  anno)
        else:
            return
            if _isArrowHead(stroke, self.arrowHeadMatcher): #We've matched an arrowhead
                head = stroke
                isArrowHead = True
                strokeNorm = GeomUtils.strokeNormalizeSpacing(stroke, numpoints = 5)
                tip = strokeNorm.Points[2] #Middle normalized point is the tip
                
        
        #Match it to any tails we have
        if isArrowHead:
            matchedTails = self._matchHeadtoTail(head = stroke, point = tip)
            for headpoint, tail in matchedTails:
                #Orient the tail correctly
                if tail.Points[0] == headpoint:
                    endpoint = tail.Points[-1]
                else:
                    endpoint = tail.Points[0]
                anno = ArrowAnnotation(tip, endpoint)
                BoardSingleton().AnnotateStrokes([head, tail],anno)
        
        #Match it like a tail even if we think it's an arrowhead. Oh ambiguity!
        matchedHeads = self._matchHeadtoTail(tail = stroke, point = ep1)
        for tip, head in matchedHeads:
            anno = ArrowAnnotation(tip, ep2)
            BoardSingleton().AnnotateStrokes([head, stroke],anno)
            
        matchedHeads = self._matchHeadtoTail(tail = stroke, point = ep2)
        for tip, head in matchedHeads:
            anno = ArrowAnnotation(tip, ep1)
            BoardSingleton().AnnotateStrokes([head, stroke],anno)
        
        #Add this stroke to the pool for future evaluation
        self._endpoints.append( (ep1, stroke) )
        self._endpoints.append( (ep2, stroke) )
        if isArrowHead:
            self._arrowHeads.append( (tip, stroke) )
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:57,代码来源:ArrowObserver.py

示例6: _isArrowHead

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
def _isArrowHead(stroke, matcher):
    
    numPts = 11
    sNorm = GeomUtils.strokeNormalizeSpacing(stroke, numpoints = numPts)
    curvatures = GeomUtils.strokeGetPointsCurvature(sNorm)
    maxCurv = max(curvatures)
    maxCurvIdx = curvatures.index(maxCurv)
    #Make sure the max curvature is roughly in the middle of the stroke before even bothering
    #   with more complicated checks
    if maxCurvIdx > (numPts / 5.0) and maxCurvIdx < ( 4 * numPts / 5.0): 
        strkLen = GeomUtils.strokeLength(stroke)
        arrowHeadStroke = GeomUtils.strokeNormalizeSpacing(Stroke([sNorm.Points[0], sNorm.Points[maxCurvIdx], sNorm.Points[-1]]), numpoints = strkLen) #What would the approximated arrowhead look like?
        origStroke = GeomUtils.strokeNormalizeSpacing(stroke, numpoints = strkLen)
        approxAcc = GeomUtils.strokeDTWDist(sNorm, arrowHeadStroke)
        #logger.debug("Stroke approximates arrowhead with %s accuracy" % (approxAcc))

        return approxAcc < 500000
        #_isArrowHead_Template(stroke, matcher) or _isArrowHead_Template(Stroke(list(reversed(stroke.Points))), matcher)
    
    return False
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:22,代码来源:ArrowObserver.py

示例7: scoreStroke

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
def scoreStroke(stroke, template):
    sNorm = GeomUtils.strokeNormalizeSpacing(stroke, TEMPLATE_SAMPLE)
    centr = GeomUtils.centroid(sNorm.Points)
    point_vect = []
    templ_vect = []
    for q in template:
       templ_vect.append(q.X)
       templ_vect.append(q.Y)
    for p in sNorm.Points:
       point_vect.append(p.X - centr.X)
       point_vect.append(p.Y - centr.Y)
    angularDist = GeomUtils.vectorDistance(point_vect, templ_vect)
    return angularDist
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:15,代码来源:TkTemplateInput.py

示例8: tagBox

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
    def tagBox(self, stroke):

        endPointDistPct = 0.10 #How close (as % of length) the points have to be to each other
        boxApproxThresh = 50000 #The DTW distance between the stroke and how it best fits a box
        stkLen = GeomUtils.strokeLength(stroke)
        ep1, ep2 = stroke.Points[0], stroke.Points[-1]
        epDistSqr = GeomUtils.pointDistanceSquared(ep1.X, ep1.Y, ep2.X, ep2.Y)
        if  epDistSqr > (endPointDistPct * stkLen) ** 2:
            print "Endpoints aren't close enough to be a box"
            return
        overshoot = max(1, len(stroke.Points)/10)
        norm_stroke = GeomUtils.strokeSmooth(GeomUtils.strokeNormalizeSpacing(Stroke(stroke.Points + stroke.Points[0:overshoot]), numpoints = 70))
        #D.strokeCurvatureHistogram(norm_stroke)
        curvatures = GeomUtils.strokeGetPointsCurvature(norm_stroke)
        corners = set([])
        curvatures_cpy = list(curvatures)
        while len(corners) < 4:
            crnr_idx = curvatures_cpy.index(max(curvatures_cpy))
            crnr = curvatures_cpy[crnr_idx] * 57.295
            for nBor in range(crnr_idx -2, crnr_idx + 3):
                if nBor < len(curvatures_cpy) and nBor > 0:
                    curvatures_cpy[nBor] = 0
            if crnr > 0: #30 and crnr < 150:
                #Have a curvature, and we haven't already classified its immed neighbors as a corner
                corners.add(crnr_idx)
            else:
                break
        if len(corners) != 4:
            return
        else:
            c_list = [norm_stroke.Points[c_idx] for c_idx in sorted(list(corners))]
            cornerStroke = Stroke(c_list + c_list[:2])
            boxStroke = GeomUtils.strokeNormalizeSpacing(Stroke(c_list + [c_list[0]]))
            origStroke = GeomUtils.strokeNormalizeSpacing(Stroke(stroke.Points + [stroke.Points[0]]))
            approxAcc = GeomUtils.strokeDTWDist(boxStroke, origStroke)
            print "Box approximates original with %s accuracy" % (approxAcc)
            if approxAcc < boxApproxThresh:
                self.getBoard().AnnotateStrokes([stroke], BoxAnnotation(c_list))
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:40,代码来源:TuringMachineObserver.py

示例9: SaveTemplate

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
 def SaveTemplate(self, sender, e, numSamples = TEMPLATE_SAMPLE):
     if len(self.StrokeList) > 0:
         #last_stroke = self.StrokeList[-1]
         pts = []
         for stk in self.StrokeList:
             pts.extend(stk.Points)
         templ_stroke = Stroke.Stroke(points= pts)
         template_name = TEMPLATE_TEXT.Text 
         if template_name.strip() == '':
             template_name = 'Blob'
         sNorm = GeomUtils.strokeNormalizeSpacing(templ_stroke, numSamples * len(self.StrokeList))
         centroid = GeomUtils.centroid(sNorm.Points)
         sNorm = sNorm.translate(-1*centroid.X, -1 * centroid.Y)
         storeTemplate(sNorm, len(self.StrokeList), tag=template_name)
     self.Clear()
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:17,代码来源:WpfTemplateInput.py

示例10: drawAnno

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
 def drawAnno(self, anno):
     #pdb.set_trace()
     if self.trackedAnno == None:
         self.trackedAnno = anno
     for stk in anno.Strokes:
         prevPt = None
         for i, point in enumerate(GeomUtils.strokeNormalizeSpacing(stk, numpoints = len(stk.Points)).Points):
             if prevPt != None:
                 color = self.colors[anno.pattern[ (i + anno.idx) % len(anno.pattern) ] ]
                 self.getBoard().getGUI().drawLine(prevPt.X, prevPt.Y, point.X, point.Y, color=color, width = 3)
             prevPt = point
     if anno == self.trackedAnno:
         dt = time.time() - self.lastDraw
         self.lastDraw = time.time()
         logger.debug("Effective FPS = %s" % (1 / float(dt)))
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:17,代码来源:TestAnimObserver.py

示例11: classifyArrowhead

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
def classifyArrowhead(board, stroke):
    """Following the class 1 semantics, this classifies arrowheads"""
    if _isArrowHead(stroke, arrowHeadMatcher):
        #                * (tip-point)
        #              o   o
        #             o      o
        #            o         o
        #          o            o
        
        #Get the endpoints/tip point as max curvature
        strokeNorm = GeomUtils.strokeNormalizeSpacing(stroke, numpoints = 7)
        curvatures = GeomUtils.strokeGetPointsCurvature(strokeNorm)
        ptIdx = curvatures.index(max(curvatures))
        tip = strokeNorm.Points[ptIdx] #Middle is the point of max curvature
        annotation = ArrowHeadAnnotation(stroke.Points[0], tip, stroke.Points[-1])
        return annotation
    return None
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:19,代码来源:ArrowObserver.py

示例12: onStrokeAdded

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
    def onStrokeAdded( self, stroke ):
        "Watches for Strokes with Circularity > threshold to Annotate"
        # need at least 6 points to be a circle
	if stroke.length()<6:
            return
	s_norm = GeomUtils.strokeNormalizeSpacing( stroke, 20 ) 
	s_chop = GeomUtils.strokeChopEnds( s_norm, 0.20 ) 
        circ_norm = GeomUtils.strokeCircularity( s_norm ) 
        circ_chop = GeomUtils.strokeCircularity( s_chop ) 

        logger.debug( "stroke: %s", [str(p) for p in s_norm.Points] )
        logger.debug( "potential circles (%f,%f) <> %f", circ_norm, circ_chop, self.threshold )

        if( circ_norm>self.threshold or circ_chop>self.threshold):
            cen = stroke.Center
            avgDist = GeomUtils.averageDistance( cen, stroke.Points )
            anno = CircleAnnotation( circ_norm, cen, avgDist )
            BoardSingleton().AnnotateStrokes( [stroke],  anno)
开发者ID:loserpenguin15,项目名称:UCSBsketch,代码行数:20,代码来源:CircleObserver.py

示例13: strokeCurvatureHistogram

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
def strokeCurvatureHistogram(stroke, norm_len=None, gran=10):
    # points = GeomUtils.strokeNormalizeSpacing( stroke, numpoints=50).Points
    rad2deg = 57.295
    if norm_len == None:
        norm_len = len(stroke.Points)

    norm_stroke = GeomUtils.strokeNormalizeSpacing(stroke, numpoints=norm_len)

    # find the first 90 degree turn in the stroke
    curvatures = GeomUtils.strokeGetPointsCurvature(norm_stroke)

    for idx, ori in enumerate(curvatures):
        print "%s:\t|" % (idx),
        quantity = ori * rad2deg
        while quantity > 0:
            quantity -= gran
            print "X",
        print "\t\t%s" % (ori * rad2deg)
    print "_______________________________"
    print "Max:%s, Avg%s" % (max(curvatures), sum(curvatures) / float(len(curvatures)))
    print "_______________________________"
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:23,代码来源:Debugging.py

示例14: _isSingleStrokeArrow

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
def _isSingleStrokeArrow(stroke):
    "Input: Single stroke for evaluation. Returns a tuple of points (tip, tail) if the stroke is an arrow, (None, None) otherwise"
    logger.debug("stroke len %d", stroke.length() )
    if len(stroke.Points) < 10:
        return (None, None)# too small to be arrow

    norm_len = len(stroke.Points)
    points = GeomUtils.strokeNormalizeSpacing( stroke, numpoints=norm_len).Points

    points.reverse() # start from end
    # find the first 90 degree turn in the stroke
    orilist = GeomUtils.strokeLineSegOrientations( Stroke(points) )
    logger.debug("stroke ori %s", str(orilist) )
    prev = None
    i = 0
    for i,ori in enumerate(orilist):
        if prev is None:
            prev = ori
            continue
        if GeomUtils.angleDiff(ori,prev)>90: break  # found the first turn at index i
    first_corner = i
    # now we know the scale of the arrow head if there is one
    # if the first corner is more than 1/4 of the way from the end of the stroke
    if first_corner > norm_len/5:
        return (None, None) # scale is wrong for an arrowhead        

    tail = stroke.Points[0] # first of the original points
    tip = points[i] # reverse point

    # create a list of the monoticity of all substrokes from the first corner to some dist after
    m_list = [ GeomUtils.strokeMonotonicity(Stroke(points[first_corner:x])) for x in range(first_corner+2,first_corner*3) ]
    if len(m_list) == 0:
        return (None, None)
    m_min = min(m_list) 
    logger.debug("stroke mon (%f)", m_min )
    if m_min>0.65:
        return (None, None)# too monotonic after the first corner, need to double back
    
    return (tip, tail)
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:41,代码来源:ArrowObserver.py

示例15: refreshTuringMachines

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokeNormalizeSpacing [as 别名]
    def refreshTuringMachines(self):

        #Remove all of the current Turing Machines
        for tmAnno in set(self.tmMap.keys()):
            self.getBoard().RemoveAnnotation(tmAnno)
            del(self.tmMap[tmAnno])
        
        #Match all of the labels we've seen with their closest edges
        #    in any graph
        labelEdgeMatches = {} # { label : {edge, distance} }
        for textAnno in self.labelMap.keys():
            labelTL, labelBR = GeomUtils.strokelistBoundingBox(textAnno.Strokes)
            #Midpoint of the label's bounding box
            labelCenterPt = Point ( (labelTL.X + labelBR.X) / 2.0, (labelTL.Y + labelBR.Y) / 2.0) 
            labelMatchDict = labelEdgeMatches.setdefault(textAnno, {}) 

            for graphAnno in self.graphMap:
                #Check to make sure the label doesn't share strokes with the graph structure
                skipThisGraph = False
                for textStroke in textAnno.Strokes:
                    if textStroke in graphAnno.Strokes:
                        skipThisGraph = True
                        break
                if skipThisGraph:
                    continue
                
                #Match edges to labels
                for edgeAnno in graphAnno.edge_set:
                    #Find the best choice among 19 evenly spaced points along the edge tailstroke
                    edgeLabelPoints = GeomUtils.strokeNormalizeSpacing(edgeAnno.tailstroke, 19).Points
                    for elp in edgeLabelPoints:
                        dist = GeomUtils.pointDistanceSquared(elp.X, elp.Y, labelCenterPt.X, labelCenterPt.Y)
                        if 'bestmatch' not in labelMatchDict or dist < labelMatchDict['bestmatch']['dist']:
                            labelMatchDict['bestmatch'] = {'edge': edgeAnno, 'dist': dist}

        #labelEdgeMatches contains each label paired with its best edge
        
        #Get the median size
        sizes = sorted([anno.scale for anno in self.labelMap.keys()])

        if len(sizes) > 0:
            medianSize = sizes[len(sizes) / 2]
        else:
            medianSize = 0

        #Have each edge claim a label
        edge2LabelMatching = {}
        for textAnno, matchDict in labelEdgeMatches.items():
            if 'bestmatch' in matchDict \
                and textAnno.scale < medianSize * TuringMachineCollector.LABELMATCH_DISTANCE[1] \
                and textAnno.scale > medianSize * TuringMachineCollector.LABELMATCH_DISTANCE[0]: 
                edgeLabelList = edge2LabelMatching.setdefault(matchDict['bestmatch']['edge'], [])
                edgeLabelList.append(textAnno)
            else:
                tm_logger.debug("TextAnno %s not matched to an edge" % (textAnno.text))

        #Make the associations and add the turing machine annotation
        for graphAnno, tmAnno in self.graphMap.items():
            assocSet = set([graphAnno])
            shouldAddAnno = False
            if tmAnno == None:
                shouldAddAnno = True
                tmAnno = TuringMachineAnnotation(state_graph_anno = graphAnno)

            for edgeAnno in graphAnno.edge_set:
                if edgeAnno in edge2LabelMatching:
                    assocLabelsList = edge2LabelMatching[edgeAnno]
                    for label in assocLabelsList:
                        assocSet.add(label)
                        tmAnno.assocLabel2Edge(label, edgeAnno)

            if shouldAddAnno:
                self.getBoard().AnnotateStrokes(tmAnno.getAssociatedStrokes(), tmAnno)
                self.tmMap[tmAnno] = assocSet
            else:
                self.getBoard().UpdateAnnotation(tmAnno, new_strokes = tmAnno.getAssociatedStrokes())
                self.tmMap[tmAnno] = assocSet
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:79,代码来源:TuringMachineObserver.py


注:本文中的Utils.GeomUtils.strokeNormalizeSpacing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。