two_distance.dart 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import 'package:fis_measure/interfaces/date_types/vector.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/urology.dart';
  5. import 'package:fis_measure/process/primitives/combos/two_straightline.dart';
  6. import 'package:fis_measure/process/primitives/straightline.dart';
  7. import 'package:vid/us/vid_us_unit.dart';
  8. import 'calculator.dart';
  9. import 'formulas/general.dart';
  10. import 'lv_study.dart';
  11. class TwoDistanceCalBase extends Calculator<TwoStraightLine, double> {
  12. TwoDistanceCalBase(TwoStraightLine ref) : super(ref);
  13. @override
  14. void calculate() {
  15. // TODO: implement calculate
  16. }
  17. }
  18. class ResidualUrineCal extends Calculator<TwoStraightLine, double> {
  19. ResidualUrineCal(TwoStraightLine ref) : super(ref);
  20. @override
  21. void calculate() {
  22. if (ref.feature == null) return;
  23. final x = _pickChildValue(ref.x);
  24. final y = _pickChildValue(ref.y);
  25. final feature = ref.feature!;
  26. final viewport = feature.hostVisualArea!.viewport!;
  27. if (x != null && y != null) {
  28. final value = UrologyFormulas.calcRUV(
  29. x,
  30. y,
  31. );
  32. updateFloatValue(value);
  33. }
  34. }
  35. double? _pickChildValue(StraightLine item) {
  36. if (item.calculator == null) return null;
  37. ValueBase? value;
  38. if (item.measuredFeatures.isNotEmpty) {
  39. value = item.measuredFeatures.first.value;
  40. } else if (item.feature != null) {
  41. value = item.feature!.value;
  42. }
  43. if (value != null) {
  44. return (value as FloatValue).value ?? 0;
  45. }
  46. return null;
  47. }
  48. }
  49. class TwoDistanceVolumeCal extends Calculator<TwoStraightLine, double> {
  50. TwoDistanceVolumeCal(TwoStraightLine ref) : super(ref);
  51. @override
  52. void calculate() {
  53. if (ref.feature == null) return;
  54. final f1 = findChildFeature(ref.child1);
  55. final f2 = findChildFeature(ref.child2);
  56. if (f1 == null || f2 == null) return;
  57. final feature = ref.feature!;
  58. final val1 = f1.value?.pickFloat() ?? 0;
  59. final val2 = f2.value?.pickFloat() ?? 0;
  60. final unitY = f1.hostVisualArea!.viewport!.yUnit;
  61. for (var ouput in ref.meta.outputs) {
  62. if (ouput.name == MeasureTerms.Volume) {
  63. var volume = GeneralFormulas.volumeTwoLine(val1, val2);
  64. final unit = unitY == VidUsUnit.cm ? VidUsUnit.cm3 : VidUsUnit.None;
  65. feature.updateFloatValue(
  66. ouput,
  67. roundDouble(volume, ouput.fractionalDigits),
  68. unit,
  69. );
  70. } else if (ouput.name == MeasureTerms.AvgDistance) {
  71. double avg = (val1 + val2) / 2;
  72. feature.updateFloatValue(
  73. ouput,
  74. roundDouble(avg, ouput.fractionalDigits),
  75. unitY,
  76. );
  77. }
  78. }
  79. }
  80. }
  81. class TwoDistanceSumCal extends Calculator<TwoStraightLine, double> {
  82. TwoDistanceSumCal(TwoStraightLine ref) : super(ref);
  83. @override
  84. void calculate() {
  85. if (ref.feature == null) return;
  86. final f1 = findChildFeature(ref.child1);
  87. final f2 = findChildFeature(ref.child2);
  88. if (f1 == null || f2 == null) return;
  89. final feature = ref.feature!;
  90. final val1 = f1.value?.pickFloat() ?? 0;
  91. final val2 = f2.value?.pickFloat() ?? 0;
  92. var unitY = f1.hostVisualArea!.viewport!.yUnit;
  93. if (unitY == VidUsUnit.None) {
  94. if (f1.value != null) {
  95. unitY = f1.value!.unit;
  96. }
  97. }
  98. for (var ouput in ref.meta.outputs) {
  99. if (ouput.name == MeasureTerms.Distance) {
  100. var dis = val1 + val2;
  101. feature.updateFloatValue(
  102. ouput,
  103. roundDouble(dis, ouput.fractionalDigits),
  104. unitY,
  105. );
  106. } else if (ouput.name == MeasureTerms.AvgDistance) {
  107. double avg = (val1 + val2) / 2;
  108. feature.updateFloatValue(
  109. ouput,
  110. roundDouble(avg, ouput.fractionalDigits),
  111. unitY,
  112. );
  113. }
  114. }
  115. }
  116. }
  117. class TwoStraightLineAngleCal extends Calculator<TwoStraightLine, double> {
  118. TwoStraightLineAngleCal(TwoStraightLine ref) : super(ref);
  119. @override
  120. void calculate() {
  121. if (ref.feature == null) return;
  122. final f1 = findChildFeature(ref.child1);
  123. final f2 = findChildFeature(ref.child2);
  124. if (f1 == null || f2 == null) return;
  125. if (f1.innerPoints.length == f2.innerPoints.length) {
  126. var l1 = f1.innerPoints[0] - f1.innerPoints[1];
  127. var l2 = f2.innerPoints[0] - f2.innerPoints[1];
  128. var value = (DVector.angleBetween(l1, l2)).abs();
  129. updateFloatValue(value, unit: VidUsUnit.degree, useRound: true);
  130. }
  131. }
  132. }
  133. class IvsThckCal extends Calculator<TwoStraightLine, double> {
  134. IvsThckCal(TwoStraightLine ref) : super(ref);
  135. @override
  136. void calculate() {
  137. if (ref.feature == null) return;
  138. final len1 = pickChildFloatValue(ref.child1) ?? 0;
  139. final len2 = pickChildFloatValue(ref.child2) ?? 0;
  140. final ivs = calcIvs(len1, len2);
  141. updateFloatValue(ivs, unit: VidUsUnit.percent, useRound: true);
  142. }
  143. static double calcIvs(double ivsd, double ivss) {
  144. if (ivsd == 0) {
  145. return 0;
  146. }
  147. return (ivss - ivsd) / ivsd * 100;
  148. }
  149. }
  150. abstract class EfCal extends LvStudyCalculatorBase<TwoStraightLine> {
  151. late final StraightLine kidLVIDd;
  152. late final StraightLine kidLVIDs;
  153. EfCal(super.ref) {
  154. kidLVIDd = ref.child1;
  155. kidLVIDs = ref.child2;
  156. }
  157. @override
  158. void calculate() {
  159. if (ref.feature == null) return;
  160. updateStringValue('');
  161. restoreVals();
  162. uv.lvidd = pickChildToFloatValue(kidLVIDd)?.toUnitFloatValue();
  163. uv.lvids = pickChildToFloatValue(kidLVIDs)?.toUnitFloatValue();
  164. for (var output in ref.meta.outputs) {
  165. switch (output.name) {
  166. case MeasureTerms.LVEDV:
  167. updateLVEDV();
  168. break;
  169. case MeasureTerms.LVESV:
  170. updateLVESV();
  171. break;
  172. case MeasureTerms.EF:
  173. updateEF();
  174. break;
  175. case MeasureTerms.CO:
  176. updateCO();
  177. break;
  178. }
  179. }
  180. }
  181. }
  182. class EfTeichCal extends EfCal {
  183. EfTeichCal(TwoStraightLine ref) : super(ref);
  184. }
  185. class RvStudyCal extends TwoDistanceCalBase {
  186. RvStudyCal(super.ref);
  187. @override
  188. void calculate() {
  189. if (ref.feature == null) return;
  190. final feature = ref.feature!;
  191. for (var output in ref.meta.outputs) {
  192. switch (output.name) {
  193. case MeasureTerms.RVStudy:
  194. feature.updateStringValue(output, "");
  195. break;
  196. case MeasureTerms.RVIDd:
  197. final rvidd = pickChildFloatValue(ref.x);
  198. if (rvidd != null) {
  199. feature.updateFloatValue(output, rvidd, VidUsUnit.cm);
  200. }
  201. break;
  202. case MeasureTerms.RVIDs:
  203. final rvids = pickChildFloatValue(ref.y);
  204. if (rvids != null) {
  205. feature.updateFloatValue(output, rvids, VidUsUnit.cm);
  206. }
  207. break;
  208. }
  209. }
  210. }
  211. }
  212. class AreaPerimeterByLAndWCal extends Calculator<TwoStraightLine, double> {
  213. AreaPerimeterByLAndWCal(TwoStraightLine ref) : super(ref);
  214. @override
  215. void calculate() {
  216. if (ref.feature == null) return;
  217. final f1 = findChildFeature(ref.child1);
  218. final f2 = findChildFeature(ref.child2);
  219. if (f1 == null || f2 == null) return;
  220. final feature = ref.feature!;
  221. final val1 = f1.value?.pickFloat() ?? 0;
  222. final val2 = f2.value?.pickFloat() ?? 0;
  223. var unitY = f1.hostVisualArea!.viewport!.yUnit;
  224. if (unitY == VidUsUnit.None) {
  225. if (f1.value != null) {
  226. unitY = f1.value!.unit;
  227. }
  228. }
  229. for (var ouput in ref.meta.outputs) {
  230. if (ouput.name == MeasureTerms.Area) {
  231. var area = GeneralFormulas.area(val1, val2);
  232. feature.updateFloatValue(
  233. ouput,
  234. roundDouble(area, ouput.fractionalDigits),
  235. unitY,
  236. );
  237. } else if (ouput.name == MeasureTerms.Perimeter) {
  238. var perimeter = GeneralFormulas.perimeter(val1, val2);
  239. feature.updateFloatValue(
  240. ouput,
  241. roundDouble(perimeter, ouput.fractionalDigits),
  242. unitY,
  243. );
  244. }
  245. }
  246. }
  247. }