Browse Source

update(measure): 完成 M 模式下的 Slope

gavin.chen 2 years ago
parent
commit
e36ea3b561

+ 33 - 0
assets/items.json

@@ -1,4 +1,37 @@
 [
+    {
+        "Name": "Slope",
+        "Description": "Slope",
+        "BriefAnnotation": "Slope",
+        "MeasureTypeName": "Slope",
+        "Categories": [
+            "Common"
+        ],
+        "Calculator": {
+            "AvailableOutputs": [
+                {
+                    "Name": "Slope",
+                    "Description": "Slope",
+                    "Unit": 70,
+                    "IsWorking": true
+                },
+                {
+                    "Name": "Timespan",
+                    "Description": "Time",
+                    "Unit": 20,
+                    "IsWorking": true
+                },
+                {
+                    "Name": "Distance",
+                    "Description": "Distance",
+                    "Unit": 10,
+                    "IsWorking": true
+                }
+            ]
+        },
+        "MultiMethodItems": [],
+        "MethodChildItems": []
+    },
     {
         "Name": "A/B Ratio",
         "Description": "A/B Ratio",

+ 1 - 0
lib/interfaces/process/items/types.dart

@@ -108,4 +108,5 @@ class MeasureTypes {
 /* Two StraightLine  [end] */
 
   static const TimeSpan = "TimeSpan";
+  static const Slope = "Slope";
 }

+ 1 - 0
lib/measure_page_test.dart

@@ -366,6 +366,7 @@ class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
     MeasureTerms.Depth,
     MeasureTerms.Stenosis,
     MeasureTerms.AbRatio,
+    MeasureTerms.Slope,
     "Qp/Qs",
   ];
 

+ 9 - 0
lib/process/calcuators/formulas/general.dart

@@ -64,4 +64,13 @@ class GeneralFormulas {
     dis = (lineK * pt.x - pt.y + lineC).abs() / (math.sqrt(lineK * lineK + 1));
     return dis;
   }
+
+  ///计算斜率
+  static double countSlope(DPoint p1, DPoint p2) {
+    if (doubleAlmostEquals(p2.x, p1.x)) return 0;
+    double vertical = p2.y - p1.y;
+    double time = (p2.x - p1.x).abs();
+    double slope = vertical / time;
+    return slope;
+  }
 }

+ 31 - 0
lib/process/calcuators/time_motion.dart

@@ -1,4 +1,5 @@
 import 'package:fis_measure/interfaces/process/calculators/values.dart';
+import 'package:fis_measure/interfaces/process/items/terms.dart';
 import 'package:fis_measure/process/calcuators/formulas/general.dart';
 import 'package:fis_measure/process/items/item.dart';
 import 'package:fis_measure/process/primitives/combos/two_length.dart';
@@ -80,3 +81,33 @@ class StenosisCal extends Calculator<TwoLengthAbstract, double> {
     return null;
   }
 }
+
+class SlopeCal extends Calculator<StraightLine, double> {
+  SlopeCal(StraightLine ref) : super(ref);
+
+  @override
+  void calculate() {
+    if (ref.feature == null) return;
+
+    final feature = ref.feature!;
+    final viewport = feature.hostVisualArea!.viewport!;
+    final p1 = feature.startPoint;
+    final p2 = feature.endPoint;
+    final pp1 = viewport.convert(p1);
+    final pp2 = viewport.convert(p2);
+
+    final distance = (pp2.y - pp1.y).abs();
+    final time = (pp2.x - pp1.x).abs();
+
+    for (var output in ref.meta.outputs) {
+      if (output.name == MeasureTerms.Slope) {
+        var slope = GeneralFormulas.countSlope(pp1, pp2);
+        feature.updateFloatValue(output, slope, output.unit);
+      } else if (output.name == MeasureTerms.Timespan) {
+        feature.updateFloatValue(output, time, output.unit);
+      } else if (output.name == MeasureTerms.Distance) {
+        feature.updateFloatValue(output, distance, output.unit);
+      }
+    }
+  }
+}

+ 1 - 0
lib/process/items/factory.dart

@@ -98,6 +98,7 @@ class MeasureItemFactory {
         TwoStraightLine.createStenosisTwoVerticalDistance);
     _singleton._register(MeasureTypes.AbRatioTwoVerticalDistance,
         TwoStraightLine.createAbRatioTwoVerticalDistance);
+    _singleton._register(MeasureTypes.Slope, StraightLine.createSlope);
 
     // Area Perimeter
     _singleton._register(

+ 29 - 0
lib/process/primitives/straightline.dart

@@ -29,6 +29,12 @@ class StraightLine extends MeasureItem<StraightLineFeature> {
     return sraightLine;
   }
 
+  static StraightLine createSlope(ItemMeta meta, [IMeasureItem? parent]) {
+    StraightLine sraightLine = StraightLine(meta, parent);
+    sraightLine.calculator = SlopeCal(sraightLine);
+    return sraightLine;
+  }
+
   static StraightLine createVerticalDistance(ItemMeta meta,
       [IMeasureItem? parent]) {
     StraightLine sraightLine = StraightLine(meta, parent);
@@ -131,6 +137,9 @@ class StraightLine extends MeasureItem<StraightLineFeature> {
           mouseState.crossIndicatorStyleChanged
               .emit(this, CrossIndicatorStyle.horizontal);
           break;
+        case MeasureTypes.Slope:
+          feature = StraightLineSlopeFeature(this, point, point);
+          break;
         default:
       }
     } else {
@@ -200,3 +209,23 @@ class StraightLineTimeMotionFeature extends StraightLineFeature {
     }
   }
 }
+
+class StraightLineSlopeFeature extends StraightLineFeature {
+  StraightLineSlopeFeature(
+      IMeasureItem refItem, DPoint startPoint, DPoint endPoint)
+      : super(refItem, startPoint, endPoint);
+  @override
+  void paint(Canvas canvas, Size size) {
+    if (startPoint == endPoint) return;
+
+    var idText = '$id';
+    drawId(canvas, size, idText);
+
+    final startOffset = convert2ViewPoint(size, startPoint).toOffset();
+    drawVertex(canvas, startOffset);
+
+    final endOffset = convert2ViewPoint(size, endPoint).toOffset();
+    canvas.drawDashLine(startOffset, endOffset, 1, 10, paintPan);
+    drawVertex(canvas, endOffset, isActive);
+  }
+}