# interpolate_coords.py # # CREATED 2019.09.30 ABS copied from polyhc2w3d.py # MODIFIED 2019.10.01 ABS worked on parsing # MODIFIED 2019.10.02 ABS got working # MODIFIED 2019.10.23 ABS cleaned up # MODIFIED 2019.10.24 ABS cleaned up # # to do: # # [X] read both files # [X] compute deltas # [X] write coords # [X] clean up code: [X] build filenames; [X] arg types [_] remove dummy vars # [_] automate SED file # [_] add polygon edges # [_] polygon edges on radio button # [X] iPhone ready # from __future__ import print_function import sys import argparse def debugWrite(flag, message, var): if (flag): print('DEBUG:', message, var, file=sys.stderr) def translateName(prefix, step): return prefix + str(step) + '.html' # START:readCoords def readCoords(inputName, coords_list): # typical coords file: # # triples = 0 input = open(inputName, 'r') for line in input: if (line.find('<') == -1): # debugWrite(args.debugFlag, "line = ", line) xyz = line.split(",") # debugWrite(args.debugFlag, "xyz[0] = ", xyz[0]) # debugWrite(args.debugFlag, "xyz[1] = ", xyz[1]) # debugWrite(args.debugFlag, "xyz[2] = ", xyz[2]) coords_list[triples][0] = float(xyz[0]) coords_list[triples][1] = float(xyz[1]) coords_list[triples][2] = float(xyz[2]) # debugWrite(args.debugFlag, "coords_list[triples] = ", coords_list[triples]) triples = triples + 1 input.close() # debugWrite(args.debugFlag, "triples = ", triples) # END:readCoords def writeCoords(outputName, coords, deltas, s): output = open(outputName, 'w') print("",file=output) output.close() # MAIN: start running # parser = argparse.ArgumentParser(description='interpolate X3DOM coordinates') parser.add_argument('-D', '--DEBUG', dest='debugFlag', action='store_true', help='debug write') parser.add_argument('-s', '--start_file', dest='start_file', default='c0.html', action='store', help='start file name') parser.add_argument('-e', '--end_file', dest='end_file', default='c1.html', action='store', help='end file name') parser.add_argument('-m', '--max', dest='max_rows', default=64, action='store', help='maximum vertices') parser.add_argument('-n', '--steps', dest='steps', default=10, action='store', help='number of steps') parser.add_argument('-p', '--prefix', dest='prefix', default='coords', action='store', help='filename prefix') args = parser.parse_args() debugWrite(args.debugFlag, "start_file =", args.start_file) debugWrite(args.debugFlag, "end_file =", args.end_file) debugWrite(args.debugFlag, "steps =", args.steps) debugWrite(args.debugFlag, "max_rows =", args.max_rows) debugWrite(args.debugFlag, "prefix =", args.prefix) rows = int(args.max_rows) cols = int(3) coords_list0 = [[0.0 for y in xrange(cols)] for x in xrange(rows)] coords_list1 = [[0.0 for y in xrange(cols)] for x in xrange(rows)] delta_list = [[0.0 for y in xrange(cols)] for x in xrange(rows)] # read start file inputName = args.start_file readCoords(inputName, coords_list0) debugWrite(args.debugFlag, "coords_list0 =", coords_list0) # read end file inputName = args.end_file readCoords(inputName, coords_list1) debugWrite(args.debugFlag, "coords_list1 =", coords_list1) # compute deltas steps = int(args.steps) for r in range(0, rows): for c in range(0, cols): delta_list[r][c] = \ (coords_list1[r][c] - coords_list0[r][c])/float(steps - 1) debugWrite(args.debugFlag, "delta_list =", delta_list) # write files for s in range(0, steps): writeCoords(translateName(args.prefix, s), coords_list0, delta_list, float(s))