skyTile.py   skyTile.py 
#!/usr/bin/python #!/usr/bin/python
# Fabien Chereau fchereau@eso.org # Fabien Chereau fchereau@eso.org
import sys
import os import os
import math import gzip
import qt
def writePolys(pl, f): def writePolys(pl, f):
"""Write a list of polygons pl into the file f.
The result is under the form [[[ra1, de1],[ra2, de2],[ra3, de3],[ra4
, de4]], [[ra1, de1],[ra2, de2],[ra3, de3]]]"""
f.write('[') f.write('[')
for idx,poly in enumerate(pl): for idx,poly in enumerate(pl):
f.write('[') f.write('[')
for iv,v in enumerate(poly): for iv,v in enumerate(poly):
f.write('[%.8f, %.8f]' % (v[0], v[1])) f.write('[%.8f, %.8f]' % (v[0], v[1]))
if iv!=len(poly)-1: if iv!=len(poly)-1:
f.write(', ') f.write(', ')
f.write(']') f.write(']')
if idx!=len(pl)-1: if idx!=len(pl)-1:
f.write(', ') f.write(', ')
f.write(']') f.write(']')
class StructCredits:
def __init__(self):
self.short = None;
self.full = None;
self.infoUrl = None;
return
def outJSON(self, f, levTab):
if self.short!=None:
f.write(levTab+'\t\t"short": "'+self.short+'",\n')
if self.full!=None:
f.write(levTab+'\t\t"full": "'+self.full+'",\n')
if self.infoUrl!=None:
f.write(levTab+'\t\t"infoUrl": "'+self.infoUrl+'",\n
')
f.seek(-2, os.SEEK_CUR)
f.write('\n')
class SkyImageTile: class SkyImageTile:
"""Contains all the properties needed to describe a multiresolution image tile"""
def __init__(self): def __init__(self):
self.subTiles = [] self.subTiles = []
self.credits = None self.imageCredits = StructCredits()
self.infoUrl = None self.serverCredits = StructCredits()
self.imageInfo = StructCredits()
self.imageUrl = None self.imageUrl = None
self.alphaBlend = None
self.maxBrightness = None self.maxBrightness = None
return return
def outputJSON(self, prefix='', qCompress=False, maxLevelPerFile=10, outDir=''): def outputJSON(self, prefix='', qCompress=False, maxLevelPerFile=10, outDir=''):
"""Output the tiles tree in the JSON format""" """Output the tiles tree in the JSON format"""
fName = outDir+prefix+"x%.2d_%.2d_%.2d.json" % (2**self.leve l, self.i, self.j) fName = outDir+prefix+"x%.2d_%.2d_%.2d.json" % (2**self.leve l, self.i, self.j)
# Actually write the file with maxLevelPerFile level # Actually write the file with maxLevelPerFile level
f = open(fName, 'w') f = open(fName, 'w')
self.__subOutJSON(prefix, qCompress, maxLevelPerFile, f, 0, outDir) self.__subOutJSON(prefix, qCompress, maxLevelPerFile, f, 0, outDir)
f.close() f.close()
if (qCompress): if (qCompress):
ff = qt.QFile(fName) ff = open(fName)
ff.open(qt.IO_ReadOnly) fout = gzip.GzipFile(fName+".gz", 'w')
data = qt.qCompress(ff.readAll()) fout.write(ff.read())
fout = open(fName+".qZ", 'w')
fout.write(data.data())
fout.close() fout.close()
os.remove(fName) os.remove(fName)
def __subOutJSON(self, prefix, qCompress, maxLevelPerFile, f, curLev , outDir): def __subOutJSON(self, prefix, qCompress, maxLevelPerFile, f, curLev , outDir):
"""Write the tile in the file f"""
levTab = "" levTab = ""
for i in range(0,curLev): for i in range(0,curLev):
levTab += '\t' levTab += '\t'
f.write(levTab+'{\n') f.write(levTab+'{\n')
if self.credits: if self.imageInfo.short!=None or self.imageInfo.full!=None o
f.write(levTab+'\t"credits" : "'+self.credits+'",\n' r self.imageInfo.infoUrl!=None:
) f.write(levTab+'\t"imageInfo": {\n')
if self.infoUrl: self.imageInfo.outJSON(f, levTab)
f.write(levTab+'\t"infoUrl" : "'+self.infoUrl+'",\n' f.write(levTab+'\t},\n')
) if self.imageCredits.short!=None or self.imageCredits.full!=
None or self.imageCredits.infoUrl!=None:
f.write(levTab+'\t"imageCredits": {\n')
self.imageCredits.outJSON(f, levTab)
f.write(levTab+'\t},\n')
if self.serverCredits.short!=None or self.serverCredits.full
!=None or self.serverCredits.infoUrl!=None:
f.write(levTab+'\t"serverCredits": {\n')
self.serverCredits.outJSON(f, levTab)
f.write(levTab+'\t},\n')
if self.imageUrl: if self.imageUrl:
f.write(levTab+'\t"imageUrl" : "'+self.imageUrl+'",\ f.write(levTab+'\t"imageUrl": "'+self.imageUrl+'",\n
n') ')
f.write(levTab+'\t"worldCoords" : ') f.write(levTab+'\t"worldCoords": ')
writePolys(self.skyConvexPolygons, f) writePolys(self.skyConvexPolygons, f)
f.write(',\n') f.write(',\n')
f.write(levTab+'\t"textureCoords" : ') f.write(levTab+'\t"textureCoords": ')
writePolys(self.textureCoords, f) writePolys(self.textureCoords, f)
f.write(',\n') f.write(',\n')
if self.maxBrightness: if self.maxBrightness:
f.write(levTab+'\t"maxBrightness" : %f,\n' % self.ma f.write(levTab+'\t"maxBrightness": %f,\n' % self.max
xBrightness) Brightness)
f.write(levTab+'\t"minResolution" : %f' % self.minResolution if self.alphaBlend==True:
) f.write(levTab+'\t"alphaBlend": true,\n')
f.write(levTab+'\t"minResolution": %f' % self.minResolution)
if len(self.subTiles)==0: if len(self.subTiles)==0:
f.write('\n'+levTab+'}') f.write('\n'+levTab+'}')
return return
f.write(',\n') f.write(',\n')
f.write(levTab+'\t"subTiles" : [\n') f.write(levTab+'\t"subTiles": [\n')
if curLev+1<maxLevelPerFile: if curLev+1<maxLevelPerFile:
# Write the tiles in the same file # Write the tiles in the same file
for st in self.subTiles: for st in self.subTiles:
assert isinstance(st, SkyImageTile) assert isinstance(st, SkyImageTile)
st.__subOutJSON(prefix, qCompress, maxLevelP erFile, f, curLev+1, outDir) st.__subOutJSON(prefix, qCompress, maxLevelP erFile, f, curLev+1, outDir)
f.write(',\n') f.write(',\n')
else: else:
# Write the tiles in a new file # Write the tiles in a new file
for st in self.subTiles: for st in self.subTiles:
st.outputJSON(prefix, qCompress, maxLevelPer File, outDir) st.outputJSON(prefix, qCompress, maxLevelPer File, outDir)
f.write(levTab+'\t\t"'+prefix+"x%.2d_%.2d_%. 2d.json" % (2**st.level, st.i, st.j)) f.write(levTab+'\t\t{"$ref": "'+prefix+"x%.2 d_%.2d_%.2d.json" % (2**st.level, st.i, st.j))
if qCompress: if qCompress:
f.write(".qZ") f.write(".gz")
f.write('",\n') f.write('"},\n')
f.seek(-2, os.SEEK_CUR) f.seek(-2, os.SEEK_CUR)
f.write('\n'+levTab+'\t]\n') f.write('\n'+levTab+'\t]\n')
f.write(levTab+'}') f.write(levTab+'}')
 End of changes. 16 change blocks. 
28 lines changed or deleted 59 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/