pyvale 2025.5.3__cp311-cp311-musllinux_1_2_aarch64.whl → 2025.7.0__cp311-cp311-musllinux_1_2_aarch64.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.
Potentially problematic release.
This version of pyvale might be problematic. Click here for more details.
- pyvale/__init__.py +12 -0
- pyvale/blendercalibrationdata.py +3 -1
- pyvale/blenderscene.py +7 -5
- pyvale/blendertools.py +27 -5
- pyvale/camera.py +1 -0
- pyvale/cameradata.py +3 -0
- pyvale/camerasensor.py +147 -0
- pyvale/camerastereo.py +4 -4
- pyvale/cameratools.py +23 -61
- pyvale/cython/rastercyth.c +1657 -1352
- pyvale/cython/rastercyth.cpython-311-aarch64-linux-musl.so +0 -0
- pyvale/cython/rastercyth.py +71 -26
- pyvale/data/plate_hole_def0000.tiff +0 -0
- pyvale/data/plate_hole_def0001.tiff +0 -0
- pyvale/data/plate_hole_ref0000.tiff +0 -0
- pyvale/data/plate_rigid_def0000.tiff +0 -0
- pyvale/data/plate_rigid_def0001.tiff +0 -0
- pyvale/data/plate_rigid_ref0000.tiff +0 -0
- pyvale/dataset.py +96 -6
- pyvale/dic/cpp/dicbruteforce.cpp +370 -0
- pyvale/dic/cpp/dicfourier.cpp +648 -0
- pyvale/dic/cpp/dicinterpolator.cpp +559 -0
- pyvale/dic/cpp/dicmain.cpp +215 -0
- pyvale/dic/cpp/dicoptimizer.cpp +675 -0
- pyvale/dic/cpp/dicrg.cpp +137 -0
- pyvale/dic/cpp/dicscanmethod.cpp +677 -0
- pyvale/dic/cpp/dicsmooth.cpp +138 -0
- pyvale/dic/cpp/dicstrain.cpp +383 -0
- pyvale/dic/cpp/dicutil.cpp +563 -0
- pyvale/dic2d.py +164 -0
- pyvale/dic2dcpp.cpython-311-aarch64-linux-musl.so +0 -0
- pyvale/dicchecks.py +476 -0
- pyvale/dicdataimport.py +247 -0
- pyvale/dicregionofinterest.py +887 -0
- pyvale/dicresults.py +55 -0
- pyvale/dicspecklegenerator.py +238 -0
- pyvale/dicspecklequality.py +305 -0
- pyvale/dicstrain.py +387 -0
- pyvale/dicstrainresults.py +37 -0
- pyvale/errorintegrator.py +10 -8
- pyvale/examples/basics/ex1_1_basicscalars_therm2d.py +124 -113
- pyvale/examples/basics/ex1_2_sensormodel_therm2d.py +124 -132
- pyvale/examples/basics/ex1_3_customsens_therm3d.py +199 -195
- pyvale/examples/basics/ex1_4_basicerrors_therm3d.py +125 -121
- pyvale/examples/basics/ex1_5_fielderrs_therm3d.py +145 -141
- pyvale/examples/basics/ex1_6_caliberrs_therm2d.py +96 -101
- pyvale/examples/basics/ex1_7_spatavg_therm2d.py +109 -105
- pyvale/examples/basics/ex2_1_basicvectors_disp2d.py +92 -91
- pyvale/examples/basics/ex2_2_vectorsens_disp2d.py +96 -90
- pyvale/examples/basics/ex2_3_sensangle_disp2d.py +88 -89
- pyvale/examples/basics/ex2_4_chainfielderrs_disp2d.py +172 -171
- pyvale/examples/basics/ex2_5_vectorfields3d_disp3d.py +88 -86
- pyvale/examples/basics/ex3_1_basictensors_strain2d.py +90 -90
- pyvale/examples/basics/ex3_2_tensorsens2d_strain2d.py +93 -91
- pyvale/examples/basics/ex3_3_tensorsens3d_strain3d.py +172 -160
- pyvale/examples/basics/ex4_1_expsim2d_thermmech2d.py +154 -148
- pyvale/examples/basics/ex4_2_expsim3d_thermmech3d.py +249 -231
- pyvale/examples/dic/ex1_region_of_interest.py +98 -0
- pyvale/examples/dic/ex2_plate_with_hole.py +149 -0
- pyvale/examples/dic/ex3_plate_with_hole_strain.py +93 -0
- pyvale/examples/dic/ex4_dic_blender.py +95 -0
- pyvale/examples/dic/ex5_dic_challenge.py +102 -0
- pyvale/examples/imagedef2d/ex_imagedef2d_todisk.py +4 -2
- pyvale/examples/renderblender/ex1_1_blenderscene.py +152 -105
- pyvale/examples/renderblender/ex1_2_blenderdeformed.py +151 -100
- pyvale/examples/renderblender/ex2_1_stereoscene.py +183 -116
- pyvale/examples/renderblender/ex2_2_stereodeformed.py +185 -112
- pyvale/examples/renderblender/ex3_1_blendercalibration.py +164 -109
- pyvale/examples/renderrasterisation/ex_rastenp.py +74 -35
- pyvale/examples/renderrasterisation/ex_rastercyth_oneframe.py +6 -13
- pyvale/examples/renderrasterisation/ex_rastercyth_static_cypara.py +2 -2
- pyvale/examples/renderrasterisation/ex_rastercyth_static_pypara.py +2 -4
- pyvale/imagedef2d.py +3 -2
- pyvale/imagetools.py +137 -0
- pyvale/rastercy.py +34 -4
- pyvale/rasternp.py +300 -276
- pyvale/rasteropts.py +58 -0
- pyvale/renderer.py +47 -0
- pyvale/rendermesh.py +52 -62
- pyvale/renderscene.py +51 -0
- pyvale/sensorarrayfactory.py +2 -2
- pyvale/sensortools.py +19 -35
- pyvale/simcases/case21.i +1 -1
- pyvale/simcases/run_1case.py +8 -0
- pyvale/simtools.py +2 -2
- pyvale/visualsimplotter.py +180 -0
- {pyvale-2025.5.3.dist-info → pyvale-2025.7.0.dist-info}/METADATA +11 -57
- {pyvale-2025.5.3.dist-info → pyvale-2025.7.0.dist-info}/RECORD +94 -56
- {pyvale-2025.5.3.dist-info → pyvale-2025.7.0.dist-info}/WHEEL +1 -1
- pyvale.libs/libgcc_s-69c45f16.so.1 +0 -0
- pyvale.libs/libgomp-b626072d.so.1.0.0 +0 -0
- pyvale.libs/libstdc++-1f1a71be.so.6.0.33 +0 -0
- pyvale/examples/visualisation/ex1_1_plot_traces.py +0 -102
- pyvale/examples/visualisation/ex2_1_animate_sim.py +0 -89
- {pyvale-2025.5.3.dist-info → pyvale-2025.7.0.dist-info}/licenses/LICENSE +0 -0
- {pyvale-2025.5.3.dist-info → pyvale-2025.7.0.dist-info}/top_level.txt +0 -0
|
@@ -4,125 +4,192 @@
|
|
|
4
4
|
# Copyright (C) 2025 The Computer Aided Validation Team
|
|
5
5
|
# ==============================================================================
|
|
6
6
|
|
|
7
|
+
"""
|
|
8
|
+
Blender example: Creating a scene with stereo DIC
|
|
9
|
+
-------------------------------------------------
|
|
10
|
+
|
|
11
|
+
This example takes you through creating a scene and adding all the necessary
|
|
12
|
+
objects required to represent a stereo DIC setup (two cameras, lighting and
|
|
13
|
+
sample). This example will then show you how to render a static image of this
|
|
14
|
+
scene.
|
|
15
|
+
|
|
16
|
+
Test case: mechanical analysis of a plate with a hole loaded in tension.
|
|
17
|
+
"""
|
|
7
18
|
import numpy as np
|
|
8
19
|
from scipy.spatial.transform import Rotation
|
|
9
20
|
from pathlib import Path
|
|
10
21
|
import pyvale
|
|
11
22
|
import mooseherder as mh
|
|
12
23
|
|
|
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
|
-
|
|
24
|
+
# %%
|
|
25
|
+
# The simulation results are loaded in here in the same way as the previous
|
|
26
|
+
# example. As mentioned this `data_path` can be replaced with your own MOOSE
|
|
27
|
+
# simulation output in exodus format (*.e).
|
|
28
|
+
|
|
29
|
+
data_path = pyvale.DataSet.render_mechanical_3d_path()
|
|
30
|
+
sim_data = mh.ExodusReader(data_path).read_all_sim_data()
|
|
31
|
+
|
|
32
|
+
# %%
|
|
33
|
+
# This is then scaled to mm, as all lengths in Blender are to be set in mm.
|
|
34
|
+
# The `SimData` object is then converted into a `RenderMeshData` object, as
|
|
35
|
+
# this skins the mesh ready to be imported into Blender.
|
|
36
|
+
# The `disp_comps` are the expected direction of displacement. Since this is a
|
|
37
|
+
# 3D deformation test case, displacement is expected in the x, y and z directions.
|
|
38
|
+
|
|
39
|
+
disp_comps = ("disp_x","disp_y", "disp_z")
|
|
40
|
+
sim_data = pyvale.scale_length_units(scale=1000.0,
|
|
41
|
+
sim_data=sim_data,
|
|
42
|
+
disp_comps=disp_comps)
|
|
43
|
+
|
|
44
|
+
render_mesh = pyvale.create_render_mesh(sim_data,
|
|
45
|
+
("disp_y","disp_x"),
|
|
46
|
+
sim_spat_dim=3,
|
|
47
|
+
field_disp_keys=disp_comps)
|
|
48
|
+
|
|
49
|
+
# %%
|
|
50
|
+
# Firstly, a save path must be set.
|
|
51
|
+
# In order to do this a base path must be set. Then all the generated files will
|
|
52
|
+
# be saved to a subfolder within this specified base directory
|
|
53
|
+
# (e.g. blenderimages).
|
|
54
|
+
# If no base directory is specified, it will be set as your home directory.
|
|
55
|
+
|
|
56
|
+
base_dir = Path.cwd()
|
|
57
|
+
|
|
58
|
+
# %%
|
|
59
|
+
# Creating the scene
|
|
60
|
+
# ^^^^^^^^^^^^^^^^^^
|
|
61
|
+
# In order to create a DIC setup in Blender, first a scene must be created.
|
|
62
|
+
# A scene is initialised using the `BlenderScene` class. All the subsequent
|
|
63
|
+
# objects and actions necessary are then methods of this class.
|
|
64
|
+
scene = pyvale.BlenderScene()
|
|
65
|
+
|
|
66
|
+
# %%
|
|
67
|
+
# The next thing that can be added to the scene is a sample.
|
|
68
|
+
# This is done by passing in the `RenderMeshData` object.
|
|
69
|
+
# It should be noted that the mesh will be centred on the origin to allow for
|
|
70
|
+
# the cameras to be centred on the mesh.
|
|
71
|
+
# Once the part is added to the Blender scene, it can be both moved and rotated.
|
|
72
|
+
|
|
73
|
+
part = scene.add_part(render_mesh, sim_spat_dim=3)
|
|
74
|
+
# Set the part location
|
|
75
|
+
part_location = np.array([0, 0, 0])
|
|
76
|
+
pyvale.BlenderTools.move_blender_obj(part=part, pos_world=part_location)
|
|
77
|
+
# Set part rotation
|
|
78
|
+
part_rotation = Rotation.from_euler("xyz", [0, 0, 0], degrees=True)
|
|
79
|
+
pyvale.BlenderTools.rotate_blender_obj(part=part, rot_world=part_rotation)
|
|
80
|
+
|
|
81
|
+
# %%
|
|
82
|
+
# The cameras can then be initialised. A stereo camera system is defined by a
|
|
83
|
+
# `CameraStereo` object, which contains the intrinsic parameters of both cameras
|
|
84
|
+
# as well as the extrinsic parameters between them.
|
|
85
|
+
# There are two ways to initialise a `CameraStereo` object.
|
|
86
|
+
# One way is to specify the camera parameters separately for each camera, create
|
|
87
|
+
# a `CameraStereo` object, and then add the stereo system using the
|
|
88
|
+
# `add_stereo_system` method.
|
|
89
|
+
# The other method is to use a convenience function, as shown below.
|
|
90
|
+
# This requires you to first initialise one camera. Then you can choose between
|
|
91
|
+
# either a face-on or symmetric stereo system. Then, either of the
|
|
92
|
+
# `symmetric_stereo_cameras` or `faceon_stereo_cameras` functions can be used to
|
|
93
|
+
# initialise a `CameraStereo` object. The only input required to these functions
|
|
94
|
+
# are the camera parameters for the first camera, and the desired stereo angle
|
|
95
|
+
# between the two. The cameras can then be added to the Blender scene using the
|
|
96
|
+
# `add_stereo_system` method.
|
|
97
|
+
|
|
98
|
+
cam_data_0 = pyvale.CameraData(pixels_num=np.array([1540, 1040]),
|
|
99
|
+
pixels_size=np.array([0.00345, 0.00345]),
|
|
100
|
+
pos_world=np.array([0, 0, 400]),
|
|
101
|
+
rot_world=Rotation.from_euler("xyz", [0, 0, 0]),
|
|
102
|
+
roi_cent_world=(0, 0, 0),
|
|
103
|
+
focal_length=15.0)
|
|
104
|
+
# Set this to "symmetric" to get a symmetric stereo system or set this to
|
|
105
|
+
# "faceon" to get a face-on stereo system
|
|
106
|
+
stereo_setup = "faceon"
|
|
107
|
+
if stereo_setup == "symmetric":
|
|
108
|
+
stereo_system = pyvale.CameraTools.symmetric_stereo_cameras(
|
|
109
|
+
cam_data_0=cam_data_0,
|
|
110
|
+
stereo_angle=15.0)
|
|
111
|
+
if stereo_setup == "faceon":
|
|
112
|
+
stereo_system = pyvale.CameraTools.faceon_stereo_cameras(
|
|
113
|
+
cam_data_0=cam_data_0,
|
|
114
|
+
stereo_angle=15.0)
|
|
115
|
+
cam0, cam1 = scene.add_stereo_system(stereo_system)
|
|
116
|
+
|
|
117
|
+
# %%
|
|
118
|
+
# Since this scene contains a stereo DIC system, a calibration file will be
|
|
119
|
+
# required to run the images through a DIC engine.
|
|
120
|
+
# A calibration file can be generated directly from the `CameraStereo` object.
|
|
121
|
+
# The calibration file will be saved in `YAML` format. However, if you wish to
|
|
122
|
+
# use MatchID to process the images, `save_calibration_mid` can be used instead
|
|
123
|
+
# to save the calibration in a format readable by MatchID.
|
|
124
|
+
# The calibration file will be saved to a sub-directory of the base directory
|
|
125
|
+
# called "calibration".
|
|
126
|
+
stereo_system.save_calibration(base_dir)
|
|
127
|
+
|
|
128
|
+
# %%
|
|
129
|
+
# A light can the be added to the scene.
|
|
130
|
+
# Blender offers different light types: Point, Sun, Spot and Area.
|
|
131
|
+
# The light can also be moved and rotated like the camera.
|
|
132
|
+
|
|
133
|
+
light_data = pyvale.BlenderLightData(type=pyvale.BlenderLightType.POINT,
|
|
134
|
+
pos_world=(0, 0, 400),
|
|
135
|
+
rot_world=Rotation.from_euler("xyz",
|
|
136
|
+
[0, 0, 0]),
|
|
137
|
+
energy=1)
|
|
138
|
+
light = scene.add_light(light_data)
|
|
139
|
+
light.location = (0, 0, 410)
|
|
140
|
+
light.rotation_euler = (0, 0, 0) # NOTE: The default is an XYZ Euler angle
|
|
141
|
+
|
|
142
|
+
# %%
|
|
143
|
+
# A speckle pattern can then be applied to the sample.
|
|
144
|
+
# Firstly, the material properties of the sample must be specified, but these
|
|
145
|
+
# will all be defaulted if no inputs are provided.
|
|
146
|
+
#The speckle pattern can then be specified by providing a path to an image file
|
|
147
|
+
# with the pattern.
|
|
148
|
+
# The mm/px resolution of the camera must also be specified in order to
|
|
149
|
+
# correctly scale the speckle pattern.
|
|
150
|
+
# It should be noted that for a bigger camera or sample you may need to generate
|
|
151
|
+
# a larger speckle pattern.
|
|
152
|
+
|
|
153
|
+
material_data = pyvale.BlenderMaterialData()
|
|
154
|
+
speckle_path = pyvale.DataSet.dic_pattern_5mpx_path()
|
|
155
|
+
|
|
156
|
+
mm_px_resolution = pyvale.CameraTools.calculate_mm_px_resolution(cam_data_0)
|
|
157
|
+
scene.add_speckle(part=part,
|
|
158
|
+
speckle_path=speckle_path,
|
|
159
|
+
mat_data=material_data,
|
|
160
|
+
mm_px_resolution=mm_px_resolution)
|
|
161
|
+
|
|
162
|
+
# %%
|
|
163
|
+
# Rendering a set of images
|
|
164
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
165
|
+
# Once all the objects have been added to the scene, a set of images can be
|
|
166
|
+
# rendered.Firstly, all the rendering parameters must be set, including
|
|
167
|
+
# parameters such as the number of threads to use.
|
|
168
|
+
# Differently to a 2D DIC system, both cameras' parameters must be specified in
|
|
169
|
+
# the `RenderData` object.
|
|
170
|
+
|
|
171
|
+
render_data = pyvale.RenderData(cam_data=(stereo_system.cam_data_0,
|
|
172
|
+
stereo_system.cam_data_1),
|
|
173
|
+
base_dir=base_dir,
|
|
174
|
+
threads=8)
|
|
175
|
+
|
|
176
|
+
# %%
|
|
177
|
+
# A single set of images of the scene can then be rendered.
|
|
178
|
+
# This will render a single image from each of the cameras.
|
|
179
|
+
# If `stage_image` is set to True, the image will be saved to disk, converted to
|
|
180
|
+
# an array, deleted and the image array will be returned. This is due to the
|
|
181
|
+
# fact that an image cannot be saved directly as an array through Blender.
|
|
182
|
+
|
|
183
|
+
scene.render_single_image(stage_image=False,
|
|
184
|
+
render_data=render_data)
|
|
185
|
+
|
|
186
|
+
# %%
|
|
187
|
+
# The rendered images will be saved to this filepath:
|
|
188
|
+
|
|
189
|
+
print("Save directory of the image:", (render_data.base_dir / "blenderimages"))
|
|
190
|
+
|
|
191
|
+
# %%
|
|
192
|
+
# There is also the option to save the scene as a Blender project file.
|
|
193
|
+
# This file can be opened with the Blender GUI to view the scene.
|
|
194
|
+
|
|
195
|
+
pyvale.BlenderTools.save_blender_file(base_dir)
|
|
@@ -4,128 +4,201 @@
|
|
|
4
4
|
# Copyright (C) 2025 The Computer Aided Validation Team
|
|
5
5
|
# ==============================================================================
|
|
6
6
|
|
|
7
|
+
"""
|
|
8
|
+
Blender example: Deforming a sample with stereo DIC
|
|
9
|
+
===================================================
|
|
10
|
+
|
|
11
|
+
This example takes you through creating stereo DIC scene, applying deformation
|
|
12
|
+
to the sample, and rendering images at each deformation timestep.
|
|
13
|
+
|
|
14
|
+
Test case: mechanical analysis of a plate with a hole loaded in tension.
|
|
15
|
+
"""
|
|
16
|
+
|
|
7
17
|
import numpy as np
|
|
8
18
|
from scipy.spatial.transform import Rotation
|
|
9
19
|
from pathlib import Path
|
|
10
20
|
import pyvale
|
|
11
21
|
import mooseherder as mh
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
# %%
|
|
24
|
+
# The simulation results are loaded in here in the same way as the previous
|
|
25
|
+
# example. As mentioned this `data_path` can be replaced with your own MOOSE
|
|
26
|
+
# simulation output in exodus format (*.e).
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
data_path = pyvale.DataSet.render_mechanical_3d_path()
|
|
29
|
+
sim_data = mh.ExodusReader(data_path).read_all_sim_data()
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
# %%
|
|
32
|
+
# This is then scaled to mm, as all lengths in Blender are to be set in mm.
|
|
33
|
+
# The `SimData` object is then converted into a `RenderMeshData` object, as
|
|
34
|
+
# this skins the mesh ready to be imported into Blender.
|
|
35
|
+
# The `disp_comps` are the expected direction of displacement. Since this is a
|
|
36
|
+
# 3D deformation test case, displacement is expected in the x, y and z directions.
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
disp_comps = ("disp_x","disp_y", "disp_z")
|
|
39
|
+
sim_data = pyvale.scale_length_units(scale=1000.0,
|
|
40
|
+
sim_data=sim_data,
|
|
41
|
+
disp_comps=disp_comps)
|
|
42
|
+
|
|
43
|
+
render_mesh = pyvale.create_render_mesh(sim_data,
|
|
24
44
|
("disp_y","disp_x"),
|
|
25
45
|
sim_spat_dim=3,
|
|
26
46
|
field_disp_keys=disp_comps)
|
|
27
47
|
|
|
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
|
-
|
|
48
|
+
# %%
|
|
49
|
+
# Firstly, a save path must be set.
|
|
50
|
+
# In order to do this a base path must be set. Then all the generated files will
|
|
51
|
+
# be saved to a subfolder within this specified base directory
|
|
52
|
+
# (e.g. blenderimages).
|
|
53
|
+
# If no base directory is specified, it will be set as your home directory.
|
|
54
|
+
|
|
55
|
+
base_dir = Path.cwd()
|
|
56
|
+
|
|
57
|
+
# %%
|
|
58
|
+
# Creating the scene
|
|
59
|
+
# ^^^^^^^^^^^^^^^^^^
|
|
60
|
+
# In order to create a DIC setup in Blender, first a scene must be created.
|
|
61
|
+
# A scene is initialised using the `BlenderScene` class. All the subsequent
|
|
62
|
+
# objects and actions necessary are then methods of this class.
|
|
63
|
+
scene = pyvale.BlenderScene()
|
|
64
|
+
|
|
65
|
+
# %%
|
|
66
|
+
# The next thing that can be added to the scene is a sample.
|
|
67
|
+
# This is done by passing in the `RenderMeshData` object.
|
|
68
|
+
# It should be noted that the mesh will be centred on the origin to allow for
|
|
69
|
+
# the cameras to be centred on the mesh.
|
|
70
|
+
# Once the part is added to the Blender scene, it can be both moved and rotated.
|
|
71
|
+
|
|
72
|
+
part = scene.add_part(render_mesh, sim_spat_dim=3)
|
|
73
|
+
# Set the part location
|
|
74
|
+
part_location = np.array([0, 0, 0])
|
|
75
|
+
pyvale.BlenderTools.move_blender_obj(part=part, pos_world=part_location)
|
|
76
|
+
# Set part rotation
|
|
77
|
+
part_rotation = Rotation.from_euler("xyz", [0, 0, 0], degrees=True)
|
|
78
|
+
pyvale.BlenderTools.rotate_blender_obj(part=part, rot_world=part_rotation)
|
|
79
|
+
|
|
80
|
+
# %%
|
|
81
|
+
# The cameras can then be initialised. A stereo camera system is defined by a
|
|
82
|
+
# `CameraStereo` object, which contains the intrinsic parameters of both cameras
|
|
83
|
+
# as well as the extrinsic parameters between them.
|
|
84
|
+
# There are two ways to initialise a `CameraStereo` object.
|
|
85
|
+
# One way is to specify the camera parameters separately for each camera, create
|
|
86
|
+
# a `CameraStereo` object, and then add the stereo system using the
|
|
87
|
+
# `add_stereo_system` method.
|
|
88
|
+
# The other method is to use a convenience function, as shown below.
|
|
89
|
+
# This requires you to first initialise one camera. Then you can choose between
|
|
90
|
+
# either a face-on or symmetric stereo system. Then, either of the
|
|
91
|
+
# `symmetric_stereo_cameras` or `faceon_stereo_cameras` functions can be used to
|
|
92
|
+
# initialise a `CameraStereo` object. The only input required to these functions
|
|
93
|
+
# are the camera parameters for the first camera, and the desired stereo angle
|
|
94
|
+
# between the two. The cameras can then be added to the Blender scene using the
|
|
95
|
+
# `add_stereo_system` method.
|
|
96
|
+
|
|
97
|
+
cam_data_0 = pyvale.CameraData(pixels_num=np.array([1540, 1040]),
|
|
98
|
+
pixels_size=np.array([0.00345, 0.00345]),
|
|
99
|
+
pos_world=np.array([0, 0, 400]),
|
|
100
|
+
rot_world=Rotation.from_euler("xyz", [0, 0, 0]),
|
|
101
|
+
roi_cent_world=(0, 0, 0),
|
|
102
|
+
focal_length=15.0)
|
|
103
|
+
# Set this to "symmetric" to get a symmetric stereo system or set this to
|
|
104
|
+
# "faceon" to get a face-on stereo system
|
|
105
|
+
stereo_setup = "faceon"
|
|
106
|
+
if stereo_setup == "symmetric":
|
|
107
|
+
stereo_system = pyvale.CameraTools.symmetric_stereo_cameras(
|
|
108
|
+
cam_data_0=cam_data_0,
|
|
109
|
+
stereo_angle=15.0)
|
|
110
|
+
if stereo_setup == "faceon":
|
|
111
|
+
stereo_system = pyvale.CameraTools.faceon_stereo_cameras(
|
|
112
|
+
cam_data_0=cam_data_0,
|
|
113
|
+
stereo_angle=15.0)
|
|
114
|
+
cam0, cam1 = scene.add_stereo_system(stereo_system)
|
|
115
|
+
|
|
116
|
+
# %%
|
|
117
|
+
# Since this scene contains a stereo DIC system, a calibration file will be
|
|
118
|
+
# required to run the images through a DIC engine.
|
|
119
|
+
# A calibration file can be generated directly from the `CameraStereo` object.
|
|
120
|
+
# The calibration file will be saved in `YAML` format. However, if you wish to
|
|
121
|
+
# use MatchID to process the images, `save_calibration_mid` can be used instead
|
|
122
|
+
# to save the calibration in a format readable by MatchID.
|
|
123
|
+
# The calibration file will be saved to a sub-directory of the base directory
|
|
124
|
+
# called "calibration".
|
|
125
|
+
stereo_system.save_calibration(base_dir)
|
|
126
|
+
|
|
127
|
+
# %%
|
|
128
|
+
# A light can the be added to the scene.
|
|
129
|
+
# Blender offers different light types: Point, Sun, Spot and Area.
|
|
130
|
+
# The light can also be moved and rotated like the camera.
|
|
131
|
+
light_data = pyvale.BlenderLightData(type=pyvale.BlenderLightType.POINT,
|
|
132
|
+
pos_world=(0, 0, 400),
|
|
133
|
+
rot_world=Rotation.from_euler("xyz",
|
|
134
|
+
[0, 0, 0]),
|
|
135
|
+
energy=1)
|
|
136
|
+
light = scene.add_light(light_data)
|
|
137
|
+
light.location = (0, 0, 410)
|
|
138
|
+
light.rotation_euler = (0, 0, 0) # NOTE: The default is an XYZ Euler angle
|
|
139
|
+
|
|
140
|
+
# Apply the speckle pattern
|
|
141
|
+
material_data = pyvale.BlenderMaterialData()
|
|
142
|
+
speckle_path = pyvale.DataSet.dic_pattern_5mpx_path()
|
|
143
|
+
# NOTE: If you wish to use a bigger camera, you will need to generate a
|
|
144
|
+
# bigger speckle pattern generator
|
|
145
|
+
|
|
146
|
+
# %%
|
|
147
|
+
# A speckle pattern can then be applied to the sample.
|
|
148
|
+
# Firstly, the material properties of the sample must be specified, but these
|
|
149
|
+
# will all be defaulted if no inputs are provided.
|
|
150
|
+
#The speckle pattern can then be specified by providing a path to an image file
|
|
151
|
+
# with the pattern.
|
|
152
|
+
# The mm/px resolution of the camera must also be specified in order to
|
|
153
|
+
# correctly scale the speckle pattern.
|
|
154
|
+
# It should be noted that for a bigger camera or sample you may need to generate
|
|
155
|
+
# a larger speckle pattern.
|
|
156
|
+
|
|
157
|
+
mm_px_resolution = pyvale.CameraTools.calculate_mm_px_resolution(cam_data_0)
|
|
158
|
+
scene.add_speckle(part=part,
|
|
159
|
+
speckle_path=speckle_path,
|
|
160
|
+
mat_data=material_data,
|
|
161
|
+
mm_px_resolution=mm_px_resolution)
|
|
162
|
+
|
|
163
|
+
# %%
|
|
164
|
+
# Deforming the sample and rendering images
|
|
165
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
166
|
+
# Once all the objects have been added to the scene, the sample can be deformed,
|
|
167
|
+
# and images can be rendered.
|
|
168
|
+
# Firstly, all the rendering parameters must be set, including parameters such as
|
|
169
|
+
# the number of threads to use.
|
|
170
|
+
# Differently to a 2D DIC system, both cameras' parameters must be specified in
|
|
171
|
+
# the `RenderData` object.
|
|
172
|
+
render_data = pyvale.RenderData(cam_data=(stereo_system.cam_data_0,
|
|
173
|
+
stereo_system.cam_data_1),
|
|
174
|
+
base_dir=base_dir,
|
|
175
|
+
threads=8)
|
|
176
|
+
|
|
177
|
+
# %%
|
|
178
|
+
# A series of deformed images can then be rendered.
|
|
179
|
+
# This is done by passing in rendering parameters, as well as the
|
|
180
|
+
# `RenderMeshData` object, the part(sample) and the spatial dimension of the
|
|
181
|
+
# simulation.
|
|
182
|
+
# This will automatically deform the sample, and render images from each camera
|
|
183
|
+
# at each deformation timestep.
|
|
184
|
+
# If `stage_image` is set to True, the image will be saved to disk, converted to
|
|
185
|
+
# an array, deleted and the image array will be returned. This is due to the
|
|
186
|
+
# fact that an image cannot be saved directly as an array through Blender.
|
|
187
|
+
|
|
188
|
+
scene.render_deformed_images(render_mesh=render_mesh,
|
|
189
|
+
sim_spat_dim=3,
|
|
190
|
+
render_data=render_data,
|
|
191
|
+
part=part,
|
|
192
|
+
stage_image=False)
|
|
193
|
+
|
|
194
|
+
# %%
|
|
195
|
+
# The rendered image will be saved to this filepath:
|
|
196
|
+
|
|
197
|
+
print("Save directory of the image:", (render_data.base_dir / "blenderimages"))
|
|
198
|
+
|
|
199
|
+
# %%
|
|
200
|
+
# There is also the option to save the scene as a Blender project file.
|
|
201
|
+
# This file can be opened with the Blender GUI to view the scene.
|
|
202
|
+
|
|
203
|
+
pyvale.BlenderTools.save_blender_file(base_dir)
|
|
204
|
+
|