VinnoPhysicalCoordinate.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. using System;
  2. using System.IO;
  3. namespace fis.Vid.Visuals
  4. {
  5. public enum PhysicalCoordinateType
  6. {
  7. Tissue = 0,
  8. TimeMotion,
  9. ConvexTissue,
  10. LinearTissue,
  11. ConvexTVTissue,
  12. LinearTVTissue,
  13. Doppler,
  14. TissueTimeMotion,
  15. MAM,
  16. PWV
  17. }
  18. public abstract class VinnoPhysicalCoordinate
  19. {
  20. public PhysicalCoordinateType Type { get; protected set; }
  21. public virtual byte[] ToBytes()
  22. {
  23. byte[] result;
  24. using (var stream = new MemoryStream())
  25. {
  26. var writer = new VinnoStreamWriter(stream);
  27. writer.WriteByte((byte)Type);
  28. result = stream.ToArray();
  29. }
  30. return result;
  31. }
  32. public static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  33. {
  34. VinnoPhysicalCoordinate physicalCoordinate = null;
  35. using (var stream = new MemoryStream(bytes))
  36. {
  37. stream.Position = 0;
  38. var reader = new VinnoStreamReader(stream);
  39. var type = (PhysicalCoordinateType) reader.ReadByte();
  40. switch (type)
  41. {
  42. case PhysicalCoordinateType.ConvexTissue:
  43. physicalCoordinate = VinnoConvexTissuePhysicalCoordinate.FromBytes(bytes);
  44. break;
  45. case PhysicalCoordinateType.LinearTissue:
  46. physicalCoordinate = VinnoLinearTissuePhysicalCoordinate.FromBytes(bytes);
  47. break;
  48. case PhysicalCoordinateType.ConvexTVTissue:
  49. physicalCoordinate = VinnoConvexTVTissuePhysicalCoordinate.FromBytes(bytes);
  50. break;
  51. case PhysicalCoordinateType.LinearTVTissue:
  52. physicalCoordinate = VinnoLinearTVTissuePhysicalCoordinate.FromBytes(bytes);
  53. break;
  54. case PhysicalCoordinateType.Doppler:
  55. physicalCoordinate = VinnoDopplerPhysicalCoordinate.FromBytes(bytes);
  56. break;
  57. case PhysicalCoordinateType.TissueTimeMotion:
  58. physicalCoordinate = VinnoTissueTimeMotionPhysicalCoordinate.FromBytes(bytes);
  59. break;
  60. case PhysicalCoordinateType.MAM:
  61. physicalCoordinate = VinnoMAMPhysicalCoordinate.FromBytes(bytes);
  62. break;
  63. case PhysicalCoordinateType.PWV:
  64. physicalCoordinate = VinnoPWVPhysicalCoordinate.FromBytes(bytes);
  65. break;
  66. }
  67. }
  68. return physicalCoordinate;
  69. }
  70. }
  71. public abstract class VinnoTissuePhysicalCoordinate : VinnoPhysicalCoordinate
  72. {
  73. public double DepthEnd { get; }
  74. public double DepthStart { get; }
  75. public double Width { get; }
  76. public double BeamPosition { get; }
  77. protected VinnoTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition)
  78. {
  79. Type = PhysicalCoordinateType.Tissue;
  80. BeamPosition = beamPosition;
  81. Width = width;
  82. DepthStart = depthStart;
  83. DepthEnd = depthEnd;
  84. }
  85. public override byte[] ToBytes()
  86. {
  87. byte[] result;
  88. using (var stream = new MemoryStream())
  89. {
  90. var baseData = base.ToBytes();
  91. stream.Write(baseData, 0, baseData.Length);
  92. stream.Position = stream.Length;
  93. var writer = new VinnoStreamWriter(stream);
  94. writer.WriteDouble(DepthStart);
  95. writer.WriteDouble(DepthEnd);
  96. writer.WriteDouble(Width);
  97. writer.WriteDouble(BeamPosition);
  98. result = stream.ToArray();
  99. }
  100. return result;
  101. }
  102. }
  103. public abstract class VinnoTimeMotionPhysicalCoordinate : VinnoPhysicalCoordinate
  104. {
  105. public double SweepSpeed { get; }
  106. public double Max { get; }
  107. public double Min { get; }
  108. protected VinnoTimeMotionPhysicalCoordinate(double sweepSpeed, double max, double min)
  109. {
  110. Type = PhysicalCoordinateType.TimeMotion;
  111. Min = min;
  112. Max = max;
  113. SweepSpeed = sweepSpeed;
  114. }
  115. public override byte[] ToBytes()
  116. {
  117. byte[] result;
  118. using (var stream = new MemoryStream())
  119. {
  120. var baseData = base.ToBytes();
  121. stream.Write(baseData, 0, baseData.Length);
  122. stream.Position = stream.Length;
  123. var writer = new VinnoStreamWriter(stream);
  124. writer.WriteDouble(Min);
  125. writer.WriteDouble(Max);
  126. writer.WriteDouble(SweepSpeed);
  127. result = stream.ToArray();
  128. }
  129. return result;
  130. }
  131. }
  132. public class VinnoConvexTissuePhysicalCoordinate : VinnoTissuePhysicalCoordinate
  133. {
  134. public double ZeroRadius { get; private set; }
  135. public VinnoConvexTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius)
  136. : base(depthEnd, depthStart, width, beamPosition)
  137. {
  138. Type = PhysicalCoordinateType.ConvexTissue;
  139. ZeroRadius = zeroRadius;
  140. }
  141. public override byte[] ToBytes()
  142. {
  143. byte[] result;
  144. using (var stream = new MemoryStream())
  145. {
  146. var baseData = base.ToBytes();
  147. stream.Write(baseData, 0, baseData.Length);
  148. stream.Position = stream.Length;
  149. var writer = new VinnoStreamWriter(stream);
  150. writer.WriteDouble(ZeroRadius);
  151. result = stream.ToArray();
  152. }
  153. return result;
  154. }
  155. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  156. {
  157. VinnoPhysicalCoordinate result;
  158. using (var stream = new MemoryStream(bytes))
  159. {
  160. stream.Position = 0;
  161. var reader = new VinnoStreamReader(stream);
  162. var type = (PhysicalCoordinateType)reader.ReadByte();
  163. if (type != PhysicalCoordinateType.ConvexTissue)
  164. {
  165. throw new InvalidCastException( $"Type not matched, target type:{PhysicalCoordinateType.ConvexTissue}, source type:{type}");
  166. }
  167. var depthStart = reader.ReadDouble();
  168. var depthEnd = reader.ReadDouble();
  169. var width = reader.ReadDouble();
  170. var beamPosition = reader.ReadDouble();
  171. var zeroRadius = reader.ReadDouble();
  172. result = new VinnoConvexTissuePhysicalCoordinate(depthEnd,depthStart,width,beamPosition,zeroRadius);
  173. }
  174. return result;
  175. }
  176. }
  177. public class VinnoLinearTissuePhysicalCoordinate : VinnoTissuePhysicalCoordinate
  178. {
  179. public double Steer { get; }
  180. public VinnoLinearTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double steer)
  181. : base(depthEnd, depthStart, width, beamPosition)
  182. {
  183. Type = PhysicalCoordinateType.LinearTissue;
  184. Steer = steer;
  185. }
  186. public override byte[] ToBytes()
  187. {
  188. byte[] result;
  189. using (var stream = new MemoryStream())
  190. {
  191. var baseData = base.ToBytes();
  192. stream.Write(baseData, 0, baseData.Length);
  193. stream.Position = stream.Length;
  194. var writer = new VinnoStreamWriter(stream);
  195. writer.WriteDouble(Steer);
  196. result = stream.ToArray();
  197. }
  198. return result;
  199. }
  200. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  201. {
  202. VinnoPhysicalCoordinate result;
  203. using (var stream = new MemoryStream(bytes))
  204. {
  205. stream.Position = 0;
  206. var reader = new VinnoStreamReader(stream);
  207. var type = (PhysicalCoordinateType)reader.ReadByte();
  208. if (type != PhysicalCoordinateType.LinearTissue)
  209. {
  210. throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.LinearTissue}, source type:{type}");
  211. }
  212. var depthStart = reader.ReadDouble();
  213. var depthEnd = reader.ReadDouble();
  214. var width = reader.ReadDouble();
  215. var beamPosition = reader.ReadDouble();
  216. var steer = reader.ReadDouble();
  217. result = new VinnoLinearTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, steer);
  218. }
  219. return result;
  220. }
  221. }
  222. public class VinnoConvexTVTissuePhysicalCoordinate : VinnoConvexTissuePhysicalCoordinate
  223. {
  224. public double OriginalZeroRadius { get; private set; }
  225. public double OriginalRocx { get; private set; }
  226. public VinnoConvexTVTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius, double originalZeroRadius, double originalRocx)
  227. : base(depthEnd, depthStart, width, beamPosition, zeroRadius)
  228. {
  229. Type = PhysicalCoordinateType.ConvexTVTissue;
  230. OriginalRocx = originalRocx;
  231. OriginalZeroRadius = originalZeroRadius;
  232. }
  233. public override byte[] ToBytes()
  234. {
  235. byte[] result;
  236. using (var stream = new MemoryStream())
  237. {
  238. var baseData = base.ToBytes();
  239. stream.Write(baseData, 0, baseData.Length);
  240. stream.Position = stream.Length;
  241. var writer = new VinnoStreamWriter(stream);
  242. writer.WriteDouble(OriginalZeroRadius);
  243. writer.WriteDouble(OriginalRocx);
  244. result = stream.ToArray();
  245. }
  246. return result;
  247. }
  248. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  249. {
  250. VinnoPhysicalCoordinate result;
  251. using (var stream = new MemoryStream(bytes))
  252. {
  253. stream.Position = 0;
  254. var reader = new VinnoStreamReader(stream);
  255. var type = (PhysicalCoordinateType)reader.ReadByte();
  256. if (type != PhysicalCoordinateType.ConvexTVTissue)
  257. {
  258. throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.ConvexTVTissue}, source type:{type}");
  259. }
  260. var depthStart = reader.ReadDouble();
  261. var depthEnd = reader.ReadDouble();
  262. var width = reader.ReadDouble();
  263. var beamPosition = reader.ReadDouble();
  264. var zeroRadius = reader.ReadDouble();
  265. var originalZeroRadius = reader.ReadDouble();
  266. var originalRocx = reader.ReadDouble();
  267. result = new VinnoConvexTVTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, zeroRadius,originalZeroRadius,originalRocx);
  268. }
  269. return result;
  270. }
  271. }
  272. public class VinnoLinearTVTissuePhysicalCoordinate : VinnoConvexTissuePhysicalCoordinate
  273. {
  274. public VinnoLinearTVTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius)
  275. : base(depthEnd, depthStart, width, beamPosition, zeroRadius)
  276. {
  277. Type = PhysicalCoordinateType.LinearTVTissue;
  278. }
  279. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  280. {
  281. VinnoPhysicalCoordinate result;
  282. using (var stream = new MemoryStream(bytes))
  283. {
  284. stream.Position = 0;
  285. var reader = new VinnoStreamReader(stream);
  286. var type = (PhysicalCoordinateType)reader.ReadByte();
  287. if (type != PhysicalCoordinateType.LinearTVTissue)
  288. {
  289. throw new InvalidCastException( $"Type not matched, target type:{PhysicalCoordinateType.LinearTVTissue}, source type:{type}");
  290. }
  291. var depthStart = reader.ReadDouble();
  292. var depthEnd = reader.ReadDouble();
  293. var width = reader.ReadDouble();
  294. var beamPosition = reader.ReadDouble();
  295. var zeroRadius = reader.ReadDouble();
  296. result = new VinnoLinearTVTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, zeroRadius);
  297. }
  298. return result;
  299. }
  300. }
  301. public class VinnoDopplerPhysicalCoordinate : VinnoTimeMotionPhysicalCoordinate
  302. {
  303. public double BaseLine { get; }
  304. public VinnoDopplerPhysicalCoordinate(double sweepSpeed, double max, double min, double baseLine)
  305. : base(sweepSpeed, max, min)
  306. {
  307. Type = PhysicalCoordinateType.Doppler;
  308. BaseLine = baseLine;
  309. }
  310. public override byte[] ToBytes()
  311. {
  312. byte[] result;
  313. using (var stream = new MemoryStream())
  314. {
  315. var baseData = base.ToBytes();
  316. stream.Write(baseData, 0, baseData.Length);
  317. stream.Position = stream.Length;
  318. var writer = new VinnoStreamWriter(stream);
  319. writer.WriteDouble(BaseLine);
  320. result = stream.ToArray();
  321. }
  322. return result;
  323. }
  324. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  325. {
  326. VinnoPhysicalCoordinate result;
  327. using (var stream = new MemoryStream(bytes))
  328. {
  329. stream.Position = 0;
  330. var reader = new VinnoStreamReader(stream);
  331. var type = (PhysicalCoordinateType)reader.ReadByte();
  332. if (type != PhysicalCoordinateType.Doppler)
  333. {
  334. throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.Doppler}, source type:{type}");
  335. }
  336. var min = reader.ReadDouble();
  337. var max = reader.ReadDouble();
  338. var sweepSpeed = reader.ReadDouble();
  339. var baseLine = reader.ReadDouble();
  340. result = new VinnoDopplerPhysicalCoordinate(sweepSpeed, max, min, baseLine);
  341. }
  342. return result;
  343. }
  344. }
  345. public class VinnoTissueTimeMotionPhysicalCoordinate : VinnoTimeMotionPhysicalCoordinate
  346. {
  347. public double DepthStart { get; }
  348. public double DepthEnd { get; }
  349. public VinnoTissueTimeMotionPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd)
  350. : base(sweepSpeed, max, min)
  351. {
  352. Type = PhysicalCoordinateType.TissueTimeMotion;
  353. DepthEnd = depthEnd;
  354. DepthStart = depthStart;
  355. }
  356. public override byte[] ToBytes()
  357. {
  358. byte[] result;
  359. using (var stream = new MemoryStream())
  360. {
  361. var baseData = base.ToBytes();
  362. stream.Write(baseData, 0, baseData.Length);
  363. stream.Position = stream.Length;
  364. var writer = new VinnoStreamWriter(stream);
  365. writer.WriteDouble(DepthStart);
  366. writer.WriteDouble(DepthEnd);
  367. result = stream.ToArray();
  368. }
  369. return result;
  370. }
  371. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  372. {
  373. VinnoPhysicalCoordinate result;
  374. using (var stream = new MemoryStream(bytes))
  375. {
  376. stream.Position = 0;
  377. var reader = new VinnoStreamReader(stream);
  378. var type = (PhysicalCoordinateType)reader.ReadByte();
  379. if (type != PhysicalCoordinateType.TissueTimeMotion)
  380. {
  381. throw new InvalidCastException( $"Type not matched, target type:{PhysicalCoordinateType.TissueTimeMotion}, source type:{type}");
  382. }
  383. var min = reader.ReadDouble();
  384. var max = reader.ReadDouble();
  385. var sweepSpeed = reader.ReadDouble();
  386. var depthStart = reader.ReadDouble();
  387. var depthEnd = reader.ReadDouble();
  388. result = new VinnoTissueTimeMotionPhysicalCoordinate(sweepSpeed, max, min, depthStart,depthEnd);
  389. }
  390. return result;
  391. }
  392. }
  393. public class VinnoMAMPhysicalCoordinate : VinnoTissueTimeMotionPhysicalCoordinate
  394. {
  395. public VinnoMAMPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd)
  396. : base(sweepSpeed, max, min, depthStart, depthEnd)
  397. {
  398. Type = PhysicalCoordinateType.MAM;
  399. }
  400. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  401. {
  402. VinnoPhysicalCoordinate result;
  403. using (var stream = new MemoryStream(bytes))
  404. {
  405. stream.Position = 0;
  406. var reader = new VinnoStreamReader(stream);
  407. var type = (PhysicalCoordinateType)reader.ReadByte();
  408. if (type != PhysicalCoordinateType.MAM)
  409. {
  410. throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.MAM}, source type:{type}");
  411. }
  412. var min = reader.ReadDouble();
  413. var max = reader.ReadDouble();
  414. var sweepSpeed = reader.ReadDouble();
  415. var depthStart = reader.ReadDouble();
  416. var depthEnd = reader.ReadDouble();
  417. result = new VinnoMAMPhysicalCoordinate(sweepSpeed, max, min, depthStart, depthEnd);
  418. }
  419. return result;
  420. }
  421. }
  422. public class VinnoPWVPhysicalCoordinate : VinnoTissueTimeMotionPhysicalCoordinate
  423. {
  424. public VinnoPWVPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd)
  425. : base(sweepSpeed, max, min, depthStart, depthEnd)
  426. {
  427. Type = PhysicalCoordinateType.PWV;
  428. }
  429. public new static VinnoPhysicalCoordinate FromBytes(byte[] bytes)
  430. {
  431. VinnoPhysicalCoordinate result;
  432. using (var stream = new MemoryStream(bytes))
  433. {
  434. stream.Position = 0;
  435. var reader = new VinnoStreamReader(stream);
  436. var type = (PhysicalCoordinateType)reader.ReadByte();
  437. if (type != PhysicalCoordinateType.PWV)
  438. {
  439. throw new InvalidCastException($"Type not matched, target type:{PhysicalCoordinateType.PWV}, source type:{type}");
  440. }
  441. var min = reader.ReadDouble();
  442. var max = reader.ReadDouble();
  443. var sweepSpeed = reader.ReadDouble();
  444. var depthStart = reader.ReadDouble();
  445. var depthEnd = reader.ReadDouble();
  446. result = new VinnoPWVPhysicalCoordinate(sweepSpeed, max, min, depthStart, depthEnd);
  447. }
  448. return result;
  449. }
  450. }
  451. }