com.shinolab.autd3-sdk.pattern 0.8.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,106 +7,126 @@ using System.Runtime.InteropServices;
7
7
 
8
8
  namespace AUTD3
9
9
  {
10
- [StructLayout(LayoutKind.Sequential)]
11
- internal struct PatternOptionNative
12
- {
13
- public byte Intensity;
14
- public byte PhaseOffset;
15
- }
16
-
17
- public readonly struct FocusOption
10
+ public readonly struct LaguerreGaussianOption
18
11
  {
19
- public Intensity Intensity { get; }
20
- public Phase PhaseOffset { get; }
12
+ public uint P { get; }
13
+ public int L { get; }
14
+ public Length Waist { get; }
21
15
 
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
  }
25
-
26
- public FocusOption(Intensity? intensity = null, Phase? phaseOffset = null)
27
- {
28
- Intensity = intensity ?? Intensity.Max;
29
- PhaseOffset = phaseOffset ?? Phase.Zero;
30
- }
31
-
32
- internal PatternOptionNative ToNative() =>
33
- new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
34
22
  }
35
23
 
36
- public readonly struct PlaneOption
24
+ public readonly struct HermiteGaussianOption
37
25
  {
38
- public Intensity Intensity { get; }
39
- public Phase PhaseOffset { get; }
40
-
41
- public PlaneOption() : this(intensity: null)
42
- {
43
- }
26
+ public uint M { get; }
27
+ public uint N { get; }
28
+ public Length Waist { get; }
44
29
 
45
- public PlaneOption(Intensity? intensity = null, Phase? phaseOffset = null)
30
+ public HermiteGaussianOption(uint m, uint n, Length waist)
46
31
  {
47
- Intensity = intensity ?? Intensity.Max;
48
- PhaseOffset = phaseOffset ?? Phase.Zero;
32
+ M = m;
33
+ N = n;
34
+ Waist = waist;
49
35
  }
50
-
51
- internal PatternOptionNative ToNative() =>
52
- new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
53
36
  }
54
37
 
55
- public readonly struct BesselOption
38
+ public readonly struct TransducerMask
56
39
  {
57
- public Intensity Intensity { get; }
58
- public Phase PhaseOffset { get; }
40
+ internal bool[][]? Mask { get; }
59
41
 
60
- public BesselOption() : this(intensity: null)
42
+ private TransducerMask(bool[][]? mask)
61
43
  {
44
+ Mask = mask;
62
45
  }
63
46
 
64
- public BesselOption(Intensity? intensity = null, Phase? phaseOffset = null)
65
- {
66
- Intensity = intensity ?? Intensity.Max;
67
- PhaseOffset = phaseOffset ?? Phase.Zero;
68
- }
47
+ public static TransducerMask AllEnabled => new TransducerMask(null);
69
48
 
70
- internal PatternOptionNative ToNative() =>
71
- new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
49
+ public static TransducerMask Masked(bool[][] mask) => new TransducerMask(mask);
72
50
  }
73
51
 
74
- public readonly struct TwinTrapOption
52
+ public sealed class TransducerGroups<TKey> where TKey : struct
75
53
  {
76
- public Intensity Intensity { get; }
77
- public Phase PhaseOffset { get; }
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>();
78
57
 
79
- public TwinTrapOption() : this(intensity: null)
80
- {
81
- }
82
-
83
- public TwinTrapOption(Intensity? intensity = null, Phase? phaseOffset = null)
84
- {
85
- Intensity = intensity ?? Intensity.Max;
86
- PhaseOffset = phaseOffset ?? Phase.Zero;
87
- }
58
+ internal int[] Indices { get; }
88
59
 
89
- internal PatternOptionNative ToNative() =>
90
- new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
91
- }
60
+ public IReadOnlyList<TKey> Keys => _keys;
92
61
 
93
- public readonly struct VortexOption
94
- {
95
- public Intensity Intensity { get; }
96
- public Phase PhaseOffset { get; }
62
+ public int NumDevices => _numTransducers.Length;
97
63
 
98
- public VortexOption() : this(intensity: null)
64
+ public TransducerGroups(Geometry geometry, Func<Device, int, TKey?> key)
99
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
+ }
100
91
  }
