AIConvertHelper.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using AutoDFRCalculationLib;
  2. using Vinno.AI.AutoDFRDiagnosisSDK.Enums;
  3. using Vinno.AI.AutoDFRDiagnosisSDK.Models;
  4. using Vinno.AI.CommonSDK.Models;
  5. using Vinno.AI.Service.Common.Tools;
  6. namespace Vinno.AI.AutoDFRDiagnosisService.Tools
  7. {
  8. internal static class AIConvertHelper
  9. {
  10. internal static AIAutoDFRCalcResult ConvertAutoDFRCalcResultToAIAutoDFRCalcResult(AutoDFRCalcResult autoDFRCalcResult)
  11. {
  12. if (autoDFRCalcResult == null)
  13. {
  14. return null;
  15. }
  16. var measureMarks = ConvertDFRMeasurementsToAIDFRMeasurements(autoDFRCalcResult.Measurements);
  17. AIDFRRecognizedObjectInfo[] recognizedObjects;
  18. if (autoDFRCalcResult.recognizedObjectInfos == null)
  19. {
  20. recognizedObjects = null;
  21. }
  22. else
  23. {
  24. var recognizedObjectsLength = autoDFRCalcResult.recognizedObjectInfos.Length;
  25. recognizedObjects = new AIDFRRecognizedObjectInfo[recognizedObjectsLength];
  26. for (int i = 0; i < recognizedObjectsLength; i++)
  27. {
  28. recognizedObjects[i] = ConvertDFRRecognizedObjectInfoToAIDFRRecognizedObjectInfo(autoDFRCalcResult.recognizedObjectInfos[i]);
  29. }
  30. }
  31. return new AIAutoDFRCalcResult(measureMarks, recognizedObjects);
  32. }
  33. private static AIDFRMeasurements ConvertDFRMeasurementsToAIDFRMeasurements(DFRMeasurements measurements)
  34. {
  35. if (measurements == null)
  36. {
  37. return null;
  38. }
  39. var diaphragmPoint = ConvertMeasureMarksToAIMeasureMarks(measurements.DiaphragmPoint);
  40. var sideFlapPoint = ConvertMeasureMarksToAIMeasureMarks(measurements.SideFlapPoint);
  41. var mitralValveClosurePoint = ConvertMeasureMarksToAIMeasureMarks(measurements.MitralValveClosurePoint);
  42. return new AIDFRMeasurements(diaphragmPoint, sideFlapPoint, mitralValveClosurePoint);
  43. }
  44. private static AIMeasureMarks ConvertMeasureMarksToAIMeasureMarks(MeasureMarks measureMarks)
  45. {
  46. if (measureMarks == null)
  47. {
  48. return null;
  49. }
  50. var measureMarkPoint = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(measureMarks.MeasureMarkPoint);
  51. var score = measureMarks.MeasureMarkScore;
  52. return new AIMeasureMarks(measureMarkPoint, score);
  53. }
  54. private static AIDFRRecognizedObjectInfo ConvertDFRRecognizedObjectInfoToAIDFRRecognizedObjectInfo(DFRRecognizedObjectInfo recognizedObjectInfo)
  55. {
  56. if (recognizedObjectInfo == null)
  57. {
  58. return null;
  59. }
  60. var type = (AIEnumDFRRecognizedObjectType)recognizedObjectInfo.Type;
  61. var confidence = recognizedObjectInfo.Confidence;
  62. AIPoint2D[] contour;
  63. if (recognizedObjectInfo.Contour == null)
  64. {
  65. contour = null;
  66. }
  67. else
  68. {
  69. var contourLength = recognizedObjectInfo.Contour.Length;
  70. contour = new AIPoint2D[contourLength];
  71. for (int i = 0; i < contourLength; i++)
  72. {
  73. contour[i] = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(recognizedObjectInfo.Contour[i]);
  74. }
  75. }
  76. return new AIDFRRecognizedObjectInfo(type, confidence, contour);
  77. }
  78. }
  79. }