time_motion.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import 'package:fis_measure/interfaces/date_types/point.dart';
  2. import 'package:fis_measure/interfaces/process/calculators/values.dart';
  3. import 'package:fis_measure/interfaces/process/items/terms.dart';
  4. import 'package:fis_measure/process/calcuators/formulas/general.dart';
  5. import 'package:fis_measure/process/items/item.dart';
  6. import 'package:fis_measure/process/items/item_feature.dart';
  7. import 'package:fis_measure/process/primitives/combos/two_length.dart';
  8. import 'package:vid/us/vid_us_unit.dart';
  9. import '../primitives/straightline.dart';
  10. import 'calculator.dart';
  11. class VerticalDistanceCal extends Calculator<StraightLine, double> {
  12. VerticalDistanceCal(StraightLine ref) : super(ref);
  13. @override
  14. void calculate() {
  15. if (ref.feature == null) return;
  16. final feature = ref.feature!;
  17. final viewport = feature.hostVisualArea!.viewport!;
  18. final p1 = feature.startPoint;
  19. final p2 = feature.endPoint;
  20. final pp1 = viewport.convert(p1);
  21. final pp2 = viewport.convert(p2);
  22. final value = (pp2.y - pp1.y).abs();
  23. updateFloatValue(value, useUnitY: true);
  24. }
  25. }
  26. class TimeSpanCal extends Calculator<StraightLine, double> {
  27. TimeSpanCal(StraightLine ref) : super(ref);
  28. @override
  29. void calculate() {
  30. if (ref.feature == null) return;
  31. final feature = ref.feature!;
  32. final viewport = feature.hostVisualArea!.viewport!;
  33. final p1 = feature.startPoint;
  34. final p2 = feature.endPoint;
  35. final pp1 = viewport.convert(p1);
  36. final pp2 = viewport.convert(p2);
  37. final value = (pp2.x - pp1.x).abs();
  38. updateFloatValue(value);
  39. }
  40. }
  41. class StenosisCal extends Calculator<TwoLengthAbstract, double> {
  42. StenosisCal(TwoLengthAbstract ref) : super(ref);
  43. @override
  44. void calculate() {
  45. if (ref.feature == null) return;
  46. final a1 = _pickChildValue(ref.child1);
  47. final a2 = _pickChildValue(ref.child2);
  48. final feature = ref.feature!;
  49. final viewport = feature.hostVisualArea!.viewport!;
  50. if (a1 != null && a2 != null) {
  51. final value = GeneralFormulas.countStenosis(
  52. a1,
  53. a2,
  54. );
  55. updateFloatValue(value);
  56. }
  57. }
  58. double? _pickChildValue(MeasureItem item) {
  59. if (item.calculator == null) return null;
  60. ValueBase? value;
  61. if (item.measuredFeatures.isNotEmpty) {
  62. value = item.measuredFeatures.first.value;
  63. } else if (item.feature != null) {
  64. value = item.feature!.value;
  65. }
  66. if (value != null) {
  67. return (value as FloatValue).value ?? 0;
  68. }
  69. return null;
  70. }
  71. }
  72. class SlopeCal extends Calculator<StraightLine, double> {
  73. SlopeCal(StraightLine ref) : super(ref);
  74. @override
  75. void calculate() {
  76. if (ref.feature == null) return;
  77. final feature = ref.feature!;
  78. final viewport = feature.hostVisualArea!.viewport!;
  79. final p1 = feature.startPoint;
  80. final p2 = feature.endPoint;
  81. final pp1 = viewport.convert(p1);
  82. final pp2 = viewport.convert(p2);
  83. final distance = (pp2.y - pp1.y).abs();
  84. final time = (pp2.x - pp1.x).abs();
  85. for (var output in ref.meta.outputs) {
  86. if (output.name == MeasureTerms.Slope) {
  87. var slope = GeneralFormulas.countSlope(pp1, pp2);
  88. feature.updateFloatValue(output, slope, output.unit);
  89. } else if (output.name == MeasureTerms.Timespan) {
  90. feature.updateFloatValue(output, time, output.unit);
  91. } else if (output.name == MeasureTerms.Distance) {
  92. feature.updateFloatValue(output, distance, output.unit);
  93. }
  94. }
  95. }
  96. }
  97. class SlopeDopplerCal extends Calculator<StraightLine, double> {
  98. SlopeDopplerCal(StraightLine ref) : super(ref);
  99. @override
  100. void calculate() {
  101. if (ref.feature == null) return;
  102. final feature = ref.feature!;
  103. final viewport = feature.hostVisualArea!.viewport!;
  104. final p1 = feature.startPoint;
  105. final p2 = feature.endPoint;
  106. final pp1 = viewport.convert(p1);
  107. final pp2 = viewport.convert(p2);
  108. final distance = (pp2.y - pp1.y).abs();
  109. final time = (pp2.x - pp1.x).abs();
  110. for (var output in ref.meta.outputs) {
  111. if (output.name == MeasureTerms.Slope) {
  112. var slope = GeneralFormulas.countSlope(pp2, pp1);
  113. feature.updateFloatValue(output, slope, output.unit);
  114. } else if (output.name == MeasureTerms.Timespan) {
  115. feature.updateFloatValue(output, time, output.unit);
  116. } else if (output.name == MeasureTerms.Distance) {
  117. feature.updateFloatValue(output, distance, output.unit);
  118. }
  119. }
  120. }
  121. }
  122. class DpDtCal extends Calculator<StraightLine, double> {
  123. DpDtCal(super.ref);
  124. @override
  125. void calculate() {
  126. if (ref.feature == null) return;
  127. final feature = ref.feature!;
  128. final p1 = feature.startPoint;
  129. final p2 = feature.endPoint;
  130. final pp1 = convertTimeMotionPoint(feature, p1);
  131. final pp2 = convertTimeMotionPoint(feature, p2);
  132. double dpDtRatio = GeneralFormulas.dpDtRatio(pp1, pp2);
  133. updateFloatValue(dpDtRatio, unit: VidUsUnit.mmHgs, useRound: true);
  134. }
  135. }