101
92
 
102
- public VortexOption(Intensity? intensity = null, Phase? phaseOffset = null)
93
+ public TKey? Key(int device, int transducer)
103
94
  {
104
- Intensity = intensity ?? Intensity.Max;
105
- PhaseOffset = phaseOffset ?? Phase.Zero;
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];
106
110
  }
107
111
 
108
- internal PatternOptionNative ToNative() =>
109
- new PatternOptionNative { Intensity = Intensity.Value, PhaseOffset = PhaseOffset.Value };
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
+ }
110
130
  }
111
131
 
112
132
  [StructLayout(LayoutKind.Sequential)]
@@ -159,55 +179,94 @@ namespace AUTD3
159
179
  internal static extern void autd3_pattern_buffer_free(IntPtr buffer);
160
180
 
161
181
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
162
- internal static extern int autd3_pattern_focus(GeometryHandle geometry, float[] target, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
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);
186
+
187
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
188
+ internal static extern int autd3_pattern_focus_transducer(float[] position, float[] target, float wavelengthMm, out byte @out);
189
+
190
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
191
+ internal static extern int autd3_pattern_plane(GeometryHandle geometry, float[] dir, float wavelengthMm, PatternBufferHandle buffer);
192
+
193
+ [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
194
+ internal static extern int autd3_pattern_plane_device(GeometryHandle geometry, UIntPtr dev, float[] dir, float wavelengthMm, [In, Out] EmissionNative[] dst);
163
195
 
164
196
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
165
- internal static extern int autd3_pattern_focus_device(GeometryHandle geometry, UIntPtr dev, float[] target, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
197
+ internal static extern int autd3_pattern_plane_transducer(float[] position, float[] dir, float wavelengthMm, out byte @out);
166
198
 
167
199
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
168
- internal static extern int autd3_pattern_focus_transducer(float[] position, float[] target, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
200
+ internal static extern int autd3_pattern_bessel(GeometryHandle geometry, float[] apex, float[] dir, float thetaRad, float wavelengthMm, PatternBufferHandle buffer);
169
201
 
170
202
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
171
- internal static extern int autd3_pattern_plane(GeometryHandle geometry, float[] dir, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
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);
172
204
 
173
205
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
174
- internal static extern int autd3_pattern_plane_device(GeometryHandle geometry, UIntPtr dev, float[] dir, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
206
+ internal static extern int autd3_pattern_bessel_transducer(float[] position, float[] apex, float[] dir, float thetaRad, float wavelengthMm, out byte @out);
175
207
 
176
208
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
177
- internal static extern int autd3_pattern_plane_transducer(float[] position, float[] dir, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
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);
178
210
 
179
211
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
180
- internal static extern int autd3_pattern_bessel(GeometryHandle geometry, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
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);
181
213
 
182
214
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
183
- internal static extern int autd3_pattern_bessel_device(GeometryHandle geometry, UIntPtr dev, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
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);
184
216
 
185
217
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
186
- internal static extern int autd3_pattern_bessel_transducer(float[] position, float[] apex, float[] dir, float thetaRad, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
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);
187
219
 
188
220
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
189
- internal static extern int autd3_pattern_twin_trap(GeometryHandle geometry, float[] target, float[] normal, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
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);
190
222
 
191
223
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
192
- internal static extern int autd3_pattern_twin_trap_device(GeometryHandle geometry, UIntPtr dev, float[] target, float[] normal, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
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);
193
225
 
194
226
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
195
- internal static extern int autd3_pattern_twin_trap_transducer(float[] position, float[] target, float[] normal, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
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);
196
228
 
197
229
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
198
- internal static extern int autd3_pattern_vortex(GeometryHandle geometry, float[] target, float[] axis, int order, float wavelengthMm, in PatternOptionNative option, PatternBufferHandle buffer);
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);
199
231
 
200
232
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
201
- internal static extern int autd3_pattern_vortex_device(GeometryHandle geometry, UIntPtr dev, float[] target, float[] axis, int order, float wavelengthMm, in PatternOptionNative option, [Out] EmissionNative[] dst);
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);
202
234
 
203
235
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
204
- internal static extern int autd3_pattern_vortex_transducer(float[] position, float[] target, float[] axis, int order, float wavelengthMm, in PatternOptionNative option, out EmissionNative @out);
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);
205
237
 
206
238
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
207
- internal static extern int autd3_pattern_uniform(byte phase, byte intensity, PatternBufferHandle buffer);
239
+ internal static extern int autd3_pattern_set_intensity(byte intensity, PatternBufferHandle buffer);
208
240
 
209
241
  [DllImport(Lib, CallingConvention = CallingConvention.Cdecl)]
210
- internal static extern void autd3_pattern_null(PatternBufferHandle buffer);
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);
211
270
 
