-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_from_file.py
58 lines (47 loc) · 1.96 KB
/
main_from_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from categorisation import Categorisation
from file_operation import FileOperations
from mini_boundary_rec import MBR
from plotter import Plotter
def main(polygon_file='polygon.csv', output_file='output.csv'):
categories = {'id': 'category'} # store category result in a dictionary
file_operations = FileOperations() # create objects
mbr = MBR()
categorisation = Categorisation()
plotter = Plotter()
# print('read polygon.csv')
polygon = file_operations.read_polygon(polygon_file)
# print('read input.csv')
inputs = file_operations.read_input('input.csv')
# print('categorize points')
# print('First find points outside minimum boundary rectangle')
for i in range(len(inputs)):
test = inputs[i] # test each input point
if not mbr.points_in_mbr(test, polygon): # the point is out of MBR
categories[i] = 'outside'
else: # loop through all boundaries at given clock-wise oder
boundaries = polygon.get_boundaries()
# now apply ray casting algorithm
count_inter = categorisation.ray_intersections(test, boundaries)
if count_inter % 2 == 1:
categories[i] = 'inside'
elif count_inter % 2 == 0:
categories[i] = 'outside'
for boundary in boundaries:
if categorisation.on_boundary(test, boundary):
categories[i] = 'boundary'
break
for key, cate in categories.items():
try:
p_x = inputs[key].x
p_y = inputs[key].y
except TypeError: # skip the headline
# print('This is the headline')
pass
continue
plotter.add_point(p_x, p_y, kind=cate)
plotter.ray_plotter(polygon, p_x, p_y, kind=cate)
plotter.add_polygon(polygon.points.x, polygon.points.y)
plotter.show()
file_operations.write_output(output_file, categories)
if __name__ == '__main__':
main()