com.shinolab.autd3-sdk.pattern 0.7.0 → 0.9.0
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.
package/Pattern.cs
CHANGED
|
@@ -7,68 +7,126 @@ using System.Runtime.InteropServices;
|
|
|
7
7
|
|
|
8
8
|
namespace AUTD3
|
|
9
9
|
{
|
|
10
|
-
|
|
11
|
-
internal struct PatternOptionNative
|
|
10
|
+
public readonly struct LaguerreGaussianOption
|
|
12
11
|
{
|
|
13
|
-
public
|
|
14
|
-
public
|
|
15
|
-
|
|
12
|
+
public uint P { get; }
|
|
13
|
+
public int L { get; }
|
|
14
|
+
public Length Waist { get; }
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
public Intensity Intensity { get; }
|
|
20
|
-
public Phase PhaseOffset { get; }
|
|
21
|
-
|
|
22
|
-
public FocusOption() : this(intensity: null)
|
|
16
|
+
public LaguerreGaussianOption(uint p, int l, Length waist)
|
|
23
17
|
{
|
|
18
|
+
P = p;
|
|
19
|
+
L = l;
|
|
20
|
+
Waist = waist;
|
|
24
21
|
}
|
|
22
|
+
}
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
public readonly struct HermiteGaussianOption
|
|
25
|
+
{
|
|
26
|
+
public uint M { get; }
|
|
27
|
+
public uint N { get; }
|
|
28
|
+
public Length Waist { get; }
|
|
29
|
+
|
|
30
|
+
public HermiteGaussianOption(uint m, uint n, Length waist)
|
|
27
31
|
{
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
M = m;
|
|
33
|
+
N = n;
|
|
34
|
+
Waist = waist;
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
internal PatternOptionNative ToNative() =>
|
|
33
|
-
new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
public readonly struct
|
|
38
|
+
public readonly struct TransducerMask
|
|
37
39
|
{
|
|
38
|
-
|
|
39
|
-
public Phase PhaseOffset { get; }
|
|
40
|
+
internal bool[][]? Mask { get; }
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
private TransducerMask(bool[][]? mask)
|
|
42
43
|
{
|
|
44
|
+
Mask = mask;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
public
|
|
46
|
-
{
|
|
47
|
-
Intensity = intensity ?? Intensity.Max;
|
|
48
|
-
PhaseOffset = phaseOffset ?? Phase.Zero;
|
|
49
|
-
}
|
|
47
|
+
public static TransducerMask AllEnabled => new TransducerMask(null);
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
|
|
49
|
+
public static TransducerMask Masked(bool[][] mask) => new TransducerMask(mask);
|
|
53
50
|
}
|
|
54
51
|
|
|
55
|
-
public
|
|
52
|
+
public sealed class TransducerGroups<TKey> where TKey : struct
|
|
56
53
|
{
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
private readonly int[] _numTransducers;
|
|
55
|
+
private readonly List<TKey> _keys = new List<TKey>();
|
|
56
|
+
private readonly Dictionary<TKey, int> _lookup = new Dictionary<TKey, int>();
|
|
57
|
+
|
|
58
|
+
internal int[] Indices { get; }
|
|
59
|
+
|
|
60
|
+
public IReadOnlyList<TKey> Keys => _keys;
|
|
59
61
|
|
|
60
|
-
public
|
|
62
|
+
public int NumDevices => _numTransducers.Length;
|
|
63
|
+
|
|
64
|
+
public TransducerGroups(Geometry geometry, Func<Device, int, TKey?> key)
|
|
61
65
|
{
|
|
66
|
+
_numTransducers = new int[geometry.NumDevices];
|
|
67
|
+
Indices = new int[geometry.NumTransducers];
|
|
68
|
+
var k = 0;
|
|
69
|
+
var dev = 0;
|
|
70
|
+
foreach (var device in geometry)
|
|
71
|
+
{
|
|
72
|
+
var numTransducers = device.NumTransducers;
|
|
73
|
+
_numTransducers[dev++] = numTransducers;
|
|
74
|
+
for (var tr = 0; tr < numTransducers; tr++)
|
|
75
|
+
{
|
|
76
|
+
var value = key(device, tr);
|
|
77
|
+
if (value == null)
|
|
78
|
+
{
|
|
79
|
+
Indices[k++] = -1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (!_lookup.TryGetValue(value.Value, out var index))
|
|
83
|
+
{
|
|
84
|
+
index = _keys.Count;
|
|
85
|
+
_lookup.Add(value.Value, index);
|
|
86
|
+
_keys.Add(value.Value);
|
|
87
|
+
}
|
|
88
|
+
Indices[k++] = index;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
62
91
|
}
|
|
63
92
|
|
|
64
|
-
public
|
|
93
|
+
public TKey? Key(int device, int transducer)
|
|
65
94
|
{
|
|
66
|
-
|
|
67
|
-
|
|
95
|
+
if (device < 0 || device >= _numTransducers.Length)
|
|
96
|
+
{
|
|
97
|
+
throw new ArgumentOutOfRangeException(nameof(device));
|
|
98
|
+
}
|
|
99
|
+
if (transducer < 0 || transducer >= _numTransducers[device])
|
|
100
|
+
{
|
|
101
|
+
throw new ArgumentOutOfRangeException(nameof(transducer));
|
|
102
|
+
}
|
|
103
|
+
var offset = 0;
|
|
104
|
+
for (var dev = 0; dev < device; dev++)
|
|
105
|
+
{
|
|
106
|
+
offset += _numTransducers[dev];
|
|
107
|
+
}
|
|
108
|
+
var index = Indices[offset + transducer];
|
|
109
|
+
return index < 0 ? (TKey?)null : _keys[index];
|
|
68
110
|
}
|
|
69
111
|
|
|
70
|
-
|
|
71
|
-
|
|
112
|
+
public TransducerMask Mask(TKey key)
|
|
113
|
+
{
|
|
114
|
+
if (!_lookup.TryGetValue(key, out var index))
|
|
115
|
+
{
|
|
116
|
+
throw new ArgumentException($"no transducer is assigned the key {key}", nameof(key));
|
|
117
|
+
}
|
|
118
|
+
var mask = new bool[_numTransducers.Length][];
|
|
119
|
+
var k = 0;
|
|
120
|
+
for (var dev = 0; dev < mask.Length; dev++)
|
|
121
|
+
{
|
|
122
|
+
mask[dev] = new bool[_numTransducers[dev]];
|
|
123
|
+
for (var tr = 0; tr < mask[dev].Length; tr++)
|
|
124
|
+
{
|
|
125
|
+
mask[dev][tr] = Indices[k++] == index;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return TransducerMask.Masked(mask);
|
|
129
|
+
}
|
|
72
130
|
}
|
|
73
131
|
|
|
74
132
|
[StructLayout(LayoutKind.Sequential)]
|
|
@@ -121,37 +179,94 @@ namespace AUTD3
|
|
|
121
179
|
internal static extern void autd3_pattern_buffer_free(IntPtr buffer);
|
|
122
180
|
|
|
123
181
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
124
|
-
internal static extern int autd3_pattern_focus(GeometryHandle geometry, float[] target, float wavelengthMm,
|
|
182
|
+
internal static extern int autd3_pattern_focus(GeometryHandle geometry, float[] target, float wavelengthMm, PatternBufferHandle buffer);
|
|
183
|
+
|
|
184
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
185
|
+
internal static extern int autd3_pattern_focus_device(GeometryHandle geometry, UIntPtr dev, float[] target, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
125
186
|
|
|
126
187
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
127
|
-
internal static extern int
|
|
188
|
+
internal static extern int autd3_pattern_focus_transducer(float[] position, float[] target, float wavelengthMm, out byte @out);
|
|
128
189
|
|
|
129
190
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
130
|
-
internal static extern int
|
|
191
|
+
internal static extern int autd3_pattern_plane(GeometryHandle geometry, float[] dir, float wavelengthMm, PatternBufferHandle buffer);
|
|
131
192
|
|
|
132
193
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
133
|
-
internal static extern int
|
|
194
|
+
internal static extern int autd3_pattern_plane_device(GeometryHandle geometry, UIntPtr dev, float[] dir, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
134
195
|
|
|
135
196
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
136
|
-
internal static extern int
|
|
197
|
+
internal static extern int autd3_pattern_plane_transducer(float[] position, float[] dir, float wavelengthMm, out byte @out);
|
|
137
198
|
|
|
138
199
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
139
|
-
internal static extern int
|
|
200
|
+
internal static extern int autd3_pattern_bessel(GeometryHandle geometry, float[] apex, float[] dir, float thetaRad, float wavelengthMm, PatternBufferHandle buffer);
|
|
140
201
|
|
|
141
202
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
142
|
-
internal static extern int
|
|
203
|
+
internal static extern int autd3_pattern_bessel_device(GeometryHandle geometry, UIntPtr dev, float[] apex, float[] dir, float thetaRad, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
143
204
|
|
|
144
205
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
145
|
-
internal static extern int
|
|
206
|
+
internal static extern int autd3_pattern_bessel_transducer(float[] position, float[] apex, float[] dir, float thetaRad, float wavelengthMm, out byte @out);
|
|
146
207
|
|
|
147
208
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
148
|
-
internal static extern int
|
|
209
|
+
internal static extern int autd3_pattern_laguerre_gaussian_phase(GeometryHandle geometry, float[] target, float[] axis, uint p, int l, float waistMm, float wavelengthMm, PatternBufferHandle buffer);
|
|
149
210
|
|
|
150
211
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
151
|
-
internal static extern int
|
|
212
|
+
internal static extern int autd3_pattern_laguerre_gaussian_phase_device(GeometryHandle geometry, UIntPtr dev, float[] target, float[] axis, uint p, int l, float waistMm, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
152
213
|
|
|
153
214
|
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
154
|
-
internal static extern
|
|
215
|
+
internal static extern int autd3_pattern_laguerre_gaussian_phase_transducer(float[] position, float[] target, float[] axis, uint p, int l, float waistMm, float wavelengthMm, out byte @out);
|
|
216
|
+
|
|
217
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
218
|
+
internal static extern int autd3_pattern_laguerre_gaussian_intensity(GeometryHandle geometry, float[] target, float[] axis, uint p, int l, float waistMm, float wavelengthMm, PatternBufferHandle buffer);
|
|
219
|
+
|
|
220
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
221
|
+
internal static extern int autd3_pattern_laguerre_gaussian_intensity_device(GeometryHandle geometry, UIntPtr dev, float[] target, float[] axis, uint p, int l, float waistMm, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
222
|
+
|
|
223
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
224
|
+
internal static extern int autd3_pattern_hermite_gaussian_phase(GeometryHandle geometry, float[] target, float[] axis, float[] xDir, uint m, uint n, float waistMm, float wavelengthMm, PatternBufferHandle buffer);
|
|
225
|
+
|
|
226
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
227
|
+
internal static extern int autd3_pattern_hermite_gaussian_phase_device(GeometryHandle geometry, UIntPtr dev, float[] target, float[] axis, float[] xDir, uint m, uint n, float waistMm, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
228
|
+
|
|
229
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
230
|
+
internal static extern int autd3_pattern_hermite_gaussian_phase_transducer(float[] position, float[] target, float[] axis, float[] xDir, uint m, uint n, float waistMm, float wavelengthMm, out byte @out);
|
|
231
|
+
|
|
232
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
233
|
+
internal static extern int autd3_pattern_hermite_gaussian_intensity(GeometryHandle geometry, float[] target, float[] axis, float[] xDir, uint m, uint n, float waistMm, float wavelengthMm, PatternBufferHandle buffer);
|
|
234
|
+
|
|
235
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
236
|
+
internal static extern int autd3_pattern_hermite_gaussian_intensity_device(GeometryHandle geometry, UIntPtr dev, float[] target, float[] axis, float[] xDir, uint m, uint n, float waistMm, float wavelengthMm, [In, Out] EmissionNative[] dst);
|
|
237
|
+
|
|
238
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
239
|
+
internal static extern int autd3_pattern_set_intensity(byte intensity, PatternBufferHandle buffer);
|
|
240
|
+
|
|
241
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
242
|
+
internal static extern int autd3_pattern_set_intensity_device(byte intensity, [In, Out] EmissionNative[] dst, UIntPtr len);
|
|
243
|
+
|
|
244
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
245
|
+
internal static extern int autd3_pattern_set_phase(byte phase, PatternBufferHandle buffer);
|
|
246
|
+
|
|
247
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
248
|
+
internal static extern int autd3_pattern_set_phase_device(byte phase, [In, Out] EmissionNative[] dst, UIntPtr len);
|
|
249
|
+
|
|
250
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
251
|
+
internal static extern int autd3_pattern_set_phase_and_intensity(byte phase, byte intensity, PatternBufferHandle buffer);
|
|
252
|
+
|
|
253
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
254
|
+
internal static extern int autd3_pattern_set_phase_and_intensity_device(byte phase, byte intensity, [In, Out] EmissionNative[] dst, UIntPtr len);
|
|
255
|
+
|
|
256
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
257
|
+
internal static extern int autd3_pattern_add_phase(byte phase, PatternBufferHandle buffer);
|
|
258
|
+
|
|
259
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
260
|
+
internal static extern int autd3_pattern_add_phase_device(byte phase, [In, Out] EmissionNative[] dst, UIntPtr len);
|
|
261
|
+
|
|
262
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
263
|
+
internal static extern int autd3_pattern_group(GeometryHandle geometry, int[] keys, IntPtr[] sources, UIntPtr numSources, PatternBufferHandle buffer);
|
|
264
|
+
|
|
265
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
266
|
+
internal static extern int autd3_pattern_group_null(GeometryHandle geometry, int[] indices, PatternBufferHandle buffer);
|
|
267
|
+
|
|
268
|
+
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
|
|
269
|
+
internal static extern int autd3_pattern_group_copy(GeometryHandle geometry, int[] indices, int index, PatternBufferHandle source, PatternBufferHandle buffer);
|
|
155
270
|
|
|
156
271
|
|
|
157
272
|
[DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
|
|
@@ -327,149 +442,355 @@ namespace AUTD3
|
|
|
327
442
|
new Length(NativePattern.autd3_pattern_wavelength(soundSpeed.MmS));
|
|
328
443
|
|
|
329
444
|
|
|
330
|
-
public static void Focus(Geometry geometry, Vector3 target, Length wavelength,
|
|
445
|
+
public static void Focus(Geometry geometry, Vector3 target, Length wavelength, PatternBuffer dst)
|
|
331
446
|
{
|
|
332
|
-
|
|
333
|
-
var o = option.ToNative();
|
|
334
|
-
if (NativePattern.autd3_pattern_focus(geometry.Handle, t, wavelength.Mm, in o, dst.Handle) != 0)
|
|
447
|
+
if (NativePattern.autd3_pattern_focus(geometry.Handle, Coords.PointArray(target), wavelength.Mm, dst.Handle) != 0)
|
|
335
448
|
{
|
|
336
449
|
throw new Autd3Exception("focus failed (buffer device count must match geometry)");
|
|
337
450
|
}
|
|
338
451
|
}
|
|
339
452
|
|
|
340
|
-
public static void
|
|
341
|
-
Focus(geometry, target, wavelength, new FocusOption(intensity), dst);
|
|
342
|
-
|
|
343
|
-
public static void FocusDevice(Device device, Vector3 target, Length wavelength, FocusOption option, Emission[] dst)
|
|
453
|
+
public static void FocusDevice(Device device, Vector3 target, Length wavelength, Emission[] dst)
|
|
344
454
|
{
|
|
345
455
|
var native = ToNativeDst(dst);
|
|
346
|
-
var o = option.ToNative();
|
|
347
456
|
if (NativePattern.autd3_pattern_focus_device(device.GeometryHandle, device.DeviceIndex,
|
|
348
|
-
Coords.PointArray(target), wavelength.Mm,
|
|
457
|
+
Coords.PointArray(target), wavelength.Mm, native) != 0)
|
|
349
458
|
{
|
|
350
459
|
throw new Autd3Exception("focus_device failed");
|
|
351
460
|
}
|
|
352
461
|
FromNativeDst(native, dst);
|
|
353
462
|
}
|
|
354
463
|
|
|
355
|
-
public static
|
|
464
|
+
public static Phase FocusTransducer(Vector3 position, Vector3 target, Length wavelength)
|
|
356
465
|
{
|
|
357
|
-
var o = option.ToNative();
|
|
358
466
|
if (NativePattern.autd3_pattern_focus_transducer(
|
|
359
467
|
Coords.PointArray(position),
|
|
360
|
-
Coords.PointArray(target), wavelength.Mm,
|
|
468
|
+
Coords.PointArray(target), wavelength.Mm, out var p) != 0)
|
|
361
469
|
{
|
|
362
470
|
throw new Autd3Exception("focus_transducer failed");
|
|
363
471
|
}
|
|
364
|
-
return new
|
|
472
|
+
return new Phase(p);
|
|
365
473
|
}
|
|
366
474
|
|
|
367
|
-
public static void Plane(Geometry geometry, Vector3 dir, Length wavelength,
|
|
475
|
+
public static void Plane(Geometry geometry, Vector3 dir, Length wavelength, PatternBuffer dst)
|
|
368
476
|
{
|
|
369
|
-
|
|
370
|
-
var o = option.ToNative();
|
|
371
|
-
if (NativePattern.autd3_pattern_plane(geometry.Handle, d, wavelength.Mm, in o, dst.Handle) != 0)
|
|
477
|
+
if (NativePattern.autd3_pattern_plane(geometry.Handle, Coords.DirArray(dir), wavelength.Mm, dst.Handle) != 0)
|
|
372
478
|
{
|
|
373
479
|
throw new Autd3Exception("plane failed (buffer device count must match geometry)");
|
|
374
480
|
}
|
|
375
481
|
}
|
|
376
482
|
|
|
377
|
-
public static void PlaneDevice(Device device, Vector3 dir, Length wavelength,
|
|
483
|
+
public static void PlaneDevice(Device device, Vector3 dir, Length wavelength, Emission[] dst)
|
|
378
484
|
{
|
|
379
485
|
var native = ToNativeDst(dst);
|
|
380
|
-
var o = option.ToNative();
|
|
381
486
|
if (NativePattern.autd3_pattern_plane_device(device.GeometryHandle, device.DeviceIndex,
|
|
382
|
-
Coords.DirArray(dir), wavelength.Mm,
|
|
487
|
+
Coords.DirArray(dir), wavelength.Mm, native) != 0)
|
|
383
488
|
{
|
|
384
489
|
throw new Autd3Exception("plane_device failed");
|
|
385
490
|
}
|
|
386
491
|
FromNativeDst(native, dst);
|
|
387
492
|
}
|
|
388
493
|
|
|
389
|
-
public static
|
|
494
|
+
public static Phase PlaneTransducer(Vector3 position, Vector3 dir, Length wavelength)
|
|
390
495
|
{
|
|
391
|
-
var o = option.ToNative();
|
|
392
496
|
if (NativePattern.autd3_pattern_plane_transducer(
|
|
393
497
|
Coords.PointArray(position),
|
|
394
|
-
Coords.DirArray(dir), wavelength.Mm,
|
|
498
|
+
Coords.DirArray(dir), wavelength.Mm, out var p) != 0)
|
|
395
499
|
{
|
|
396
500
|
throw new Autd3Exception("plane_transducer failed");
|
|
397
501
|
}
|
|
398
|
-
return new
|
|
502
|
+
return new Phase(p);
|
|
399
503
|
}
|
|
400
504
|
|
|
401
|
-
public static void Bessel(Geometry geometry, Vector3 apex, Vector3 dir, Angle theta, Length wavelength,
|
|
505
|
+
public static void Bessel(Geometry geometry, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, PatternBuffer dst)
|
|
402
506
|
{
|
|
403
|
-
|
|
404
|
-
var d = Coords.DirArray(dir);
|
|
405
|
-
var o = option.ToNative();
|
|
406
|
-
if (NativePattern.autd3_pattern_bessel(geometry.Handle, a, d, theta.Rad, wavelength.Mm, in o, dst.Handle) != 0)
|
|
507
|
+
if (NativePattern.autd3_pattern_bessel(geometry.Handle, Coords.PointArray(apex), Coords.DirArray(dir), theta.Rad, wavelength.Mm, dst.Handle) != 0)
|
|
407
508
|
{
|
|
408
509
|
throw new Autd3Exception("bessel failed (buffer device count must match geometry)");
|
|
409
510
|
}
|
|
410
511
|
}
|
|
411
512
|
|
|
412
|
-
public static void BesselDevice(Device device, Vector3 apex, Vector3 dir, Angle theta, Length wavelength,
|
|
513
|
+
public static void BesselDevice(Device device, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, Emission[] dst)
|
|
413
514
|
{
|
|
414
515
|
var native = ToNativeDst(dst);
|
|
415
|
-
var o = option.ToNative();
|
|
416
516
|
if (NativePattern.autd3_pattern_bessel_device(device.GeometryHandle, device.DeviceIndex,
|
|
417
517
|
Coords.PointArray(apex),
|
|
418
|
-
Coords.DirArray(dir), theta.Rad, wavelength.Mm,
|
|
518
|
+
Coords.DirArray(dir), theta.Rad, wavelength.Mm, native) != 0)
|
|
419
519
|
{
|
|
420
520
|
throw new Autd3Exception("bessel_device failed");
|
|
421
521
|
}
|
|
422
522
|
FromNativeDst(native, dst);
|
|
423
523
|
}
|
|
424
524
|
|
|
425
|
-
public static
|
|
525
|
+
public static Phase BesselTransducer(Vector3 position, Vector3 apex, Vector3 dir, Angle theta, Length wavelength)
|
|
426
526
|
{
|
|
427
|
-
var o = option.ToNative();
|
|
428
527
|
if (NativePattern.autd3_pattern_bessel_transducer(
|
|
429
528
|
Coords.PointArray(position),
|
|
430
529
|
Coords.PointArray(apex),
|
|
431
|
-
Coords.DirArray(dir), theta.Rad, wavelength.Mm,
|
|
530
|
+
Coords.DirArray(dir), theta.Rad, wavelength.Mm, out var p) != 0)
|
|
432
531
|
{
|
|
433
532
|
throw new Autd3Exception("bessel_transducer failed");
|
|
434
533
|
}
|
|
435
|
-
return new
|
|
534
|
+
return new Phase(p);
|
|
436
535
|
}
|
|
437
536
|
|
|
438
|
-
public static void
|
|
537
|
+
public static void LaguerreGaussianPhase(Geometry geometry, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, PatternBuffer dst)
|
|
439
538
|
{
|
|
440
|
-
if (NativePattern.
|
|
539
|
+
if (NativePattern.autd3_pattern_laguerre_gaussian_phase(geometry.Handle, Coords.PointArray(target), Coords.DirArray(axis),
|
|
540
|
+
option.P, option.L, option.Waist.Mm, wavelength.Mm, dst.Handle) != 0)
|
|
441
541
|
{
|
|
442
|
-
throw new Autd3Exception("
|
|
542
|
+
throw new Autd3Exception("laguerre_gaussian_phase failed (waist must be positive and buffer device count must match geometry)");
|
|
443
543
|
}
|
|
444
544
|
}
|
|
445
545
|
|
|
446
|
-
public static void
|
|
546
|
+
public static void LaguerreGaussianPhaseDevice(Device device, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, Emission[] dst)
|
|
447
547
|
{
|
|
448
|
-
|
|
548
|
+
var native = ToNativeDst(dst);
|
|
549
|
+
if (NativePattern.autd3_pattern_laguerre_gaussian_phase_device(device.GeometryHandle, device.DeviceIndex,
|
|
550
|
+
Coords.PointArray(target), Coords.DirArray(axis), option.P, option.L, option.Waist.Mm, wavelength.Mm, native) != 0)
|
|
449
551
|
{
|
|
450
|
-
|
|
552
|
+
throw new Autd3Exception("laguerre_gaussian_phase_device failed (waist must be positive)");
|
|
451
553
|
}
|
|
554
|
+
FromNativeDst(native, dst);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
public static Phase LaguerreGaussianPhaseTransducer(Vector3 position, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength)
|
|
558
|
+
{
|
|
559
|
+
if (NativePattern.autd3_pattern_laguerre_gaussian_phase_transducer(
|
|
560
|
+
Coords.PointArray(position),
|
|
561
|
+
Coords.PointArray(target),
|
|
562
|
+
Coords.DirArray(axis), option.P, option.L, option.Waist.Mm, wavelength.Mm, out var p) != 0)
|
|
563
|
+
{
|
|
564
|
+
throw new Autd3Exception("laguerre_gaussian_phase_transducer failed (waist must be positive)");
|
|
565
|
+
}
|
|
566
|
+
return new Phase(p);
|
|
452
567
|
}
|
|
453
568
|
|
|
454
|
-
public static void
|
|
569
|
+
public static void LaguerreGaussianIntensity(Geometry geometry, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, PatternBuffer dst)
|
|
570
|
+
{
|
|
571
|
+
if (NativePattern.autd3_pattern_laguerre_gaussian_intensity(geometry.Handle, Coords.PointArray(target), Coords.DirArray(axis),
|
|
572
|
+
option.P, option.L, option.Waist.Mm, wavelength.Mm, dst.Handle) != 0)
|
|
573
|
+
{
|
|
574
|
+
throw new Autd3Exception("laguerre_gaussian_intensity failed (waist must be positive and buffer device count must match geometry)");
|
|
575
|
+
}
|
|
576
|
+
}
|
|
455
577
|
|
|
456
|
-
public static void
|
|
578
|
+
public static void LaguerreGaussianIntensityDevice(Device device, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, Emission[] dst)
|
|
457
579
|
{
|
|
458
|
-
|
|
580
|
+
var native = ToNativeDst(dst);
|
|
581
|
+
if (NativePattern.autd3_pattern_laguerre_gaussian_intensity_device(device.GeometryHandle, device.DeviceIndex,
|
|
582
|
+
Coords.PointArray(target), Coords.DirArray(axis), option.P, option.L, option.Waist.Mm, wavelength.Mm, native) != 0)
|
|
583
|
+
{
|
|
584
|
+
throw new Autd3Exception("laguerre_gaussian_intensity_device failed (waist must be positive)");
|
|
585
|
+
}
|
|
586
|
+
FromNativeDst(native, dst);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
public static void HermiteGaussianPhase(Geometry geometry, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, PatternBuffer dst)
|
|
590
|
+
{
|
|
591
|
+
if (NativePattern.autd3_pattern_hermite_gaussian_phase(geometry.Handle, Coords.PointArray(target), Coords.DirArray(axis), Coords.DirArray(xDir),
|
|
592
|
+
option.M, option.N, option.Waist.Mm, wavelength.Mm, dst.Handle) != 0)
|
|
593
|
+
{
|
|
594
|
+
throw new Autd3Exception("hermite_gaussian_phase failed (waist must be positive and buffer device count must match geometry)");
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
public static void HermiteGaussianPhaseDevice(Device device, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, Emission[] dst)
|
|
599
|
+
{
|
|
600
|
+
var native = ToNativeDst(dst);
|
|
601
|
+
if (NativePattern.autd3_pattern_hermite_gaussian_phase_device(device.GeometryHandle, device.DeviceIndex,
|
|
602
|
+
Coords.PointArray(target), Coords.DirArray(axis), Coords.DirArray(xDir), option.M, option.N, option.Waist.Mm, wavelength.Mm, native) != 0)
|
|
603
|
+
{
|
|
604
|
+
throw new Autd3Exception("hermite_gaussian_phase_device failed (waist must be positive)");
|
|
605
|
+
}
|
|
606
|
+
FromNativeDst(native, dst);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
public static Phase HermiteGaussianPhaseTransducer(Vector3 position, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength)
|
|
610
|
+
{
|
|
611
|
+
if (NativePattern.autd3_pattern_hermite_gaussian_phase_transducer(
|
|
612
|
+
Coords.PointArray(position),
|
|
613
|
+
Coords.PointArray(target),
|
|
614
|
+
Coords.DirArray(axis),
|
|
615
|
+
Coords.DirArray(xDir), option.M, option.N, option.Waist.Mm, wavelength.Mm, out var p) != 0)
|
|
616
|
+
{
|
|
617
|
+
throw new Autd3Exception("hermite_gaussian_phase_transducer failed (waist must be positive)");
|
|
618
|
+
}
|
|
619
|
+
return new Phase(p);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
public static void HermiteGaussianIntensity(Geometry geometry, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, PatternBuffer dst)
|
|
623
|
+
{
|
|
624
|
+
if (NativePattern.autd3_pattern_hermite_gaussian_intensity(geometry.Handle, Coords.PointArray(target), Coords.DirArray(axis), Coords.DirArray(xDir),
|
|
625
|
+
option.M, option.N, option.Waist.Mm, wavelength.Mm, dst.Handle) != 0)
|
|
626
|
+
{
|
|
627
|
+
throw new Autd3Exception("hermite_gaussian_intensity failed (waist must be positive and buffer device count must match geometry)");
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
public static void HermiteGaussianIntensityDevice(Device device, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, Emission[] dst)
|
|
632
|
+
{
|
|
633
|
+
var native = ToNativeDst(dst);
|
|
634
|
+
if (NativePattern.autd3_pattern_hermite_gaussian_intensity_device(device.GeometryHandle, device.DeviceIndex,
|
|
635
|
+
Coords.PointArray(target), Coords.DirArray(axis), Coords.DirArray(xDir), option.M, option.N, option.Waist.Mm, wavelength.Mm, native) != 0)
|
|
636
|
+
{
|
|
637
|
+
throw new Autd3Exception("hermite_gaussian_intensity_device failed (waist must be positive)");
|
|
638
|
+
}
|
|
639
|
+
FromNativeDst(native, dst);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
public static void SetIntensity(Intensity intensity, PatternBuffer dst)
|
|
643
|
+
{
|
|
644
|
+
if (NativePattern.autd3_pattern_set_intensity(intensity.Value, dst.Handle) != 0)
|
|
459
645
|
{
|
|
460
|
-
|
|
646
|
+
throw new Autd3Exception("set_intensity failed");
|
|
461
647
|
}
|
|
462
648
|
}
|
|
463
649
|
|
|
464
|
-
public static void
|
|
650
|
+
public static void SetIntensityDevice(Intensity intensity, Emission[] dst)
|
|
651
|
+
{
|
|
652
|
+
var native = ToNativeDstAnyLength(dst);
|
|
653
|
+
if (NativePattern.autd3_pattern_set_intensity_device(intensity.Value, native, (UIntPtr)native.Length) != 0)
|
|
654
|
+
{
|
|
655
|
+
throw new Autd3Exception("set_intensity_device failed");
|
|
656
|
+
}
|
|
657
|
+
FromNativeDst(native, dst);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
public static void SetPhase(Phase phase, PatternBuffer dst)
|
|
661
|
+
{
|
|
662
|
+
if (NativePattern.autd3_pattern_set_phase(phase.Value, dst.Handle) != 0)
|
|
663
|
+
{
|
|
664
|
+
throw new Autd3Exception("set_phase failed");
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
public static void SetPhaseDevice(Phase phase, Emission[] dst)
|
|
669
|
+
{
|
|
670
|
+
var native = ToNativeDstAnyLength(dst);
|
|
671
|
+
if (NativePattern.autd3_pattern_set_phase_device(phase.Value, native, (UIntPtr)native.Length) != 0)
|
|
672
|
+
{
|
|
673
|
+
throw new Autd3Exception("set_phase_device failed");
|
|
674
|
+
}
|
|
675
|
+
FromNativeDst(native, dst);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
public static void SetPhaseAndIntensity(Phase phase, Intensity intensity, PatternBuffer dst)
|
|
679
|
+
{
|
|
680
|
+
if (NativePattern.autd3_pattern_set_phase_and_intensity(phase.Value, intensity.Value, dst.Handle) != 0)
|
|
681
|
+
{
|
|
682
|
+
throw new Autd3Exception("set_phase_and_intensity failed");
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
public static void SetPhaseAndIntensityDevice(Phase phase, Intensity intensity, Emission[] dst)
|
|
687
|
+
{
|
|
688
|
+
var native = ToNativeDstAnyLength(dst);
|
|
689
|
+
if (NativePattern.autd3_pattern_set_phase_and_intensity_device(phase.Value, intensity.Value, native, (UIntPtr)native.Length) != 0)
|
|
690
|
+
{
|
|
691
|
+
throw new Autd3Exception("set_phase_and_intensity_device failed");
|
|
692
|
+
}
|
|
693
|
+
FromNativeDst(native, dst);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
public static void AddPhase(Phase phase, PatternBuffer dst)
|
|
697
|
+
{
|
|
698
|
+
if (NativePattern.autd3_pattern_add_phase(phase.Value, dst.Handle) != 0)
|
|
699
|
+
{
|
|
700
|
+
throw new Autd3Exception("add_phase failed");
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
public static void AddPhaseDevice(Phase phase, Emission[] dst)
|
|
705
|
+
{
|
|
706
|
+
var native = ToNativeDstAnyLength(dst);
|
|
707
|
+
if (NativePattern.autd3_pattern_add_phase_device(phase.Value, native, (UIntPtr)native.Length) != 0)
|
|
708
|
+
{
|
|
709
|
+
throw new Autd3Exception("add_phase_device failed");
|
|
710
|
+
}
|
|
711
|
+
FromNativeDst(native, dst);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
public static void Group<TKey>(Geometry geometry, TransducerGroups<TKey> groups, Func<TKey, PatternBuffer> source, PatternBuffer dst) where TKey : struct
|
|
715
|
+
{
|
|
716
|
+
if (groups.Indices.Length != geometry.NumTransducers)
|
|
717
|
+
{
|
|
718
|
+
throw new Autd3Exception("groups must be built from the same geometry");
|
|
719
|
+
}
|
|
720
|
+
var keys = groups.Keys;
|
|
721
|
+
var handles = new SafeHandle[keys.Count];
|
|
722
|
+
for (var i = 0; i < keys.Count; i++)
|
|
723
|
+
{
|
|
724
|
+
var buffer = source(keys[i]);
|
|
725
|
+
if (buffer == null)
|
|
726
|
+
{
|
|
727
|
+
throw new Autd3Exception($"no source was given for the key {keys[i]}");
|
|
728
|
+
}
|
|
729
|
+
if (ReferenceEquals(buffer, dst))
|
|
730
|
+
{
|
|
731
|
+
throw new Autd3Exception("dst must not be one of the sources");
|
|
732
|
+
}
|
|
733
|
+
handles[i] = buffer.Handle;
|
|
734
|
+
}
|
|
735
|
+
using var lease = new HandleArray(handles);
|
|
736
|
+
if (NativePattern.autd3_pattern_group(geometry.Handle, groups.Indices, lease.Pointers, (UIntPtr)keys.Count, dst.Handle) != 0)
|
|
737
|
+
{
|
|
738
|
+
throw new Autd3Exception("group failed (every buffer must match the geometry)");
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
public static void GroupCompute<TKey>(Geometry geometry, TransducerGroups<TKey> groups, Action<TKey, TransducerMask, PatternBuffer> compute, PatternBuffer dst) where TKey : struct
|
|
743
|
+
{
|
|
744
|
+
if (compute == null)
|
|
745
|
+
{
|
|
746
|
+
throw new ArgumentNullException(nameof(compute));
|
|
747
|
+
}
|
|
748
|
+
if (groups.Indices.Length != geometry.NumTransducers)
|
|
749
|
+
{
|
|
750
|
+
throw new Autd3Exception("groups must be built from the same geometry");
|
|
751
|
+
}
|
|
752
|
+
if (NativePattern.autd3_pattern_group_null(geometry.Handle, groups.Indices, dst.Handle) != 0)
|
|
753
|
+
{
|
|
754
|
+
throw new Autd3Exception("group_compute failed (dst must match the geometry)");
|
|
755
|
+
}
|
|
756
|
+
using var scratch = geometry.PatternBuffer();
|
|
757
|
+
var keys = groups.Keys;
|
|
758
|
+
for (var i = 0; i < keys.Count; i++)
|
|
759
|
+
{
|
|
760
|
+
SetPhaseAndIntensity(Phase.Zero, Intensity.Max, scratch);
|
|
761
|
+
compute(keys[i], groups.Mask(keys[i]), scratch);
|
|
762
|
+
if (NativePattern.autd3_pattern_group_copy(geometry.Handle, groups.Indices, i, scratch.Handle, dst.Handle) != 0)
|
|
763
|
+
{
|
|
764
|
+
throw new Autd3Exception("group_compute failed (dst must match the geometry)");
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
465
768
|
|
|
466
769
|
private static EmissionNative[] ToNativeDst(Emission[] dst)
|
|
467
770
|
{
|
|
771
|
+
if (dst == null)
|
|
772
|
+
{
|
|
773
|
+
throw new ArgumentNullException(nameof(dst));
|
|
774
|
+
}
|
|
468
775
|
if (dst.Length != Autd3.NumTransducers)
|
|
469
776
|
{
|
|
470
777
|
throw new Autd3Exception($"dst requires {Autd3.NumTransducers} emissions");
|
|
471
778
|
}
|
|
472
|
-
return
|
|
779
|
+
return ToNativeDstAnyLength(dst);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
private static EmissionNative[] ToNativeDstAnyLength(Emission[] dst)
|
|
783
|
+
{
|
|
784
|
+
if (dst == null)
|
|
785
|
+
{
|
|
786
|
+
throw new ArgumentNullException(nameof(dst));
|
|
787
|
+
}
|
|
788
|
+
var native = new EmissionNative[dst.Length];
|
|
789
|
+
for (var i = 0; i < dst.Length; i++)
|
|
790
|
+
{
|
|
791
|
+
native[i] = new EmissionNative { Phase = dst[i].Phase.Value, Intensity = dst[i].Intensity.Value };
|
|
792
|
+
}
|
|
793
|
+
return native;
|
|
473
794
|
}
|
|
474
795
|
|
|
475
796
|
private static void FromNativeDst(EmissionNative[] native, Emission[] dst)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/THIRD-PARTY-LICENSES.md
CHANGED
|
@@ -854,9 +854,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
854
854
|
|
|
855
855
|
Used by:
|
|
856
856
|
|
|
857
|
-
- autd3-rs-core 0.
|
|
858
|
-
- autd3-rs-pattern 0.
|
|
859
|
-
- autd3-cpu-wire 0.
|
|
857
|
+
- autd3-rs-core 0.9.0 — https://github.com/shinolab/autd3-sdk
|
|
858
|
+
- autd3-rs-pattern 0.9.0 — https://github.com/shinolab/autd3-sdk
|
|
859
|
+
- autd3-cpu-wire 0.9.0 — https://github.com/shinolab/autd3-sdk
|
|
860
860
|
|
|
861
861
|
```
|
|
862
862
|
MIT License
|
|
@@ -887,8 +887,8 @@ SOFTWARE.
|
|
|
887
887
|
|
|
888
888
|
Used by:
|
|
889
889
|
|
|
890
|
-
- autd3-ffi-abi 0.
|
|
891
|
-
- autd3-ffi-pattern 0.
|
|
890
|
+
- autd3-ffi-abi 0.9.0 — https://github.com/shinolab/autd3-sdk
|
|
891
|
+
- autd3-ffi-pattern 0.9.0 — https://github.com/shinolab/autd3-sdk
|
|
892
892
|
- chrono 0.4.45 — https://github.com/chronotope/chrono
|
|
893
893
|
- wide 1.5.0 — https://github.com/Lokathor/wide
|
|
894
894
|
- winapi-i686-pc-windows-gnu 0.4.0 — https://github.com/retep998/winapi-rs
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "git+https://github.com/shinolab/autd3-sdk.git",
|
|
6
6
|
"directory": "bindings/unity/com.shinolab.autd3-sdk.pattern"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.9.0",
|
|
9
9
|
"displayName": "AUTD3 Pattern",
|
|
10
10
|
"description": "AUTD3 emission patterns: Focus, Plane, Bessel (Unity binding).",
|
|
11
11
|
"unity": "6000.0",
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
"url": "https://github.com/shinolab"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"com.shinolab.autd3-sdk.core": "0.
|
|
18
|
+
"com.shinolab.autd3-sdk.core": "0.9.0"
|
|
19
19
|
}
|
|
20
20
|
}
|