212
271
 
213
272
  [DllImport(ClientLib, CallingConvention = CallingConvention.Cdecl)]
@@ -383,221 +442,355 @@ namespace AUTD3
383
442
  new Length(NativePattern.autd3_pattern_wavelength(soundSpeed.MmS));
384
443
 
385
444
 
386
- public static void Focus(Geometry geometry, Vector3 target, Length wavelength, FocusOption option, PatternBuffer dst)
445
+ public static void Focus(Geometry geometry, Vector3 target, Length wavelength, PatternBuffer dst)
387
446
  {
388
- var t = Coords.PointArray(target);
389
- var o = option.ToNative();
390
- 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)
391
448
  {
392
449
  throw new Autd3Exception("focus failed (buffer device count must match geometry)");
393
450
  }
394
451
  }
395
452
 
396
- public static void Focus(Geometry geometry, Vector3 target, Length wavelength, Intensity intensity, PatternBuffer dst) =>
397
- Focus(geometry, target, wavelength, new FocusOption(intensity), dst);
398
-
399
- 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)
400
454
  {
401
455
  var native = ToNativeDst(dst);
402
- var o = option.ToNative();
403
456
  if (NativePattern.autd3_pattern_focus_device(device.GeometryHandle, device.DeviceIndex,
404
- Coords.PointArray(target), wavelength.Mm, in o, native) != 0)
457
+ Coords.PointArray(target), wavelength.Mm, native) != 0)
405
458
  {
406
459
  throw new Autd3Exception("focus_device failed");
407
460
  }
408
461
  FromNativeDst(native, dst);
409
462
  }
410
463
 
411
- public static Emission FocusTransducer(Vector3 position, Vector3 target, Length wavelength, FocusOption option)
464
+ public static Phase FocusTransducer(Vector3 position, Vector3 target, Length wavelength)
412
465
  {
413
- var o = option.ToNative();
414
466
  if (NativePattern.autd3_pattern_focus_transducer(
415
467
  Coords.PointArray(position),
416
- Coords.PointArray(target), wavelength.Mm, in o, out var e) != 0)
468
+ Coords.PointArray(target), wavelength.Mm, out var p) != 0)
417
469
  {
418
470
  throw new Autd3Exception("focus_transducer failed");
419
471
  }
420
- return new Emission(new Phase(e.Phase), new Intensity(e.Intensity));
472
+ return new Phase(p);
421
473
  }
422
474
 
423
- public static void Plane(Geometry geometry, Vector3 dir, Length wavelength, PlaneOption option, PatternBuffer dst)
475
+ public static void Plane(Geometry geometry, Vector3 dir, Length wavelength, PatternBuffer dst)
424
476
  {
425
- var d = Coords.DirArray(dir);
426
- var o = option.ToNative();
427
- 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)
428
478
  {
429
479
  throw new Autd3Exception("plane failed (buffer device count must match geometry)");
430
480
  }
431
481
  }
432
482
 
433
- public static void PlaneDevice(Device device, Vector3 dir, Length wavelength, PlaneOption option, Emission[] dst)
483
+ public static void PlaneDevice(Device device, Vector3 dir, Length wavelength, Emission[] dst)
434
484
  {
435
485
  var native = ToNativeDst(dst);
436
- var o = option.ToNative();
437
486
  if (NativePattern.autd3_pattern_plane_device(device.GeometryHandle, device.DeviceIndex,
438
- Coords.DirArray(dir), wavelength.Mm, in o, native) != 0)
487
+ Coords.DirArray(dir), wavelength.Mm, native) != 0)
439
488
  {
440
489
  throw new Autd3Exception("plane_device failed");
441
490
  }
