本文整理汇总了Python中Transform类的典型用法代码示例。如果您正苦于以下问题:Python Transform类的具体用法?Python Transform怎么用?Python Transform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: child
def child(i, step, totalimage, prefs, kind, finalData, monitor, nOutstart):
Start = i*step;
End = (i+1)*step;
if(Start >= totalimage):
return 0
if(End > totalimage):
End = totalimage;
for iproj in range(Start,End):
nOut = nOutstart+iproj
# outfilename = "%s/%s_%s.hdf" % (prefs['out']['filePath'], prefs['projection']['Prefix'], Transform.paddingZero(nOut, int(prefs['out']['numberDigit'])))
dataArray = []
for i in prefs['series']:
i = i -1
filename = "%s/%s%s.%s" % ( prefs['filePath'], prefs[kind]['Prefix'][0], Transform.paddingZero(int(prefs[kind]['Num'][i][iproj]), prefs['numberDigit'] ), prefs[kind]['extension'] )
im = Image.open(filename)
imarray = np.array(im)
dataArray.append(0)
dataArray[i] = imarray[(prefs['ROIy'][i][0]-1):prefs['ROIy'][i][-1] , (prefs['ROIx'][i][0]-1):prefs['ROIx'][i][-1]] # corp the array
# if prefs['slits']['shouldCorr']: #comment out for this momoent, if need corr, need to initialize in the initialize script
# dataAve[iavg] = slitposcorr(dataAve[iavg], prefs, j, kind, iavg)
dataArray[i], _, _, aveint = Transform.preprocess(dataArray[i], prefs, i)
if prefs['vis']['intMonitor']:
monitor[iproj][i]=array('d', [aveint, prefs[kind]['Num'][i][iproj], nOut])
dataResutArray, sminx, smaxx = Transform.stitching(dataArray, prefs)
finalData[iproj] = dataResutArray
return 1
示例2: redraw
def redraw(self, rotation_x, rotation_y):
resize_width = 0
resize_height = 0
if (rotation_x + self.originalRotationX > 360):
resize_width = (rotation_x + self.originalRotationX * 1.0) % 90.0
resize_width = int(resize_width * 100)
Surface.__init__(self, self.get_size(), pygame.SRCALPHA)
Transform.skew_surface(self.originalImage, 0, -rotation_y), (0, 0)
self.blit(pygame.transform.scale(Transform.skew_surface(self.originalImage, 0, -rotation_y), (resize_width, self.get_size()[1])), (-rotation_x,0))
示例3: transformFunc
def transformFunc(self):
import Image as i, Transform
self.pic = i.Image("Resources/test.jpg")
if(self.radioButton.isChecked()):
self.pic.set_img(Transform.crop(self.pic.get_img(),self.spinBox_2.value(),self.spinBox_3.value()))
if(self.radioButton_9.isChecked()):
self.pic.set_img(Transform.rotate(self.pic.get_img(),self.spinBox.value()))
if(self.radioButton_10.isChecked()):
if(self.checkBox.isChecked()):
self.pic.set_img(Transform.flip(self.pic.get_img(),1))
if(self.checkBox_2.isChecked()):
self.pic.set_img(Transform.flip(self.pic.get_img(),2))
from scipy.misc import imsave
imsave("Resources/test2.jpg",self.pic.get_img())
self.imageUpdate("Resources/test2.jpg")
示例4: remove_block
def remove_block(self, position, immediate=True):
""" Remove the block at the given `position`.
Parameters
----------
position : tuple of len 3
The (x, y, z) position of the block to remove.
immediate : bool
Whether or not to immediately remove block from canvas.
"""
# if block is dead hide it and remove it
if not self.world.getBlock(position).isAlive():
transparent = self._materialFactory.getMaterial(self.world.getBlock(position).getMaterial()).transparent
if immediate:
self.hide_block(position)
self.world.removeBlock(position)
self.sectors[Transform.sectorize(position, self.conf.getConfValue('sectorSize'))].remove(position)
# show newly exposed blocks
self.check_neighbors(position, transparent)
else:
self.world.getBlock(position).decreaseLife()
示例5: __init__
def __init__(self):
self.log = l.getLogger('model')
self.conf = EC.EngineConfig.Instance()
# A Batch is a collection of vertex lists for batched rendering.
self.batch = pyglet.graphics.Batch()
# Mapping from sector to a list of positions inside that sector.
self.sectors = {}
# Simple function queue implementation. The queue is populated with
# _show_block() and _hide_block() calls
self.queue = deque()
self._materialFactory = Materials.MaterialFactory.Instance()
# all shown blocks.
self.visibleWorld = {}
# This defines all the blocks that are currently in the world.
try:
(self.world, self.player) = Savegame.Savegame.load()
# make blocks visible after loading
for position in self.world.getBlockPositions():
# sectorize blocks
self.sectors.setdefault(Transform.sectorize(position, self.conf.getConfValue('sectorSize')), []).append(position)
self.show_sector(0)
except Exception, e:
self.log.debug("Couldn't load a savegame. Creating new world ...")
self.world = World.World()
self.player = Player.Player()
self.visibleWorld = {}
self._initialize()
示例6: savePeakListToFile
def savePeakListToFile(self,filename,initialGuess,qData,
numberOfChi,maskedPixelInfo,stddev):
peakList = Fit.getPeakList(self.theDiffractionData.data,qData,
initialGuess,numberOfChi,stddev)
# now, save to file
file = open(filename,"w")
file.write("# A list of diffraction peaks found.\n")
file.write("# Diffraction Data: %s\n" % self.theDiffractionData.filename)
file.write("# Calculated on "+time.asctime()+"\n")
file.write("# Calibration data used to find peaks:\n")
initialGuess.writeCommentString(file)
file.write("# Q data used to find peaks:\n")
file.write("# Peaks:\n")
qData.writeCommentString(file)
if maskedPixelInfo.doPolygonMask and maskedPixelInfo.numPolygons() > 0:
file.write("# All peaks inside of polygon mask(s) were ignored.\n")
file.write(maskedPixelInfo.writePolygonCommentString())
file.write("#%16s%21s%21s%21s%21s%21s%21s%21s\n" % \
("x","y","Real Q","Fit Q","chi","width","intensity","2theta"))
for peak in peakList.getMaskedPeakList(maskedPixelInfo):
x,y,realQ,fitQ,chi,width = peak
intensity=self.getPixelValueBilinearInterpolation(x,y)
twoTheta = Transform.convertQToTwoTheta(fitQ,initialGuess)
file.write("%17.10f %17.10f %17.10f %17.10f %17.10f %17.10f %17.10f %17.10f\n" % \
(x,y,realQ,fitQ,chi,width,intensity,twoTheta) )
file.close()
return peakList
示例7: addConstantQLineCakeImage
def addConstantQLineCakeImage(image,Q,qOrTwoThetaLower,
qOrTwoThetaUpper,numQOrTwoTheta,chiLower,
chiUpper,numChi,color,calibrationData,type):
draw = ImageDraw.Draw(image)
if type == "Q":
if Q < qOrTwoThetaLower or Q > qOrTwoThetaUpper:
return
qIndex = (numQOrTwoTheta-1)*(Q-qOrTwoThetaLower)/ \
(qOrTwoThetaUpper-qOrTwoThetaLower)
draw.line( (qIndex,0)+(qIndex,numChi-1),fill=color)
elif type == "2theta":
twoTheta = Transform.convertQToTwoTheta(Q,calibrationData)
if twoTheta < qOrTwoThetaLower or \
twoTheta > qOrTwoThetaUpper:
return
twoThetaIndex = (numQOrTwoTheta-1)* \
(twoTheta-qOrTwoThetaLower)/ \
(qOrTwoThetaUpper-qOrTwoThetaLower)
draw.line( (twoThetaIndex,0)+(twoThetaIndex,numChi-1),
fill=color)
else:
raise Exception("Unable to add constant Q \
lines to the cake image. The function must be passed \
for the parameter type either 'Q', or '2theta'")
示例8: hit_test
def hit_test(self, position, vector, max_distance=8):
""" Line of sight search from current position. If a block is
intersected it is returned, along with the block previously in the line
of sight. If no block is found, return None, None.
Parameters
----------
position : tuple of len 3
The (x, y, z) position to check visibility from.
vector : tuple of len 3
The line of sight vector.
max_distance : int
How many blocks away to search for a hit.
"""
m = 8
x, y, z = position
dx, dy, dz = vector
previous = None
for _ in xrange(max_distance * m):
key = Transform.normalize((x, y, z))
if key != previous and self.world.existsBlockAt(key):
return key, previous
previous = key
x, y, z = x + dx / m, y + dy / m, z + dz / m
return None, None
示例9: _paint_block
def _paint_block(self, position):
""" Creates vertexes for the block.
Parameters
----------
position : tuple of len 3
The (x, y, z) position of the block to show.
"""
x, y, z = position
try:
block = self.world.getBlock(position)
if block.getVertex():
return
vertex_data = Transform.cube_vertices(x, y, z, 0.5)
texture_data = list(block.getTexture())
# create vertex list
# FIXME Maybe `add_indexed()` should be used instead
block.setVertex(self.batch.add(24, GL_QUADS, self._materialFactory.getMaterial(block.getMaterial()).textureGroup,
('v3f/static', vertex_data),
('t2f/static', texture_data)))
#self.log.debug('Block at %s made visible' % (position,))
except Exception, e:
self.log.error("Painting block at %s failed: %s" % (position, e))
示例10: loadMaterials
def loadMaterials(self):
""" This method crawles the ressources for diffrent materials
and loads them for future use
"""
self.log.debug('loading materials from %s' % (self._materialPath, ))
textureFactory = TF.TextureFactory.Instance()
for file in os.listdir(self._materialPath):
absPath = os.path.join(self._materialPath, file)
""" if found new material, load metadata and textures """
if os.path.isdir(absPath):
self.log.debug('material found: %s' % (file, ))
# load json material definition
try:
defFile = open(os.path.join(absPath, "material.json"), 'r')
definition = "".join(defFile.readlines())
jsonObj = json.loads(definition)
except Exception, e:
self.log.error("Error loading material metadata %s: %s" %
(file, str(e)))
# create new Material object
self._materials[jsonObj['name']] = Material()
# load texture
try:
self._materials[jsonObj['name']].name = jsonObj['name']
self._materials[jsonObj['name']].sustain = int(jsonObj['sustain'])
self._materials[jsonObj['name']].clipping = bool(jsonObj['clipping'])
self._materials[jsonObj['name']].transparent = bool(jsonObj['transparent'])
self._materials[jsonObj['name']].texture['top'] = Transform.tex_coords(
tuple(jsonObj['texture']['mapping']['top']['top']),
tuple(jsonObj['texture']['mapping']['top']['bottom']),
tuple(jsonObj['texture']['mapping']['top']['sides']))
self._materials[jsonObj['name']].texture['middle'] = Transform.tex_coords(
tuple(jsonObj['texture']['mapping']['middle']['top']),
tuple(jsonObj['texture']['mapping']['middle']['bottom']),
tuple(jsonObj['texture']['mapping']['middle']['sides']))
# A TextureGroup manages an OpenGL texture.
self._materials[jsonObj['name']].textureGroup = textureFactory.loadTexture(
os.path.join(absPath,jsonObj['texture']['ressource']))
except Exception, e:
self.log.debug("Error loading material textures: %s" % (str(e), ))
示例11: draw
def draw(self, surface):
self.fill((0,0,0))
self.cubeSide.update(self.rotation, 0)
self.cubeSide.redraw(self.rotation, 0)
print ("Equation = %s" % (-33 + int(((self.rotation * 1.0) % 90)/ 90.0 * 66)))
if self.rotation <= 90:
self.blit(pygame.transform.scale(Transform.skew_surface(self.originalImage, 0, -33 + int(((self.rotation * 1.0) % 90)) ), (int((self.rotation%90.0)/90*100), 100)), self.imageLocation)
else:
self.blit(pygame.transform.scale(Transform.skew_surface(self.originalImage, 0, -33 + int(((self.rotation * 1.0) % 90))),
(100 - int((self.rotation % 90.0) / 90 * 100), 100)), self.imageLocation)
if (self.rotation == 90):
self.rotation = 0
self.rotation += 1
self.imageLocation = (100 - int((self.rotation % 90.0) / 90 * 100), self.imageLocation[1])
surface.blit(self, (200, 200))
示例12: getWavelength
def getWavelength(self):
if self.energy['val'] == None or self.energy['fixed'] == None:
return UserInputException('Cannot get the wavelength because neither the wavelength nor the energy have been set.')
val = Transform.convertEnergyToWavelength(self.energy['val'])
lower,upper=None,None
if self.energy['lower'] != None: lower = hc/self.energy['upper']
if self.energy['upper'] != None: upper = hc/self.energy['lower']
return {'val':val,'fixed':self.energy['fixed'],'lower':lower,'upper':upper}
示例13: addConstantQLineDiffractionImage
def addConstantQLineDiffractionImage(image,Q,calibrationData,color):
draw = ImageDraw.Draw(image)
polygon = []
for chi in frange(0,360,3):
x,y = Transform.getXY(calibrationData,Q,chi)
polygon += [x,y]
draw.polygon(polygon, outline=color)
示例14: __init__
def __init__(self, size, images):
Surface.__init__(self, images[0].get_size(), pygame.SRCALPHA)
self.location = (0, 34)
self.blit(images[0], (0, 0))
self.xChange = 100
self.rotationX = 45
self.rotationY = 33
self.surfaces = [CubeSide(images[x], images[0].get_size(), x) for x in range(6)]
self.surfaces[0].blit(images[0], (0, 0))
self.surfaces[1].blit(images[1], (0, 0))
self.ORIGINAL_SURFACES = [pygame.Surface((100, 100), pygame.SRCALPHA) for _ in range(6)]
self.ORIGINAL_SURFACES[0].blit(images[0], (0, 0))
self.testingSurf = Transform.skew_surface(pygame.transform.scale(self.surfaces[0], (self.xChange, 100)), 0, 33)
self.testingSurf2 = Transform.skew_surface(pygame.transform.scale(self.surfaces[4], (self.xChange, 100)), 0, -33)
示例15: __init__
def __init__(self):
self.cairoContext = None
self.RGB = "rgb"
self.HSB = "hsb"
self.CMYK = "cmyk"
self._colormode = self.RGB
self._fillState = 1
self._lineWidth = 1
self._autoclosepath = True
self._transform = Transform()
self._fontsize = 10