AIConvertHelper.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using Vinno.AI.CommonSDK.Enums;
  3. using Vinno.AI.CommonSDK.Models;
  4. using Vinno.AI.Service.Common.Tools;
  5. using AIDiagResultPerImg = global::AI.DiagSystem.AIDiagResultPerImg;
  6. using AIDiagResultPerOrgan = global::AI.DiagSystem.AIDiagResultPerOrgan;
  7. namespace Vinno.AI.OrganIdentificationService.Tools
  8. {
  9. internal static class AIConvertHelper
  10. {
  11. internal static TransAIDiagResultPerImg ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(AIDiagResultPerImg data)
  12. {
  13. if (data == null)
  14. {
  15. return null;
  16. }
  17. var priorityScore = data.PriorityScore;
  18. TransAIDiagResultPerOrgan[] aiDiagResultPerOrgans;
  19. if (data.DiagResultsForEachOrgan == null)
  20. {
  21. aiDiagResultPerOrgans = null;
  22. }
  23. else
  24. {
  25. aiDiagResultPerOrgans = new TransAIDiagResultPerOrgan[data.DiagResultsForEachOrgan.Length];
  26. for (int cursor = 0; cursor < data.DiagResultsForEachOrgan.Length; cursor++)
  27. {
  28. aiDiagResultPerOrgans[cursor] = ConvertAIDiagResultPerOrganToTransAIDiagResultPerOrgan(data.DiagResultsForEachOrgan[cursor]);
  29. }
  30. }
  31. return new TransAIDiagResultPerImg(aiDiagResultPerOrgans, priorityScore);
  32. }
  33. private static TransAIDiagResultPerOrgan ConvertAIDiagResultPerOrganToTransAIDiagResultPerOrgan(AIDiagResultPerOrgan data)
  34. {
  35. if (data == null)
  36. {
  37. return null;
  38. }
  39. var organ = (AIEnumOrgans)data.Organ;
  40. var organBoundBox = AICommonServiceConvertHelper.ConvertRectToAIRect(data.OrganBoundBox);
  41. AIPoint2D[][] organContours;
  42. if (data.OrganContours == null)
  43. {
  44. organContours = null;
  45. }
  46. else
  47. {
  48. organContours = new AIPoint2D[data.OrganContours.Length][];
  49. for (int cursorX = 0; cursorX < data.OrganContours.Length; cursorX++)
  50. {
  51. organContours[cursorX] = new AIPoint2D[data.OrganContours[cursorX].Length];
  52. for (int cursorY = 0; cursorY < data.OrganContours[cursorX].Length; cursorY++)
  53. {
  54. organContours[cursorX][cursorY] = AICommonServiceConvertHelper.ConvertPoint2DToAIPoint2D(data.OrganContours[cursorX][cursorY]);
  55. }
  56. }
  57. }
  58. List<byte[]> descriptions;
  59. if (data.OrganDescriptions == null)
  60. {
  61. descriptions = null;
  62. }
  63. else
  64. {
  65. descriptions = new List<byte[]>();
  66. for (int cursor = 0; cursor < data.OrganDescriptions.Length; cursor++)
  67. {
  68. var description = AICommonServiceConvertHelper.ConvertDescriptionToTransAIDescription(data.OrganDescriptions[cursor]);
  69. if (description != null)
  70. {
  71. descriptions.Add(description);
  72. }
  73. }
  74. }
  75. TransAIDetectedObject[] detectedObjects;
  76. if (data.DetectedObjects == null)
  77. {
  78. detectedObjects = null;
  79. }
  80. else
  81. {
  82. detectedObjects = new TransAIDetectedObject[data.DetectedObjects.Length];
  83. for (int cursor = 0; cursor < data.DetectedObjects.Length; cursor++)
  84. {
  85. detectedObjects[cursor] = AICommonServiceConvertHelper.ConvertDetectedObjectsToTransAIDetectedObject(data.DetectedObjects[cursor]);
  86. }
  87. }
  88. return new TransAIDiagResultPerOrgan(organ, organBoundBox, organContours, descriptions, detectedObjects);
  89. }
  90. }
  91. }