442
491
  FromNativeDst(native, dst);
443
492
  }
444
493
 
445
- public static Emission PlaneTransducer(Vector3 position, Vector3 dir, Length wavelength, PlaneOption option)
494
+ public static Phase PlaneTransducer(Vector3 position, Vector3 dir, Length wavelength)
446
495
  {
447
- var o = option.ToNative();
448
496
  if (NativePattern.autd3_pattern_plane_transducer(
449
497
  Coords.PointArray(position),
450
- Coords.DirArray(dir), wavelength.Mm, in o, out var e) != 0)
498
+ Coords.DirArray(dir), wavelength.Mm, out var p) != 0)
451
499
  {
452
500
  throw new Autd3Exception("plane_transducer failed");
453
501
  }
454
- return new Emission(new Phase(e.Phase), new Intensity(e.Intensity));
502
+ return new Phase(p);
455
503
  }
456
504
 
457
- public static void Bessel(Geometry geometry, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, BesselOption option, PatternBuffer dst)
505
+ public static void Bessel(Geometry geometry, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, PatternBuffer dst)
458
506
  {
459
- var a = Coords.PointArray(apex);
460
- var d = Coords.DirArray(dir);
461
- var o = option.ToNative();
462
- 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)
463
508
  {
464
509
  throw new Autd3Exception("bessel failed (buffer device count must match geometry)");
465
510
  }
466
511
  }
467
512
 
468
- public static void BesselDevice(Device device, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, BesselOption option, Emission[] dst)
513
+ public static void BesselDevice(Device device, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, Emission[] dst)
469
514
  {
470
515
  var native = ToNativeDst(dst);
471
- var o = option.ToNative();
472
516
  if (NativePattern.autd3_pattern_bessel_device(device.GeometryHandle, device.DeviceIndex,
473
517
  Coords.PointArray(apex),
474
- Coords.DirArray(dir), theta.Rad, wavelength.Mm, in o, native) != 0)
518
+ Coords.DirArray(dir), theta.Rad, wavelength.Mm, native) != 0)
475
519
  {
476
520
  throw new Autd3Exception("bessel_device failed");
477
521
  }
478
522
  FromNativeDst(native, dst);
479
523
  }
480
524
 
481
- public static Emission BesselTransducer(Vector3 position, Vector3 apex, Vector3 dir, Angle theta, Length wavelength, BesselOption option)
525
+ public static Phase BesselTransducer(Vector3 position, Vector3 apex, Vector3 dir, Angle theta, Length wavelength)
482
526
  {
483
- var o = option.ToNative();
484
527
  if (NativePattern.autd3_pattern_bessel_transducer(
485
528
  Coords.PointArray(position),
486
529
  Coords.PointArray(apex),
487
- Coords.DirArray(dir), theta.Rad, wavelength.Mm, in o, out var e) != 0)
530
+ Coords.DirArray(dir), theta.Rad, wavelength.Mm, out var p) != 0)
488
531
  {
489
532
  throw new Autd3Exception("bessel_transducer failed");
490
533
  }
491
- return new Emission(new Phase(e.Phase), new Intensity(e.Intensity));
534
+ return new Phase(p);
492
535
  }
493
536
 
494
- public static void TwinTrap(Geometry geometry, Vector3 target, Vector3 normal, Length wavelength, TwinTrapOption option, PatternBuffer dst)
537
+ public static void LaguerreGaussianPhase(Geometry geometry, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, PatternBuffer dst)
495
538
  {
496
- var t = Coords.PointArray(target);
497
- var n = Coords.DirArray(normal);
498
- var o = option.ToNative();
499
- if (NativePattern.autd3_pattern_twin_trap(geometry.Handle, t, n, wavelength.Mm, in o, dst.Handle) != 0)
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)
500
541
  {
501
- throw new Autd3Exception("twin_trap failed (buffer device count must match geometry)");
542
+ throw new Autd3Exception("laguerre_gaussian_phase failed (waist must be positive and buffer device count must match geometry)");
502
543
  }
503
544
  }
504
545
 
