123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- using AForge.Video.DirectShow;
- using AI.DiagSystem;
- using AIDiagnosis.Common.Enums;
- using AIDiagnosisDemo.Settings;
- using Common.Client;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- namespace AIDiagnosisDemo.ViewModel
- {
- public class SettingPageViewModel : Common.Client.ViewModel
- {
- private bool _isEnableAI;
- private Sourcetype _ultrasoundImageSourceType;
- private FilterInfo _ultrasoundImageSource;
- private bool _isDeviceSelected;
- private string _videoFilePath;
- private bool _cropImage;
- private int _detectTps;
- private EnumDetectMode _detectMode;
- private int _intervalTime;
- private bool _isIntervalTimeMode;
- private int _cpuUsed;
- private int _ramUsed;
- private bool _isSimulation;
- private IEnumerable<FilterInfo> _deviceSourceList;
- private EnumPerformance _performance;
- private bool _isShowOrgansContour;
- private EnumDisplayType _showLesions;
- private AIDiagnosisType _aiDiagnosisType;
- private bool _completeMyocardialImg;
- /// <summary>
- /// AI开关
- /// </summary>
- public bool IsEnableAI
- {
- get { return _isEnableAI; }
- set
- {
- if (_isEnableAI != value)
- {
- _isEnableAI = value;
- OnPropertyChanged(() => IsEnableAI);
- }
- }
- }
- /// <summary>
- /// 超声图像来源类型
- /// </summary>
- public IEnumerable<Sourcetype> UltrasoundImageSourceTypeList
- {
- get; private set;
- }
- /// <summary>
- /// 超声图像来源
- /// </summary>
- public Sourcetype UltrasoundImageSourceType
- {
- get => _ultrasoundImageSourceType;
- set
- {
- if (_ultrasoundImageSourceType != value)
- {
- _ultrasoundImageSourceType = value;
- IsDeviceSelected = _ultrasoundImageSourceType == Sourcetype.VideoCaptureDevice;
- if (IsDeviceSelected)
- {
- DeviceSourceList = new FilterInfoCollection(FilterCategory.VideoInputDevice).OfType<FilterInfo>();
- if (UltrasoundImageSource == null)
- {
- UltrasoundImageSource = DeviceSourceList.FirstOrDefault();
- }
- }
- OnPropertyChanged(() => UltrasoundImageSourceType);
- }
- }
- }
- /// <summary>
- /// 图像采集设备被选中
- /// </summary>
- public bool IsDeviceSelected
- {
- get => _isDeviceSelected;
- set
- {
- if (_isDeviceSelected != value)
- {
- _isDeviceSelected = value;
- OnPropertyChanged(() => IsDeviceSelected);
- }
- }
- }
- /// <summary>
- /// 按间隔时间检测模式被选中
- /// </summary>
- public bool IsIntervalTimeMode
- {
- get => _isIntervalTimeMode;
- set
- {
- if (_isIntervalTimeMode != value)
- {
- _isIntervalTimeMode = value;
- OnPropertyChanged(() => IsIntervalTimeMode);
- }
- }
- }
- /// <summary>
- /// 图像文件路径
- /// </summary>
- public string VideoFilePath
- {
- get => _videoFilePath;
- set
- {
- if (_videoFilePath != value)
- {
- _videoFilePath = value;
- OnPropertyChanged(() => VideoFilePath);
- }
- }
- }
- /// <summary>
- /// 图像源
- /// </summary>
- public FilterInfo UltrasoundImageSource
- {
- get => _ultrasoundImageSource;
- set
- {
- if (_ultrasoundImageSource != value)
- {
- _ultrasoundImageSource = value;
- OnPropertyChanged(() => UltrasoundImageSource);
- }
- }
- }
- /// <summary>
- /// AI每秒频次
- /// </summary>
- public int DetectTps
- {
- get => _detectTps;
- set
- {
- if (_detectTps != value)
- {
- _detectTps = value;
- OnPropertyChanged(() => DetectTps);
- }
- }
- }
- /// <summary>
- /// 图像裁切
- /// </summary>
- public bool CropImage
- {
- get => _cropImage;
- set
- {
- if (_cropImage != value)
- {
- _cropImage = value;
- OnPropertyChanged(() => CropImage);
- }
- }
- }
- /// <summary>
- /// 采集设备清单
- /// </summary>
- public IEnumerable<FilterInfo> DeviceSourceList
- {
- get => _deviceSourceList;
- private set
- {
- if (_deviceSourceList != value)
- {
- _deviceSourceList = value;
- OnPropertyChanged(() => DeviceSourceList);
- }
- }
- }
- /// <summary>
- /// 检测模式
- /// </summary>
- public EnumDetectMode DetectMode
- {
- get => _detectMode;
- set
- {
- if (_detectMode != value)
- {
- _detectMode = value;
- if (_detectMode == EnumDetectMode.PeriodicIntervals)
- {
- IsIntervalTimeMode = true;
- }
- else
- {
- IsIntervalTimeMode = false;
- }
- OnPropertyChanged(() => DetectMode);
- }
- }
- }
- /// <summary>
- /// 间隔时间
- /// </summary>
- public int IntervalTime
- {
- get => _intervalTime;
- set
- {
- if (_intervalTime != value)
- {
- _intervalTime = value;
- OnPropertyChanged(() => IntervalTime);
- }
- }
- }
- /// <summary>
- /// CPU占用
- /// </summary>
- public int CPUUsed
- {
- get => _cpuUsed;
- set
- {
- if (_cpuUsed != value)
- {
- _cpuUsed = value;
- OnPropertyChanged(() => CPUUsed);
- }
- }
- }
- /// <summary>
- /// 内存占用
- /// </summary>
- public int RAMUsed
- {
- get => _ramUsed;
- set
- {
- if (_ramUsed != value)
- {
- _ramUsed = value;
- OnPropertyChanged(() => RAMUsed);
- }
- }
- }
- /// <summary>
- /// 是否开启模拟占用CPU与内存
- /// </summary>
- public bool IsSimulation
- {
- get => _isSimulation;
- set
- {
- if (_isSimulation != value)
- {
- _isSimulation = value;
- OnPropertyChanged(() => IsSimulation);
- }
- }
- }
- /// <summary>
- /// 性能
- /// </summary>
- public EnumPerformance Performance
- {
- get => _performance;
- set
- {
- if (_performance != value)
- {
- _performance = value;
- OnPropertyChanged(() => Performance);
- }
- }
- }
- /// <summary>
- /// 是否显示脏器
- /// </summary>
- public bool IsShowOrgansContour
- {
- get => _isShowOrgansContour;
- set
- {
- if (_isShowOrgansContour != value)
- {
- _isShowOrgansContour = value;
- OnPropertyChanged(() => IsShowOrgansContour);
- }
- }
- }
- /// <summary>
- /// 显示病灶的方式
- /// </summary>
- public EnumDisplayType ShowLesions
- {
- get => _showLesions;
- set
- {
- if (_showLesions != value)
- {
- _showLesions = value;
- OnPropertyChanged(() => ShowLesions);
- }
- }
- }
- /// <summary>
- /// 选择AI SDK
- /// </summary>
- public AIDiagnosisType AIDiagnosisType
- {
- get => _aiDiagnosisType;
- set
- {
- if (_aiDiagnosisType != value)
- {
- _aiDiagnosisType = value;
- OnPropertyChanged(() => AIDiagnosisType);
- }
- }
- }
- public ButtonCommand BrowseCommand { get; }
- public bool CompleteMyocardialImg
- {
- get => _completeMyocardialImg;
- set
- {
- if (_completeMyocardialImg != value)
- {
- _completeMyocardialImg = value;
- OnPropertyChanged(() => CompleteMyocardialImg);
- }
- }
- }
- public SettingPageViewModel()
- {
- BrowseCommand = new ButtonCommand(OnBrowse);
- DeviceSourceList = new FilterInfoCollection(FilterCategory.VideoInputDevice).OfType<FilterInfo>();
- UltrasoundImageSourceTypeList = new List<Sourcetype>
- {
- Sourcetype.VideoCaptureDevice,
- Sourcetype.PictureOrVideoFile
- };
- LoadSettings();
- }
- private void OnBrowse(object args)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog
- {
- Filter = "图像或视频文件|*.png;*.bmp;*.jpg;*.jpeg;*.mp4;*.avi",
- Multiselect = false,
- Title = "选择一个图像或视频"
- };
- if (openFileDialog.ShowDialog() ?? false)
- {
- VideoFilePath = openFileDialog.FileName;
- }
- }
- private void LoadSettings()
- {
- IsEnableAI = SettingConfig.Instance.IsEnableAI;
- UltrasoundImageSourceType = SettingConfig.Instance.UltrasoundImageSourceType;
- CropImage = SettingConfig.Instance.CropImage;
- DetectTps = SettingConfig.Instance.DetectTps;
- IntervalTime = SettingConfig.Instance.IntervalTime;
- DetectMode = SettingConfig.Instance.DetectMode;
- IsDeviceSelected = _ultrasoundImageSourceType == Sourcetype.VideoCaptureDevice;
- if (IsDeviceSelected)
- {
- UltrasoundImageSource = DeviceSourceList.FirstOrDefault(s => s.MonikerString == SettingConfig.Instance.UltrasoundImageSource);
- if (UltrasoundImageSource == null)
- {
- UltrasoundImageSource = DeviceSourceList.FirstOrDefault();
- }
- }
- else
- {
- VideoFilePath = SettingConfig.Instance.UltrasoundImageSource;
- }
- IsSimulation = SettingConfig.Instance.IsSimulation;
- CPUUsed = SettingConfig.Instance.CPUUsed;
- RAMUsed = SettingConfig.Instance.RAMUsed;
- Performance = SettingConfig.Instance.Performance;
- IsShowOrgansContour = SettingConfig.Instance.IsShowOrgansContour;
- ShowLesions = SettingConfig.Instance.DisplayType;
- AIDiagnosisType = SettingConfig.Instance.AIDiagnosisType;
- CompleteMyocardialImg = SettingConfig.Instance.CompleteMyocardialImg;
- }
- public bool Save()
- {
- try
- {
- if (IntervalTime < 0)
- {
- MessageBox.Show("IntervalTime must be >=0");
- return false;
- }
- SettingConfig.PreInstance.UltrasoundImageSourceType = UltrasoundImageSourceType;
- SettingConfig.PreInstance.UltrasoundImageSource = UltrasoundImageSourceType == Sourcetype.VideoCaptureDevice ? UltrasoundImageSource?.MonikerString : VideoFilePath;
- SettingConfig.PreInstance.IsEnableAI = IsEnableAI;
- SettingConfig.PreInstance.Performance = Performance;
- SettingConfig.PreInstance.CropImage = CropImage;
- SettingConfig.PreInstance.DetectTps = DetectTps;
- SettingConfig.PreInstance.DetectMode = DetectMode;
- SettingConfig.PreInstance.IntervalTime = IntervalTime;
- SettingConfig.PreInstance.RAMUsed = RAMUsed;
- SettingConfig.PreInstance.CPUUsed = CPUUsed;
- SettingConfig.PreInstance.IsSimulation = IsSimulation;
- SettingConfig.PreInstance.IsShowOrgansContour = IsShowOrgansContour;
- SettingConfig.PreInstance.DisplayType = ShowLesions;
- SettingConfig.PreInstance.AIDiagnosisType = AIDiagnosisType;
- SettingConfig.PreInstance.CompleteMyocardialImg = CompleteMyocardialImg;
- SettingConfig.PreInstance.Save();
- return true;
- }
- catch (Exception ex)
- {
- MessageBox.Show($"OnSave command exception: {ex}");
- return false;
- }
- }
- }
- }
|