def test_routine(file_name, target_alignment, kwargs): objs = file_handler.load_mesh(file_name) info = dict() for part, content in objs.items(): mesh = content["mesh"] info[part] = dict() x = Tweak(mesh, **kwargs) info[part]["alignment"] = x.alignment info[part]["rotation_axis"] = x.rotation_axis info[part]["rotation_angle"] = x.rotation_angle info[part]["euler_parameter"] = x.euler_parameter info[part]["bottom_area"] = x.bottom_area info[part]["overhang_area"] = x.overhang_area info[part]["contour"] = x.contour info[part]["unprintability"] = x.unprintability info[part]["best_5"] = x.best_5 info[part]["time"] = x.time info[part]["tweaker_stats"] = x print("Object: {}, result: new alignment: \t{}".format( file_name, x.alignment)) assert np.allclose(info[part]["alignment"], target_alignment, atol=1e-4)
# Start of tweaking. if args.verbose: print("Calculating the optimal orientation:\n {}".format( args.inputfile.split(os.sep)[-1])) c = 0 info = dict() for part, content in objs.items(): mesh = content["mesh"] info[part] = dict() if args.convert: info[part]["matrix"] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] else: try: cstime = time() x = Tweak(mesh, args.extended_mode, args.verbose, args.show_progress, args.favside, args.volume) info[part]["matrix"] = x.matrix info[part]["tweaker_stats"] = x except (KeyboardInterrupt, SystemExit): raise SystemExit("\nError, tweaking process failed!") # List tweaking results if args.result or args.verbose: print("Result-stats:") print(" Tweaked Z-axis: \t{}".format(x.alignment)) print(" Axis, angle: \t{}".format(x.euler_parameter)) print(""" Rotation matrix: {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f}""".format(x.matrix[0][0], x.matrix[0][1], x.matrix[0][2], x.matrix[1][0],
def cli(): global FileHandler # Get the command line arguments. Run in IDE for demo tweaking. stime = time() try: args = getargs() if args is None: sys.exit() except: raise try: FileHandler = FileHandler.FileHandler() objs = FileHandler.load_mesh(args.inputfile) if objs is None: sys.exit() except (KeyboardInterrupt, SystemExit): raise SystemExit("Error, loading mesh from file failed!") # Start of tweaking. if args.verbose: print("Calculating the optimal orientation:\n {}".format( args.inputfile.split(os.sep)[-1])) c = 0 info = dict() for part, content in objs.items(): mesh = content["mesh"] info[part] = dict() if args.convert: info[part]["matrix"] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] else: try: cstime = time() x = Tweak(mesh, args.extended_mode, args.verbose, args.show_progress, args.favside, args.volume) info[part]["matrix"] = x.matrix info[part]["tweaker_stats"] = x except (KeyboardInterrupt, SystemExit): raise SystemExit("\nError, tweaking process failed!") # List tweaking results if args.result or args.verbose: print("Result-stats:") print(" Tweaked Z-axis: \t{}".format(x.alignment)) print(" Axis {}, \tangle: {}".format(x.rotation_axis, x.rotation_angle)) print(""" Rotation matrix: {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f}""".format(x.matrix[0][0], x.matrix[0][1], x.matrix[0][2], x.matrix[1][0], x.matrix[1][1], x.matrix[1][2], x.matrix[2][0], x.matrix[2][1], x.matrix[2][2])) print(" Unprintability: \t{}".format(x.unprintability)) print("Found result: \t{:2f} s\n".format(time() - cstime)) if not args.result: try: FileHandler.write_mesh(objs, info, args.outputfile, args.output_type) except FileNotFoundError: raise FileNotFoundError("Output File '{}' not found.".format( args.outputfile)) # Success message if args.verbose: print("Tweaking took: \t{:2f} s".format(time() - stime)) print("Successfully Rotated!")
print("\nError, loading mesh from file failed!") raise ## Start of tweaking. if args.verbose: print("Calculating the optimal orientation:\n {}\n" .format(args.inputfile.split("\\")[-1])) c = 0 for obj in objs: mesh = obj["Mesh"] if args.convert: R=[[1,0,0],[0,1,0],[0,0,1]] else: try: cstime = time.time() x=Tweak(mesh, args.bi_algorithmic, args.verbose, args.angle) R=x.R except (KeyboardInterrupt, SystemExit): print("\nError, tweaking process failed!") raise ## List tweaking results if args.result or args.verbose: print("\nResult-stats:") print(" Tweaked Z-axis: \t{}".format((x.Zn))) print(" Axis, angle: \t{v}, {phi}".format(v=x.v, phi=x.phi)) print(""" Rotation matrix: {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f}""".format(x.R[0][0], x.R[0][1], x.R[0][2], x.R[1][0], x.R[1][1], x.R[1][2],
def RunTweakerFromProgram(conf): # Get the command line arguments. Run in IDE for demo tweaking. stime = time() # try: # args = getargs() # if args is None: # sys.exit() # except: # raise try: FileHandler_local = FileHandler() print(conf.inputfile) objs = FileHandler_local.load_mesh(conf.inputfile) if objs is None: sys.exit() except (KeyboardInterrupt, SystemExit): raise SystemExit("Error, loading mesh from file failed!") # Start of tweaking. if conf.verbose: print("Calculating the optimal orientation:\n {}".format( conf.inputfile.split(os.sep)[-1])) c = 0 info = dict() for part, content in objs.items(): mesh = content["mesh"] info[part] = dict() if conf.convert: info[part]["matrix"] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] else: try: cstime = time() x = Tweak(mesh, conf.extended_mode, conf.verbose, conf.show_progress, conf.favside, conf.volume) info[part]["matrix"] = x.matrix info[part]["tweaker_stats"] = x except (KeyboardInterrupt, SystemExit): raise SystemExit("\nError, tweaking process failed!") # List tweaking results if conf.result or conf.verbose: print("Result-stats:") print(" Tweaked Z-axis: \t{}".format(x.alignment)) print(" Axis, angle: \t{}".format(x.euler_parameter)) print(""" Rotation matrix: {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f} {:2f}\t{:2f}\t{:2f}""".format(x.matrix[0][0], x.matrix[0][1], x.matrix[0][2], x.matrix[1][0], x.matrix[1][1], x.matrix[1][2], x.matrix[2][0], x.matrix[2][1], x.matrix[2][2])) print(" Unprintability: \t{}".format(x.unprintability)) print("Found result: \t{:2f} s\n".format(time() - cstime)) print(conf.result) if not conf.result: print('writing output file') FileHandler_local.write_mesh(objs, info, conf.outputfile, conf.output_type) # Success message if conf.verbose: print("Tweaking took: \t{:2f} s".format(time() - stime)) print("Successfully Rotated!")