505
- public static void TwinTrapDevice(Device device, Vector3 target, Vector3 normal, Length wavelength, TwinTrapOption option, Emission[] dst)
546
+ public static void LaguerreGaussianPhaseDevice(Device device, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, Emission[] dst)
506
547
  {
507
548
  var native = ToNativeDst(dst);
508
- var o = option.ToNative();
509
- if (NativePattern.autd3_pattern_twin_trap_device(device.GeometryHandle, device.DeviceIndex,
510
- Coords.PointArray(target), Coords.DirArray(normal), wavelength.Mm, in o, native) != 0)
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)
511
551
  {
512
- throw new Autd3Exception("twin_trap_device failed");
552
+ throw new Autd3Exception("laguerre_gaussian_phase_device failed (waist must be positive)");
513
553
  }
514
554
  FromNativeDst(native, dst);
515
555
  }
516
556
 
517
- public static Emission TwinTrapTransducer(Vector3 position, Vector3 target, Vector3 normal, Length wavelength, TwinTrapOption option)
557
+ public static Phase LaguerreGaussianPhaseTransducer(Vector3 position, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength)
518
558
  {
519
- var o = option.ToNative();
520
- if (NativePattern.autd3_pattern_twin_trap_transducer(
559
+ if (NativePattern.autd3_pattern_laguerre_gaussian_phase_transducer(
521
560
  Coords.PointArray(position),
522
561
  Coords.PointArray(target),
523
- Coords.DirArray(normal), wavelength.Mm, in o, out var e) != 0)
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);
567
+ }
568
+
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
+ }
577
+
578
+ public static void LaguerreGaussianIntensityDevice(Device device, Vector3 target, Vector3 axis, LaguerreGaussianOption option, Length wavelength, Emission[] dst)
579
+ {
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)
524
583
  {
525
- throw new Autd3Exception("twin_trap_transducer failed");
584
+ throw new Autd3Exception("laguerre_gaussian_intensity_device failed (waist must be positive)");
526
585
  }
527
- return new Emission(new Phase(e.Phase), new Intensity(e.Intensity));
586
+ FromNativeDst(native, dst);
528
587
  }
529
588
 
530
- public static void Vortex(Geometry geometry, Vector3 target, Vector3 axis, int order, Length wavelength, VortexOption option, PatternBuffer dst)
589
+ public static void HermiteGaussianPhase(Geometry geometry, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, PatternBuffer dst)
531
590
  {
532
- var t = Coords.PointArray(target);
533
- var a = Coords.DirArray(axis);
534
- var o = option.ToNative();
535
- if (NativePattern.autd3_pattern_vortex(geometry.Handle, t, a, order, wavelength.Mm, in o, dst.Handle) != 0)
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)
536
593
  {
537
- throw new Autd3Exception("vortex failed (buffer device count must match geometry)");
594
+ throw new Autd3Exception("hermite_gaussian_phase failed (waist must be positive and buffer device count must match geometry)");
538
595
  }
539
596
  }
540
597
 
541
- public static void VortexDevice(Device device, Vector3 target, Vector3 axis, int order, Length wavelength, VortexOption option, Emission[] dst)
598
+ public static void HermiteGaussianPhaseDevice(Device device, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, Emission[] dst)
542
599
  {
543
600
  var native = ToNativeDst(dst);
544
- var o = option.ToNative();
545
- if (NativePattern.autd3_pattern_vortex_device(device.GeometryHandle, device.DeviceIndex,
546
- Coords.PointArray(target), Coords.DirArray(axis), order, wavelength.Mm, in o, native) != 0)
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)
547
603
  {
548
- throw new Autd3Exception("vortex_device failed");
604
+ throw new Autd3Exception("hermite_gaussian_phase_device failed (waist must be positive)");
549
605
  }
550
606
  FromNativeDst(native, dst);
551
607
  }
552
608
 
