detection.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'dart:convert';
  2. import 'dart:ui';
  3. import 'package:fis_measure/interfaces/date_types/point.dart';
  4. import 'package:fis_measure/process/primitives/detection.dart';
  5. import 'package:fis_measure/utils/js_utils.dart'
  6. if (dart.library.io) 'package:fis_measure/utils/js_utils4native.dart'
  7. if (dart.library.html) 'package:fis_measure/utils/js_utils.dart';
  8. import 'package:vid/us/vid_us_unit.dart';
  9. import 'calculator.dart';
  10. class CarotidDetectionCal extends Calculator<CarotidDetection, double> {
  11. CarotidDetectionCal(CarotidDetection ref, this.type) : super(ref);
  12. String type = '';
  13. @override
  14. void calculate() {
  15. if (ref.feature == null) return;
  16. //图片尺寸
  17. final imageSize = ref.application.carotid2DSize;
  18. //画布尺寸
  19. final canavsSize = ref.application.displaySize;
  20. //图像缩放比
  21. final imageScale = ref.application.displayScaleRatio;
  22. //标准画布尺寸
  23. final stdCanavsSize =
  24. Size(canavsSize.width / imageScale, canavsSize.height / imageScale);
  25. //Vid图像左上顶点的像素坐标
  26. final imageLeftTopPoint = DPoint(
  27. (stdCanavsSize.width - imageSize.width) / 2,
  28. (stdCanavsSize.height - imageSize.height) / 2);
  29. String measureItemType = 'PlaqueDectectionMeasureItem';
  30. if (type == 'Plaque Detection') {
  31. measureItemType = 'PlaqueDectectionMeasureItem';
  32. } else if (type == 'Intima Detection') {
  33. measureItemType = 'IntimaDetectionMeasureItem';
  34. }
  35. final params = "{'MeasureItemType':'$measureItemType'}";
  36. String description = "Waiting $type";
  37. updateStringValue(description);
  38. List<Offset> getPointsFromStrList(List pointsStr) {
  39. final points = <Offset>[];
  40. for (var point in pointsStr) {
  41. final xyStr = point.split(',');
  42. points.add(Offset((double.parse(xyStr[0]) + imageLeftTopPoint.x),
  43. (double.parse(xyStr[1]) + imageLeftTopPoint.y)));
  44. }
  45. return points;
  46. }
  47. /// [Carotid] ✅在此处通知 Shell 计算,获取 description,直接绘制结果
  48. try {
  49. callShellMethod('getMeasureResult', [params]).callMethod(
  50. 'then',
  51. [
  52. (result) {
  53. if (result == 'error') {
  54. description = "$type failed";
  55. updateStringValue(description);
  56. ref.application.updateRenderReady.emit(this, null);
  57. return;
  58. }
  59. final feature = ref.feature!;
  60. final res = jsonDecode(result);
  61. // print('getMeasureResult res: $res');
  62. if (res.length > 0) {
  63. if (type == 'Plaque Detection') {
  64. description =
  65. "$type\n Area: ${res[0]['PlaqueArea'].toStringAsFixed(2)}mm²";
  66. feature.offsetsList
  67. .add(getPointsFromStrList(res[0]['PlaqueEdgePoints']));
  68. } else {
  69. if (res['LowerIntimaResult']['ErrorCode'].toString() ==
  70. "1000") {
  71. description =
  72. "$type\n Ant Max: ${res['LowerIntimaResult']['MaxThickness'].toStringAsFixed(2)}mm\n Ant.Min: ${res['LowerIntimaResult']['MinThickness'].toStringAsFixed(2)}mm\n Ant.Avg: ${res['LowerIntimaResult']['AverageThickness'].toStringAsFixed(2)}mm\n Ant.SD: ${res['LowerIntimaResult']['SdThickness'].toStringAsFixed(2)}mm\n";
  73. feature.offsetsList.add(getPointsFromStrList(
  74. res['LowerIntimaResult']['PointLower']));
  75. feature.offsetsList.add(getPointsFromStrList(
  76. res['LowerIntimaResult']['PointUpper']));
  77. } else {
  78. description = "$type\n Ant failed\n";
  79. }
  80. if (res['UpperIntimaResult']['ErrorCode'].toString() ==
  81. "1000") {
  82. description +=
  83. " Post Max: ${res['UpperIntimaResult']['MaxThickness'].toStringAsFixed(2)}mm\n Post.Min: ${res['UpperIntimaResult']['MinThickness'].toStringAsFixed(2)}mm\n Post.Avg: ${res['UpperIntimaResult']['AverageThickness'].toStringAsFixed(2)}mm\n Post.SD: ${res['UpperIntimaResult']['SdThickness'].toStringAsFixed(2)}mm\n";
  84. feature.offsetsList.add(getPointsFromStrList(
  85. res['UpperIntimaResult']['PointLower']));
  86. feature.offsetsList.add(getPointsFromStrList(
  87. res['UpperIntimaResult']['PointUpper']));
  88. } else {
  89. description += " Post failed";
  90. }
  91. }
  92. } else {
  93. description = "$type failed";
  94. }
  95. updateStringValue(description);
  96. /// [Carotid] ✅在此处通知canvas 重绘结果
  97. ref.application.updateRenderReady.emit(this, null);
  98. },
  99. ],
  100. );
  101. } catch (e) {
  102. updateStringValue("$type failed");
  103. //
  104. }
  105. }
  106. }