-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_params.py
152 lines (123 loc) · 6.03 KB
/
input_params.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from base_classes import Color
class TileParams:
def __init__(self):
# Numbers are in mm
self.TILE_WIDTH = 300
self.TILE_HEIGHT = 300
self.GROUTING_SIZE = 1
self.no_per_width = None #will be calculated later
self.no_per_height = None #will be calculated later
self.rectangle_width = 5
self.rectangle_height = 5
self.mode = "pixel_size"
# GROUTING_SIZE = 4
# rectangle_width = 4
# rectangle_height = 9
# GROUTING_SIZE = 1
# rectangle_width = 120
# rectangle_height = 60
self.symmetry = {'vertical' :True,
'horizontal' :True,
'right_diagonal':False,
'left_diagonal' :False}
self.init_colors()
self.calculate_params()
def init_colors(self):
PIXEL_COLOR = Color(r=0x3f, g=0x9a, b=0xbe, name='blue1')
PIXEL_COLOR1 = Color(r=0x07, g=0x73, b=0x92, name='blue2')
PIXEL_COLOR2 = Color(r=0xca, g=0xdb, b=0xe0, name='blue3')
self.PIXEL_COLORS = [PIXEL_COLOR, PIXEL_COLOR1, PIXEL_COLOR2]
self.PIXEL_COLORS_p = [0.7, 0.2, 0.1]
self.GROUTING_COLOR = Color(r=0x80, g=0xbf, b=0xca, name='blue4')
self.new_color = Color(r=0xff, g=0xff, b=0x00, name='yellow')
def update_color(self, BLEND_MODE_COLORS=None, SOLID_BG_COLOR=None,
GROUTING_COLOR=None):
if type(BLEND_MODE_COLORS) is dict:
PIXEL_COLORS = list()
PIXEL_COLORS_p = list()
sum_perc = 0
for i in BLEND_MODE_COLORS:
color = BLEND_MODE_COLORS[i][f'-BLEND_COLOR{i}-']
color_perc = BLEND_MODE_COLORS[i][f'-BLEND_COLOR{i}_PERCENT-']
if color is None:
continue
sum_perc = sum_perc + color_perc
PIXEL_COLORS.append (color)
PIXEL_COLORS_p.append(color_perc/100.0)
if sum_perc == 100:
self.PIXEL_COLORS = PIXEL_COLORS
self.PIXEL_COLORS_p = PIXEL_COLORS_p
else:
print("Sum of blend colors is not 100. Using older colors")
elif type(SOLID_BG_COLOR) is Color:
self.PIXEL_COLORS = [SOLID_BG_COLOR]
self.PIXEL_COLORS_p = [1]
if GROUTING_COLOR is not None:
self.GROUTING_COLOR = GROUTING_COLOR
def calculate_params(self):
self.PIXELS_PER_MM = 2
self.TILE_PX_WIDTH = self.TILE_WIDTH *self.PIXELS_PER_MM
self.TILE_PX_HEIGHT = self.TILE_HEIGHT *self.PIXELS_PER_MM
self.GROUTING_SIZE_PX = self.GROUTING_SIZE*self.PIXELS_PER_MM
self.GROUTING_OFFSET = int(self.GROUTING_SIZE_PX/2)
#height, width are in mm
(unit_width, unit_height)= self.set_unit_size()
unit_px_width = unit_width * self.PIXELS_PER_MM
unit_px_height = unit_height * self.PIXELS_PER_MM
self.pixel_width_plus_grout = unit_px_width + self.GROUTING_SIZE_PX
self.pixel_height_plus_grout = unit_px_height + self.GROUTING_SIZE_PX
if self.mode == "pixel_size":
self.no_per_width = int(self.TILE_PX_WIDTH /self.pixel_width_plus_grout)
self.no_per_height = int(self.TILE_PX_HEIGHT/self.pixel_height_plus_grout)
self.NEW_TILE_PX_WIDTH = self.no_per_width * self.pixel_width_plus_grout
self.NEW_TILE_PX_HEIGHT = self.no_per_height * self.pixel_height_plus_grout
print(f"RESIZING IMAGE TO WIDTH:{self.NEW_TILE_PX_WIDTH}, \
HEIGHT:{self.NEW_TILE_PX_HEIGHT}")
def set_unit_size(self):
if self.rectangle_width is not None and \
self.rectangle_height is not None:
self.mode = "pixel_size"
return (self.rectangle_width, self.rectangle_height)
if self.no_per_width is not None and \
self.no_per_height is not None:
width = int(self.TILE_WIDTH/self.no_per_width) - self.GROUTING_SIZE
height = int(self.TILE_WIDTH/self.no_per_height) - self.GROUTING_SIZE
if width <0 or height<0:
return (None, None)
self.mode = "pixel_number"
return (width, height)
def update_params(self, TILE_WIDTH=None, TILE_HEIGHT=None,
GROUTING_SIZE=None,
rectangle_width=None, rectangle_height=None,
num_width=None, num_height=None,
vertical_symm=None, horizontal_symm=None,
right_d_symm=None, left_d_symm=None):
##TODO: add support for no_of_pixel (_per_side)
## tile_size = no_of_pixel * (pixel_unit_size + grouting_size)
# tile_size=300, pixel_unit_size=2, grouting_size=1 so no_of_pixel=?
# tile_size=300, pixel_unit_size=2, no_of_pixel=39 so grouting_size=?
if TILE_WIDTH is not None:
self.TILE_WIDTH = TILE_WIDTH
if TILE_HEIGHT is not None:
self.TILE_HEIGHT = TILE_HEIGHT
if GROUTING_SIZE is not None:
self.GROUTING_SIZE = GROUTING_SIZE
if num_width is not None and num_height is not None:
self.no_per_width = num_width
self.no_per_height = num_height
self.rectangle_width = None
self.rectangle_height = None
if rectangle_width is not None and rectangle_height is not None:
self.no_per_width = None
self.no_per_height = None
self.rectangle_width = rectangle_width
self.rectangle_height = rectangle_height
if vertical_symm is not None:
self.symmetry['vertical'] = vertical_symm
if horizontal_symm is not None:
self.symmetry['horizontal'] = horizontal_symm
if right_d_symm is not None:
self.symmetry['right_diagonal'] = right_d_symm
if left_d_symm is not None:
self.symmetry['left_diagonal'] = left_d_symm
self.calculate_params()