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


Python GeomUtils.strokelistBoundingBox方法代码示例

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


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

示例1: merg

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def merg(self, to_anno, from_anno):

        bb_from = GeomUtils.strokelistBoundingBox( from_anno.Strokes )
        center_from = Point( (bb_from[0].X + bb_from[1].X) / 2.0, (bb_from[0].Y + bb_from[1].Y) / 2.0)
        tl = Point (center_from.X - from_anno.scale/ 2.0, center_from.Y + (from_anno.scale / 2.0) )
        br = Point (center_from.X + from_anno.scale/ 2.0, center_from.Y - (from_anno.scale / 2.0) )
        bb_from = (tl, br)

        bb_to = GeomUtils.strokelistBoundingBox( to_anno.Strokes )
        center_to = Point( (bb_to[0].X + bb_to[1].X) / 2.0, (bb_to[0].Y + bb_to[1].Y) / 2.0)
        tl = Point (center_to.X - to_anno.scale/ 2.0, center_to.Y + (to_anno.scale / 2.0) )
        br = Point (center_to.X + to_anno.scale/ 2.0, center_to.Y - (to_anno.scale / 2.0) )
        bb_to = (tl, br)

        if bb_from[0].X - bb_to[0].X > 0 :
            outText = to_anno.text + from_anno.text
        else :
            outText = from_anno.text + to_anno.text

        #Weight the scale per letter
        to_anno.scale = ( to_anno.scale * len(to_anno.text) + from_anno.scale * len(from_anno.text) )\
                        / float(len(to_anno.text) + len(from_anno.text))
        tc_logger.debug("MERGED: %s and %s to %s" % (to_anno.text, from_anno.text, outText))
        to_anno.text = outText
        to_anno.alternates = []

        return True
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:29,代码来源:BinObserver.py

示例2: onStrokeAdded

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def onStrokeAdded( self, stroke ):
        "Compare this stroke to all templates, and annotate those matching within some threshold."
        logger.debug("Scoring stroke")
        #strokeVector = ( len(stroke.Points), GeomUtils.pointListOrientationHistogram(GeomUtils.strokeNormalizeSpacing(stroke, numpoints = len(stroke.Points) / 3.0).Points) )
        strokeVector = generateFeatureVector(stroke)
        logger.debug("Stroke Vector: %s" % (str(strokeVector)))
        if self._matchVector == None:
            self._matchVector = strokeVector
        else:
            bb1 = GeomUtils.strokelistBoundingBox([stroke])
            for prevStk in self._features.keys():
                bb2 = GeomUtils.strokelistBoundingBox([prevStk])
                if GeomUtils.boundingboxOverlap(bb1, bb2):
                    self.overlaps.setdefault(stroke, set()).add(prevStk)
                    self.overlaps.setdefault(prevStk, set()).add(stroke)
            self._features[stroke] = strokeVector
            score = scoreVector(self._matchVector, strokeVector)
            logger.debug("  Distance %s from baseline" % (score) )
            if score < 0.02:
                self.getBoard().AnnotateStrokes([stroke], MultiStrokeAnnotation("Match"))

            for stk in self.overlaps.get(stroke, []):
                multiVect = addVectors( [self._features[stroke], self._features[stk] ] )
                logger.debug("Multiple vector: %s" % (str(multiVect)))
                score = scoreVector(self._matchVector, multiVect)
                logger.debug("  Distance %s from baseline" % (score) )
                if score < 0.02:
                    self.getBoard().AnnotateStrokes([stroke, stk], MultiStrokeAnnotation("Match"))
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:30,代码来源:MultiStrokeFeatureObserver.py

示例3: drawAnno

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def drawAnno(self, a):
        bbox = GeomUtils.strokelistBoundingBox(a.Strokes)
        gui = self.getBoard().getGUI()
        drawBox = False
        if drawBox:  # Draw the logical box
            minScale = 20
            heights = [s.BoundTopLeft.Y - s.BoundBottomRight.Y for s in a.Strokes]
            bb_from = GeomUtils.strokelistBoundingBox(a.Strokes)
            from_scale = max(minScale, heights[len(heights) / 2])
