molde 0.1.11__py3-none-any.whl → 0.1.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
|
|
1
1
|
from dataclasses import dataclass
|
2
|
+
from typing import Callable
|
2
3
|
|
3
|
-
from molde import Color
|
4
|
-
from molde.utils import transform_polydata
|
5
4
|
from vtkmodules.vtkCommonCore import (
|
6
5
|
vtkDoubleArray,
|
7
6
|
vtkIntArray,
|
@@ -9,14 +8,21 @@ from vtkmodules.vtkCommonCore import (
|
|
9
8
|
vtkUnsignedCharArray,
|
10
9
|
)
|
11
10
|
from vtkmodules.vtkCommonDataModel import vtkPolyData
|
12
|
-
from vtkmodules.vtkRenderingCore import
|
11
|
+
from vtkmodules.vtkRenderingCore import (
|
12
|
+
vtkActor,
|
13
|
+
vtkDistanceToCamera,
|
14
|
+
vtkGlyph3DMapper,
|
15
|
+
vtkRenderer,
|
16
|
+
)
|
17
|
+
|
18
|
+
from molde import Color
|
13
19
|
|
14
20
|
Triple = tuple[float, float, float]
|
15
21
|
|
16
22
|
|
17
23
|
@dataclass
|
18
24
|
class Symbol:
|
19
|
-
|
25
|
+
shape_function: Callable
|
20
26
|
position: Triple
|
21
27
|
orientation: Triple
|
22
28
|
color: Color
|
@@ -25,34 +31,18 @@ class Symbol:
|
|
25
31
|
|
26
32
|
class CommonSymbolsActor(vtkActor):
|
27
33
|
def __init__(self, *args, **kwargs):
|
28
|
-
self._shapes: dict[str, vtkPolyData] = dict()
|
29
34
|
self._symbols: list[Symbol] = list()
|
30
35
|
|
31
|
-
def register_shape(
|
32
|
-
self,
|
33
|
-
name: str,
|
34
|
-
shape: vtkPolyData,
|
35
|
-
position: Triple = (0, 0, 0),
|
36
|
-
rotation: Triple = (0, 0, 0),
|
37
|
-
scale: Triple = (1, 1, 1),
|
38
|
-
):
|
39
|
-
self._shapes[name] = transform_polydata(
|
40
|
-
shape,
|
41
|
-
position,
|
42
|
-
rotation,
|
43
|
-
scale,
|
44
|
-
)
|
45
|
-
|
46
36
|
def add_symbol(
|
47
37
|
self,
|
48
|
-
|
38
|
+
shape_function: Callable,
|
49
39
|
position: Triple,
|
50
40
|
orientation: Triple,
|
51
41
|
color: Triple,
|
52
42
|
scale: float = 1,
|
53
43
|
):
|
54
44
|
symbol = Symbol(
|
55
|
-
|
45
|
+
shape_function,
|
56
46
|
position,
|
57
47
|
orientation,
|
58
48
|
color,
|
@@ -60,16 +50,9 @@ class CommonSymbolsActor(vtkActor):
|
|
60
50
|
)
|
61
51
|
self._symbols.append(symbol)
|
62
52
|
|
63
|
-
def clear_shapes(self):
|
64
|
-
self._shapes.clear()
|
65
|
-
|
66
53
|
def clear_symbols(self):
|
67
54
|
self._symbols.clear()
|
68
55
|
|
69
|
-
def clear_all(self):
|
70
|
-
self.clear_shapes()
|
71
|
-
self.clear_symbols()
|
72
|
-
|
73
56
|
def common_build(self):
|
74
57
|
self.data = vtkPolyData()
|
75
58
|
points = vtkPoints()
|
@@ -91,17 +74,18 @@ class CommonSymbolsActor(vtkActor):
|
|
91
74
|
colors.SetNumberOfComponents(4)
|
92
75
|
colors.SetName("colors")
|
93
76
|
|
94
|
-
|
95
|
-
for index, (name, shape) in enumerate(self._shapes.items()):
|
96
|
-
shape_name_to_index[name] = index
|
97
|
-
self.mapper.SetSourceData(index, shape)
|
98
|
-
|
77
|
+
shape_function_to_index = dict()
|
99
78
|
for symbol in self._symbols:
|
79
|
+
if symbol.shape_function not in shape_function_to_index:
|
80
|
+
index = len(shape_function_to_index)
|
81
|
+
shape_function_to_index[symbol.shape_function] = index
|
82
|
+
self.mapper.SetSourceData(index, symbol.shape_function())
|
83
|
+
|
100
84
|
points.InsertNextPoint(symbol.position)
|
101
85
|
rotations.InsertNextTuple(symbol.orientation)
|
102
86
|
colors.InsertNextTuple(symbol.color.to_rgba())
|
103
87
|
scales.InsertNextValue(symbol.scale)
|
104
|
-
sources.InsertNextValue(
|
88
|
+
sources.InsertNextValue(shape_function_to_index[symbol.shape_function])
|
105
89
|
|
106
90
|
self.data.SetPoints(points)
|
107
91
|
self.data.GetPointData().AddArray(sources)
|
molde/colors/color.py
CHANGED
@@ -11,44 +11,43 @@ class Color:
|
|
11
11
|
|
12
12
|
@typing.overload
|
13
13
|
def __init__(self, r: int, g: int, b: int, a: int = 255):
|
14
|
-
|
14
|
+
"""
|
15
15
|
Initialize Colors with RGB or RGBA integer values ranging from 0 to 255.
|
16
|
-
|
17
|
-
|
16
|
+
"""
|
17
|
+
|
18
18
|
@typing.overload
|
19
19
|
def __init__(self, r: float, g: float, b: float, a: float = 1.0):
|
20
|
-
|
20
|
+
"""
|
21
21
|
Initialize Colors with RGB or RGBA floating values ranging from 0.0 to 1.0.
|
22
|
-
|
23
|
-
|
22
|
+
"""
|
23
|
+
|
24
24
|
@typing.overload
|
25
25
|
def __init__(self, hexa: str):
|
26
|
-
|
26
|
+
"""
|
27
27
|
Initialize colors from hex values.
|
28
28
|
The valid formats incluce RGB (#FF0000 for example)
|
29
29
|
and RGBA (#FF0000FF for example)
|
30
|
-
|
30
|
+
"""
|
31
31
|
|
32
32
|
@typing.overload
|
33
33
|
def __init__(self, qcolor: QColor):
|
34
|
-
|
34
|
+
"""
|
35
35
|
Initialize the color class with an instance of QColor
|
36
|
-
|
37
|
-
|
36
|
+
"""
|
37
|
+
|
38
38
|
@typing.overload
|
39
39
|
def __init__(self, color: "Color"):
|
40
|
-
|
40
|
+
"""
|
41
41
|
Initialize the color class with an instance it's own class
|
42
|
-
|
43
|
-
|
42
|
+
"""
|
43
|
+
|
44
44
|
@typing.overload
|
45
45
|
def __init__(self):
|
46
|
-
|
46
|
+
"""
|
47
47
|
Initialize an empty black color
|
48
|
-
|
48
|
+
"""
|
49
49
|
|
50
50
|
def __init__(self, *args):
|
51
|
-
|
52
51
|
all_int = all([isinstance(i, int) for i in args])
|
53
52
|
all_float = all([isinstance(i, float) for i in args])
|
54
53
|
|
@@ -57,10 +56,10 @@ class Color:
|
|
57
56
|
|
58
57
|
elif len(args) == 1 and isinstance(args[0], str):
|
59
58
|
self.from_hex(*args)
|
60
|
-
|
59
|
+
|
61
60
|
elif len(args) == 1 and isinstance(args[0], QColor):
|
62
61
|
self.from_qcolor(*args)
|
63
|
-
|
62
|
+
|
64
63
|
elif len(args) == 1 and isinstance(args[0], Color):
|
65
64
|
self.from_color(*args)
|
66
65
|
|
@@ -76,11 +75,11 @@ class Color:
|
|
76
75
|
def from_rgb(self, r: int, g: int, b: int) -> "Color":
|
77
76
|
return self.from_rgba(r, g, b)
|
78
77
|
|
79
|
-
def from_rgba(self, r: int, g: int, b: int, a: int=255) -> "Color":
|
80
|
-
self.r =
|
81
|
-
self.g =
|
82
|
-
self.b =
|
83
|
-
self.a =
|
78
|
+
def from_rgba(self, r: int, g: int, b: int, a: int = 255) -> "Color":
|
79
|
+
self.r = round(np.clip(r, 0, 255))
|
80
|
+
self.g = round(np.clip(g, 0, 255))
|
81
|
+
self.b = round(np.clip(b, 0, 255))
|
82
|
+
self.a = round(np.clip(a, 0, 255))
|
84
83
|
return self
|
85
84
|
|
86
85
|
def from_rgb_f(self, r: float, g: float, b: float) -> "Color":
|
@@ -88,14 +87,14 @@ class Color:
|
|
88
87
|
|
89
88
|
def from_rgba_f(self, r: float, g: float, b: float, a: float = 1) -> "Color":
|
90
89
|
return self.from_rgba(
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
round(r * 255),
|
91
|
+
round(g * 255),
|
92
|
+
round(b * 255),
|
93
|
+
round(a * 255),
|
95
94
|
)
|
96
95
|
|
97
96
|
def from_hex(self, color: str) -> "Color":
|
98
|
-
color = color.lstrip(
|
97
|
+
color = color.lstrip("#")
|
99
98
|
if len(color) == 6:
|
100
99
|
r, g, b = int(color[0:2], 16), int(color[2:4], 16), int(color[4:6], 16)
|
101
100
|
return self.from_rgb(r, g, b)
|
@@ -104,6 +103,35 @@ class Color:
|
|
104
103
|
return self.from_rgba(r, g, b, a)
|
105
104
|
raise ValueError("Invalid hex color format")
|
106
105
|
|
106
|
+
def from_hsv(self, hue: float, saturation: float, value: float):
|
107
|
+
v = value / 100
|
108
|
+
s = saturation / 100
|
109
|
+
|
110
|
+
c = v * s
|
111
|
+
h = hue / 60
|
112
|
+
x = c * (1 - abs(h % 2 - 1))
|
113
|
+
|
114
|
+
if 0 < h < 1:
|
115
|
+
r, g, b = c, x, 0
|
116
|
+
elif 1 < h < 2:
|
117
|
+
r, g, b = x, c, 0
|
118
|
+
elif 2 < h < 3:
|
119
|
+
r, g, b = 0, c, x
|
120
|
+
elif 3 < h < 4:
|
121
|
+
r, g, b = 0, x, c
|
122
|
+
elif 4 < h < 5:
|
123
|
+
r, g, b = x, 0, c
|
124
|
+
elif 5 < h < 6:
|
125
|
+
r, g, b = c, 0, x
|
126
|
+
else:
|
127
|
+
r, g, b = 0, 0, 0
|
128
|
+
|
129
|
+
return self.from_rgb_f(
|
130
|
+
(r + v - c),
|
131
|
+
(g + v - c),
|
132
|
+
(b + v - c),
|
133
|
+
)
|
134
|
+
|
107
135
|
def from_qcolor(self, color: QColor) -> "Color":
|
108
136
|
return self.from_rgba(color.red(), color.green(), color.blue(), color.alpha())
|
109
137
|
|
@@ -127,24 +155,59 @@ class Color:
|
|
127
155
|
return ((self.r / 255), (self.g / 255), (self.b / 255), (self.a / 255))
|
128
156
|
|
129
157
|
def to_hex(self) -> str:
|
130
|
-
return
|
158
|
+
return f"#{self.r:02X}{self.g:02X}{self.b:02X}"
|
131
159
|
|
132
160
|
def to_hexa(self) -> str:
|
133
|
-
return
|
161
|
+
return f"#{self.r:02X}{self.g:02X}{self.b:02X}{self.a:02X}"
|
162
|
+
|
163
|
+
def to_hsv(self) -> tuple[int, int, int]:
|
164
|
+
r, g, b = self.to_rgb_f()
|
165
|
+
min_, mid_, max_ = sorted((r, g, b))
|
166
|
+
delta = max_ - min_
|
167
|
+
|
168
|
+
if max_ == r:
|
169
|
+
hue = (g - b) / delta
|
170
|
+
elif max_ == g:
|
171
|
+
hue = (b - r) / delta + 2
|
172
|
+
elif max_ == b:
|
173
|
+
hue = (r - g) / delta + 4
|
174
|
+
else:
|
175
|
+
hue = 0
|
176
|
+
|
177
|
+
hue = round(60 * hue)
|
178
|
+
value = round(100 * max_)
|
179
|
+
saturation = round(100 * delta / max_) if (max_ != 0) else 0
|
180
|
+
|
181
|
+
return (
|
182
|
+
np.clip(0, 360, hue),
|
183
|
+
np.clip(0, 100, saturation),
|
184
|
+
np.clip(0, 100, value),
|
185
|
+
)
|
134
186
|
|
135
187
|
def to_qt(self) -> QColor:
|
136
188
|
return QColor(self.r, self.g, self.b, self.a)
|
137
189
|
|
138
|
-
def copy(self):
|
190
|
+
def copy(self) -> "Color":
|
139
191
|
return Color(self.r, self.g, self.b, self.a)
|
140
|
-
|
141
|
-
def apply_factor(self, factor: float|int):
|
192
|
+
|
193
|
+
def apply_factor(self, factor: float | int) -> "Color":
|
142
194
|
new_color = self.copy()
|
143
|
-
new_color.r =
|
144
|
-
new_color.g =
|
145
|
-
new_color.b =
|
195
|
+
new_color.r = round(np.clip(self.r * factor, 0, 255))
|
196
|
+
new_color.g = round(np.clip(self.g * factor, 0, 255))
|
197
|
+
new_color.b = round(np.clip(self.b * factor, 0, 255))
|
146
198
|
|
147
199
|
return new_color
|
148
200
|
|
201
|
+
def set_brightness(self, brightness: int) -> "Color":
|
202
|
+
h, s, _ = self.to_hsv()
|
203
|
+
return self.to_hsv(h, s, brightness)
|
204
|
+
|
205
|
+
def set_saturation(self, saturation: int) -> "Color":
|
206
|
+
h, _, v = self.to_hsv()
|
207
|
+
return self.to_hsv(h, saturation, v)
|
208
|
+
|
209
|
+
def __repr__(self):
|
210
|
+
return f"Color(r={self.r}, g={self.g}, b={self.b}, a={self.a})"
|
149
211
|
|
150
|
-
|
212
|
+
def __eq__(self, other: "Color"):
|
213
|
+
return self.r == other.r and self.g == other.g and self.b == other.b and self.a == other.a
|
@@ -1,13 +1,13 @@
|
|
1
1
|
molde/__init__.py,sha256=0iu27Lpdn0XBDRjRuRqhZHT7zoHNNMqf3E1zDJjuXX8,417
|
2
2
|
molde/__main__.py,sha256=A3nZwfdOB-DjKOI_NVPl7EUYBsLq5_Yg8pP4GDI2mTQ,2811
|
3
3
|
molde/actors/__init__.py,sha256=hIWbRlKTYleqyVWtcGE7X8Nu9oiZoc2ceRdQ5gZfe3c,266
|
4
|
-
molde/actors/common_symbols_actor.py,sha256=
|
4
|
+
molde/actors/common_symbols_actor.py,sha256=2ZMeWBwS7ChLPyjnIg8EAIb8Ug0lbXfDHcpoknYG0ZY,4669
|
5
5
|
molde/actors/ghost_actor.py,sha256=m7fu_bhIZM1kWhObZ_c8t_w9ZsAdDo9SlAT-pYUu_Lg,493
|
6
6
|
molde/actors/lines_actor.py,sha256=EI2jnaHMVIa7Ru6rDWRnei8_UlRbYz9rMbu4Z0pcjJk,1091
|
7
7
|
molde/actors/round_points_actor.py,sha256=z2-xAS70LAupK2ZNjgSDI7jtylGqljwp1RUQJv0Rn5U,222
|
8
8
|
molde/actors/square_points_actor.py,sha256=FdtPWHPCd9Ll6M4xmEkfGpaj98JzsLS0ZUcIkY1f8jw,1147
|
9
9
|
molde/colors/__init__.py,sha256=1btZnmV8oHnqK6n9vzB9rLrUAQg7YxnRALSXUtH2NlM,51
|
10
|
-
molde/colors/color.py,sha256=
|
10
|
+
molde/colors/color.py,sha256=AIYDSQYg4s7eB2K_hja8w6n_CLRR-hBvxUEluxUmCIg,6321
|
11
11
|
molde/colors/color_names.py,sha256=e4kluhl8BRxiZKs1DE8nfmGtIbTeyli_yje1eb_Jxk0,2958
|
12
12
|
molde/fonts/IBMPlexMono-Bold.ttf,sha256=ykA8VpMbrvMH0gumS2mstxq8rWH3XmZBRmHVdIS2kOw,157924
|
13
13
|
molde/fonts/IBMPlexMono-Regular.ttf,sha256=_hEwSl_pVtV0TptqJGzIPZBCUkXnWmIjAESWbKlqf1A,155940
|
@@ -63,6 +63,6 @@ molde/utils/format_sequences.py,sha256=RHxWGpWBRi89jTk3F4sdlGsKqeheRD49PZMeM36Rs
|
|
63
63
|
molde/utils/poly_data_utils.py,sha256=WoeW46ciuSZB4KO9oh0ksPoxARUbheQDROcjwlpjL4c,2125
|
64
64
|
molde/utils/tree_info.py,sha256=FxgT_uKjtgi0-NVcH41LBoqRmAKt26NJmsjBk1WTqt8,1760
|
65
65
|
molde/windows/loading_window.py,sha256=3U1VEujSKWWWIu1aSqSkYCupTpstI0xks6csJhdKh5Y,6288
|
66
|
-
molde-0.1.
|
67
|
-
molde-0.1.
|
68
|
-
molde-0.1.
|
66
|
+
molde-0.1.13.dist-info/METADATA,sha256=FYU-9RbnBvEwa-9QoFLJ06uLGdfHDaoxRWPTrUkqkgU,2102
|
67
|
+
molde-0.1.13.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
68
|
+
molde-0.1.13.dist-info/RECORD,,
|