123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- using AI.DiagSystem;
- using AIDiagnosis.Common.Enums;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading.Tasks;
- namespace AIDiagnosisDemo.Settings
- {
- public enum AIDiagnosisType
- {
- Normal,
- Myocardial,
- MiceMyocardial,
- RatMyocardial,
- ThyroidClassification,
- OrganIdentification
- }
- public class SettingConfig
- {
- public event EventHandler<List<SettingProperty>> ValueChangedEvent;
- public static SettingConfig Instance { get; private set; }
- public static SettingConfig PreInstance { get; private set; }
- /// <summary>
- /// CPU占用
- /// </summary>
- public int CPUUsed
- {
- get; set;
- }
- /// <summary>
- /// 图像裁剪
- /// </summary>
- public bool CropImage
- {
- get; set;
- }
- /// <summary>
- /// 检测模式
- /// </summary>
- public EnumDetectMode DetectMode
- {
- get; set;
- }
- /// <summary>
- /// 检测间隔
- /// </summary>
- public int DetectTps
- {
- get; set;
- }
- /// <summary>
- /// 间隔时间
- /// </summary>
- public int IntervalTime
- {
- get; set;
- }
- /// <summary>
- /// AI开关
- /// </summary>
- public bool IsEnableAI
- {
- get;
- set;
- }
- /// <summary>
- /// 模拟占用模式是否开启
- /// </summary>
- public bool IsSimulation
- {
- get; set;
- }
- /// <summary>
- /// 是否是视频
- /// </summary>
- public bool IsVideo
- {
- get
- {
- if (UltrasoundImageSourceType == Sourcetype.PictureOrVideoFile)
- {
- var fileExtension = Path.GetExtension(UltrasoundImageSource);
- if (fileExtension == ".mp4" || fileExtension == ".avi")
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
- }
- /// <summary>
- /// AI性能
- /// </summary>
- public EnumPerformance Performance
- {
- get; set;
- }
- /// <summary>
- /// 内存占用
- /// </summary>
- public int RAMUsed
- {
- get; set;
- }
- /// <summary>
- /// 超声图像来源
- /// </summary>
- public string UltrasoundImageSource
- {
- get; set;
- }
- /// <summary>
- /// 超声图像来源类型
- /// </summary>
- public Sourcetype UltrasoundImageSourceType
- {
- get; set;
- }
- /// <summary>
- /// 显示方式
- /// </summary>
- public EnumDisplayType DisplayType
- {
- get; set;
- }
- /// <summary>
- /// 是否显示脏器轮廓
- /// </summary>
- public bool IsShowOrgansContour
- {
- get; set;
- }
- /// <summary>
- /// 是否播放循环TestImages文件夹内单帧图
- /// </summary>
- public bool IsCycleImagesPlay
- {
- get; set;
- }
- /// <summary>
- /// AI计算类型,按理来说应该全部合成到AIDiagnosisSDK,但是有一些AI组并没有合成到AIDiagSystemLib, 有些数据结构名字用途一样但是属于不同的dll,所以目前没合成的单独创建SDK project并引入。
- /// 后期AI组会统一合成到AIDiagSystemLib.dll.
- /// </summary>
- public AIDiagnosisType AIDiagnosisType { get; set; }
- /// <summary>
- /// 是否对心肌圆形轮廓进行补全
- /// </summary>
- public bool CompleteMyocardialImg { get; set; }
- static SettingConfig()
- {
- if (!LoadConfig())
- {
- Instance = new SettingConfig
- {
- UltrasoundImageSourceType = Sourcetype.PictureOrVideoFile,
- UltrasoundImageSource = null,
- IsEnableAI = true,
- Performance = EnumPerformance.Low,
- DetectTps = 2,
- CropImage = false,
- DetectMode = EnumDetectMode.PeriodicIntervals,
- IntervalTime = 1000,
- IsShowOrgansContour = true,
- DisplayType = EnumDisplayType.Border,
- IsSimulation = true,
- RAMUsed = 0,
- CPUUsed = 0,
- IsCycleImagesPlay = false,
- AIDiagnosisType = AIDiagnosisType.Normal
- };
- PreInstance = new SettingConfig
- {
- UltrasoundImageSourceType = Sourcetype.PictureOrVideoFile,
- UltrasoundImageSource = null,
- IsEnableAI = true,
- Performance = EnumPerformance.Low,
- DetectTps = 2,
- CropImage = false,
- DetectMode = EnumDetectMode.PeriodicIntervals,
- IntervalTime = 1000,
- IsShowOrgansContour = true,
- DisplayType = EnumDisplayType.Border,
- IsSimulation = true,
- RAMUsed = 0,
- CPUUsed = 0,
- IsCycleImagesPlay = false,
- AIDiagnosisType = AIDiagnosisType.Normal
- };
- }
- }
- private static bool LoadConfig()
- {
- var settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Setting", "Setting.json");
- if (!File.Exists(settingFilePath))
- {
- return false;
- }
- try
- {
- var jsonString = File.ReadAllText(settingFilePath);
- Instance = JsonConvert.DeserializeObject<SettingConfig>(jsonString);
- PreInstance = JsonConvert.DeserializeObject<SettingConfig>(jsonString);
- return true;
- }
- catch
- {
- }
- return false;
- }
- public void RaiseSavedEvent(List<SettingProperty> changeList)
- {
- Instance.ValueChangedEvent?.Invoke(this, changeList);
- }
- public async void Save()
- {
- var changeList = new List<SettingProperty>();
- if (Instance.UltrasoundImageSource != UltrasoundImageSource)
- {
- Instance.UltrasoundImageSource = UltrasoundImageSource;
- changeList.Add(SettingProperty.UltrasoundImageSource);
- }
- if (Instance.UltrasoundImageSourceType != UltrasoundImageSourceType)
- {
- Instance.UltrasoundImageSourceType = UltrasoundImageSourceType;
- changeList.Add(SettingProperty.UltrasoundImageSourceType);
- }
- if (Instance.IsEnableAI != IsEnableAI)
- {
- Instance.IsEnableAI = IsEnableAI;
- changeList.Add(SettingProperty.IsEnableAI);
- }
- if (Instance.Performance != Performance)
- {
- Instance.Performance = Performance;
- changeList.Add(SettingProperty.Performance);
- }
- if (Instance.CropImage != CropImage)
- {
- Instance.CropImage = CropImage;
- changeList.Add(SettingProperty.CropImage);
- }
- if (Instance.DetectTps != DetectTps)
- {
- Instance.DetectTps = DetectTps;
- changeList.Add(SettingProperty.DetectTps);
- }
- if (Instance.DetectMode != DetectMode)
- {
- Instance.DetectMode = DetectMode;
- changeList.Add(SettingProperty.DetectMode);
- }
- if (Instance.IntervalTime != IntervalTime)
- {
- Instance.IntervalTime = IntervalTime;
- changeList.Add(SettingProperty.IntervalTime);
- }
- if (Instance.RAMUsed != RAMUsed)
- {
- Instance.RAMUsed = RAMUsed;
- changeList.Add(SettingProperty.RAMUsed);
- }
- if (Instance.CPUUsed != CPUUsed)
- {
- Instance.CPUUsed = CPUUsed;
- changeList.Add(SettingProperty.CPUUsed);
- }
- if (Instance.IsSimulation != IsSimulation)
- {
- Instance.IsSimulation = IsSimulation;
- changeList.Add(SettingProperty.IsSimulation);
- }
- if (Instance.DisplayType != DisplayType)
- {
- Instance.DisplayType = DisplayType;
- changeList.Add(SettingProperty.DisplayType);
- }
- if (Instance.IsShowOrgansContour != IsShowOrgansContour)
- {
- Instance.IsShowOrgansContour = IsShowOrgansContour;
- changeList.Add(SettingProperty.IsShowOrgansContour);
- }
- if (Instance.AIDiagnosisType != AIDiagnosisType)
- {
- Instance.AIDiagnosisType = AIDiagnosisType;
- changeList.Add(SettingProperty.AIDiagnosisType);
- }
- if (Instance.CompleteMyocardialImg != CompleteMyocardialImg)
- {
- Instance.CompleteMyocardialImg = CompleteMyocardialImg;
- changeList.Add(SettingProperty.AIDiagnosisType);
- }
- var settingFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Setting");
- var settingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Setting", "Setting.json");
- var jsonString = JsonConvert.SerializeObject(Instance);
- if (!Directory.Exists(settingFolderPath))
- {
- Directory.CreateDirectory(settingFolderPath);
- }
- File.WriteAllText(settingFilePath, jsonString);
- if (changeList.Count > 0)
- {
- await Task.Run(() =>
- {
- Instance.ValueChangedEvent?.Invoke(this, changeList);
- });
- }
- }
- }
- }
|