#            from_scale = max(minScale, sum(heights)/float(len(heights)))
            tl = Point (bb_from[0].X - from_scale, bb_from[0].Y + from_scale / 2)
            br = Point (bb_from[1].X + from_scale, bb_from[1].Y - from_scale / 2)
            bb_from = (tl, br)
            gui.drawBox(tl, br, color="#FFFFFF")

        visLogger.debug("Drawing Anno: {}".format(a.latex))
        if a.latex and len(a.latex) > 0:
            try:
                if hasattr(gui, 'drawBitmap'):
                    if a.latex not in self._cachedPixbuf:
                        self._cachedPixbuf[a.latex] = pixbufFromLatex(a.latex)

                    pixbuf = self._cachedPixbuf[a.latex]
                    gui.drawBitmap(bbox[1].X, bbox[1].Y, pixbuf=pixbuf)
                else:
                    gui.drawText(bbox[1].X, bbox[1].Y, a.latex)
            except Exception as e:
                print "Cannot draw equation {}: {}".format(a.latex, e)
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:30,代码来源:EquationObserver.py

示例4: mergeCollections

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def mergeCollections( self, from_anno, to_anno ):
        "merge from_anno into to_anno if possible"
        # check that they have compatable scales
        scale_diff = to_anno.scale / from_anno.scale
        if scale_diff>2.5 or scale_diff<0.4:
            return False
        # check that they are not overlapping
        bb_from = GeomUtils.strokelistBoundingBox( from_anno.Strokes )
        bb_to = GeomUtils.strokelistBoundingBox( to_anno.Strokes )
        if GeomUtils.boundingboxOverlap( bb_from, bb_to ):
            return False

        #  bb[0]-------+
        #   |          |
        #   |          |
        #   | (0,0)    |
        #   +--------bb[1]

        # check that they are next to each other
        if    abs( bb_from[1].X - bb_to[0].X ) > to_anno.scale * 0.75 \
          and abs( bb_from[0].X - bb_to[1].X ) > to_anno.scale * 0.75 :
            return False
        # check y's overlap
        if   bb_from[0].Y - bb_to[1].Y < 0 \
          or bb_to[0].Y - bb_from[1].Y < 0 :
            return False

        # now we know that we want to merge these text annotations
        if bb_from[0].X - bb_to[0].X > 0 :
            to_anno.text = to_anno.text + from_anno.text 
        else :
            to_anno.text = from_anno.text + to_anno.text 
        to_anno.scale = max( to_anno.scale, from_anno.scale )
        return True
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:36,代码来源:TextObserver.py

示例5: isToRight

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def isToRight(self, stroke_to, stroke_from, scale):
        '''
            if from is to the right of to
        '''

        bb_from = GeomUtils.strokelistBoundingBox( [stroke_from] )
        center_from = Point( (bb_from[0].X + bb_from[1].X) / 2.0, (bb_from[0].Y + bb_from[1].Y) / 2.0)

        bb_to = GeomUtils.strokelistBoundingBox( [stroke_to] )
        center_to = Point( (bb_to[0].X + bb_to[1].X) / 2.0, (bb_to[0].Y + bb_to[1].Y) / 2.0)

        if 0 < center_from.X - center_to.X < self.horizDistRatio * scale:
            return True

        return False
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:17,代码来源:BinObserver.py

示例6: onAnnotationAdded

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def onAnnotationAdded( self, strokes, annotation ):
        "Checks to see if an divide sign has been added"

        ul,br = GeomUtils.strokelistBoundingBox(strokes)
        height = ul.Y - br.Y
        self.getBoard().AnnotateStrokes( strokes, DivideAnnotation(height))
        return
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:9,代码来源:DivideObserver.py

示例7: _makeLetterAnnotation

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
 def _makeLetterAnnotation(self, strokelist, char, alternates):
     bb = GeomUtils.strokelistBoundingBox(strokelist)
     height = bb[0].Y - bb[1].Y
     width = bb[1].X - bb[0].X 
     scale = max(height, width, 1)
     retAnnotation = TextAnnotation(char,  (alternates,), [strokelist], scale)
     return retAnnotation
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:9,代码来源:TextObserver.py

