veux 0.0.4__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.
- veux/__init__.py +190 -0
- veux/__main__.py +60 -0
- veux/archive/_render.py +1415 -0
- veux/assets/chrystals_moment.stl +0 -0
- veux/assets/pointer_arrows.glb +0 -0
- veux/canvas/canvas.py +41 -0
- veux/canvas/gltf.py +499 -0
- veux/canvas/mpl.py +89 -0
- veux/canvas/ply.py +238 -0
- veux/canvas/tri.py +49 -0
- veux/config.py +174 -0
- veux/errors.py +7 -0
- veux/fibers.py +9 -0
- veux/frame/__init__.py +497 -0
- veux/frame/extrude.py +247 -0
- veux/layer.py +0 -0
- veux/model.py +531 -0
- veux/parser.py +368 -0
- veux/plane/__init__.py +134 -0
- veux/reader/__main__.py +8 -0
- veux/reader/csi.py +519 -0
- veux/reader/tables.py +344 -0
- veux/section.py +188 -0
- veux/server.py +96 -0
- veux/state.py +361 -0
- veux/tcl.py +29 -0
- veux/utility/__init__.py +26 -0
- veux/utility/alpha_shape.py +85 -0
- veux/utility/consolidate.py +191 -0
- veux/utility/earcut.py +769 -0
- veux/utility/earcut2.py +227 -0
- veux/utility/earcut3.py +269 -0
- veux/utility/earcut4.py +100 -0
- veux/utility/earcut5.py +277 -0
- veux/viewer/__init__.py +59 -0
- veux/viewer/__main__.py +21 -0
- veux-0.0.4.dist-info/METADATA +242 -0
- veux-0.0.4.dist-info/RECORD +41 -0
- veux-0.0.4.dist-info/WHEEL +5 -0
- veux-0.0.4.dist-info/entry_points.txt +2 -0
- veux-0.0.4.dist-info/top_level.txt +1 -0
veux/__init__.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#===----------------------------------------------------------------------===#
|
|
2
|
+
#
|
|
3
|
+
# STAIRLab -- STructural Artificial Intelligence Laboratory
|
|
4
|
+
#
|
|
5
|
+
#===----------------------------------------------------------------------===#
|
|
6
|
+
#
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .errors import RenderError
|
|
10
|
+
from .config import Config, apply_config
|
|
11
|
+
from .parser import sketch_show
|
|
12
|
+
from .frame import FrameArtist
|
|
13
|
+
from . import utility
|
|
14
|
+
|
|
15
|
+
assets = Path(__file__).parents[0]/"assets/"
|
|
16
|
+
|
|
17
|
+
def Canvas(subplots=None, backend=None):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
def __getattr__(name: str):
|
|
21
|
+
import opensees.openseespy
|
|
22
|
+
if name == "Model":
|
|
23
|
+
return opensees.openseespy.Model
|
|
24
|
+
elif name == "openseespy":
|
|
25
|
+
return opensees.openseespy
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def serve(artist, viewer="mv", port=None):
|
|
29
|
+
import veux.server
|
|
30
|
+
if hasattr(artist.canvas, "to_glb"):
|
|
31
|
+
server = veux.server.Server(glb=artist.canvas.to_glb(),
|
|
32
|
+
viewer=viewer)
|
|
33
|
+
server.run(port=port)
|
|
34
|
+
|
|
35
|
+
elif hasattr(artist.canvas, "to_html"):
|
|
36
|
+
server = veux.server.Server(html=artist.canvas.to_html())
|
|
37
|
+
server.run(port=port)
|
|
38
|
+
|
|
39
|
+
elif hasattr(artist.canvas, "show"):
|
|
40
|
+
artist.canvas.show()
|
|
41
|
+
|
|
42
|
+
else:
|
|
43
|
+
raise ValueError("Cannot serve artist")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _create_canvas(name=None, config=None):
|
|
47
|
+
if name is None:
|
|
48
|
+
name = "gltf"
|
|
49
|
+
|
|
50
|
+
if not isinstance(name, str):
|
|
51
|
+
return name
|
|
52
|
+
elif name == "matplotlib":
|
|
53
|
+
import veux.canvas.mpl
|
|
54
|
+
return veux.canvas.mpl.MatplotlibCanvas(config=config)
|
|
55
|
+
elif name == "plotly":
|
|
56
|
+
import veux.canvas.ply
|
|
57
|
+
return veux.canvas.ply.PlotlyCanvas(config=config)
|
|
58
|
+
elif name == "gltf":
|
|
59
|
+
import veux.canvas.gltf
|
|
60
|
+
return veux.canvas.gltf.GltfLibCanvas(config=config)
|
|
61
|
+
elif name == "trimesh":
|
|
62
|
+
import veux.canvas.tri
|
|
63
|
+
return veux.canvas.tri.TrimeshCanvas(config=config)
|
|
64
|
+
else:
|
|
65
|
+
raise ValueError("Unknown canvas name " + str(name))
|
|
66
|
+
|
|
67
|
+
def render(sam_file, res_file=None, ndf=6,
|
|
68
|
+
canvas=None,
|
|
69
|
+
show=None,
|
|
70
|
+
hide=None,
|
|
71
|
+
verbose=False,
|
|
72
|
+
vertical=2,
|
|
73
|
+
displaced=None,
|
|
74
|
+
reference=None,
|
|
75
|
+
**opts):
|
|
76
|
+
|
|
77
|
+
import veux.model
|
|
78
|
+
|
|
79
|
+
# Configuration is determined by successively layering
|
|
80
|
+
# from sources with the following priorities:
|
|
81
|
+
# defaults < file configs < kwds
|
|
82
|
+
|
|
83
|
+
if sam_file is None:
|
|
84
|
+
raise RenderError("Expected required argument <sam-file>")
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Read model data
|
|
88
|
+
#
|
|
89
|
+
if isinstance(sam_file, (str, Path)):
|
|
90
|
+
model_data = veux.model.read_model(sam_file)
|
|
91
|
+
|
|
92
|
+
elif hasattr(sam_file, "asdict"):
|
|
93
|
+
# Assuming an opensees.openseespy.Model
|
|
94
|
+
model_data = sam_file.asdict()
|
|
95
|
+
|
|
96
|
+
elif hasattr(sam_file, "read"):
|
|
97
|
+
model_data = veux.model.read_model(sam_file)
|
|
98
|
+
|
|
99
|
+
elif isinstance(sam_file, tuple):
|
|
100
|
+
# TODO: (nodes, cells)
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
elif not isinstance(sam_file, dict):
|
|
104
|
+
model_data = veux.model.FrameModel(sam_file)
|
|
105
|
+
|
|
106
|
+
else:
|
|
107
|
+
model_data = sam_file
|
|
108
|
+
|
|
109
|
+
# Setup config
|
|
110
|
+
config = Config()
|
|
111
|
+
|
|
112
|
+
if "RendererConfiguration" in model_data:
|
|
113
|
+
apply_config(model_data["RendererConfiguration"], config)
|
|
114
|
+
|
|
115
|
+
config["artist_config"]["vertical"] = vertical
|
|
116
|
+
apply_config(opts, config)
|
|
117
|
+
if show is not None and reference is None and displaced is None:
|
|
118
|
+
reference = show
|
|
119
|
+
|
|
120
|
+
if reference is not None:
|
|
121
|
+
preserve = set()
|
|
122
|
+
sketch_show(config["artist_config"], f"reference", "show")
|
|
123
|
+
for arg in reference:
|
|
124
|
+
sketch_show(config["artist_config"], f"reference:{arg}", "show", exclusive=True, preserve=preserve)
|
|
125
|
+
if displaced is not None:
|
|
126
|
+
preserve = set()
|
|
127
|
+
for arg in displaced:
|
|
128
|
+
sketch_show(config["artist_config"], f"displaced:{arg}", "show", exclusive=True, preserve=preserve)
|
|
129
|
+
|
|
130
|
+
if hide is not None:
|
|
131
|
+
preserve = set()
|
|
132
|
+
sketch = "reference"; # "displaced"
|
|
133
|
+
for arg in hide:
|
|
134
|
+
sketch_show(config["artist_config"], f"{sketch}:{arg}", "hide", exclusive=True, preserve=preserve)
|
|
135
|
+
|
|
136
|
+
if verbose:
|
|
137
|
+
import pprint
|
|
138
|
+
pprint.pp(config["artist_config"])
|
|
139
|
+
|
|
140
|
+
#
|
|
141
|
+
# Create Artist
|
|
142
|
+
#
|
|
143
|
+
# A Model is created from model_data by the artist
|
|
144
|
+
# so that the artist can inform it how to transform
|
|
145
|
+
# things if neccessary.
|
|
146
|
+
artist = FrameArtist(model_data, ndf=ndf,
|
|
147
|
+
config=config["artist_config"],
|
|
148
|
+
model_config=config["model_config"],
|
|
149
|
+
canvas=_create_canvas(canvas or config["canvas_config"]["type"],
|
|
150
|
+
config=config["canvas_config"]))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
#
|
|
154
|
+
# Read and process displacements
|
|
155
|
+
#
|
|
156
|
+
if res_file is not None:
|
|
157
|
+
artist.add_state(res_file,
|
|
158
|
+
scale=config["scale"],
|
|
159
|
+
only=config["mode_num"],
|
|
160
|
+
**config["state_config"])
|
|
161
|
+
|
|
162
|
+
elif config["displ"] is not None:
|
|
163
|
+
pass
|
|
164
|
+
# TODO: reimplement point displacements
|
|
165
|
+
# cases = [artist.add_point_displacements(config["displ"], scale=config["scale"])]
|
|
166
|
+
|
|
167
|
+
if "Displacements" in model_data:
|
|
168
|
+
cases.extend(artist.add_state(model_data["Displacements"],
|
|
169
|
+
scale=config["scale"],
|
|
170
|
+
only=config["mode_num"]))
|
|
171
|
+
|
|
172
|
+
artist.draw()
|
|
173
|
+
|
|
174
|
+
return artist
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def render_mode(model, mode_number, scale=1, file_name=None, canvas="gltf", **kwds):
|
|
178
|
+
|
|
179
|
+
# Define a function that tells the renderer the displacement
|
|
180
|
+
# at a given node. We will pass this function as an argument
|
|
181
|
+
# when constructing the "artist" object, which in turn will
|
|
182
|
+
# invoke this function for each node tag in the model.
|
|
183
|
+
def displ_func(tag: int)->list:
|
|
184
|
+
return [float(scale)*ui for ui in model.nodeEigenvector(tag, mode_number)]
|
|
185
|
+
|
|
186
|
+
# Create the rendering
|
|
187
|
+
return render(model, displ_func, canvas=canvas, **kwds)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
veux/__main__.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#===----------------------------------------------------------------------===#
|
|
2
|
+
#
|
|
3
|
+
# STAIRLab -- STructural Artificial Intelligence Laboratory
|
|
4
|
+
#
|
|
5
|
+
#===----------------------------------------------------------------------===#
|
|
6
|
+
#
|
|
7
|
+
# Main command line interface
|
|
8
|
+
#
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from veux import render
|
|
12
|
+
from veux.parser import parse_args
|
|
13
|
+
from veux.errors import RenderError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
NAME="sees"
|
|
17
|
+
|
|
18
|
+
def main(argv):
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
config = parse_args(argv)
|
|
22
|
+
|
|
23
|
+
if config is None:
|
|
24
|
+
sys.exit()
|
|
25
|
+
|
|
26
|
+
artist = render(**config)
|
|
27
|
+
|
|
28
|
+
# write plot to file if output file name provided
|
|
29
|
+
if config["write_file"]:
|
|
30
|
+
artist.save(config["write_file"])
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
# Otherwise either create popup, or start server
|
|
34
|
+
elif hasattr(artist.canvas, "popup"):
|
|
35
|
+
artist.canvas.popup()
|
|
36
|
+
|
|
37
|
+
elif hasattr(artist.canvas, "to_glb"):
|
|
38
|
+
import veux.server
|
|
39
|
+
viewer = config["viewer_config"].get("name", None)
|
|
40
|
+
port = config["server_config"].get("port", None)
|
|
41
|
+
server = veux.server.Server(glb=artist.canvas.to_glb(),
|
|
42
|
+
viewer=viewer)
|
|
43
|
+
server.run(port=port)
|
|
44
|
+
|
|
45
|
+
elif hasattr(artist.canvas, "to_html"):
|
|
46
|
+
import veux.server
|
|
47
|
+
port = config["server_config"].get("port", None)
|
|
48
|
+
server = veux.server.Server(html=artist.canvas.to_html())
|
|
49
|
+
server.run(port=port)
|
|
50
|
+
|
|
51
|
+
except (FileNotFoundError, RenderError) as e:
|
|
52
|
+
# Catch expected errors to avoid printing an ugly/unnecessary stack trace.
|
|
53
|
+
print(f"ERROR - {e}", file=sys.stderr)
|
|
54
|
+
print(" Run '{NAME} --help' for more information".format(NAME=NAME), file=sys.stderr)
|
|
55
|
+
sys.exit(-1)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
main(sys.argv)
|
|
60
|
+
|