AIDiagnosisService.cs 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  1. using AI.Common;
  2. using AI.Common.Log;
  3. using AI.DiagSystem;
  4. using AIDiagnosis.Common.Enums;
  5. using AIDiagnosis.Common.Models;
  6. using AIDiagnosisSDK.Enums;
  7. using System;
  8. using System.Collections.Concurrent;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Threading;
  13. using Vinno.AI.AIDiagnosisSDK.Interfaces;
  14. using Vinno.AI.AIDiagnosisSDK.Models;
  15. using Vinno.AI.AIDiagnosisService.Tools;
  16. using Vinno.AI.CommonSDK.Enums;
  17. using Vinno.AI.CommonSDK.Models;
  18. using Vinno.AI.CommonSDK.Tools;
  19. using Vinno.AI.Service.Common.Interfaces;
  20. using Vinno.AI.Service.Common.Models;
  21. using Vinno.AI.Service.Common.Tools;
  22. namespace Vinno.AI.AIDiagnosisService
  23. {
  24. public class AIDiagnosisService : IAIDiagnosisService, IDisposable, IEngine
  25. {
  26. private readonly string _modelFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
  27. private readonly ConcurrentStack<byte[]> _singleImageCacheForAbdomen;
  28. private readonly ConcurrentStack<byte[]> _singleImageCacheForBreast;
  29. private readonly ConcurrentStack<byte[]> _singleImageCacheForThyroid;
  30. private readonly ConcurrentStack<byte[]> _singleImageCacheForCarotid;
  31. private PipeServer _singleImagePipeServerForAbdomen;
  32. private PipeServer _singleImagePipeServerForBreast;
  33. private PipeServer _singleImagePipeServerForThyroid;
  34. private PipeServer _singleImagePipeServerForCarotid;
  35. private ImageProvider _imageProviderForAbdomen;
  36. private ImageProvider _imageProviderForBreast;
  37. private ImageProvider _imageProviderForThyroid;
  38. private ImageProvider _imageProviderForCarotid;
  39. private AIDiagnosisParameter _abdomenDiagnosisParameter;
  40. private AIDiagnosisParameter _breastDiagnosisParameter;
  41. private AIDiagnosisParameter _thyroidDiagnosisParameter;
  42. private AIDiagnosisParameter _carotidDiagnosisParameter;
  43. private global::AIDiagnosisSDK.AIDiagnosis _aiDiagnosis;
  44. private bool _disposed;
  45. public static List<FunctionInfo> AllFunctions { get; }
  46. static AIDiagnosisService()
  47. {
  48. AllFunctions = global::AIDiagnosisSDK.AIDiagnosis.AllFunctions.Where(x => x.FunctionName != EnumAIDiagnosisFunction.OrganIdentification.ToString()).ToList();
  49. }
  50. public static void Init(List<FunctionInfo> enableFunctions, List<FunctionInfo> currentUsedFunctions)
  51. {
  52. global::AIDiagnosisSDK.AIDiagnosis.InitForAIDiagnosis(enableFunctions, currentUsedFunctions);
  53. }
  54. public AIDiagnosisService()
  55. {
  56. try
  57. {
  58. _singleImageCacheForAbdomen = new ConcurrentStack<byte[]>();
  59. _singleImagePipeServerForAbdomen = new PipeServer(AIDiagnosisSystemConsts.PipeForAbdomenDiagnosisSingleImage);
  60. _singleImagePipeServerForAbdomen.LogMsgThrow += OnLogMsgThrow;
  61. _singleImagePipeServerForAbdomen.DataReceived += OnDataReceived;
  62. _singleImagePipeServerForAbdomen.StartAndReceive();
  63. _imageProviderForAbdomen = new ImageProvider(AIEnumType.AbdomenDiagnosis);
  64. _singleImageCacheForBreast = new ConcurrentStack<byte[]>();
  65. _singleImagePipeServerForBreast = new PipeServer(AIDiagnosisSystemConsts.PipeForBreastDiagnosisSingleImage);
  66. _singleImagePipeServerForBreast.LogMsgThrow += OnLogMsgThrow;
  67. _singleImagePipeServerForBreast.DataReceived += OnDataReceived;
  68. _singleImagePipeServerForBreast.StartAndReceive();
  69. _imageProviderForBreast = new ImageProvider(AIEnumType.BreastDiagnosis);
  70. _singleImageCacheForThyroid = new ConcurrentStack<byte[]>();
  71. _singleImagePipeServerForThyroid = new PipeServer(AIDiagnosisSystemConsts.PipeForThyroidDiagnosisSingleImage);
  72. _singleImagePipeServerForThyroid.LogMsgThrow += OnLogMsgThrow;
  73. _singleImagePipeServerForThyroid.DataReceived += OnDataReceived;
  74. _singleImagePipeServerForThyroid.StartAndReceive();
  75. _imageProviderForThyroid = new ImageProvider(AIEnumType.ThyroidDiagnosis);
  76. _singleImageCacheForCarotid = new ConcurrentStack<byte[]>();
  77. _singleImagePipeServerForCarotid = new PipeServer(AIDiagnosisSystemConsts.PipeForCarotidDiagnosisSingleImage);
  78. _singleImagePipeServerForCarotid.LogMsgThrow += OnLogMsgThrow;
  79. _singleImagePipeServerForCarotid.DataReceived += OnDataReceived;
  80. _singleImagePipeServerForCarotid.StartAndReceive();
  81. _imageProviderForCarotid = new ImageProvider(AIEnumType.CarotidDiagnosis);
  82. }
  83. catch (Exception ex)
  84. {
  85. Logger.Error($"AIDiagnosisService-Constructor error:{ex}");
  86. }
  87. }
  88. /// <summary>
  89. /// 切换引擎
  90. /// </summary>
  91. /// <param name="functionInfo"></param>
  92. public void SwitchEngines(FunctionInfo functionInfo)
  93. {
  94. try
  95. {
  96. global::AIDiagnosisSDK.AIDiagnosis.SwitchAIEngines(functionInfo);
  97. if (_aiDiagnosis != null)
  98. {
  99. _aiDiagnosis.SwitchAIEngines2(functionInfo);
  100. }
  101. }
  102. catch (Exception ex)
  103. {
  104. Logger.Error($"AIDiagnosisService-SwitchEngines error:{ex}");
  105. }
  106. }
  107. private void OnDataReceived(object sender, byte[] e)
  108. {
  109. try
  110. {
  111. var pipeServer = (PipeServer)sender;
  112. switch (pipeServer.PipeName)
  113. {
  114. case AIDiagnosisSystemConsts.PipeForAbdomenDiagnosisSingleImage:
  115. _singleImageCacheForAbdomen.Push(e);
  116. break;
  117. case AIDiagnosisSystemConsts.PipeForBreastDiagnosisSingleImage:
  118. _singleImageCacheForBreast.Push(e);
  119. break;
  120. case AIDiagnosisSystemConsts.PipeForThyroidDiagnosisSingleImage:
  121. _singleImageCacheForThyroid.Push(e);
  122. break;
  123. case AIDiagnosisSystemConsts.PipeForCarotidDiagnosisSingleImage:
  124. _singleImageCacheForCarotid.Push(e);
  125. break;
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. Logger.Error($"AIDiagnosisService-OnDataReceived error:{ex}");
  131. }
  132. }
  133. private void OnLogMsgThrow(object sender, AILogEventArgs e)
  134. {
  135. if (e == null)
  136. {
  137. return;
  138. }
  139. switch (e.LogType)
  140. {
  141. case AIEnumLogType.ErrorLog:
  142. case AIEnumLogType.FatalLog:
  143. Logger.Error(e.Msg);
  144. break;
  145. case AIEnumLogType.WarnLog:
  146. Logger.Warning(e.Msg);
  147. break;
  148. case AIEnumLogType.InfoLog:
  149. default:
  150. Logger.Info(e.Msg);
  151. break;
  152. }
  153. }
  154. public void InitializeAbdomenDiagnosis(AIDiagnosisParameter abdomenDiagnosisParameter, bool hasImageProvider)
  155. {
  156. try
  157. {
  158. _abdomenDiagnosisParameter = abdomenDiagnosisParameter;
  159. CloseDiagnosis();
  160. var performance = (EnumPerformance)abdomenDiagnosisParameter.Performance;
  161. var detectMode = (EnumDetectMode)abdomenDiagnosisParameter.DetectMode;
  162. var isCropped = abdomenDiagnosisParameter.IsCropped;
  163. var detectTps = abdomenDiagnosisParameter.DetectTps;
  164. var intervalTime = abdomenDiagnosisParameter.IntervalTime;
  165. var enableLesionSeg = abdomenDiagnosisParameter.EnableLesionSeg;
  166. var enableLesionDescription = abdomenDiagnosisParameter.EnableLesionDescription;
  167. var enableOrganDescription = abdomenDiagnosisParameter.EnableOrganDescription;
  168. _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Abdomen, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForAbdomen : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLesionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
  169. _aiDiagnosis.StartEvaluation += OnStartEvaluation;
  170. _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
  171. _aiDiagnosis.NotifyError += OnNotifyError;
  172. _aiDiagnosis.NotifyLog += OnNotifyLog;
  173. }
  174. catch (Exception ex)
  175. {
  176. Logger.Error($"AIDiagnosisService-InitializeAbdomenDiagnosis error:{ex}");
  177. }
  178. }
  179. public void InitializeBreastDiagnosis(AIDiagnosisParameter breastDiagnosisParameter, bool hasImageProvider)
  180. {
  181. try
  182. {
  183. _breastDiagnosisParameter = breastDiagnosisParameter;
  184. CloseDiagnosis();
  185. var performance = (EnumPerformance)breastDiagnosisParameter.Performance;
  186. var detectMode = (EnumDetectMode)breastDiagnosisParameter.DetectMode;
  187. var isCropped = breastDiagnosisParameter.IsCropped;
  188. var detectTps = breastDiagnosisParameter.DetectTps;
  189. var intervalTime = breastDiagnosisParameter.IntervalTime;
  190. var enableLesionSeg = breastDiagnosisParameter.EnableLesionSeg;
  191. var enableLessionDescription = breastDiagnosisParameter.EnableLesionDescription;
  192. var enableOrganDescription = breastDiagnosisParameter.EnableOrganDescription;
  193. _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Breast, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForBreast : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLessionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
  194. _aiDiagnosis.StartEvaluation += OnStartEvaluation;
  195. _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
  196. _aiDiagnosis.NotifyError += OnNotifyError;
  197. _aiDiagnosis.NotifyLog += OnNotifyLog;
  198. }
  199. catch (Exception ex)
  200. {
  201. Logger.Error($"AIDiagnosisService-InitializeBreastDiagnosis error:{ex}");
  202. }
  203. }
  204. public void InitializeThyroidDiagnosis(AIDiagnosisParameter thyroidDiagnosisParameter, bool hasImageProvider)
  205. {
  206. try
  207. {
  208. _thyroidDiagnosisParameter = thyroidDiagnosisParameter;
  209. CloseDiagnosis();
  210. var performance = (EnumPerformance)thyroidDiagnosisParameter.Performance;
  211. var detectMode = (EnumDetectMode)thyroidDiagnosisParameter.DetectMode;
  212. var isCropped = thyroidDiagnosisParameter.IsCropped;
  213. var detectTps = thyroidDiagnosisParameter.DetectTps;
  214. var intervalTime = thyroidDiagnosisParameter.IntervalTime;
  215. var enableLesionSeg = thyroidDiagnosisParameter.EnableLesionSeg;
  216. var enableLessionDescription = thyroidDiagnosisParameter.EnableLesionDescription;
  217. var enableOrganDescription = thyroidDiagnosisParameter.EnableOrganDescription;
  218. _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Thyroid, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForThyroid : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLessionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
  219. _aiDiagnosis.StartEvaluation += OnStartEvaluation;
  220. _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
  221. _aiDiagnosis.NotifyError += OnNotifyError;
  222. _aiDiagnosis.NotifyLog += OnNotifyLog;
  223. }
  224. catch (Exception ex)
  225. {
  226. Logger.Error($"AIDiagnosisService-InitializeBreastDiagnosis error:{ex}");
  227. }
  228. }
  229. public void InitializeCarotidDiagnosis(AIDiagnosisParameter carotidDiagnosisParameter, bool hasImageProvider)
  230. {
  231. try
  232. {
  233. _carotidDiagnosisParameter = carotidDiagnosisParameter;
  234. CloseDiagnosis();
  235. var performance = (EnumPerformance)carotidDiagnosisParameter.Performance;
  236. var detectMode = (EnumDetectMode)carotidDiagnosisParameter.DetectMode;
  237. var isCropped = carotidDiagnosisParameter.IsCropped;
  238. var detectTps = carotidDiagnosisParameter.DetectTps;
  239. var intervalTime = carotidDiagnosisParameter.IntervalTime;
  240. var enableLesionSeg = carotidDiagnosisParameter.EnableLesionSeg;
  241. var enableLessionDescription = carotidDiagnosisParameter.EnableLesionDescription;
  242. var enableOrganDescription = carotidDiagnosisParameter.EnableOrganDescription;
  243. _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Carotid, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForCarotid : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLessionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
  244. _aiDiagnosis.StartEvaluation += OnStartEvaluation;
  245. _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
  246. _aiDiagnosis.NotifyError += OnNotifyError;
  247. _aiDiagnosis.NotifyLog += OnNotifyLog;
  248. }
  249. catch (Exception ex)
  250. {
  251. Logger.Error($"AIDiagnosisService-InitializeCarotidDiagnosis error:{ex}");
  252. }
  253. }
  254. public void Start()
  255. {
  256. try
  257. {
  258. if (_aiDiagnosis != null)
  259. {
  260. _aiDiagnosis.Start();
  261. }
  262. }
  263. catch (Exception ex)
  264. {
  265. Logger.Error($"AIDiagnosisService-Start error:{ex}");
  266. }
  267. }
  268. public void Stop()
  269. {
  270. try
  271. {
  272. if (_aiDiagnosis != null)
  273. {
  274. _aiDiagnosis.Stop();
  275. }
  276. }
  277. catch (Exception ex)
  278. {
  279. Logger.Error($"AIDiagnosisService-Stop error:{ex}");
  280. }
  281. }
  282. private void OnStartEvaluation(object sender, EventArgs e)
  283. {
  284. var aiDiagnosis = (global::AIDiagnosisSDK.AIDiagnosis)sender;
  285. switch (aiDiagnosis.AIModule)
  286. {
  287. case EnumAIModule.Breast:
  288. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.BreastDiagnosisStartEvaluationRaised, Params = e });
  289. break;
  290. case EnumAIModule.Abdomen:
  291. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AbdomenDiagnosisStartEvaluationRaised, Params = e });
  292. break;
  293. case EnumAIModule.Thyroid:
  294. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.ThyroidDiagnosisStartEvaluationRaised, Params = e });
  295. break;
  296. case EnumAIModule.Carotid:
  297. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.CarotidDiagnosisStartEvaluationRaised, Params = e });
  298. break;
  299. }
  300. }
  301. private void OnFinishEvaluation(object sender, global::AI.DiagSystem.AIDiagResultPerImg e)
  302. {
  303. var aiDiagnosis = (global::AIDiagnosisSDK.AIDiagnosis)sender;
  304. var transAIDiagresultPerImg = AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(e);
  305. switch (aiDiagnosis.AIModule)
  306. {
  307. case EnumAIModule.Breast:
  308. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.BreastDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
  309. break;
  310. case EnumAIModule.Abdomen:
  311. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AbdomenDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
  312. break;
  313. case EnumAIModule.Thyroid:
  314. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.ThyroidDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
  315. break;
  316. case EnumAIModule.Carotid:
  317. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.CarotidDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
  318. break;
  319. }
  320. }
  321. private void OnNotifyError(object sender, ErrorEventArgs e)
  322. {
  323. Logger.Error($"AIDiagnosisService OnNotifyError:{e.GetException()}");
  324. var logEventArgs = AICommonServiceConvertHelper.ConvertErrorEventArgsToAILogEventArgs(e);
  325. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AIDiagnosisNotifyLogRaised, Params = logEventArgs });
  326. }
  327. private void OnNotifyLog(object sender, LogEventArgs e)
  328. {
  329. if (e == null)
  330. {
  331. return;
  332. }
  333. switch (e.LogType)
  334. {
  335. case EnumLogType.InfoLog:
  336. Logger.Info($"AIDiagnosisService OnNotifyLog:{e.Msg}");
  337. break;
  338. case EnumLogType.WarnLog:
  339. Logger.Warning($"AIDiagnosisService OnNotifyLog:{e.Msg}");
  340. break;
  341. case EnumLogType.ErrorLog:
  342. case EnumLogType.FatalLog:
  343. default:
  344. Logger.Error($"AIDiagnosisService OnNotifyLog:{e.Msg}");
  345. break;
  346. }
  347. var logEventArgs = AICommonServiceConvertHelper.ConvertLogEventArgsToAILogEventArgs(e);
  348. NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AIDiagnosisNotifyLogRaised, Params = logEventArgs });
  349. }
  350. public TransAIDiagResultPerImg DetectOneByteImage(AIEnumModuleType type)
  351. {
  352. try
  353. {
  354. byte[] byteImage = null;
  355. int retryCount = 0;
  356. switch (type)
  357. {
  358. case AIEnumModuleType.Abdomen:
  359. while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
  360. {
  361. Thread.Sleep(10);
  362. retryCount++;
  363. }
  364. break;
  365. case AIEnumModuleType.Breast:
  366. while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
  367. {
  368. Thread.Sleep(10);
  369. retryCount++;
  370. }
  371. break;
  372. case AIEnumModuleType.Thyroid:
  373. while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
  374. {
  375. Thread.Sleep(10);
  376. retryCount++;
  377. }
  378. break;
  379. case AIEnumModuleType.Carotid:
  380. while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
  381. {
  382. Thread.Sleep(10);
  383. retryCount++;
  384. }
  385. break;
  386. }
  387. if (byteImage == null)
  388. {
  389. Logger.Error($"AIDiagnosisService-DetectOneByteImage Get Image Cache Fail");
  390. return null;
  391. }
  392. if (_aiDiagnosis == null)
  393. {
  394. Logger.Error($"Detect One Byte Image Error:AI Diagnosis is null");
  395. return null;
  396. }
  397. switch (type)
  398. {
  399. case AIEnumModuleType.Abdomen:
  400. if (_abdomenDiagnosisParameter != null)
  401. {
  402. if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
  403. {
  404. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  405. _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
  406. _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
  407. _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
  408. _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
  409. _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
  410. _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
  411. _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
  412. }
  413. }
  414. break;
  415. case AIEnumModuleType.Breast:
  416. if (_breastDiagnosisParameter != null)
  417. {
  418. if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
  419. {
  420. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  421. _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
  422. _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
  423. _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
  424. _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
  425. _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
  426. _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
  427. _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
  428. }
  429. }
  430. break;
  431. case AIEnumModuleType.Thyroid:
  432. if (_thyroidDiagnosisParameter != null)
  433. {
  434. if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
  435. {
  436. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  437. _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
  438. _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
  439. _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
  440. _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
  441. _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
  442. _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
  443. _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
  444. }
  445. }
  446. break;
  447. case AIEnumModuleType.Carotid:
  448. if (_carotidDiagnosisParameter != null)
  449. {
  450. if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
  451. {
  452. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  453. _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
  454. _aiDiagnosis.EnableLesionDescription = _carotidDiagnosisParameter.EnableLesionDescription;
  455. _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
  456. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  457. _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
  458. _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
  459. _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
  460. }
  461. }
  462. break;
  463. }
  464. var result = _aiDiagnosis?.DetectOneImage(byteImage);
  465. return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
  466. }
  467. catch (Exception ex)
  468. {
  469. Logger.Error($"AIDiagnosisService-DetectOneByteImage error:{ex}");
  470. return null;
  471. }
  472. }
  473. /// <summary>
  474. /// 评估单幅图像 ,图像计算完成后,使用者希望调整结果,使部分结果在选定的矩形框内。
  475. /// </summary>
  476. /// <param name="aiRect">使用者给出的矩形框</param>
  477. /// <param name="transAIDiagResultPerImg">图像的初始计算结果</param>
  478. /// <summary>
  479. public TransAIDiagResultPerImg CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage(AIRect aiRect, TransAIDiagResultPerImg transAIDiagResultPerImg)
  480. {
  481. try
  482. {
  483. byte[] byteImage = null;
  484. int retryCount = 0;
  485. while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
  486. {
  487. Thread.Sleep(10);
  488. retryCount++;
  489. }
  490. if (byteImage == null)
  491. {
  492. Logger.Error($"AIDiagnosisService-CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage Get Image Cache Fail");
  493. return null;
  494. }
  495. if (_aiDiagnosis == null)
  496. {
  497. Logger.Error($"CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage Error:AI Diagnosis is null");
  498. return null;
  499. }
  500. var rect = AICommonServiceConvertHelper.ConvertAIRectToRect(aiRect);
  501. var aiDiagResultPerImg = AIConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(transAIDiagResultPerImg);
  502. var result = _aiDiagnosis?.CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRect(byteImage, rect, aiDiagResultPerImg);
  503. return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
  504. }
  505. catch (Exception ex)
  506. {
  507. Logger.Error($"AIDiagnosisService-DetectOneByteImageWithTempSetting error:{ex}");
  508. return null;
  509. }
  510. }
  511. /// <summary>
  512. /// 评估单幅图像 ,图像计算完成后,使用者希望调整结果,使部分结果在选定的矩形框内。
  513. /// </summary>
  514. /// <param name="aiRect">使用者给出的矩形框</param>
  515. /// <param name="transAIDiagResultPerImg">图像的初始计算结果</param>
  516. public TransAIDiagResultPerImg CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage(int height, int width, AIEnumColorType colorType, AIRect aiRect, TransAIDiagResultPerImg transAIDiagResultPerImg)
  517. {
  518. try
  519. {
  520. byte[] byteImage = null;
  521. int retryCount = 0;
  522. while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
  523. {
  524. Thread.Sleep(10);
  525. retryCount++;
  526. }
  527. if (byteImage == null)
  528. {
  529. Logger.Error($"AIDiagnosisService-CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage Get Image Cache Fail");
  530. return null;
  531. }
  532. if (_aiDiagnosis == null)
  533. {
  534. Logger.Error($"CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage Error:AI Diagnosis is null");
  535. return null;
  536. }
  537. var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
  538. var rect = AICommonServiceConvertHelper.ConvertAIRectToRect(aiRect);
  539. var aiDiagResultPerImg = AIConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(transAIDiagResultPerImg);
  540. var result = _aiDiagnosis?.CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRect(rawImage, rect, aiDiagResultPerImg);
  541. return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
  542. }
  543. catch (Exception ex)
  544. {
  545. Logger.Error($"AIDiagnosisService-CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage error:{ex}");
  546. return null;
  547. }
  548. }
  549. public TransAIDiagResultPerImg DetectOneByteImageWithTempSetting(AIEnumModuleType type, bool enableLesionSeg, bool enableLessionDescription, bool enableOrganDescription)
  550. {
  551. try
  552. {
  553. byte[] byteImage = null;
  554. int retryCount = 0;
  555. switch (type)
  556. {
  557. case AIEnumModuleType.Abdomen:
  558. while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
  559. {
  560. Thread.Sleep(10);
  561. retryCount++;
  562. }
  563. break;
  564. case AIEnumModuleType.Breast:
  565. while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
  566. {
  567. Thread.Sleep(10);
  568. retryCount++;
  569. }
  570. break;
  571. case AIEnumModuleType.Thyroid:
  572. while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
  573. {
  574. Thread.Sleep(10);
  575. retryCount++;
  576. }
  577. break;
  578. case AIEnumModuleType.Carotid:
  579. while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
  580. {
  581. Thread.Sleep(10);
  582. retryCount++;
  583. }
  584. break;
  585. }
  586. if (byteImage == null)
  587. {
  588. Logger.Error($"AIDiagnosisService-DetectOneByteImageWithTempSetting Get Image Cache Fail");
  589. return null;
  590. }
  591. if (_aiDiagnosis == null)
  592. {
  593. Logger.Error($"DetectOneByteImageWithTempSetting Error:AI Diagnosis is null");
  594. return null;
  595. }
  596. switch (type)
  597. {
  598. case AIEnumModuleType.Abdomen:
  599. if (_abdomenDiagnosisParameter != null)
  600. {
  601. if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
  602. {
  603. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  604. _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
  605. _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
  606. _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
  607. _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
  608. _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
  609. _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
  610. _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
  611. }
  612. }
  613. break;
  614. case AIEnumModuleType.Breast:
  615. if (_breastDiagnosisParameter != null)
  616. {
  617. if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
  618. {
  619. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  620. _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
  621. _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
  622. _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
  623. _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
  624. _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
  625. _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
  626. _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
  627. }
  628. }
  629. break;
  630. case AIEnumModuleType.Thyroid:
  631. if (_thyroidDiagnosisParameter != null)
  632. {
  633. if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
  634. {
  635. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  636. _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
  637. _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
  638. _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
  639. _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
  640. _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
  641. _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
  642. _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
  643. }
  644. }
  645. break;
  646. case AIEnumModuleType.Carotid:
  647. if (_carotidDiagnosisParameter != null)
  648. {
  649. if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
  650. {
  651. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  652. _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
  653. _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
  654. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  655. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  656. _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
  657. _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
  658. _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
  659. }
  660. }
  661. break;
  662. }
  663. var result = _aiDiagnosis?.DetectOneImage(byteImage, enableLesionSeg, enableLessionDescription, enableOrganDescription);
  664. return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
  665. }
  666. catch (Exception ex)
  667. {
  668. Logger.Error($"AIDiagnosisService-DetectOneByteImageWithTempSetting error:{ex}");
  669. return null;
  670. }
  671. }
  672. public TransAIDiagResultPerImg DetectOneRawImage(AIEnumModuleType type, int height, int width, AIEnumColorType colorType)
  673. {
  674. try
  675. {
  676. byte[] byteImage = null;
  677. int retryCount = 0;
  678. switch (type)
  679. {
  680. case AIEnumModuleType.Abdomen:
  681. while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
  682. {
  683. Thread.Sleep(10);
  684. retryCount++;
  685. }
  686. break;
  687. case AIEnumModuleType.Breast:
  688. while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
  689. {
  690. Thread.Sleep(10);
  691. retryCount++;
  692. }
  693. break;
  694. case AIEnumModuleType.Thyroid:
  695. while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
  696. {
  697. Thread.Sleep(10);
  698. retryCount++;
  699. }
  700. break;
  701. case AIEnumModuleType.Carotid:
  702. while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
  703. {
  704. Thread.Sleep(10);
  705. retryCount++;
  706. }
  707. break;
  708. }
  709. if (byteImage == null)
  710. {
  711. Logger.Error($"AIDiagnosisService-DetectOneRawImage Get Image Cache Fail");
  712. return null;
  713. }
  714. if (_aiDiagnosis == null)
  715. {
  716. Logger.Error($"Detect One Raw Image Error:AI Diagnosis is null");
  717. return null;
  718. }
  719. switch (type)
  720. {
  721. case AIEnumModuleType.Abdomen:
  722. if (_abdomenDiagnosisParameter != null)
  723. {
  724. if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
  725. {
  726. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  727. _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
  728. _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
  729. _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
  730. _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
  731. _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
  732. _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
  733. _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
  734. }
  735. }
  736. break;
  737. case AIEnumModuleType.Breast:
  738. if (_breastDiagnosisParameter != null)
  739. {
  740. if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
  741. {
  742. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  743. _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
  744. _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
  745. _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
  746. _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
  747. _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
  748. _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
  749. _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
  750. }
  751. }
  752. break;
  753. case AIEnumModuleType.Thyroid:
  754. if (_thyroidDiagnosisParameter != null)
  755. {
  756. if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
  757. {
  758. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  759. _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
  760. _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
  761. _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
  762. _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
  763. _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
  764. _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
  765. _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
  766. }
  767. }
  768. break;
  769. case AIEnumModuleType.Carotid:
  770. if (_carotidDiagnosisParameter != null)
  771. {
  772. if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
  773. {
  774. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  775. _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
  776. _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
  777. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  778. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  779. _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
  780. _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
  781. _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
  782. }
  783. }
  784. break;
  785. }
  786. var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
  787. var result = _aiDiagnosis?.DetectOneImage(rawImage);
  788. return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
  789. }
  790. catch (Exception ex)
  791. {
  792. Logger.Error($"AIDiagnosisService-DetectOneRawImage error:{ex}");
  793. return null;
  794. }
  795. }
  796. public TransAIDiagResultPerImg DetectOneRawImageWithTempSetting(AIEnumModuleType type, int height, int width, AIEnumColorType colorType, bool enableLesionSeg, bool enableLessionDescription, bool enableOrganDescription)
  797. {
  798. try
  799. {
  800. byte[] byteImage = null;
  801. int retryCount = 0;
  802. switch (type)
  803. {
  804. case AIEnumModuleType.Abdomen:
  805. while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
  806. {
  807. Thread.Sleep(10);
  808. retryCount++;
  809. }
  810. break;
  811. case AIEnumModuleType.Breast:
  812. while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
  813. {
  814. Thread.Sleep(10);
  815. retryCount++;
  816. }
  817. break;
  818. case AIEnumModuleType.Thyroid:
  819. while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
  820. {
  821. Thread.Sleep(10);
  822. retryCount++;
  823. }
  824. break;
  825. case AIEnumModuleType.Carotid:
  826. while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
  827. {
  828. Thread.Sleep(10);
  829. retryCount++;
  830. }
  831. break;
  832. }
  833. if (byteImage == null)
  834. {
  835. Logger.Error($"AIDiagnosisService-DetectOneRawImageWithTempSetting Get Image Cache Fail");
  836. return null;
  837. }
  838. if (_aiDiagnosis == null)
  839. {
  840. Logger.Error($"DetectOneRawImageWithTempSetting Error:AI Diagnosis is null");
  841. return null;
  842. }
  843. switch (type)
  844. {
  845. case AIEnumModuleType.Abdomen:
  846. if (_abdomenDiagnosisParameter != null)
  847. {
  848. if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
  849. {
  850. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  851. _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
  852. _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
  853. _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
  854. _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
  855. _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
  856. _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
  857. _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
  858. }
  859. }
  860. break;
  861. case AIEnumModuleType.Breast:
  862. if (_breastDiagnosisParameter != null)
  863. {
  864. if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
  865. {
  866. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  867. _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
  868. _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
  869. _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
  870. _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
  871. _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
  872. _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
  873. _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
  874. }
  875. }
  876. break;
  877. case AIEnumModuleType.Thyroid:
  878. if (_thyroidDiagnosisParameter != null)
  879. {
  880. if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
  881. {
  882. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  883. _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
  884. _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
  885. _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
  886. _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
  887. _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
  888. _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
  889. _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
  890. }
  891. }
  892. break;
  893. case AIEnumModuleType.Carotid:
  894. if (_carotidDiagnosisParameter != null)
  895. {
  896. if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
  897. {
  898. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  899. _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
  900. _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
  901. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  902. _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
  903. _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
  904. _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
  905. _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
  906. }
  907. }
  908. break;
  909. }
  910. var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
  911. var result = _aiDiagnosis?.DetectOneImage(rawImage, enableLesionSeg, enableLessionDescription, enableOrganDescription);
  912. return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
  913. }
  914. catch (Exception ex)
  915. {
  916. Logger.Error($"AIDiagnosisService-DetectOneRawImageWithTempSetting error:{ex}");
  917. return null;
  918. }
  919. }
  920. public void SetIsCropped(AIEnumModuleType type, bool isCropped)
  921. {
  922. try
  923. {
  924. switch (type)
  925. {
  926. case AIEnumModuleType.Abdomen:
  927. if (_abdomenDiagnosisParameter != null)
  928. {
  929. _abdomenDiagnosisParameter.IsCropped = isCropped;
  930. }
  931. if (_aiDiagnosis != null)
  932. {
  933. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  934. _aiDiagnosis.IsCropped = isCropped;
  935. }
  936. break;
  937. case AIEnumModuleType.Breast:
  938. if (_breastDiagnosisParameter != null)
  939. {
  940. _breastDiagnosisParameter.IsCropped = isCropped;
  941. }
  942. if (_aiDiagnosis != null)
  943. {
  944. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  945. _aiDiagnosis.IsCropped = isCropped;
  946. }
  947. break;
  948. case AIEnumModuleType.Thyroid:
  949. if (_thyroidDiagnosisParameter != null)
  950. {
  951. _thyroidDiagnosisParameter.IsCropped = isCropped;
  952. }
  953. if (_aiDiagnosis != null)
  954. {
  955. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  956. _aiDiagnosis.IsCropped = isCropped;
  957. }
  958. break;
  959. case AIEnumModuleType.Carotid:
  960. if (_carotidDiagnosisParameter != null)
  961. {
  962. _carotidDiagnosisParameter.IsCropped = isCropped;
  963. }
  964. if (_aiDiagnosis != null)
  965. {
  966. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  967. _aiDiagnosis.IsCropped = isCropped;
  968. }
  969. break;
  970. }
  971. }
  972. catch (Exception ex)
  973. {
  974. Logger.Error($"AIDiagnosisService-SetIsCropped error:{ex}");
  975. }
  976. }
  977. public void SetDetectTps(AIEnumModuleType type, int detectTps)
  978. {
  979. try
  980. {
  981. switch (type)
  982. {
  983. case AIEnumModuleType.Abdomen:
  984. if (_abdomenDiagnosisParameter != null)
  985. {
  986. _abdomenDiagnosisParameter.DetectTps = detectTps;
  987. }
  988. if (_aiDiagnosis != null)
  989. {
  990. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  991. _aiDiagnosis.DetectTps = detectTps;
  992. }
  993. break;
  994. case AIEnumModuleType.Breast:
  995. if (_breastDiagnosisParameter != null)
  996. {
  997. _breastDiagnosisParameter.DetectTps = detectTps;
  998. }
  999. if (_aiDiagnosis != null)
  1000. {
  1001. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  1002. _aiDiagnosis.DetectTps = detectTps;
  1003. }
  1004. break;
  1005. case AIEnumModuleType.Thyroid:
  1006. if (_thyroidDiagnosisParameter != null)
  1007. {
  1008. _thyroidDiagnosisParameter.DetectTps = detectTps;
  1009. }
  1010. if (_aiDiagnosis != null)
  1011. {
  1012. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  1013. _aiDiagnosis.DetectTps = detectTps;
  1014. }
  1015. break;
  1016. case AIEnumModuleType.Carotid:
  1017. if (_carotidDiagnosisParameter != null)
  1018. {
  1019. _carotidDiagnosisParameter.DetectTps = detectTps;
  1020. }
  1021. if (_aiDiagnosis != null)
  1022. {
  1023. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  1024. _aiDiagnosis.DetectTps = detectTps;
  1025. }
  1026. break;
  1027. }
  1028. }
  1029. catch (Exception ex)
  1030. {
  1031. Logger.Error($"AIDiagnosisService-SetDetectTps error:{ex}");
  1032. }
  1033. }
  1034. public void SetIntervalTime(AIEnumModuleType type, int intervalTime)
  1035. {
  1036. try
  1037. {
  1038. switch (type)
  1039. {
  1040. case AIEnumModuleType.Abdomen:
  1041. if (_abdomenDiagnosisParameter != null)
  1042. {
  1043. _abdomenDiagnosisParameter.IntervalTime = intervalTime;
  1044. }
  1045. if (_aiDiagnosis != null)
  1046. {
  1047. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  1048. _aiDiagnosis.IntervalTime = intervalTime;
  1049. }
  1050. break;
  1051. case AIEnumModuleType.Breast:
  1052. if (_breastDiagnosisParameter != null)
  1053. {
  1054. _breastDiagnosisParameter.IntervalTime = intervalTime;
  1055. }
  1056. if (_aiDiagnosis != null)
  1057. {
  1058. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  1059. _aiDiagnosis.IntervalTime = intervalTime;
  1060. }
  1061. break;
  1062. case AIEnumModuleType.Thyroid:
  1063. if (_thyroidDiagnosisParameter != null)
  1064. {
  1065. _thyroidDiagnosisParameter.IntervalTime = intervalTime;
  1066. }
  1067. if (_aiDiagnosis != null)
  1068. {
  1069. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  1070. _aiDiagnosis.IntervalTime = intervalTime;
  1071. }
  1072. break;
  1073. case AIEnumModuleType.Carotid:
  1074. if (_carotidDiagnosisParameter != null)
  1075. {
  1076. _carotidDiagnosisParameter.IntervalTime = intervalTime;
  1077. }
  1078. if (_aiDiagnosis != null)
  1079. {
  1080. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  1081. _aiDiagnosis.IntervalTime = intervalTime;
  1082. }
  1083. break;
  1084. }
  1085. }
  1086. catch (Exception ex)
  1087. {
  1088. Logger.Error($"AIDiagnosisService-SetIntervalTime error:{ex}");
  1089. }
  1090. }
  1091. public void SetDetectMode(AIEnumModuleType type, AIEnumDetectMode detectMode)
  1092. {
  1093. try
  1094. {
  1095. switch (type)
  1096. {
  1097. case AIEnumModuleType.Abdomen:
  1098. if (_abdomenDiagnosisParameter != null)
  1099. {
  1100. _abdomenDiagnosisParameter.DetectMode = detectMode;
  1101. }
  1102. if (_aiDiagnosis != null)
  1103. {
  1104. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  1105. _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
  1106. }
  1107. break;
  1108. case AIEnumModuleType.Breast:
  1109. if (_breastDiagnosisParameter != null)
  1110. {
  1111. _breastDiagnosisParameter.DetectMode = detectMode;
  1112. }
  1113. if (_aiDiagnosis != null)
  1114. {
  1115. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  1116. _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
  1117. }
  1118. break;
  1119. case AIEnumModuleType.Thyroid:
  1120. if (_thyroidDiagnosisParameter != null)
  1121. {
  1122. _thyroidDiagnosisParameter.DetectMode = detectMode;
  1123. }
  1124. if (_aiDiagnosis != null)
  1125. {
  1126. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  1127. _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
  1128. }
  1129. break;
  1130. case AIEnumModuleType.Carotid:
  1131. if (_carotidDiagnosisParameter != null)
  1132. {
  1133. _carotidDiagnosisParameter.DetectMode = detectMode;
  1134. }
  1135. if (_aiDiagnosis != null)
  1136. {
  1137. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  1138. _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
  1139. }
  1140. break;
  1141. }
  1142. }
  1143. catch (Exception ex)
  1144. {
  1145. Logger.Error($"AIDiagnosisService-SetDetectMode error:{ex}");
  1146. }
  1147. }
  1148. public void SetEnableLesionSeg(AIEnumModuleType type, bool enableLesionSeg)
  1149. {
  1150. try
  1151. {
  1152. switch (type)
  1153. {
  1154. case AIEnumModuleType.Abdomen:
  1155. if (_abdomenDiagnosisParameter != null)
  1156. {
  1157. _abdomenDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
  1158. }
  1159. if (_aiDiagnosis != null)
  1160. {
  1161. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  1162. _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
  1163. }
  1164. break;
  1165. case AIEnumModuleType.Breast:
  1166. if (_breastDiagnosisParameter != null)
  1167. {
  1168. _breastDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
  1169. }
  1170. if (_aiDiagnosis != null)
  1171. {
  1172. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  1173. _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
  1174. }
  1175. break;
  1176. case AIEnumModuleType.Thyroid:
  1177. if (_thyroidDiagnosisParameter != null)
  1178. {
  1179. _thyroidDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
  1180. }
  1181. if (_aiDiagnosis != null)
  1182. {
  1183. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  1184. _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
  1185. }
  1186. break;
  1187. case AIEnumModuleType.Carotid:
  1188. if (_carotidDiagnosisParameter != null)
  1189. {
  1190. _carotidDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
  1191. }
  1192. if (_aiDiagnosis != null)
  1193. {
  1194. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  1195. _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
  1196. }
  1197. break;
  1198. }
  1199. }
  1200. catch (Exception ex)
  1201. {
  1202. Logger.Error($"AIDiagnosisService-SetEnableLesionSeg error:{ex}");
  1203. }
  1204. }
  1205. public void SetEnableDescription(AIEnumModuleType type, bool enableLessionDescription, bool enableOrganDescription)
  1206. {
  1207. try
  1208. {
  1209. switch (type)
  1210. {
  1211. case AIEnumModuleType.Abdomen:
  1212. if (_abdomenDiagnosisParameter != null)
  1213. {
  1214. _abdomenDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
  1215. _abdomenDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
  1216. }
  1217. if (_aiDiagnosis != null)
  1218. {
  1219. _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
  1220. _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
  1221. _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
  1222. }
  1223. break;
  1224. case AIEnumModuleType.Breast:
  1225. if (_breastDiagnosisParameter != null)
  1226. {
  1227. _breastDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
  1228. _breastDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
  1229. }
  1230. if (_aiDiagnosis != null)
  1231. {
  1232. _aiDiagnosis.AIModule = EnumAIModule.Breast;
  1233. _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
  1234. _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
  1235. }
  1236. break;
  1237. case AIEnumModuleType.Thyroid:
  1238. if (_thyroidDiagnosisParameter != null)
  1239. {
  1240. _thyroidDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
  1241. _thyroidDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
  1242. }
  1243. if (_aiDiagnosis != null)
  1244. {
  1245. _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
  1246. _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
  1247. _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
  1248. }
  1249. break;
  1250. case AIEnumModuleType.Carotid:
  1251. if (_carotidDiagnosisParameter != null)
  1252. {
  1253. _carotidDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
  1254. _carotidDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
  1255. }
  1256. if (_aiDiagnosis != null)
  1257. {
  1258. _aiDiagnosis.AIModule = EnumAIModule.Carotid;
  1259. _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
  1260. _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
  1261. }
  1262. break;
  1263. }
  1264. }
  1265. catch (Exception ex)
  1266. {
  1267. Logger.Error($"AIDiagnosisService-SetEnableLesionDescription error:{ex}");
  1268. }
  1269. }
  1270. public void Close(AIEnumModuleType type)
  1271. {
  1272. try
  1273. {
  1274. Logger.Info($"AIDiagnosisService-Close Invoke {type}");
  1275. CloseDiagnosis(type);
  1276. }
  1277. catch (Exception ex)
  1278. {
  1279. Logger.Error($"AIDiagnosisService-Close error:{ex}");
  1280. }
  1281. }
  1282. private void CloseDiagnosis(AIEnumModuleType type)
  1283. {
  1284. switch (type)
  1285. {
  1286. case AIEnumModuleType.Abdomen:
  1287. _abdomenDiagnosisParameter = null;
  1288. break;
  1289. case AIEnumModuleType.Breast:
  1290. _breastDiagnosisParameter = null;
  1291. break;
  1292. case AIEnumModuleType.Thyroid:
  1293. _thyroidDiagnosisParameter = null;
  1294. break;
  1295. case AIEnumModuleType.Carotid:
  1296. _carotidDiagnosisParameter = null;
  1297. break;
  1298. }
  1299. if (_abdomenDiagnosisParameter == null && _breastDiagnosisParameter == null && _thyroidDiagnosisParameter == null && _carotidDiagnosisParameter == null)
  1300. {
  1301. CloseDiagnosis();
  1302. }
  1303. }
  1304. private void CloseDiagnosis()
  1305. {
  1306. if (_aiDiagnosis != null)
  1307. {
  1308. _aiDiagnosis.StartEvaluation -= OnStartEvaluation;
  1309. _aiDiagnosis.FinishEvaluation -= OnFinishEvaluation;
  1310. _aiDiagnosis.NotifyError -= OnNotifyError;
  1311. _aiDiagnosis.NotifyLog -= OnNotifyLog;
  1312. _aiDiagnosis.Close();
  1313. _aiDiagnosis = null;
  1314. }
  1315. }
  1316. public void Dispose()
  1317. {
  1318. try
  1319. {
  1320. if (!_disposed)
  1321. {
  1322. Logger.Info($"AIDiagnosisService Start Dispose");
  1323. CloseDiagnosis(AIEnumModuleType.Abdomen);
  1324. CloseDiagnosis(AIEnumModuleType.Breast);
  1325. CloseDiagnosis(AIEnumModuleType.Thyroid);
  1326. CloseDiagnosis(AIEnumModuleType.Carotid);
  1327. if (_singleImagePipeServerForAbdomen != null)
  1328. {
  1329. _singleImagePipeServerForAbdomen.DataReceived -= OnDataReceived;
  1330. _singleImagePipeServerForAbdomen.Dispose();
  1331. _singleImagePipeServerForAbdomen.LogMsgThrow -= OnLogMsgThrow;
  1332. _singleImagePipeServerForAbdomen = null;
  1333. }
  1334. if (_imageProviderForAbdomen != null)
  1335. {
  1336. _imageProviderForAbdomen.Dispose();
  1337. _imageProviderForAbdomen = null;
  1338. }
  1339. if (_singleImagePipeServerForBreast != null)
  1340. {
  1341. _singleImagePipeServerForBreast.DataReceived -= OnDataReceived;
  1342. _singleImagePipeServerForBreast.Dispose();
  1343. _singleImagePipeServerForBreast.LogMsgThrow -= OnLogMsgThrow;
  1344. _singleImagePipeServerForBreast = null;
  1345. }
  1346. if (_imageProviderForBreast != null)
  1347. {
  1348. _imageProviderForBreast.Dispose();
  1349. _imageProviderForBreast = null;
  1350. }
  1351. if (_singleImagePipeServerForThyroid != null)
  1352. {
  1353. _singleImagePipeServerForThyroid.DataReceived -= OnDataReceived;
  1354. _singleImagePipeServerForThyroid.Dispose();
  1355. _singleImagePipeServerForThyroid.LogMsgThrow -= OnLogMsgThrow;
  1356. _singleImagePipeServerForThyroid = null;
  1357. }
  1358. if (_imageProviderForThyroid != null)
  1359. {
  1360. _imageProviderForThyroid.Dispose();
  1361. _imageProviderForThyroid = null;
  1362. }
  1363. if (_singleImagePipeServerForCarotid != null)
  1364. {
  1365. _singleImagePipeServerForCarotid.DataReceived -= OnDataReceived;
  1366. _singleImagePipeServerForCarotid.Dispose();
  1367. _singleImagePipeServerForCarotid.LogMsgThrow -= OnLogMsgThrow;
  1368. _singleImagePipeServerForCarotid = null;
  1369. }
  1370. if (_imageProviderForCarotid != null)
  1371. {
  1372. _imageProviderForCarotid.Dispose();
  1373. _imageProviderForCarotid = null;
  1374. }
  1375. _disposed = true;
  1376. Logger.Info($"AIDiagnosisService Dispose End");
  1377. }
  1378. }
  1379. catch (Exception ex)
  1380. {
  1381. Logger.Error($"AIDiagnosisService-Dispose error:{ex}");
  1382. }
  1383. }
  1384. /// <summary>
  1385. /// Send Raw Image Data For Pipe
  1386. /// </summary>
  1387. /// <param name="length"></param>
  1388. /// <param name="height"></param>
  1389. /// <param name="width"></param>
  1390. /// <param name="colorType"></param>
  1391. public void SendRawImageData(AIEnumModuleType type, int height, int width, AIEnumColorType colorType)
  1392. {
  1393. try
  1394. {
  1395. switch (type)
  1396. {
  1397. case AIEnumModuleType.Abdomen:
  1398. _imageProviderForAbdomen?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
  1399. break;
  1400. case AIEnumModuleType.Breast:
  1401. _imageProviderForBreast?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
  1402. break;
  1403. case AIEnumModuleType.Thyroid:
  1404. _imageProviderForThyroid?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
  1405. break;
  1406. case AIEnumModuleType.Carotid:
  1407. _imageProviderForCarotid?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
  1408. break;
  1409. }
  1410. }
  1411. catch (Exception ex)
  1412. {
  1413. Logger.Error($"AIDiagnosisService-SendRawImageData error:{ex}");
  1414. }
  1415. }
  1416. /// <summary>
  1417. /// Send Byte Image Data For Pipe
  1418. /// </summary>
  1419. /// <param name="length"></param>
  1420. public void SendByteImageData(AIEnumModuleType type)
  1421. {
  1422. try
  1423. {
  1424. switch (type)
  1425. {
  1426. case AIEnumModuleType.Abdomen:
  1427. _imageProviderForAbdomen?.ReceiveByteImageData();
  1428. break;
  1429. case AIEnumModuleType.Breast:
  1430. _imageProviderForBreast?.ReceiveByteImageData();
  1431. break;
  1432. case AIEnumModuleType.Thyroid:
  1433. _imageProviderForThyroid?.ReceiveByteImageData();
  1434. break;
  1435. case AIEnumModuleType.Carotid:
  1436. _imageProviderForCarotid?.ReceiveByteImageData();
  1437. break;
  1438. }
  1439. }
  1440. catch (Exception ex)
  1441. {
  1442. Logger.Error($"AIDiagnosisService-SendByteImageData error:{ex}");
  1443. }
  1444. }
  1445. }
  1446. }