553
- public static Emission VortexTransducer(Vector3 position, Vector3 target, Vector3 axis, int order, Length wavelength, VortexOption option)
609
+ public static Phase HermiteGaussianPhaseTransducer(Vector3 position, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength)
554
610
  {
555
- var o = option.ToNative();
556
- if (NativePattern.autd3_pattern_vortex_transducer(
611
+ if (NativePattern.autd3_pattern_hermite_gaussian_phase_transducer(
557
612
  Coords.PointArray(position),
558
613
  Coords.PointArray(target),
559
- Coords.DirArray(axis), order, wavelength.Mm, in o, out var e) != 0)
614
+ Coords.DirArray(axis),
615
+ Coords.DirArray(xDir), option.M, option.N, option.Waist.Mm, wavelength.Mm, out var p) != 0)
560
616
  {
561
- throw new Autd3Exception("vortex_transducer failed");
617
+ throw new Autd3Exception("hermite_gaussian_phase_transducer failed (waist must be positive)");
562
618
  }
563
- return new Emission(new Phase(e.Phase), new Intensity(e.Intensity));
619
+ return new Phase(p);
564
620
  }
565
621
 
566
- public static void Uniform(Emission emission, PatternBuffer dst)
622
+ public static void HermiteGaussianIntensity(Geometry geometry, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, PatternBuffer dst)
567
623
  {
568
- if (NativePattern.autd3_pattern_uniform(emission.Phase.Value, emission.Intensity.Value, dst.Handle) != 0)
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)
569
626
  {
570
- throw new Autd3Exception("uniform failed");
627
+ throw new Autd3Exception("hermite_gaussian_intensity failed (waist must be positive and buffer device count must match geometry)");
571
628
  }
572
629
  }
573
630
 
574
- public static void UniformDevice(Emission emission, Emission[] dst)
631
+ public static void HermiteGaussianIntensityDevice(Device device, Vector3 target, Vector3 axis, Vector3 xDir, HermiteGaussianOption option, Length wavelength, Emission[] dst)
575
632
  {
576
- for (var i = 0; i < dst.Length; i++)
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)
577
636
  {
578
- dst[i] = emission;
637
+ throw new Autd3Exception("hermite_gaussian_intensity_device failed (waist must be positive)");
579
638
  }
639
+ FromNativeDst(native, dst);
580
640
  }
581
641
 
582
- public static void Null(PatternBuffer dst) => NativePattern.autd3_pattern_null(dst.Handle);
642
+ public static void SetIntensity(Intensity intensity, PatternBuffer dst)
643
+ {
644
+ if (NativePattern.autd3_pattern_set_intensity(intensity.Value, dst.Handle) != 0)
645
+ {
646
+ throw new Autd3Exception("set_intensity failed");
647
+ }
648
+ }
583
649
 
584
- public static void NullDevice(Emission[] dst)
650
+ public static void SetIntensityDevice(Intensity intensity, Emission[] dst)
585
651
  {
586
- for (var i = 0; i < dst.Length; i++)
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)
587
690
  {
588
- dst[i] = Emission.Null;
691
+ throw new Autd3Exception("set_phase_and_intensity_device failed");
589
692
  }
693
+ FromNativeDst(native, dst);
590
694
  }
591
695
 
592
- public static void NullTransducer(ref Emission dst) => dst = Emission.Null;
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
+ }
593
768
 
594
769
  private static EmissionNative[] ToNativeDst(Emission[] dst)
595
770
  {
771
+ if (dst == null)
772
+ {
773
+ throw new ArgumentNullException(nameof(dst));
774
+ }
596
775
  if (dst.Length != Autd3.NumTransducers)
597
776
  {
598
777
  throw new Autd3Exception($"dst requires {Autd3.NumTransducers} emissions");
599
778
  }
600
- return new EmissionNative[dst.Length];
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;
601
794
  }
602
795
 
603
796
  private static void FromNativeDst(EmissionNative[] native, Emission[] dst)
Binary file
@@ -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.8.0 — https://github.com/shinolab/autd3-sdk
858
- - autd3-rs-pattern 0.8.0 — https://github.com/shinolab/autd3-sdk
859
- - autd3-cpu-wire 0.6.0 — https://github.com/shinolab/autd3-sdk
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.8.0 — https://github.com/shinolab/autd3-sdk
891
- - autd3-ffi-pattern 0.8.0 — https://github.com/shinolab/autd3-sdk
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.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.8.0"
18
+ "com.shinolab.autd3-sdk.core": "0.9.0"
19
19
  }
20
20
  }