detection.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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:fis_measure/utils/prompt_box.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 = "\n 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.detect Failed";
  55. PromptBox.toast("$type.detect Failed");
  56. // updateStringValue(description);
  57. // ref.application.updateRenderReady.emit(this, null);
  58. return;
  59. }
  60. final feature = ref.feature!;
  61. final res = jsonDecode(result);
  62. // print('getMeasureResult res: $res');
  63. if (res.length > 0) {
  64. if (type == 'Plaque Detection') {
  65. description =
  66. "\n Area: ${res[0]['PlaqueArea'].toStringAsFixed(2)}mm²";
  67. feature.offsetsList
  68. .add(getPointsFromStrList(res[0]['PlaqueEdgePoints']));
  69. } else {
  70. description = "";
  71. if (res['UpperIntimaResult']['ErrorCode'].toString() ==
  72. "1000") {
  73. description +=
  74. "\n Ant.Max: ${res['UpperIntimaResult']['MaxThickness'].toStringAsFixed(2)}mm\n Ant.Min: ${res['UpperIntimaResult']['MinThickness'].toStringAsFixed(2)}mm\n Ant.Avg: ${res['UpperIntimaResult']['AverageThickness'].toStringAsFixed(2)}mm\n Ant.SD: ${res['UpperIntimaResult']['SdThickness'].toStringAsFixed(2)}mm";
  75. feature.offsetsList.add(getPointsFromStrList(
  76. res['UpperIntimaResult']['PointLower']));
  77. feature.offsetsList.add(getPointsFromStrList(
  78. res['UpperIntimaResult']['PointUpper']));
  79. } else {
  80. description += "\n Ant.detect Failed";
  81. }
  82. if (res['LowerIntimaResult']['ErrorCode'].toString() ==
  83. "1000") {
  84. description +=
  85. "\n Post.Max: ${res['LowerIntimaResult']['MaxThickness'].toStringAsFixed(2)}mm\n Post.Min: ${res['LowerIntimaResult']['MinThickness'].toStringAsFixed(2)}mm\n Post.Avg: ${res['LowerIntimaResult']['AverageThickness'].toStringAsFixed(2)}mm\n Post.SD: ${res['LowerIntimaResult']['SdThickness'].toStringAsFixed(2)}mm";
  86. feature.offsetsList.add(getPointsFromStrList(
  87. res['LowerIntimaResult']['PointLower']));
  88. feature.offsetsList.add(getPointsFromStrList(
  89. res['LowerIntimaResult']['PointUpper']));
  90. } else {
  91. description += "\n Post.detect Failed";
  92. }
  93. }
  94. } else {
  95. description = "$type.detect Failed";
  96. PromptBox.toast("$type.detect Failed");
  97. }
  98. updateStringValue(description);
  99. /// [Carotid] ✅在此处通知canvas 重绘结果
  100. ref.application.updateRenderReady.emit(this, null);
  101. },
  102. ],
  103. );
  104. } catch (e) {
  105. updateStringValue("$type.detect Failed");
  106. PromptBox.toast("$type.detect Failed");
  107. //
  108. }
  109. }
  110. }