示例8: displayDataManager

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def displayDataManager(self):
        """Paint whatever the display manager wants on the board"""
        global HEIGHT, WIDTH, BOARDSCALE
        self.ResetBoard()
        print self.dataset.participants[self.participant].diagrams[self.diagram].type

        xMax = 0
        yMax = 0
        xMin = sys.maxint
        yMin = sys.maxint

        par = self.participant
        dig = self.diagram


        # Finds the min and max points so we can scale the data to fit on the screen
        for stkNum, inkStroke in self.dataset.participants[par].diagrams[dig].InkStrokes.items():
            stroke = traceStroke(inkStroke.stroke)
            ul,br = GeomUtils.strokelistBoundingBox([stroke])
            xMax = max(ul.X, br.X, xMax)
            yMax = max(ul.Y, br.Y, yMax)
            xMin = min(ul.X, br.X, xMin)
            yMin = min(ul.Y, br.Y, yMin)

        # Find the distance that the strokes take up
        # the "+ 20" is so we can have a 10 pixle buffer around the edges

        setBoardScale(xMax, yMax)


        labelStrokeMap = {} #Maps groupLabel : set(strokes)
        for stkNum, inkStroke in self.dataset.participants[par].diagrams[dig].InkStrokes.items():
            #print inkStroke.id
            stroke = inkStroke.stroke
            for groupLabel in self.dataset.participants[par].diagrams[dig].groupLabels:
                if stroke.id in groupLabel.ids:
                    labelStrokeMap.setdefault(groupLabel, set()).add(stroke)
            points = []
            
            """
            # scale each point to it's new position
            for p in stroke.Points:
                x = (p.X - xMin) * scaleFactor + 10 # the "+10 is for the 10 pixle boarder
                # y axis points in the data manager are inverted compaired to our screen
                # so we invert them
                y = HEIGHT - ((p.Y - yMin) * scaleFactor + 10)
                points.append(Point(x,y))
            """

            # create a new stroke out of the scaled points and add it to the board.
            #s = Stroke(points)
            s = inkStroke.stroke
            self.Board.AddStroke(s)
            self.StrokeList.append(s)
            # Annotate the stroke with the type given in the data manager

        for groupLabel, strokeSet in labelStrokeMap.items():
            self.Board.AnnotateStrokes(list(strokeSet), 
                                       DataManager.DataManagerAnnotation(groupLabel.type))
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:61,代码来源:DataManagerGUI.py

示例9: mergeCollections

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def mergeCollections(self, from_anno, to_anno):
        "merge from_anno into to_anno if they are naer enough to each other"
        minScale = 30
        vertOverlapRatio = 0
        horizOverlapRatio = 0
        groupingDistScale = 0.4  # multiplier for the median scale of how far to check around
                                # The strokes
        def annoScale(anno):
            """Helper function to get the scale of this annotation"""
            heights = [s.BoundTopLeft.Y - s.BoundBottomRight.Y for s in anno.Strokes]
#            scale = max(minScale, heights[len(heights)/2]) # median
            scale = sum(heights) / float(max(1, len(heights)))
            return max(scale, minScale)

        #  bb[0]-------+
        #   |          |
        #   |          |
        #   |          |
        #   +--------bb[1]
        # (0,0)

        from_scale = annoScale(from_anno)
        bb_from = GeomUtils.strokelistBoundingBox(from_anno.Strokes)
        tl = Point (bb_from[0].X - from_scale, bb_from[0].Y + from_scale * groupingDistScale)
        br = Point (bb_from[1].X + from_scale, bb_from[1].Y - from_scale * groupingDistScale)
        bb_from = (tl, br)

        to_scale = annoScale(to_anno)
        bb_to = GeomUtils.strokelistBoundingBox(to_anno.Strokes)
        tl = Point (bb_to[0].X - to_scale, bb_to[0].Y + to_scale * groupingDistScale)
        br = Point (bb_to[1].X + to_scale, bb_to[1].Y - to_scale * groupingDistScale)
        bb_to = (tl, br)
        # check x's overlap
        if   bb_from[1].X - bb_to[0].X < horizOverlapRatio \
          or bb_to[1].X - bb_from[0].X < horizOverlapRatio :
            logger.debug("Not merging %s and %s: horizontal overlap too small" % (from_anno, to_anno))
            return False

        # check y's overlap
        if   bb_from[0].Y - bb_to[1].Y < vertOverlapRatio \
          or bb_to[0].Y - bb_from[1].Y < vertOverlapRatio :
            logger.debug("Not merging %s and %s: vertical overlap too small" % (from_anno, to_anno))
            return False

        self.annoQueue.put(to_anno)
        return True
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:48,代码来源:EquationObserver.py

