|
| 1 | +namespace OpenEphys.ProbeInterface; |
| 2 | + |
| 3 | +public class ProbeGroup |
| 4 | +{ |
| 5 | + public string? Specification { get; set; } |
| 6 | + public string? Version { get; set; } |
| 7 | + public Probe[]? Probes { get; set; } |
| 8 | + |
| 9 | + public ProbeGroup() { } |
| 10 | + |
| 11 | + public ProbeGroup(string specification, string version, Probe[] probes) |
| 12 | + { |
| 13 | + Specification = specification; |
| 14 | + Version = version; |
| 15 | + Probes = probes; |
| 16 | + |
| 17 | + ValidateContactIds(); |
| 18 | + ValidateShankIds(); |
| 19 | + ValidateDeviceChannelIndices(); |
| 20 | + } |
| 21 | + |
| 22 | + public ProbeGroup(ProbeGroup probeGroup) |
| 23 | + { |
| 24 | + Specification = probeGroup.Specification; |
| 25 | + Version = probeGroup.Version; |
| 26 | + Probes = probeGroup.Probes; |
| 27 | + } |
| 28 | + |
| 29 | + public int NumContacts |
| 30 | + { |
| 31 | + get |
| 32 | + { |
| 33 | + int numContacts = 0; |
| 34 | + |
| 35 | + foreach (var probe in Probes) |
| 36 | + { |
| 37 | + numContacts += probe.NumContacts; |
| 38 | + } |
| 39 | + |
| 40 | + return numContacts; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public string[] GetContactIds() |
| 45 | + { |
| 46 | + string[] contactIds = new string[NumContacts]; |
| 47 | + |
| 48 | + var length = 0; |
| 49 | + |
| 50 | + foreach (var probe in Probes) |
| 51 | + { |
| 52 | + probe.Contact_Ids.CopyTo(contactIds, length); |
| 53 | + length += probe.NumContacts; |
| 54 | + } |
| 55 | + |
| 56 | + return contactIds; |
| 57 | + } |
| 58 | + |
| 59 | + private void ValidateContactIds() |
| 60 | + { |
| 61 | + int contactNum = 0; |
| 62 | + |
| 63 | + for (int i = 0; i < Probes.Length; i++) |
| 64 | + { |
| 65 | + if (Probes[i].Contact_Ids == null) |
| 66 | + { |
| 67 | + Probes[i].Contact_Ids = new string[Probes[i].Contact_Positions.Length]; |
| 68 | + |
| 69 | + for (int j = 0; j < Probes[i].Contact_Ids.Length; j++) |
| 70 | + { |
| 71 | + Probes[i].Contact_Ids[j] = contactNum.ToString(); |
| 72 | + contactNum++; |
| 73 | + } |
| 74 | + } |
| 75 | + else |
| 76 | + contactNum += Probes[i].Contact_Ids.Length; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + private void ValidateShankIds() |
| 81 | + { |
| 82 | + for (int i = 0; i < Probes.Length; i++) |
| 83 | + { |
| 84 | + if (Probes[i].Shank_Ids == null) |
| 85 | + { |
| 86 | + Probes[i].Shank_Ids = new string[Probes[i].Contact_Positions.Length]; |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + private void ValidateDeviceChannelIndices() |
| 92 | + { |
| 93 | + for (int i = 0; i < Probes.Length; i++) |
| 94 | + { |
| 95 | + if (Probes[i].Device_Channel_Indices == null) |
| 96 | + { |
| 97 | + Probes[i].Device_Channel_Indices = new uint[Probes[i].Contact_Ids.Length]; |
| 98 | + |
| 99 | + for (int j = 0; j < Probes[i].Device_Channel_Indices.Length; j++) |
| 100 | + { |
| 101 | + if (uint.TryParse(Probes[i].Contact_Ids[j], out uint result)) |
| 102 | + { |
| 103 | + Probes[i].Device_Channel_Indices[j] = result; |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +public class Probe |
| 112 | +{ |
| 113 | + public uint? Ndim { get; set; } |
| 114 | + public string? Si_Units { get; set; } |
| 115 | + public ProbeAnnotations? Annotations { get; set; } |
| 116 | + public ContactAnnotations? Contact_Annotations { get; set; } |
| 117 | + public float[][]? Contact_Positions { get; set; } |
| 118 | + public float[][][]? Contact_Plane_Axes { get; set; } |
| 119 | + public string[]? Contact_Shapes { get; set; } |
| 120 | + public ContactShapeParam[]? Contact_Shape_Params { get; set; } |
| 121 | + public float[][]? Probe_Planar_Contour { get; set; } |
| 122 | + public uint[]? Device_Channel_Indices { get; set; } |
| 123 | + public string[]? Contact_Ids { get; set; } |
| 124 | + public string[]? Shank_Ids { get; set; } |
| 125 | + |
| 126 | + public Probe() { } |
| 127 | + |
| 128 | + public Probe(uint ndim, string si_units, ProbeAnnotations annotations, ContactAnnotations contact_annotations, |
| 129 | + float[][] contact_positions, float[][][] contact_plane_axes, string[] contact_shapes, |
| 130 | + ContactShapeParam[] contact_shape_params, float[][] probe_planar_contour, uint[] device_channel_indices, |
| 131 | + string[] contact_ids, string[] shank_ids) |
| 132 | + { |
| 133 | + Ndim = ndim; |
| 134 | + Si_Units = si_units; |
| 135 | + Annotations = annotations; |
| 136 | + Contact_Annotations = contact_annotations; |
| 137 | + Contact_Positions = contact_positions; |
| 138 | + Contact_Plane_Axes = contact_plane_axes; |
| 139 | + Contact_Shapes = contact_shapes; |
| 140 | + Contact_Shape_Params = contact_shape_params; |
| 141 | + Probe_Planar_Contour = probe_planar_contour; |
| 142 | + Device_Channel_Indices = device_channel_indices; |
| 143 | + Contact_Ids = contact_ids; |
| 144 | + Shank_Ids = shank_ids; |
| 145 | + } |
| 146 | + |
| 147 | + /// <summary> |
| 148 | + /// Returns a Contact object that contains the position, shape, shape params, and IDs (device / contact / shank) |
| 149 | + /// for a single contact at the given index |
| 150 | + /// </summary> |
| 151 | + /// <param name="index">Relative index of the contact in this Probe</param> |
| 152 | + /// <returns></returns> |
| 153 | + public Contact GetContact(int index) |
| 154 | + { |
| 155 | + return new Contact(Contact_Positions[index][0], Contact_Positions[index][1], Contact_Shapes[index], Contact_Shape_Params[index], |
| 156 | + Device_Channel_Indices[index], Contact_Ids[index], Shank_Ids[index]); |
| 157 | + } |
| 158 | + |
| 159 | + public int NumContacts => Contact_Ids.Length; |
| 160 | +} |
| 161 | + |
| 162 | +public struct Contact |
| 163 | +{ |
| 164 | + public float PosX { get; set; } |
| 165 | + public float PosY { get; set; } |
| 166 | + public string Shape { get; set; } |
| 167 | + public ContactShapeParam ShapeParams { get; set; } |
| 168 | + public uint DeviceId { get; set; } |
| 169 | + public string ContactId { get; set; } |
| 170 | + public string ShankId { get; set; } |
| 171 | + |
| 172 | + public Contact(float posX, float posY, string shape, ContactShapeParam shapeParam, uint device_id, string contact_id, string shank_id) |
| 173 | + { |
| 174 | + PosX = posX; |
| 175 | + PosY = posY; |
| 176 | + Shape = shape; |
| 177 | + ShapeParams = shapeParam; |
| 178 | + DeviceId = device_id; |
| 179 | + ContactId = contact_id; |
| 180 | + ShankId = shank_id; |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +public struct ContactShapeParam |
| 185 | +{ |
| 186 | + public float Radius { get; set; } |
| 187 | + |
| 188 | + public ContactShapeParam() |
| 189 | + { |
| 190 | + Radius = float.NaN; |
| 191 | + } |
| 192 | + |
| 193 | + public ContactShapeParam(float radius) |
| 194 | + { |
| 195 | + Radius = radius; |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +public struct ProbeAnnotations |
| 200 | +{ |
| 201 | + public string Name { get; set; } |
| 202 | + public string Manufacturer { get; set; } |
| 203 | + |
| 204 | + public ProbeAnnotations() |
| 205 | + { |
| 206 | + Name = string.Empty; |
| 207 | + Manufacturer = string.Empty; |
| 208 | + } |
| 209 | + |
| 210 | + public ProbeAnnotations(string name, string manufacturer) |
| 211 | + { |
| 212 | + Name = name; |
| 213 | + Manufacturer = manufacturer; |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +public struct ContactAnnotations |
| 218 | +{ |
| 219 | + public string[] Contact_Annotations { get; set; } |
| 220 | + |
| 221 | + public ContactAnnotations() |
| 222 | + { |
| 223 | + Contact_Annotations = new string[0]; |
| 224 | + } |
| 225 | + |
| 226 | + public ContactAnnotations(string[] contact_annotations) |
| 227 | + { |
| 228 | + Contact_Annotations = contact_annotations; |
| 229 | + } |
| 230 | +} |
0 commit comments