本文整理匯總了Python中region.Region.set_vertices方法的典型用法代碼示例。如果您正苦於以下問題:Python Region.set_vertices方法的具體用法?Python Region.set_vertices怎麽用?Python Region.set_vertices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類region.Region
的用法示例。
在下文中一共展示了Region.set_vertices方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _region_leaf
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import set_vertices [as 別名]
def _region_leaf( level, op ):
token, details = op['token'], op['orig']
if token != 'KW_Region':
parse_def = token + '<' + ' '.join( details ) + '>'
## conns = [group.conn for group in domain.groups.itervalues()]
## vertex_groups = [group.vertices
## for group in domain.groups.itervalues()]
region = Region( 'leaf', rdef, domain, parse_def )
if token == 'KW_Region':
details = details[1][2:]
aux = regions.find( details )
if not aux:
raise ValueError, 'region %s does not exist' % details
else:
if rdef[:4] == 'copy':
region = aux.copy()
else:
region = aux
elif token == 'KW_All':
region.set_vertices( nm.arange( domain.mesh.nod0.shape[0],
dtype = nm.int32 ) )
elif token == 'E_NIR':
where = details[2]
if where[0] == '[':
out = nm.array( eval( where ), dtype = nm.int32 )
assert_( nm.amin( out ) >= 0 )
assert_( nm.amax( out ) < domain.mesh.nod0.shape[0] )
else:
x = domain.mesh.nod0[:,0]
y = domain.mesh.nod0[:,1]
if domain.mesh.dim == 3:
z = domain.mesh.nod0[:,2]
else:
z = None
coor_dict = {'x' : x, 'y' : y, 'z': z}
out = nm.where( eval( where, {}, coor_dict ) )[0]
region.set_vertices( out )
elif token == 'E_NOS':
if domain.fa: # 3D.
fa, nfa = domain.fa, domain.nfa
else:
fa, nfa = domain.ed, domain.ned
flag = dm_mark_surface_faces( fa, nfa )
ii = nm.where( flag > 0 )[0]
aux = la.unique1d( fa.data[ii,3:].ravel() )
if aux[0] == -1: # Triangular faces have -1 as 4. point.
aux = aux[1:]
region.can_cells = False
region.set_vertices( aux )
elif token == 'E_NBF':
where = details[2]
x = domain.mesh.nod0[:,0]
if domain.shape.dim > 1:
y = domain.mesh.nod0[:,1]
if domain.shape.dim > 2:
z = domain.mesh.nod0[:,2]
else:
z = None
else:
y = None
aux = {'x' : x, 'y' : y, 'z': z}
fun = 'funmod.' + where
# print fun
out = nm.where( eval( fun, {'funmod' : funmod}, aux ) )[0]
region.set_vertices( out )
elif token == 'E_EBF':
where = details[2]
aux = {'domain' : domain}
fun = 'funmod.' + where
# print fun
out = eval( fun, {'funmod' : funmod}, aux )
print out
region.set_cells( out )
elif token == 'E_EOG':
group = int( details[3] )
ig = domain.mat_ids_to_i_gs[group]
group = domain.groups[ig]
region.set_from_group( ig, group.vertices, group.shape.n_el )
elif token == 'E_ONIR':
aux = regions[details[3][2:]]
region.set_vertices( aux.all_vertices[0:1] )
#.........這裏部分代碼省略.........
示例2: _region_leaf
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import set_vertices [as 別名]
def _region_leaf( level, op ):
token, details = op['token'], op['orig']
if token != 'KW_Region':
parse_def = token + '<' + ' '.join( details ) + '>'
region = Region('leaf', rdef, domain, parse_def=parse_def)
if token == 'KW_Region':
details = details[1][2:]
aux = regions.find( details )
if not aux:
raise ValueError, 'region %s does not exist' % details
else:
if rdef[:4] == 'copy':
region = aux.copy()
else:
region = aux
elif token == 'KW_All':
region.set_vertices( nm.arange( domain.mesh.n_nod,
dtype = nm.int32 ) )
elif token == 'E_NIR':
where = details[2]
if where[0] == '[':
out = nm.array( eval( where ), dtype = nm.int32 )
assert_( nm.amin( out ) >= 0 )
assert_( nm.amax( out ) < domain.mesh.n_nod )
else:
coors = domain.get_mesh_coors()
x = coors[:,0]
y = coors[:,1]
if domain.mesh.dim == 3:
z = coors[:,2]
else:
z = None
coor_dict = {'x' : x, 'y' : y, 'z': z}
out = nm.where( eval( where, {}, coor_dict ) )[0]
region.set_vertices( out )
elif token == 'E_NOS':
if domain.fa: # 3D.
fa = domain.fa
else:
fa = domain.ed
flag = fa.mark_surface_facets()
ii = nm.where( flag > 0 )[0]
aux = nm.unique(fa.facets[ii])
if aux[0] == -1: # Triangular faces have -1 as 4. point.
aux = aux[1:]
region.can_cells = False
region.set_vertices( aux )
elif token == 'E_NBF':
where = details[2]
coors = domain.get_mesh_coors()
fun = functions[where]
out = fun(coors, domain=domain)
region.set_vertices( out )
elif token == 'E_EBF':
where = details[2]
coors = domain.get_mesh_coors()
fun = functions[where]
out = fun(coors, domain=domain)
region.set_cells( out )
elif token == 'E_EOG':
group = int( details[3] )
ig = domain.mat_ids_to_i_gs[group]
group = domain.groups[ig]
region.set_from_group( ig, group.vertices, group.shape.n_el )
elif token == 'E_NOG':
try:
group = int(details[3])
group_nodes = nm.where(domain.mesh.ngroups == group)[0]
except ValueError:
try:
group_nodes = domain.mesh.nodal_bcs[details[3]]
except KeyError:
msg = 'undefined nodal group! (%s)' % details[3]
raise ValueError(msg)
#.........這裏部分代碼省略.........
示例3: load_level
# 需要導入模塊: from region import Region [as 別名]
# 或者: from region.Region import set_vertices [as 別名]
def load_level(game, filename):
filename = os.path.join('levels', filename)
try:
tmx_data = pytmx.load_pygame(filename, pixelalpha=True)
except:
print 'Level %s could not be read as a TMX file.' % (filename)
raise
try:
name = tmx_data.name
except AttributeError:
print 'Level %s has no name: invalid level file.' % (filename)
width = tmx_data.width
height = tmx_data.height
state_images = defaultdict(dict)
animations = defaultdict(lambda: defaultdict(Animation))
for tile_id, properties in tmx_data.tile_properties.items():
image = tmx_data.getTileImageByGid(tile_id)
try:
name = properties['name']
except KeyError:
continue
state = properties.get('state', 'default')
frame = properties.get('frame', None)
if frame:
delay = properties.get('frame-delay', '4')
try:
delay = int(delay)
except ValueError:
print "Level %s has invalid frame delay of %s for frame %s/%s/%s" % (filename, delay, name, state, frame)
try:
frame = int(frame)
except ValueError:
print "Level %s has invalid frame: %s/%s/%s" % (filename, name, state, frame)
animations[name][state].add_frame(frame, image, delay)
else:
state_images[name][state] = image
for state in animations.values():
for animation in state.values():
animation.finalise()
level = Level(game, name, width, height)
for layer in tmx_data.tilelayers:
for (x, y, tile) in layer:
if tile == 0:
continue
name = tmx_data.tile_properties[tile]['name']
state = tmx_data.tile_properties[tile].get('state', 'default')
objtype = OBJECTS[name]
obj = objtype(level=level, location=(x, y))
obj.state = state
obj.state_images = state_images[name]
obj.animations = animations[name]
if isinstance(obj, Player):
level.player = obj
for obj in tmx_data.getObjects():
x = int(obj.x / TILE_W)
y = int(obj.y / TILE_H)
w = int(obj.width / TILE_W)
h = int(obj.height / TILE_H)
region = Region(obj.name, level, (x, y), (w, h))
if hasattr(obj, 'message'):
region.message = obj.message.decode('string-escape')
if hasattr(obj, 'points'):
region.set_vertices([(px/TILE_W, py/TILE_H) for (px, py) in obj.points])
if hasattr(obj, 'dependencies'):
for name in obj.dependencies.split(','):
region.add_dependency(name)
if hasattr(obj, 'anti_dependencies'):
for name in obj.anti_dependencies.split(','):
region.add_anti_dependency(name)
region.visible = hasattr(obj, 'show')
region.state_images = {'default' : None, 'visible' : state_images['hint']['default']}
level.load_finished()
return level