示例10: refreshTuringMachines

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [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

示例11: onAnnotationAdded

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def onAnnotationAdded( self, strokes, annotation ):
        "Checks to see if an equals sign has been added"
        
        # Find the midpoints         
        ul,br = GeomUtils.strokelistBoundingBox( strokes )
        midpointY = (ul.Y + br.Y) / 2
        midpointX = (ul.X + br.X) / 2
        strokeLen = GeomUtils.strokeLength(strokes[0])

        for a in self.possibleAnnotations:
            s = a.Strokes[0]
            prevStrokeLen = GeomUtils.strokeLength(s)

            # test the the two segments are of similar length
            lengthRange = 0.4
            if prevStrokeLen * (1-lengthRange) < strokeLen < prevStrokeLen * (1+lengthRange):
                pass # were the right length
            else: # not the right length, so lets start again
                continue

            ul,br = GeomUtils.strokelistBoundingBox( [s] )
            prevMidpointY = (ul.Y + br.Y) / 2
            prevMidpointX = (ul.X + br.X) / 2

            # Test that the two segments are close enough horizontally
            if GeomUtils.pointDistance(midpointX, 0, prevMidpointX, 0) < prevStrokeLen * 0.4:
                pass # there are close enough horizontally
            else: # we start again
                continue

            # Test that the two segments are close enough vertically
            if GeomUtils.pointDistance(0,midpointY, 0, prevMidpointY) < prevStrokeLen * 0.5:
                pass # there are close enough vertically
            else: # we start again
                continue

            # we found a match
            self.possibleAnnotations.remove(a)
            self.getBoard().AnnotateStrokes( strokes + [s],  EqualsAnnotation(1))
            return


        # no match was found, add to the list of possible
        self.possibleAnnotations.append(annotation)
        return
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:47,代码来源:EqualsObserver.py

示例12: drawAnno

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def drawAnno( self, a ):
        ul,br = GeomUtils.strokelistBoundingBox( a.Strokes )
        spaceing = 5
        ul.X -= spaceing
        ul.Y += spaceing
        br.X += spaceing
        br.Y -= spaceing

        self.getBoard().getGUI().drawBox(ul, br, color="#a0a0a0");
        self.getBoard().getGUI().drawText( br.X - 15, br.Y, a.text, size=15, color="#a0a0a0" )
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:12,代码来源:DataManager.py

示例13: drawAnno

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
 def drawAnno( self, a ):
     ul,br = GeomUtils.strokelistBoundingBox( a.Strokes )
     logger.debug(a.Strokes)
     height = ul.Y - br.Y
     midpointY = (ul.Y + br.Y) / 2
     midpointX = (ul.X + br.X) / 2
     left_x = midpointX - a.scale / 2.0
     right_x = midpointX + a.scale / 2.0
     #self.getBoard().getGUI().drawLine( left_x, midpointY, right_x, midpointY, color="#a0a0a0")
     y = br.Y
     self.getBoard().getGUI().drawText( br.X, y, a.text, size=15, color="#a0a0a0" )
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:13,代码来源:BinObserver.py

示例14: findOnLeft

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
    def findOnLeft( self, anno, list):
        bb_e = GeomUtils.strokelistBoundingBox( anno.Strokes )
        center_e = Point( (bb_e[0].X + bb_e[1].X) / 2.0, (bb_e[0].Y + bb_e[1].Y) / 2.0)

        v_offset = anno.scale / 4
        h_offset = anno.scale / 2

        for a in list:
            bb_a = GeomUtils.strokelistBoundingBox( a.Strokes )
            center_a = Point( (bb_a[0].X + bb_a[1].X) / 2.0, (bb_a[0].Y + bb_a[1].Y) / 2.0)

            # is it vertically alligned?
            if not ((center_e.Y < center_a.Y + v_offset) and (center_e.Y > center_a.Y - v_offset)):
                continue

            # is it to the Left?
            if center_e.X <= center_a.X:
                continue

            return a

        return None       
开发者ID:jbrowne,项目名称:UCSBsketch,代码行数:24,代码来源:ExpressionObserver.py

示例15: drawAnno

# 需要导入模块: from Utils import GeomUtils [as 别名]
# 或者: from Utils.GeomUtils import strokelistBoundingBox [as 别名]
 def drawAnno( self, a ):
     if len(a.text) >= 1:
         ul,br = GeomUtils.strokelistBoundingBox( a.Strokes )
         logger.debug(a.Strokes)
         height = ul.Y - br.Y
         left_x = ul.X# - height/3
         right_x = br.X + height/2
         midpoint = (ul.Y + br.Y) / 2
         SketchGUI.drawLine( left_x, midpoint, right_x, midpoint, color="#a0a0a0")
         y = br.Y + 5
         for idx, text in enumerate(a.alternates):
             SketchGUI.drawText( br.X, y, text, size=20, color="#a0a0a0" )
             y -= 20
开发者ID:ASayre,项目名称:UCSBsketch,代码行数:15,代码来源:TextObserver.py


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