#!/usr/bin/env python # lim2pov by David Dumas """lim2pov: convert postscript output from Curt McMullen's lim to POV-Ray input""" import sys import getopt def usage(): print(''' usage: lim2pov [options] Lim output postscript is read from STDIN and povray input is sent to STDOUT. Options: -h or --help Display this help message. -r or --raw Raw mode: output a povray-formatted list of center-radius pairs, but no scripting or graphics primitives. -s or --sphere Sphere mode: write sphere primitives. -m MACRO or --macro MACRO Macro mode: write povray code calling MACRO with parameters (centerx,centery,radius) for each circle. -R MAX or --maxradius MAX Ignore all circles with radius >= MAX --minradius MIN Ignore all circles with radius < MIN ''') class _conf(object): def __init__(self): # DEFAULT CONFIGURATION OPTIONS self.mode = 'sphere' # sphere, raw, macro self.macro = None self.maxradius = 0.9999999 self.minradius = 0 def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "hsrm:R:", ["help", "sphere", "raw","macro=","maxradius=", "minradius="]) except getopt.GetoptError: usage() sys.exit(2) conf = _conf() for o, a in opts: if o in ("-h", "--help"): usage() sys.exit() if o in ("-s","--sphere"): conf.mode = 'sphere' if o in ("-r","--raw"): conf.mode = 'raw' if o in ("-m","--macro"): conf.mode = 'macro' conf.macro = a if o in ("-R","--maxradius"): conf.maxradius = float(a) if o in ("--minradius",): conf.minradius = float(a) # look for the start of the input circles for line in sys.stdin: if (line[:2] == '/c') and (line[-4:-1] == 'def'): break # process the circles. for line in sys.stdin: if line[-3:-1] != ' c': break x,y,r = map(float,line.split(' ')[:3]) if (r < conf.maxradius) and (r > conf.minradius): if conf.mode=='sphere': print '\tsphere { <%f,%f,0>, %f }' % (x,y,r) elif conf.mode=='raw': print '<%f,%f,0>, %f,' % (x,y,r) elif conf.mode=='macro': print "%s(%f,%f,%f)" % (conf.macro,x,y,r) if __name__=='__main__': main()