本文整理汇总了Python中shape.Shape类的典型用法代码示例。如果您正苦于以下问题:Python Shape类的具体用法?Python Shape怎么用?Python Shape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shape类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:bhatturam,项目名称:IncisorSegmentation,代码行数:25,代码来源:models.py
示例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
开发者ID:ivanvenosdel,项目名称:colored-shapes,代码行数:6,代码来源:octagon.py
示例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
开发者ID:benjaminbradley,项目名称:pacworld,代码行数:25,代码来源:map.py
示例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)
开发者ID:huigao80,项目名称:pcbmode,代码行数:29,代码来源:footprint.py
示例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)
开发者ID:huigao80,项目名称:pcbmode,代码行数:26,代码来源:module.py
示例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()
开发者ID:agateau,项目名称:annot8,代码行数:26,代码来源:bubble.py
示例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
开发者ID:gabsima,项目名称:Design3-Team03-H2016,代码行数:25,代码来源:allShapes.py
示例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)
开发者ID:0x55aa,项目名称:500lines,代码行数:8,代码来源:poly.py
示例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)
开发者ID:cscheid,项目名称:tiny_gfx,代码行数:9,代码来源:poly.py
示例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()
开发者ID:Sankluj,项目名称:PyWidget,代码行数:10,代码来源:ellipse.py
示例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)
开发者ID:agateau,项目名称:annot8,代码行数:10,代码来源:line.py
示例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
开发者ID:cryptogoth,项目名称:qec,代码行数:11,代码来源:hamiltonian.py
示例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()
开发者ID:Sankluj,项目名称:PyWidget,代码行数:11,代码来源:rectangle.py
示例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)
开发者ID:grepler,项目名称:CSC148-SLOG,代码行数:13,代码来源:Square.py
示例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()
开发者ID:Sankluj,项目名称:PyWidget,代码行数:14,代码来源:triangle.py
示例16: _processAssemblyShapes
def _processAssemblyShapes(self):
"""
"""
try:
shapes = self._footprint['layout']['assembly']['shapes']
except:
return
for shape_dict in shapes:
layers = shape_dict.get('layer') or ['top']
for layer in layers:
shape = Shape(shape_dict)
style = Style(shape_dict, 'assembly')
shape.setStyle(style)
self._shapes['assembly'][layer].append(shape)
开发者ID:hobzcalvin,项目名称:pcbmode,代码行数:15,代码来源:footprint.py
示例17: __init__
def __init__(self, thickness=.4, branches=5, *args, **kwargs):
'''Create a cross.
:Parameters:
`thickness` : int
Thickness of the cross
`branches` : int
Number of branches
'''
self._thickness = thickness
self._branches = branches
Shape.__init__(self, *args, **kwargs)
self._fill_mode = GL_TRIANGLES
self._update_position()
self._update_shape()
开发者ID:Sankluj,项目名称:PyWidget,代码行数:15,代码来源:star.py
示例18: __init__
def __init__(self, corners):
"""
Create RightAngleTriangle self with vertices corners.
Overrides Shape.__init__
Assume corners[0] is the 90 degree angle.
@param RightAngleTriangle self: this RightAngleTriangle object
@param list[Point] corners: corners that define this RightAngleTriangle
@rtype: None
>>> s = RightAngleTriangle([Point(0, 0), Point(1, 0), Point(0, 2)])
"""
Shape.__init__(self, corners)
开发者ID:grepler,项目名称:CSC148-SLOG,代码行数:15,代码来源:right_angle_triangle.py
示例19: _getOutline
def _getOutline(self):
"""
Process the module's outline shape. Modules don't have to have an outline
defined, so in that case return None.
"""
shape = None
outline_dict = self._module_dict.get('outline')
if outline_dict != None:
shape_dict = outline_dict.get('shape')
if shape_dict != None:
shape = Shape(shape_dict)
style = Style(shape_dict, 'outline')
shape.setStyle(style)
return shape
开发者ID:huigao80,项目名称:pcbmode,代码行数:16,代码来源:module.py
示例20: add_shape
def add_shape(self):
assert not self.shape
sh, col = random.choice(shape_color)
self.shape = Shape(sh, self.window, col, self.width/2, 0, self.xinit, self.yinit)
if self.collides(self.shape):
raise GameOver()
self.shape.draw()
开发者ID:jaffee,项目名称:ristet,代码行数:7,代码来源:board.py
注:本文中的shape.Shape类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论