AIConvertHelper.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using AI.Common;
  2. using AutoEFCalculationLib;
  3. using Vinno.AI.AutoEFDiagnosisSDK.Enums;
  4. using Vinno.AI.AutoEFDiagnosisSDK.Models;
  5. using Vinno.AI.CommonSDK.Models;
  6. using Vinno.AI.Service.Common.Tools;
  7. namespace Vinno.AI.AutoEFDiagnosisService.Tools
  8. {
  9. internal static class AIConvertHelper
  10. {
  11. internal static AILVVolumeCalcResult ConvertLVVolumeCalcResultToAILVVolumeCalcResult(LVVolumeCalcResult lvVolumeCalcResult)
  12. {
  13. AIPoint2D[] contours;
  14. if (lvVolumeCalcResult.Contours == null)
  15. {
  16. contours = null;
  17. }
  18. else
  19. {
  20. var contoursLength = lvVolumeCalcResult.Contours.Length;
  21. contours = new AIPoint2D[lvVolumeCalcResult.Contours.Length];
  22. for (int i = 0; i < contoursLength; i++)
  23. {
  24. contours[i] = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(lvVolumeCalcResult.Contours[i]);
  25. }
  26. }
  27. var measureMarks = ConvertLVVolumeMeasureMarksToAILVVolumeMeasureMarks(lvVolumeCalcResult.MeasureMarks);
  28. var aiImageSize = ConvertImgSizeToAIImgSize(lvVolumeCalcResult.OrImgSize);
  29. return new AILVVolumeCalcResult(contours, lvVolumeCalcResult.Volume, lvVolumeCalcResult.Score, measureMarks, aiImageSize);
  30. }
  31. private static AIImgSize ConvertImgSizeToAIImgSize(ImgSize orImgSize)
  32. {
  33. return new AIImgSize(orImgSize.ImgWidth, orImgSize.ImgHeight);
  34. }
  35. private static AILVVolumeMeasureMarks ConvertLVVolumeMeasureMarksToAILVVolumeMeasureMarks(LVVolumeMeasureMarks measureMarks)
  36. {
  37. var apexPoint = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(measureMarks.ApexPoint);
  38. AIPoint2D[] endPoints;
  39. if (measureMarks.EndPoints == null)
  40. {
  41. endPoints = null;
  42. }
  43. else
  44. {
  45. var endPointsLength = measureMarks.EndPoints.Length;
  46. endPoints = new AIPoint2D[endPointsLength];
  47. for (int i = 0; i < endPointsLength; i++)
  48. {
  49. endPoints[i] = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(measureMarks.EndPoints[i]);
  50. }
  51. }
  52. AIPoint2D[] slicePoints;
  53. if (measureMarks.SlicePoints == null)
  54. {
  55. slicePoints = null;
  56. }
  57. else
  58. {
  59. var slicePointsLength = measureMarks.SlicePoints.Length;
  60. slicePoints = new AIPoint2D[slicePointsLength];
  61. for (int i = 0; i < slicePointsLength; i++)
  62. {
  63. slicePoints[i] = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(measureMarks.SlicePoints[i]);
  64. }
  65. }
  66. AIPoint2D[] controlPoints;
  67. if (measureMarks.ControlPoints == null)
  68. {
  69. controlPoints = null;
  70. }
  71. else
  72. {
  73. var controlPointsLength = measureMarks.ControlPoints.Length;
  74. controlPoints = new AIPoint2D[controlPointsLength];
  75. for (int i = 0; i < controlPointsLength; i++)
  76. {
  77. controlPoints[i] = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(measureMarks.ControlPoints[i]);
  78. }
  79. }
  80. return new AILVVolumeMeasureMarks(apexPoint, endPoints, slicePoints, controlPoints);
  81. }
  82. internal static AIEDESDetectResult ConvertEDESDetectResultToAIEDESDetectResult(EDESDetectResult edESDetectResult)
  83. {
  84. var aiLVVolume = ConvertLVVolumeCalcResultToAILVVolumeCalcResult(edESDetectResult.LVVolume);
  85. return new AIEDESDetectResult((AIEnumFrameType)edESDetectResult.FrameType, aiLVVolume);
  86. }
  87. internal static LVVolumeCalcResult ConvertAILVVolumeCalcResultToLVVolumeCalcResult(AILVVolumeCalcResult aiLVVolumeCalcResult)
  88. {
  89. if (aiLVVolumeCalcResult == null)
  90. {
  91. return default(LVVolumeCalcResult);
  92. }
  93. Point2D[] contours;
  94. if (aiLVVolumeCalcResult.Contours == null)
  95. {
  96. contours = null;
  97. }
  98. else
  99. {
  100. var contoursLength = aiLVVolumeCalcResult.Contours.Length;
  101. contours = new Point2D[aiLVVolumeCalcResult.Contours.Length];
  102. for (int i = 0; i < contoursLength; i++)
  103. {
  104. contours[i] = AICommonServiceConvertHelper.ConvertAIPoint2DToPoint2D(aiLVVolumeCalcResult.Contours[i]);
  105. }
  106. }
  107. var measureMarks = ConvertAILVVolumeMeasureMarksToLVVolumeMeasureMarks(aiLVVolumeCalcResult.MeasureMarks);
  108. var imageSize = ConvertAIImgSizeToImgSize(aiLVVolumeCalcResult.OrImgSize);
  109. return new LVVolumeCalcResult(contours, aiLVVolumeCalcResult.Volume, aiLVVolumeCalcResult.Score, measureMarks, imageSize);
  110. }
  111. private static LVVolumeMeasureMarks ConvertAILVVolumeMeasureMarksToLVVolumeMeasureMarks(AILVVolumeMeasureMarks measureMarks)
  112. {
  113. if (measureMarks == null)
  114. {
  115. return default(LVVolumeMeasureMarks);
  116. }
  117. var apexPoint = AICommonServiceConvertHelper.ConvertAIPoint2DToPoint2D(measureMarks.ApexPoint);
  118. Point2D[] endPoints;
  119. if (measureMarks.EndPoints == null)
  120. {
  121. endPoints = null;
  122. }
  123. else
  124. {
  125. var endPointsLength = measureMarks.EndPoints.Length;
  126. endPoints = new Point2D[endPointsLength];
  127. for (int i = 0; i < endPointsLength; i++)
  128. {
  129. endPoints[i] = AICommonServiceConvertHelper.ConvertAIPoint2DToPoint2D(measureMarks.EndPoints[i]);
  130. }
  131. }
  132. Point2D[] slicePoints;
  133. if (measureMarks.SlicePoints == null)
  134. {
  135. slicePoints = null;
  136. }
  137. else
  138. {
  139. var slicePointsLength = measureMarks.SlicePoints.Length;
  140. slicePoints = new Point2D[slicePointsLength];
  141. for (int i = 0; i < slicePointsLength; i++)
  142. {
  143. slicePoints[i] = AICommonServiceConvertHelper.ConvertAIPoint2DToPoint2D(measureMarks.SlicePoints[i]);
  144. }
  145. }
  146. Point2D[] controlPoints;
  147. if (measureMarks.ControlPoints == null)
  148. {
  149. controlPoints = null;
  150. }
  151. else
  152. {
  153. var controlPointsLength = measureMarks.ControlPoints.Length;
  154. controlPoints = new Point2D[controlPointsLength];
  155. for (int i = 0; i < controlPointsLength; i++)
  156. {
  157. controlPoints[i] = AICommonServiceConvertHelper.ConvertAIPoint2DToPoint2D(measureMarks.ControlPoints[i]);
  158. }
  159. }
  160. return new LVVolumeMeasureMarks(apexPoint, endPoints, slicePoints, controlPoints);
  161. }
  162. private static ImgSize ConvertAIImgSizeToImgSize(AIImgSize orImgSize)
  163. {
  164. if (orImgSize == null)
  165. {
  166. return default(ImgSize);
  167. }
  168. return new ImgSize(orImgSize.ImgWidth, orImgSize.ImgHeight);
  169. }
  170. }
  171. }