AutoEFCalcResult.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. using AI.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Runtime.Serialization;
  5. using System.Text;
  6. namespace AutoEFInferenceCalcLib
  7. {
  8. /// <summary>
  9. /// 单个心动周期相关信息
  10. /// </summary>
  11. [DataContract]
  12. public struct CardiacCycleInfos
  13. {
  14. #region field
  15. private double _startTimeStamp;
  16. private double _endTimeStamp;
  17. private double _esTimeStamp;
  18. private double _edTimeStamp;
  19. private float _esVolume;
  20. private float _edVolume;
  21. #endregion
  22. #region public
  23. /// <summary>
  24. /// 心动周期开始的时间戳
  25. /// </summary>
  26. public double StartTimeStamp
  27. {
  28. get => _startTimeStamp;
  29. set => _startTimeStamp = value;
  30. }
  31. /// <summary>
  32. /// 心动周期结束的时间戳
  33. /// </summary>
  34. public double EndTimeStamp
  35. {
  36. get => _endTimeStamp;
  37. set => _endTimeStamp = value;
  38. }
  39. /// <summary>
  40. /// ES帧的时间戳
  41. /// </summary>
  42. public double ESTimeStamp
  43. {
  44. get => _esTimeStamp;
  45. set => _esTimeStamp = value;
  46. }
  47. /// <summary>
  48. /// ED帧的时间戳
  49. /// </summary>
  50. public double EDTimeStamp
  51. {
  52. get => _edTimeStamp;
  53. set => _edTimeStamp = value;
  54. }
  55. /// <summary>
  56. /// 当前心动周期内,收缩末期的左心室容积
  57. /// </summary>
  58. public float ESVolume
  59. {
  60. get => _esVolume;
  61. set => _esVolume = value;
  62. }
  63. /// <summary>
  64. /// 当前心动周期内,舒张末期的左心室容积
  65. /// </summary>
  66. public float EDVolume
  67. {
  68. get => _edVolume;
  69. set => _edVolume = value;
  70. }
  71. /// <summary>
  72. /// 空
  73. /// </summary>
  74. public static readonly CardiacCycleInfos Empty = new CardiacCycleInfos();
  75. /// <summary>
  76. /// 判断是否相等
  77. /// </summary>
  78. /// <param name="other"></param>
  79. /// <returns></returns>
  80. public bool Equals(CardiacCycleInfos other)
  81. {
  82. return Equals(this, other);
  83. }
  84. /// <summary>
  85. /// 判断是否相等
  86. /// </summary>
  87. /// <param name="obj"></param>
  88. /// <returns></returns>
  89. public override bool Equals(object obj)
  90. {
  91. if (obj == null || !(obj is CardiacCycleInfos))
  92. {
  93. return false;
  94. }
  95. CardiacCycleInfos info = (CardiacCycleInfos)obj;
  96. return Equals(this, info);
  97. }
  98. /// <summary>
  99. /// 判断是否相等
  100. /// </summary>
  101. /// <param name="one"></param>
  102. /// <param name="other"></param>
  103. /// <returns></returns>
  104. public static bool Equals(CardiacCycleInfos one, CardiacCycleInfos other)
  105. {
  106. return one.StartTimeStamp == other.StartTimeStamp && one.EndTimeStamp == other.EndTimeStamp &&
  107. one.ESTimeStamp == other.ESTimeStamp && one.EDTimeStamp == other.EDTimeStamp &&
  108. one.ESVolume == other.ESVolume && one.EDVolume == other.EDVolume;
  109. }
  110. /// <summary>
  111. /// 判断是否相等
  112. /// </summary>
  113. /// <param name="one"></param>
  114. /// <param name="other"></param>
  115. /// <returns></returns>
  116. public static bool operator ==(CardiacCycleInfos one, CardiacCycleInfos other)
  117. {
  118. return Equals(one, other);
  119. }
  120. /// <summary>
  121. /// 判断是否相等
  122. /// </summary>
  123. /// <param name="one"></param>
  124. /// <param name="other"></param>
  125. /// <returns></returns>
  126. public static bool operator !=(CardiacCycleInfos one, CardiacCycleInfos other)
  127. {
  128. return !Equals(one, other);
  129. }
  130. /// <summary>
  131. /// 构造函数
  132. /// </summary>
  133. /// <param name="startTimeStamp"></param>
  134. /// <param name="endTimeStamp"></param>
  135. /// <param name="esTimeStamp"></param>
  136. /// <param name="edTimeStamp"></param>
  137. /// <param name="esVolume"></param>
  138. /// <param name="edVolume"></param>
  139. public CardiacCycleInfos(double startTimeStamp, double endTimeStamp, double esTimeStamp, double edTimeStamp,
  140. float esVolume, float edVolume)
  141. {
  142. _startTimeStamp = startTimeStamp;
  143. _endTimeStamp = endTimeStamp;
  144. _esTimeStamp = esTimeStamp;
  145. _edTimeStamp = edTimeStamp;
  146. _esVolume = esVolume;
  147. _edVolume = edVolume;
  148. }
  149. #endregion
  150. }
  151. /// <summary>
  152. /// 左心室容积测量的关键点
  153. /// </summary>
  154. public struct LVVolumeMeasureMarks
  155. {
  156. #region field
  157. private Point2D _apexPoint;
  158. private Point2D[] _endPoints;
  159. private Point2D[] _slicePoints;
  160. private Point2D[] _controlPoints;
  161. #endregion
  162. #region public
  163. /// <summary>
  164. /// 左心室内轮廓心尖点,只有一个
  165. /// </summary>
  166. public Point2D ApexPoint
  167. {
  168. get => _apexPoint;
  169. set => _apexPoint = value;
  170. }
  171. /// <summary>
  172. /// 左心室内轮廓末端点,有两个
  173. /// </summary>
  174. public Point2D[] EndPoints
  175. {
  176. get => _endPoints;
  177. set => _endPoints = value;
  178. }
  179. /// <summary>
  180. /// 左心室内轮廓切片点
  181. /// </summary>
  182. public Point2D[] SlicePoint
  183. {
  184. get => _slicePoints;
  185. set => _slicePoints = value;
  186. }
  187. /// <summary>
  188. /// 左心室内轮廓控制点
  189. /// </summary>
  190. public Point2D[] ControlPoints
  191. {
  192. get => _controlPoints;
  193. set => _controlPoints = value;
  194. }
  195. /// <summary>
  196. /// 构造函数
  197. /// </summary>
  198. /// <param name="apexPoint"></param>
  199. /// <param name="endPoints"></param>
  200. /// <param name="slicePoints"></param>
  201. /// <param name="controlPoints"></param>
  202. public LVVolumeMeasureMarks(Point2D apexPoint, Point2D[] endPoints,
  203. Point2D[] slicePoints, Point2D[] controlPoints)
  204. {
  205. _apexPoint = apexPoint;
  206. _endPoints = endPoints;
  207. _slicePoints = slicePoints;
  208. _controlPoints = controlPoints;
  209. }
  210. public static readonly LVVolumeMeasureMarks Empty = new LVVolumeMeasureMarks();
  211. /// <summary>
  212. /// 判断是否相等
  213. /// </summary>
  214. /// <param name="other"></param>
  215. /// <returns></returns>
  216. public bool Equals(LVVolumeMeasureMarks other)
  217. {
  218. return Equals(this, other);
  219. }
  220. public override bool Equals(object obj)
  221. {
  222. if (obj == null || !(obj is LVVolumeMeasureMarks))
  223. {
  224. return false;
  225. }
  226. LVVolumeMeasureMarks measureMarks = (LVVolumeMeasureMarks)obj;
  227. return Equals(this, measureMarks);
  228. }
  229. public static bool Equals(LVVolumeMeasureMarks one, LVVolumeMeasureMarks other)
  230. {
  231. if (one.ApexPoint != other.ApexPoint)
  232. {
  233. return false;
  234. }
  235. if (one.EndPoints != null && other.EndPoints == null || one.EndPoints == null && other.EndPoints != null ||
  236. one.SlicePoint != null && other.SlicePoint == null || one.SlicePoint == null && other.SlicePoint != null
  237. || one.ControlPoints != null && one.ControlPoints == null || one.ControlPoints == null && other.ControlPoints != null)
  238. {
  239. return false;
  240. }
  241. if (one.EndPoints.Length != other.EndPoints.Length || one.SlicePoint.Length != other.EndPoints.Length ||
  242. one.ControlPoints.Length != other.ControlPoints.Length)
  243. {
  244. return false;
  245. }
  246. for (int i = 0; i < one.EndPoints.Length; i++)
  247. {
  248. if (one.EndPoints[i] != other.EndPoints[i])
  249. {
  250. return false;
  251. }
  252. }
  253. for (int i = 0; i < one.SlicePoint.Length; i++)
  254. {
  255. if (one.SlicePoint[i] != other.SlicePoint[i])
  256. {
  257. return false;
  258. }
  259. }
  260. for (int i = 0; i < other.ControlPoints.Length; i++)
  261. {
  262. if (one.ControlPoints[i] != other.ControlPoints[i])
  263. {
  264. return false;
  265. }
  266. }
  267. return true;
  268. }
  269. public static bool operator ==(LVVolumeMeasureMarks one, LVVolumeMeasureMarks other)
  270. {
  271. return Equals(one, other);
  272. }
  273. public static bool operator !=(LVVolumeMeasureMarks one, LVVolumeMeasureMarks other)
  274. {
  275. return !Equals(one, other);
  276. }
  277. #endregion
  278. }
  279. /// <summary>
  280. /// 单帧图像上的推理结果
  281. /// </summary>
  282. public struct LVVolumeCalcResult
  283. {
  284. #region field
  285. private Point2D[] _contour;
  286. private double _volume;
  287. private float _score;
  288. private LVVolumeMeasureMarks _measureMarks;
  289. #endregion
  290. #region public
  291. /// <summary>
  292. /// 左心室内轮廓原始点
  293. /// </summary>
  294. public Point2D[] Contour
  295. {
  296. get => _contour;
  297. set => _contour = value;
  298. }
  299. /// <summary>
  300. /// 左心室的容积值
  301. /// </summary>
  302. public double Volume
  303. {
  304. get => _volume;
  305. set => _volume = value;
  306. }
  307. /// <summary>
  308. /// 心肌分割的得分
  309. /// </summary>
  310. public float Score
  311. {
  312. get => _score;
  313. set => _score = value;
  314. }
  315. /// <summary>
  316. /// 左心室容积测量的关键点
  317. /// </summary>
  318. public LVVolumeMeasureMarks MeasureMarks
  319. {
  320. get => _measureMarks;
  321. set => _measureMarks = value;
  322. }
  323. /// <summary>
  324. /// 构造函数
  325. /// </summary>
  326. /// <param name="contour"></param>
  327. /// <param name="Volume"></param>
  328. /// <param name="score"></param>
  329. /// <param name="measureMarks"></param>
  330. public LVVolumeCalcResult(Point2D[] contour, double Volume, float score,
  331. LVVolumeMeasureMarks measureMarks)
  332. {
  333. _contour = contour;
  334. _volume = Volume;
  335. _score = score;
  336. _measureMarks = measureMarks;
  337. }
  338. /// <summary>
  339. /// 空
  340. /// </summary>
  341. public static readonly LVVolumeCalcResult Empty = new LVVolumeCalcResult(new Point2D[0], 0, 0,
  342. new LVVolumeMeasureMarks(new Point2D(0, 0), new Point2D[0], new Point2D[0], new Point2D[0]));
  343. public bool Equals(LVVolumeCalcResult other)
  344. {
  345. return Equals(this, other);
  346. }
  347. public override bool Equals(object obj)
  348. {
  349. if (obj == null || !(obj is LVVolumeCalcResult))
  350. {
  351. return false;
  352. }
  353. LVVolumeCalcResult calcResult = (LVVolumeCalcResult)obj;
  354. return Equals(this, calcResult);
  355. }
  356. public static bool Equals(LVVolumeCalcResult one, LVVolumeCalcResult other)
  357. {
  358. if (one.Volume != other.Volume)
  359. {
  360. return false;
  361. }
  362. if (one.Score != other.Score)
  363. {
  364. return false;
  365. }
  366. if (one.Contour == null && other.Contour != null || one.Contour != null && other.Contour == null)
  367. {
  368. return false;
  369. }
  370. if (one.Contour.Length != other.Contour.Length)
  371. {
  372. return false;
  373. }
  374. if (one.MeasureMarks != other.MeasureMarks)
  375. {
  376. return false;
  377. }
  378. for (int i = 0; i < one.Contour.Length; i++)
  379. {
  380. if (one.Contour[i] != other.Contour[i])
  381. {
  382. return false;
  383. }
  384. }
  385. return true;
  386. }
  387. public static bool operator ==(LVVolumeCalcResult one, LVVolumeCalcResult other)
  388. {
  389. return Equals(one, other);
  390. }
  391. public static bool operator !=(LVVolumeCalcResult one, LVVolumeCalcResult other)
  392. {
  393. return !Equals(one, other);
  394. }
  395. #endregion
  396. }
  397. [DataContract]
  398. [KnownType(typeof(CardiacCurveInfos))]
  399. public class CardiacCurveInfos
  400. {
  401. #region field
  402. private Dictionary<double, LVVolumeCalcResult> _resultsPerImage;
  403. private int _bestCycleIndex;
  404. private CardiacCycleInfos[] _cardiacCycles;
  405. #endregion
  406. #region properties
  407. /// <summary>
  408. /// 每张图对应的左心室容积的计算结果
  409. /// </summary>
  410. [DataMember]
  411. public Dictionary<double, LVVolumeCalcResult> ResultPerImage
  412. {
  413. get => _resultsPerImage;
  414. set => _resultsPerImage = value;
  415. }
  416. /// <summary>
  417. /// 最好周期的Index
  418. /// </summary>
  419. [DataMember]
  420. public int BestCycleIndex
  421. {
  422. get => _bestCycleIndex;
  423. set => _bestCycleIndex = value;
  424. }
  425. /// <summary>
  426. /// 心动周期的信息
  427. /// </summary>
  428. [DataMember]
  429. public CardiacCycleInfos[] CardiacCycles
  430. {
  431. get => _cardiacCycles;
  432. set => _cardiacCycles = value;
  433. }
  434. /// <summary>
  435. /// 构造函数
  436. /// </summary>
  437. public CardiacCurveInfos()
  438. {
  439. _resultsPerImage = new Dictionary<double, LVVolumeCalcResult>();
  440. _bestCycleIndex = 0;
  441. _cardiacCycles = Array.Empty<CardiacCycleInfos>();
  442. }
  443. /// <summary>
  444. /// 构造函数
  445. /// </summary>
  446. /// <param name="resultsPerImage"></param>
  447. /// <param name="bestCycleIndex"></param>
  448. /// <param name="cardiacCycles"></param>
  449. public CardiacCurveInfos(Dictionary<double, LVVolumeCalcResult> resultsPerImage, int bestCycleIndex,
  450. CardiacCycleInfos[] cardiacCycles)
  451. {
  452. _resultsPerImage = resultsPerImage;
  453. _bestCycleIndex = bestCycleIndex;
  454. _cardiacCycles = cardiacCycles;
  455. }
  456. /// <summary>
  457. /// 空
  458. /// </summary>
  459. public static readonly CardiacCurveInfos Empty = new CardiacCurveInfos();
  460. #endregion
  461. }
  462. }