本文整理汇总了Python中shape.Shape类的典型用法代码示例。如果您正苦于以下问题:Python Shape类的具体用法?Python Shape怎么用?Python Shape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit
def fit(self, test_image, tol=0.1, max_iters=10000, initial_shape=None):
"""
Fits the shape model to the test image to find the shape
:param test_image: The test image in the form of a numpy matrix
:param tol: Fraction of points changed
:param max_iters: Maximum number of iterations
:param initial_shape: The starting Shape - if None get_default_initial_shape() is used
:return: The final Shape, the fit error and the number of iterations performed
"""
if initial_shape is None:
current_shape = self.get_default_initial_shape()
else:
current_shape = initial_shape.round()
num_iter = 0
fit_error = float("inf")
for num_iter in range(max_iters):
previous_shape = Shape(current_shape.as_numpy_matrix().copy())
new_shape_grey, error_list = self._gm.search(test_image, current_shape)
current_shape, fit_error, num_iters = self._pdm.fit(new_shape_grey)
moved_points = np.sum(
np.sum(current_shape.as_numpy_matrix().round() - previous_shape.as_numpy_matrix().round(),
axis=1) > 0)
if moved_points / float(self._pdm.get_size()) < tol:
break
return current_shape, fit_error, num_iter
示例2: __init__
def __init__(self, size, rotation, color="blue"):
texture_path = Shape.build_texture_path(color, Octagon.shape_type)
Shape.__init__(self, texture_path, size, rotation, Octagon.shape_type, color)
self.sides = 8
self.color = color
示例3: addShapes
def addShapes(self):
"""adds more shapes to the world"""
# how many shapes to generate
# we want roughly one piece per screen
screenArea = self.displayGridSize[0] * self.displayGridSize[1]
worldArea = self.world.cols * self.world.rows
minTotalShapes = 1 + int(worldArea / screenArea)
#logging.debug("generating {0} shape pieces...".format(minTotalShapes))
curTotalShapes = 0
shapes = []
while curTotalShapes < minTotalShapes:
# until enough shape generated
# create new shape, placed randomly
num_sides = random.randint(3,6)
newShape = Shape(self.display, self, self.character_size, num_sides)
newShape.autonomous = True # all new shapes will be autonomous by default
# add shape to the list of objects
if(self.world.addObject(newShape)):
curTotalShapes += 1
shapes.append(newShape)
logging.debug ("shape #{0} added to the map, id {1} with position {2} and rect={3}".format(curTotalShapes, newShape, newShape.getMapTopLeft(), newShape.rect))
# now there's enough shape in the world
self.shapes = shapes
return shapes
示例4: _processShapes
def _processShapes(self):
"""
"""
sheets = ['conductor', 'silkscreen', 'soldermask']
for sheet in sheets:
try:
shapes = self._footprint['layout'][sheet]['shapes']
except:
shapes = []
for shape_dict in shapes:
layers = utils.getExtendedLayerList(shape_dict.get('layers') or ['top'])
for layer in layers:
# Mirror the shape if it's text and on bottom later,
# but let explicit shape setting override
if layer == 'bottom':
if shape_dict['type'] == 'text':
shape_dict['mirror'] = shape_dict.get('mirror') or 'True'
shape = Shape(shape_dict)
style = Style(shape_dict, sheet)
shape.setStyle(style)
try:
self._shapes[sheet][layer].append(shape)
except:
self._shapes[sheet][layer] = []
self._shapes[sheet][layer].append(shape)
示例5: _placeDocs
def _placeDocs(self):
"""
Places documentation blocks on the documentation layer
"""
try:
docs_dict = config.brd['documentation']
except:
return
for key in docs_dict:
location = utils.toPoint(docs_dict[key]['location'])
docs_dict[key]['location'] = [0, 0]
shape_group = et.SubElement(self._layers['documentation']['layer'], 'g')
shape_group.set('{'+config.cfg['ns']['pcbmode']+'}type', 'module-shapes')
shape_group.set('{'+config.cfg['ns']['pcbmode']+'}doc-key', key)
shape_group.set('transform', "translate(%s,%s)" % (location.x, config.cfg['invert-y']*location.y))
location = docs_dict[key]['location']
docs_dict[key]['location'] = [0, 0]
shape = Shape(docs_dict[key])
style = Style(docs_dict[key], 'documentation')
shape.setStyle(style)
element = place.placeShape(shape, shape_group)
示例6: __init__
def __init__(self):
def initHandle(handle):
self.handles.append(handle)
QObject.connect(handle, SIGNAL("moved(QGraphicsObject*)"), self.handleMoved)
Shape.__init__(self, BubbleItem(self))
# Item
self.item.setFlag(QGraphicsItem.ItemIsSelectable)
self.item.setBrush(COLOR)
# Text item
self.textItem = QGraphicsTextItem(self.item)
self.textItem.setTextInteractionFlags(Qt.TextEditorInteraction)
QObject.connect(self.textItem.document(), SIGNAL("contentsChanged()"), \
self.adjustSizeFromText)
# Handles
self.anchorHandle = Handle(self.item, 0, 0)
# Position the bubble to the right of the anchor so that it can grow
# vertically without overflowing the anchor
self.bubbleHandle = Handle(self.item, ANCHOR_THICKNESS, -ANCHOR_THICKNESS)
initHandle(self.anchorHandle)
initHandle(self.bubbleHandle)
self.setHandlesVisible(False)
self.adjustSizeFromText()
示例7: __init__
def __init__(self, geometricName, contour):
Shape.__init__(self, geometricName, contour)
cornerList = []
self.minX = 1000
self.maxX = 0
self.minY = 1000
self.maxY = 0
contourCopy = contour
if len(contourCopy) > 1:
for corner in contourCopy:
cornerList.append((corner.item(0), corner.item(1)))
for corner in cornerList:
if corner[0] > self.maxX:
self.maxX = corner[0]
if corner[1] > self.maxY:
self.maxY = corner[1]
if corner[0] < self.minX:
self.minX = corner[0]
if corner[1] < self.minY:
self.minY = corner[1]
else:
self.minX = 0
self.maxX = 960
self.minY = 0
self.maxY = 720
示例8: __init__
def __init__(self, ps, color=None):
Shape.__init__(self, color)
self.vs = ps
self.bound = AABox.from_vectors(*self.vs)
self.half_planes = []
for i in xrange(len(self.vs)):
h = HalfPlane(self.vs[i], self.vs[(i+1) % len(self.vs)])
self.half_planes.append(h)
示例9: __init__
def __init__(self, ps, color=None):
Shape.__init__(self, color)
mn = min(enumerate(ps), key=lambda (i,v): (v.y, v.x))[0]
self.vs = list(ps[mn:]) + list(ps[:mn])
self.bound = Vector.union(*self.vs)
self.half_planes = []
for i in xrange(len(self.vs)):
h = HalfPlane(self.vs[i], self.vs[(i+1) % len(self.vs)])
self.half_planes.append(h)
示例10: __init__
def __init__(self, theta1=0, theta2=360, *args, **kwargs):
'''Create an ellipse '''
self._theta1 = theta1
self._theta2 = theta2
Shape.__init__(self, *args, **kwargs)
self._fill_mode = GL_TRIANGLES
self._line_mode = GL_LINE_LOOP
self._update_position()
self._update_shape()
示例11: __init__
def __init__(self):
Shape.__init__(self, LineItem(self))
self.item.setFlag(QGraphicsItem.ItemIsSelectable)
self.handles.append(Handle(self.item, 0, 0))
self.handles.append(Handle(self.item, 0, 0))
self.handles[1].setZValue(self.handles[0].zValue() + 1)
for handle in self.handles:
QObject.connect(handle, SIGNAL("moved(QGraphicsObject*)"), self.handleMoved)
self.setHandlesVisible(False)
示例12: translate_errors
def translate_errors(self, physical_error):
encoded_error = Shape([])
for triplet in self.triplets:
anticommute_count = 0
for op in triplet:
if (not op.commutes_with(physical_error)):
anticommute_count = anticommute_count + 1
if (anticommute_count > 1):
raise RuntimeError("Invalid triplet\n" + str(triplet))
encoded_error.multiply_with_self(op)
return encoded_error
示例13: __init__
def __init__(self, radius=0, *args, **kwargs):
'''Create an (optionable) round rectangle.
:Parameters:
`radius` : int or tuple of 4 int
Radius of corners.
'''
self._radius = radius
Shape.__init__(self,*args,**kwargs)
self._update_position()
self._update_shape()
示例14: __init__
def __init__(self, corners):
"""
Create Square self with vertices corners.
Assume all sides are equal and corners are square.
@param Square self: this Square object
@param list[Point] corners: corners that define this Square
@rtype: None
>>> s = Square([Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 0)])
"""
Shape.__init__(self, corners)
示例15: __init__
def __init__(self, direction='up', *args, **kwargs):
'''Create an oriented triangle.
:Parameters:
`direction` : str
The triangle is oriented relative to its center to this property,
which must be one of the alignment constants `left`, `right`,
`up` or `down`.
'''
self._direction = direction
Shape.__init__(self,*args, **kwargs)
self._update_position()
self._update_shape()