Skip to content
Permalink
dev
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 91 lines (74 sloc) 4 KB
#!/usr/bin/env python
"""
@author Peter Zaffetti 2017
"""
import argparse
import cmd
import os
import sys
from user_interface.curve_parser import parse_curve_file, parse_subdivided_curve_file
from logger import get_logger
from data_objects.subdivision_generator import generate_curve_values
from data_objects.monotonicity_calculator import calculate_monotonicity
class CliApplication(cmd.Cmd):
def __init__(self, application_path=None, args="test.curve"):
self.logger = get_logger(__name__)
self.test_curves_path = os.path.join(application_path, "test_curves")
self.arguments = args
self.logger.debug("Test Curves Path is: %s", self.test_curves_path)
self.logger.debug("Arguments are: %s", self.arguments)
self.parse_cmd_args(self.arguments)
sys.exit(1)
def parse_cmd_args(self, args):
if args is not None:
if args.generate_m_value:
self.logger.debug(args.generate_m_value)
if os.path.exists(args.generate_m_value):
if os.path.isdir(args.generate_m_value):
self.logger.error("Please input a filename not a directory name.")
else:
self.generate_m_value(args.generate_m_value)
else:
curve_path = os.path.join(self.test_curves_path, args.generate_m_value)
if os.path.exists(curve_path):
self.generate_m_value(curve_path)
else:
self.logger.info("The curve file doesn't exist. Please choose an appropriate file.")
elif args.calculate_monotonicity:
self.logger.debug(args.calculate_monotonicity)
if os.path.exists(args.calculate_monotonicity):
if os.path.isdir(args.calculate_monotonicity):
self.logger.error("Please input a filename not a directory name.")
else:
self.calculate_monotonicity(args.calculate_monotonicity)
else:
curve_path = os.path.join(self.test_curves_path, args.calculate_monotonicity)
if os.path.exists(curve_path):
self.generate_m_value(curve_path)
else:
self.logger.info("The curve file doesn't exist. Please choose an appropriate file.")
else:
raise Exception("There were no arguments when running the application")
def generate_m_value(self, curve_file="test.curve"):
knot_curve = parse_curve_file(curve_file)
generate_curve_values(knot_curve.get_points_as_np_arrays())
pass
def calculate_monotonicity(self, subdivided_file="subdivided_test.curve"):
subdivided_knot_curve_list = parse_subdivided_curve_file(subdivided_file)
for subdivided_knot_curve in subdivided_knot_curve_list:
calculate_monotonicity(subdivided_knot_curve)
pass
def main():
"""The main function that runs the Subdivision Generator application"""
application_path = os.path.dirname(os.path.abspath(__file__))
application_name = os.path.splitext(os.path.basename(__file__))[0]
argument_parser = argparse.ArgumentParser(
description='Generates the required number of subdivisions for a Bezier curve to match the stick knot it was created from')
argument_parser.add_argument("-g", "--generate_m_value", help="generates the minimum number of iterations needed for the supplied \
stick knot's Bezier cure to match the stick knot", default=None, action="store")
argument_parser.add_argument("-m", "--calculate_monotonicity", help="calculates whether the coordinates of the subdivided curves in the file are monotonically increasing or decreasing", default=None, action="store")
arguments = argument_parser.parse_args()
get_logger().debug("Subdivision-Generator Starting Up")
application = CliApplication(application_path, arguments)
if __name__ == "__main__":
main()