diff --git a/tools/cut.py b/tools/cut.py index eba77e9..dc11a82 100644 --- a/tools/cut.py +++ b/tools/cut.py @@ -5,7 +5,7 @@ import glob import copy import logging -def cut_file(filename, _from, _to): +def cut_file(filename, _from, _to, reverse = False): imported_frames = [] anim_id = "" @@ -52,15 +52,27 @@ def cut_file(filename, _from, _to): _to = len(imported_frames)-1 path = '{}/cut_{}_{}'.format(os.path.dirname(filename),_from,_to) + + if reverse: + path += '_r' csv_file = open(path+'/'+os.path.basename(filename), mode='w+') with csv_file: csv_writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) if anim_id != "": csv_writer.writerow([anim_id]) - for i in range(_from, _to+1): - csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'], - imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']]) + if not reverse: + for i in range(_from, _to+1): + csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'], + imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']]) + else: + for i in range(_from): + csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'], + imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']]) + for i in range(_to, len(imported_frames)): + csv_writer.writerow([imported_frames[i]['number'], imported_frames[i]['x'], imported_frames[i]['y'], imported_frames[i]['z'], + imported_frames[i]['yaw'], imported_frames[i]['red'], imported_frames[i]['green'], imported_frames[i]['blue']]) + print("Successfully created file {}".format(path+'/'+os.path.basename(filename))) @@ -73,13 +85,15 @@ if __name__ == "__main__": help="Cut from this frame, default is 0 (from the beginning)") parser.add_argument('-t','--to', type=int, default=0, help="Cut to this frame (including this one), default is 0 (to the end)") + parser.add_argument('-r', '--reverse', action='store_true', help="Reverse cutting, this tool will cut from the beginning to frame and from frame to the end") args = parser.parse_args() _from = args.frm _to = args.to path = '{}/cut_{}_{}'.format(args.directory,_from,_to) - + if args.reverse: + path += '_r' if not os.path.exists(path): try: @@ -91,7 +105,7 @@ if __name__ == "__main__": files = [f for f in glob.glob(args.directory + '/*.csv')] for f in files: - cut_file(f, _from, _to) + cut_file(f, _from, _to, args.reverse)