def add_hull_to_simulation(): ctrl, vil, xyz_centroid = convexhull.giftwrap( cloud=np.array(cells('nodes/x')) * 1e6, ignore_half=True, quantile_gut=0.4, #original 0.4 divide_remove=5, #5 originally seedlen=75, debug=False) ctrl *= 1e-6 xyz_centroid *= 1e-6 vil = [el[::-1] for el in vil] # Normals should point inwards thehull.controlPoints.add_and_set_particles(xBF=list(map(tuple, ctrl))) thehull.hull.add_and_set_particles(vertexIndices=list(map(tuple, vil)), layer_width=10 * erange.get_value()) # orig 5 if param_xml.get_value('scale_hull_factor', ['process_flow']) != 1: scale_hull( param_xml.get_value('scale_hull_factor', ['process_flow']), xyz_centroid ) #wth: loose fit for smoothing (in conjunction with larger repulsion distance) print("Introduced and positioned hull") hull.VTKWriterCmd(executeInterval=.05, select_all=True, directory=str(output_folder)) return
def giftwrap(): '''Testing (Gift-Wrapping Algorithm)''' setA = 'Set_A.dat' setB = 'Set_B.dat' print("---GIFT-WRAPPING TESTING---") print('Set A:') for i in range(2000, 32000, 2000): listPts = convexhull.readDataPts(setA, i) start = time.time() convexhull.giftwrap(listPts) end = time.time() elapsed = end - start print(elapsed) print() print('Set B:') for i in range(2000, 32000, 2000): listPts = convexhull.readDataPts(setB, i) start = time.time() convexhull.giftwrap(listPts) end = time.time() elapsed = end - start print(elapsed)
def test_all_same_answer(tests=tests_A): for test_case in tests: answer = read_answer(test_case) filename = "Data/{}.dat".format(test_case) listPts = readDataPts(filename) gift = giftwrap(listPts) graham = grahamscan(listPts) mono_tone = amethod(listPts) print("Giftwrap = answer: {}".format(gift == answer)) print("Grahamscan = answer: {}".format(graham == answer)) print("Monotone Chain = answer: {}".format(mono_tone == answer))
def main(): """Add-on time tracker for Convex Hull Algorithms of Giftwrap, Graham Scan and Andrew's Monotone Chain Algorithm """ listPts = convexhull.readDataPts('B_30000.dat', 30000) #change to whichever needed #Gift Wrap Timer start_timer = time() giftwrap_list = convexhull.giftwrap(listPts) print("Gift Wrap algorithm used {:.15f} seconds.".format(time() - start_timer)) #Graham Scan Timer start_timer = time() graham_list = convexhull.grahamscan(listPts) print("Graham Scan algorithm used {:.15f} seconds.".format(time() - start_timer)) #Monotone Chain Timer start_timer = time() monotone_list = convexhull.amethod(listPts) print("Monotone Chain algorithm used {:.15f} seconds.".format(time() - start_timer))
def test_setA(): """test all the files in set A against their expected output, prints the results with the time it took each method to get the convex hull""" # test file A_10 filename = 'A_10.dat' output_file = 'A_10.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_50 filename = 'A_50.dat' output_file = 'A_50.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_500 filename = 'A_500.dat' output_file = 'A_500.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_3000 filename = 'A_3000.dat' output_file = 'A_3000.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_6000 filename = 'A_6000.dat' output_file = 'A_6000.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_9000 filename = 'A_9000.dat' output_file = 'A_9000.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_15000 filename = 'A_15000.dat' output_file = 'A_15000.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------') # test file A_30000 filename = 'A_30000.dat' output_file = 'A_30000.out' print("Convex hull for file", filename + ":") print(expected_output(output_file)) listPts = convexhull.readDataPts(filename) print('giftwrap method gives expected output:', expected_output(output_file) == convexhull.giftwrap(listPts), '\tTime taken:'.expandtabs(6), convexhull.time_giftwrap) print('grahamscan method gives expected output:', expected_output(output_file) == convexhull.grahamscan(listPts), '\tTime taken:'.expandtabs(4), convexhull.time_grahamscan) print('amethod method gives expected output:', expected_output(output_file) == convexhull.amethod(listPts), '\tTime taken:'.expandtabs(7), convexhull.time_amethod) print('------------------------------------------------')
def output_tests(): """ Runs tests that validate all algrithms """ sizes = [3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 27000, 30000] """ These filenames may need to be altered dependent on their location """ filenames_a = ["Set_A/A_3000.dat", "Set_A/A_6000.dat", "Set_A/A_9000.dat", "Set_A/A_12000.dat", "Set_A/A_15000.dat", "Set_A/A_18000.dat", "Set_A/A_21000.dat", "Set_A/A_24000.dat", "Set_A/A_27000.dat", "Set_A/A_30000.dat"] filenames_b = ["Set_B/B_3000.dat", "Set_B/B_6000.dat", "Set_B/B_9000.dat", "Set_B/B_12000.dat", "Set_B/B_15000.dat", "Set_B/B_18000.dat", "Set_B/B_21000.dat", "Set_B/B_24000.dat", "Set_B/B_27000.dat", "Set_B/B_30000.dat"] print("Set A") print("---------------") #Looping over each file in set A for index, filename in enumerate(filenames_a): #Testing data set A print(filename) #Getting points listPts = convex.readDataPts(filename, sizes[index]) #Calling algorithms gft_hull = convex.giftwrap(listPts[:]) grs_hull = convex.grahamscan(listPts[:]) mono_hull = convex.monotone_chain(listPts[:]) #Getting result of the algorithm expected = outputs_A[index] gft = "Fail" grs = "Fail" mono = "Fail" if gft_hull == expected: gft = "Pass" if grs_hull == expected: grs = "Pass" if sorted(mono_hull) == sorted(expected): mono = "Pass" #Outputting results of the test print("Gifftwrap: " + gft) print("Grahamscan: " + grs) print("Monotone chain: " + mono) print("---------------") print("\nSet B") print("---------------") #Looping over each file in set B for index, filename in enumerate(filenames_b): #Testing data set B print(filename) #Getting points listPts = convex.readDataPts(filename, sizes[index]) #Calling algorithms gft_hull = convex.giftwrap(listPts[:]) grs_hull = convex.grahamscan(listPts[:]) mono_hull = convex.monotone_chain(listPts[:]) #Getting result of the algorithm expected = outputs_B[index] gft = "Fail" grs = "Fail" mono = "Fail" if gft_hull == expected: gft = "Pass" if grs_hull == expected: grs = "Pass" if sorted(mono_hull) == sorted(expected): mono = "Pass" #Outputting results of the test print("Gifftwrap: " + gft) print("Grahamscan: " + grs) print("Monotone chain: " + mono) print("---------------")