@@ -58,16 +58,9 @@ class BigDataViewerMetadata(XMLMetadata):
58
58
"""
59
59
60
60
def __init__ (self ) -> None :
61
- """Initialize the BigDataViewer metadata object.
62
-
63
- Parameters
64
- ----------
65
- configuration : Optional[Dict[str, Any]]
66
- Configuration dictionary.
67
- """
61
+ """Initialize the BigDataViewer metadata object."""
68
62
super ().__init__ ()
69
63
70
- # Affine Transform Parameters
71
64
#: bool: Shear the data.
72
65
self .shear_data = False
73
66
@@ -80,7 +73,6 @@ def __init__(self) -> None:
80
73
#: npt.NDArray: Shear transform matrix.
81
74
self .shear_transform = np .eye (3 , 4 )
82
75
83
- # Rotation Transform Parameters
84
76
#: bool: Rotate the data.
85
77
self .rotate_data = False
86
78
@@ -194,9 +186,23 @@ def bdv_xml_dict(
194
186
}
195
187
196
188
# Calculate shear and rotation transforms
189
+ pixel_size = [self .dx , self .dy , self .dz ]
197
190
self .bdv_shear_transform ()
198
191
self .bdv_rotate_transform ()
199
192
193
+ if self .shear_data :
194
+ shear_angle = np .deg2rad (self .shear_angle )
195
+ # Must scale the voxel size to account for shear
196
+ if self .shear_dimension == "YZ" :
197
+ scaled_z = abs (self .dz * np .sin (shear_angle ))
198
+ pixel_size = [self .dx , self .dy , scaled_z ]
199
+ elif self .shear_dimension == "XZ" :
200
+ # TODO: Implement
201
+ pass
202
+ else :
203
+ # TODO: Implement
204
+ pass
205
+
200
206
# Populate ViewSetups
201
207
bdv_dict ["SequenceDescription" ]["ViewSetups" ] = {}
202
208
bdv_dict ["SequenceDescription" ]["ViewSetups" ]["ViewSetup" ] = []
@@ -210,6 +216,7 @@ def bdv_xml_dict(
210
216
{"name" : "tile" , "Tile" : []},
211
217
{"name" : "angle" , "Angle" : {"id" : {"text" : 0 }, "name" : {"text" : 0 }}},
212
218
]
219
+
213
220
# The actual loop that populates ViewSetup
214
221
view_id = 0
215
222
for c in range (self .shape_c ):
@@ -226,7 +233,9 @@ def bdv_xml_dict(
226
233
"size" : {"text" : f"{ self .shape_x } { self .shape_y } { self .shape_z } " },
227
234
"voxelSize" : {
228
235
"unit" : {"text" : "um" },
229
- "size" : {"text" : f"{ self .dx } { self .dy } { self .dz } " },
236
+ "size" : {
237
+ "text" : f"{ pixel_size [0 ]} { pixel_size [1 ]} { pixel_size [2 ]} "
238
+ },
230
239
},
231
240
"attributes" : {
232
241
"illumination" : {"text" : "0" },
@@ -238,7 +247,8 @@ def bdv_xml_dict(
238
247
239
248
bdv_dict ["SequenceDescription" ]["ViewSetups" ]["ViewSetup" ].append (d )
240
249
view_id += 1
241
- # Finish up the Tile Attributes outside of the channels loop so we have
250
+
251
+ # Finish up the Tile Attributes outside the channels loop so we have
242
252
# one per tile
243
253
for pos in range (self .positions ):
244
254
tile = {"id" : {"text" : str (pos )}, "name" : {"text" : str (pos )}}
@@ -254,6 +264,7 @@ def bdv_xml_dict(
254
264
}
255
265
256
266
# View registrations
267
+ reference_position = np .eye (3 , 4 , dtype = float )
257
268
bdv_dict ["ViewRegistrations" ] = {"ViewRegistration" : []}
258
269
for t in range (self .shape_t ):
259
270
for p in range (self .positions ):
@@ -282,6 +293,13 @@ def bdv_xml_dict(
282
293
# an acquisition.
283
294
pass
284
295
296
+ if t == 0 and p == 0 and c == 0 :
297
+ # Save reference position to allow translation offsets for
298
+ # shear to be applied relative to this position.
299
+ reference_position = mat .ravel ()
300
+
301
+ current_position = mat .ravel ()
302
+
285
303
view_transforms = [
286
304
{
287
305
"type" : "affine" ,
@@ -308,6 +326,33 @@ def bdv_xml_dict(
308
326
}
309
327
)
310
328
329
+ delta_z_position = current_position [- 1 ] - reference_position [- 1 ]
330
+ shear_offset = np .eye (3 , 4 , dtype = float ).ravel ()
331
+ if self .shear_dimension == "YZ" :
332
+ shear_offset [7 ] = (
333
+ delta_z_position
334
+ * self .dz
335
+ * np .tan (np .deg2rad (self .shear_angle ))
336
+ / self .dy
337
+ )
338
+
339
+ elif self .shear_dimension == "XZ" :
340
+ # TODO: Implement
341
+ pass
342
+ else :
343
+ # TODO: Implement
344
+ pass
345
+
346
+ view_transforms .append (
347
+ {
348
+ "type" : "affine" ,
349
+ "Name" : "Shear Offset Transform" ,
350
+ "affine" : {
351
+ "text" : " " .join ([f"{ x :.6f} " for x in shear_offset ])
352
+ },
353
+ }
354
+ )
355
+
311
356
if self .rotate_data :
312
357
view_transforms .append (
313
358
{
@@ -328,9 +373,7 @@ def bdv_xml_dict(
328
373
329
374
bdv_dict ["ViewRegistrations" ]["ViewRegistration" ].append (d )
330
375
331
- bdv_dict ["Misc" ] = {
332
- "Entry" : {"Key" : "Note" , "text" : self .misc }
333
- }
376
+ bdv_dict ["Misc" ] = {"Entry" : {"Key" : "Note" , "text" : self .misc }}
334
377
335
378
return bdv_dict
336
379
0 commit comments