urm.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. import 'dart:math';
  2. import 'dart:ui';
  3. import 'package:fis_common/logger/logger.dart';
  4. import 'package:fis_jsonrpc/rpc.dart';
  5. import 'package:fis_measure/interfaces/date_types/point.dart';
  6. import 'package:fis_measure/interfaces/process/calculators/values.dart';
  7. import 'package:fis_measure/interfaces/process/items/terms.dart';
  8. import 'package:fis_measure/interfaces/process/items/types.dart';
  9. import 'package:fis_measure/process/items/item.dart';
  10. import 'package:fis_measure/process/primitives/area_abstract.dart';
  11. import 'package:fis_measure/process/primitives/combos/urm_den_combo.dart';
  12. import 'package:fis_measure/process/primitives/combos/urm_sr_roi_rect_combo.dart';
  13. import 'package:fis_measure/process/primitives/combos/urm_vel_combo.dart';
  14. import 'package:fis_measure/process/primitives/location.dart';
  15. import 'package:fis_measure/process/primitives/straightline.dart';
  16. import 'package:fis_measure/process/primitives/urm_measure/urm_rect_measure.dart';
  17. // import 'package:fis_measure/process/primitives/urm_straightline.dart';
  18. import 'package:fis_measure/process/workspace/urm/application.dart';
  19. import 'package:vid/us/vid_us_unit.dart';
  20. import 'calculator.dart';
  21. class URMRectCal extends Calculator<URMRectMeasure, double> {
  22. URMRectCal(
  23. URMRectMeasure ref, {
  24. required this.type,
  25. }) : super(ref);
  26. final String type;
  27. @override
  28. void calculate() {}
  29. @override
  30. Future<void> calculateAsync() async {
  31. if (ref.feature == null) return;
  32. Size urmResultSize = const Size(0, 0);
  33. try {
  34. if (ref.application is! URMApplication) {
  35. return;
  36. }
  37. final URMApplication urmApplication = ref.application as URMApplication;
  38. urmResultSize = Size(urmApplication.resultWidth.toDouble(),
  39. urmApplication.resultHeight.toDouble());
  40. final p1 = ref.feature!.startPoint;
  41. final p2 = ref.feature!.endPoint;
  42. //左上顶点
  43. final leftTopPercent =
  44. DPoint(p1.x < p2.x ? p1.x : p2.x, p1.y < p2.y ? p1.y : p2.y);
  45. //右下顶点
  46. final rightBottomPercent =
  47. DPoint(p1.x > p2.x ? p1.x : p2.x, p1.y > p2.y ? p1.y : p2.y);
  48. final startPoint = leftTopPercent.scale2Size(urmResultSize);
  49. final endPoint = rightBottomPercent.scale2Size(urmResultSize);
  50. String description = "URM\n Calculating...";
  51. updateStringValue(description);
  52. // switch (type) {
  53. // case MeasureTypes.DensitySR:
  54. // case MeasureTypes.SRRoiDensity:
  55. // case MeasureTypes.Roi1:
  56. // case MeasureTypes.Roi2:
  57. // await getSRRoiDensityResult(urmApplication, startPoint, endPoint);
  58. // break;
  59. // case MeasureTypes.FractalDimSR:
  60. // case MeasureTypes.SRROIFractalDim:
  61. // await getSRRoiFractalDimResult(urmApplication, startPoint, endPoint);
  62. // break;
  63. // case MeasureTypes.SRRoiVel:
  64. // await getSRRoiVelResult(urmApplication, startPoint, endPoint);
  65. // break;
  66. // case MeasureTypes.URMVelMeasure:
  67. // await getURMVelMeasureResult(urmApplication, startPoint, endPoint);
  68. // break;
  69. // default:
  70. // }
  71. } catch (e) {
  72. logger.e('URM Measure error: $e');
  73. return;
  74. }
  75. }
  76. // //✅ URM 测量项 2
  77. // Future<void> getSRRoiDensityResult(
  78. // URMApplication app, DPoint startPoint, DPoint endPoint) async {
  79. // String description = "URM\n Measuring";
  80. // try {
  81. // GetSRRoiVelResult? result =
  82. // await app.getSRRoiVelResult(startPoint, endPoint);
  83. // if (result != null) {
  84. // print("URM Measure output: ${result.output} ");
  85. // final feature = ref.feature!;
  86. // for (var output in ref.meta.outputs) {
  87. // if ([MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim]
  88. // .contains(output.name)) {
  89. // output.unit = VidUsUnit.percent;
  90. // feature.updateFloatValue(output, result.output, output.unit);
  91. // }
  92. // }
  93. // } else {
  94. // throw Exception("URM Measure API error");
  95. // }
  96. // } catch (e) {
  97. // description = " ";
  98. // updateStringValue(description);
  99. // return;
  100. // }
  101. // ref.application.updateRenderReady.emit(this, null);
  102. // }
  103. // //✅ URM 测量项 3 未验证需要组合测量项
  104. // Future<void> getSRRoiFractalDimResult(
  105. // URMApplication app, DPoint startPoint, DPoint endPoint) async {
  106. // String description = "URM\n Measuring";
  107. // try {
  108. // GetSRRoiFractalDimResult? result =
  109. // await app.getSRRoiFractalDimResult(startPoint, endPoint);
  110. // if (result != null) {
  111. // print("URM Measure output: ${result.output} ");
  112. // final feature = ref.feature!;
  113. // for (var output in ref.meta.outputs) {
  114. // if (output.name == MeasureTerms.URMDenFractalDim) {
  115. // output.unit = VidUsUnit.None;
  116. // feature.updateFloatValue(output, result.output, output.unit);
  117. // }
  118. // }
  119. // } else {
  120. // throw Exception("URM Measure API error");
  121. // }
  122. // } catch (e) {
  123. // description = " ";
  124. // updateStringValue(description);
  125. // return;
  126. // }
  127. // ref.application.updateRenderReady.emit(this, null);
  128. // }
  129. // //✅ URM 测量项 7 未验证需要组合测量项
  130. // Future<void> getSRRoiVelResult(
  131. // URMApplication app, DPoint startPoint, DPoint endPoint) async {
  132. // String description = "URM\n Measuring";
  133. // try {
  134. // GetSRRoiVelResult? result =
  135. // await app.getSRRoiVelResult(startPoint, endPoint);
  136. // if (result != null) {
  137. // print("URM Measure output: ${result.output} ");
  138. // final feature = ref.feature!;
  139. // for (var output in ref.meta.outputs) {
  140. // if (output.name == MeasureTerms.SRRoiVel) {
  141. // output.unit = VidUsUnit.percent;
  142. // feature.updateFloatValue(output, result.output, output.unit);
  143. // }
  144. // }
  145. // } else {
  146. // throw Exception("URM Measure API error");
  147. // }
  148. // } catch (e) {
  149. // description = " ";
  150. // updateStringValue(description);
  151. // return;
  152. // }
  153. // ref.application.updateRenderReady.emit(this, null);
  154. // }
  155. // //✅ URM 测量项 9
  156. // Future<void> getURMVelMeasureResult(
  157. // URMApplication app, DPoint startPoint, DPoint endPoint) async {
  158. // String description = "URM\n Measuring";
  159. // try {
  160. // GetURMVelMeasureResult? result =
  161. // await app.getURMVelMeasureResult(startPoint, endPoint);
  162. // if (result != null) {
  163. // // TODO 全部内容展示
  164. // print("URM Measure inMaxVel: ${result.inMaxVel} ");
  165. // final feature = ref.feature!;
  166. // for (var output in ref.meta.outputs) {
  167. // if (output.name == MeasureTerms.URMVelMax) {
  168. // output.unit = VidUsUnit.mms;
  169. // feature.updateFloatValue(
  170. // output, result.maxVel + app.urmMinVel, VidUsUnit.mms);
  171. // }
  172. // if (output.name == MeasureTerms.URMVelMin) {
  173. // output.unit = VidUsUnit.mms;
  174. // feature.updateFloatValue(
  175. // output, result.minVel + app.urmMinVel, VidUsUnit.mms);
  176. // }
  177. // if (output.name == MeasureTerms.URMVelMean) {
  178. // output.unit = VidUsUnit.mms;
  179. // feature.updateFloatValue(
  180. // output, result.meanVel + app.urmMinVel, VidUsUnit.mms);
  181. // }
  182. // if (output.name == MeasureTerms.URMVelStd) {
  183. // output.unit = VidUsUnit.mms;
  184. // feature.updateFloatValue(
  185. // output, sqrt(result.varianceVel), VidUsUnit.mms);
  186. // }
  187. // if (output.name == MeasureTerms.Area) {
  188. // output.unit = VidUsUnit.cm2;
  189. // feature.updateFloatValue(output, result.roiArea, VidUsUnit.cm2);
  190. // }
  191. // }
  192. // } else {
  193. // throw Exception("URM Measure API error");
  194. // }
  195. // } catch (e) {
  196. // description = " ";
  197. // updateStringValue(description);
  198. // return;
  199. // }
  200. // ref.application.updateRenderReady.emit(this, null);
  201. // }
  202. }
  203. class URMLocationCal extends Calculator<Location, double> {
  204. URMLocationCal(Location ref) : super(ref);
  205. @override
  206. void calculate() {}
  207. @override
  208. Future<void> calculateAsync() async {
  209. if (ref.feature == null) return;
  210. Size urmResultSize = const Size(0, 0);
  211. try {
  212. if (ref.application is! URMApplication) {
  213. return;
  214. }
  215. final URMApplication urmApplication = ref.application as URMApplication;
  216. urmResultSize = Size(urmApplication.resultWidth.toDouble(),
  217. urmApplication.resultHeight.toDouble());
  218. // urmResultWidth = urmApplication.resultWidth;
  219. // urmResultHeight = urmApplication.resultHeight;
  220. final point = ref.feature!.point.clone();
  221. final startPoint = point.scale2Size(urmResultSize);
  222. print("URM Measure startPoint: $startPoint");
  223. // await getSRLoactionVelResult(urmApplication, startPoint);
  224. return;
  225. } catch (e) {
  226. logger.e('URM Measure error: $e');
  227. return;
  228. }
  229. }
  230. // ✅ URM 测量项 6
  231. // Future<void> getSRLoactionVelResult(
  232. // URMApplication app, DPoint startPoint) async {
  233. // String description = "URM\n Measuring";
  234. // try {
  235. // GetSRLoactionVelResult? result =
  236. // await app.getSRLoactionVelResult(startPoint);
  237. // if (result != null) {
  238. // print("URM Measure output: ${result.output}");
  239. // final feature = ref.feature!;
  240. // for (var output in ref.meta.outputs) {
  241. // if (output.name == MeasureTerms.SRVel) {
  242. // output.unit = VidUsUnit.mms;
  243. // feature.updateFloatValue(output, result.output, output.unit);
  244. // }
  245. // }
  246. // } else {
  247. // throw Exception("URM Measure API error");
  248. // }
  249. // } catch (e) {
  250. // description = " ";
  251. // updateStringValue(description);
  252. // return;
  253. // }
  254. // ref.application.updateRenderReady.emit(this, null);
  255. // }
  256. }
  257. /// 自动弯曲度测量
  258. // class URMAutoLineLineCal extends Calculator<StraightLine, double> {
  259. // URMAutoLineLineCal(
  260. // StraightLine ref, {
  261. // required this.type,
  262. // }) : super(ref);
  263. // final String type;
  264. // @override
  265. // void calculate() {}
  266. // @override
  267. // Future<void> calculateAsync() async {
  268. // try {
  269. // if (ref.feature == null) return;
  270. // if (ref.application is! URMApplication) return;
  271. // Size urmResultSize = const Size(0, 0);
  272. // final URMApplication urmApplication = ref.application as URMApplication;
  273. // urmResultSize = Size(urmApplication.resultWidth.toDouble(),
  274. // urmApplication.resultHeight.toDouble());
  275. // final p1 = ref.feature!.startPoint;
  276. // final p2 = ref.feature!.endPoint;
  277. // // final startPoint = leftTopPercent.scale2Size(urmResultSize);
  278. // // final endPoint = rightBottomPercent.scale2Size(urmResultSize);
  279. // // final startPoint = DPoint(0.478335, 0.315384);
  280. // // final endPoint = DPoint(0.538395, 0.526373);
  281. // switch (type) {
  282. // case MeasureTypes.SRCurvature:
  283. // await getSRCurvatureResult(urmApplication, p1, p2);
  284. // break;
  285. // // case MeasureTypes.URMDensityMeasure:
  286. // // await getURMDenMeasureResult(urmApplication, startPoint, endPoint);
  287. // // break;
  288. // // case MeasureTypes.URMVesselMeasure:
  289. // // final feature = ref.feature!;
  290. // // final viewport = feature.hostVisualArea!.viewport!;
  291. // // final p1 = feature.startPoint;
  292. // // final p2 = feature.endPoint;
  293. // // final pp1 = viewport.convert(p1);
  294. // // final pp2 = viewport.convert(p2);
  295. // // final cmlength = (pp2 - pp1).length.abs();
  296. // // await getURMVessMeasureResult(
  297. // // urmApplication, startPoint, endPoint, cmlength);
  298. // // break;
  299. // default:
  300. // }
  301. // } catch (e) {
  302. // logger.e('URM Measure error: $e');
  303. // return;
  304. // }
  305. // }
  306. // // // ✅ URM 测量项 1
  307. // Future<void> getSRCurvatureResult(
  308. // URMApplication app, DPoint startPoint, DPoint endPoint) async {
  309. // String description = "URM\n Measuring";
  310. // try {
  311. // URMMeasureProcessResult? result = await app.getURMMeasureResult(
  312. // urmMeasureType: URMMeasureType.URMCurvature,
  313. // rOIType: URMROIType.placeHolder_0,
  314. // srcDPoints: [
  315. // UrmPoint(x: startPoint.x, y: startPoint.y),
  316. // UrmPoint(x: endPoint.x, y: endPoint.y)
  317. // ],
  318. // );
  319. // if (result != null) {
  320. // print(
  321. // "URM Measure curvature: ${result} nums: ${result.resultDPoints?.length}");
  322. // // TODO 将返回的视图百分比区域的点集转换为全图百分比点集,然会然后绘制
  323. // final feature = ref.feature!;
  324. // if (feature is! StraightCurvatureFeature) return;
  325. // feature.autoLinePoints = urmPointsToDPoints(result.resultDPoints);
  326. // /// TODO 只转数据类型还不够,需要将 视图区域百分比坐标转为全图百分比坐标
  327. // for (var output in ref.meta.outputs) {
  328. // if (output.name == MeasureTerms.SRCurvature) {
  329. // output.unit = VidUsUnit.None;
  330. // feature.updateFloatValue(output, result.resultData, output.unit);
  331. // }
  332. // }
  333. // } else {
  334. // throw Exception("URM Measure API error");
  335. // }
  336. // } catch (e) {
  337. // description = " ";
  338. // updateStringValue(description);
  339. // return;
  340. // }
  341. // ref.application.updateRenderReady.emit(this, null);
  342. // }
  343. // // //✅ URM 测量项 8
  344. // // Future<void> getURMDenMeasureResult(
  345. // // URMApplication app, DPoint startPoint, DPoint endPoint) async {
  346. // // String description = "URM\n Measuring";
  347. // // try {
  348. // // GetURMDenMeasureResult? result =
  349. // // await app.getURMDenMeasureResult(startPoint, endPoint);
  350. // // if (result != null) {
  351. // // print(
  352. // // "URM Measure inMaxDensity: ${result.inMaxDensity} inMeanDensity: ${result.inMeanDensity}");
  353. // // // description = "${(result.inMaxDensity).toStringAsFixed(2)}mm/s ...";
  354. // // final feature = ref.feature!;
  355. // // for (var output in ref.meta.outputs) {
  356. // // if (output.name == MeasureTerms.URMDenROI) {
  357. // // output.unit = VidUsUnit.percent;
  358. // // feature.updateFloatValue(
  359. // // output, result.roiDen * 100, VidUsUnit.percent);
  360. // // }
  361. // // if (output.name == MeasureTerms.URMDenFractalDim) {
  362. // // output.unit = VidUsUnit.None;
  363. // // feature.updateFloatValue(
  364. // // output, result.roiFractalDim, VidUsUnit.None);
  365. // // }
  366. // // if (output.name == MeasureTerms.URMDenMax) {
  367. // // output.unit = VidUsUnit.None;
  368. // // feature.updateFloatValue(output, result.maxDensity, VidUsUnit.None);
  369. // // }
  370. // // if (output.name == MeasureTerms.URMDenMin) {
  371. // // output.unit = VidUsUnit.None;
  372. // // feature.updateFloatValue(output, result.minDensity, VidUsUnit.None);
  373. // // }
  374. // // if (output.name == MeasureTerms.URMDenMean) {
  375. // // output.unit = VidUsUnit.None;
  376. // // feature.updateFloatValue(
  377. // // output, result.meanDensity, VidUsUnit.None);
  378. // // }
  379. // // if (output.name == MeasureTerms.URMDenStd) {
  380. // // output.unit = VidUsUnit.None;
  381. // // feature.updateFloatValue(
  382. // // output, sqrt(result.varianceDensity), VidUsUnit.None);
  383. // // }
  384. // // if (output.name == MeasureTerms.Area) {
  385. // // output.unit = VidUsUnit.cm2;
  386. // // feature.updateFloatValue(output, result.roiArea, VidUsUnit.cm2);
  387. // // }
  388. // // }
  389. // // } else {
  390. // // throw Exception("URM Measure API error");
  391. // // }
  392. // // } catch (e) {
  393. // // description = " ";
  394. // // updateStringValue(description);
  395. // // return;
  396. // // }
  397. // // ref.application.updateRenderReady.emit(this, null);
  398. // // }
  399. // // //✅ URM 测量项 10
  400. // // Future<void> getURMVessMeasureResult(URMApplication app, DPoint startPoint,
  401. // // DPoint endPoint, double cmlength) async {
  402. // // String description = "URM\n Measuring";
  403. // // try {
  404. // // GetUrmVessMeasureResult? result =
  405. // // await app.getURMVessMeasureResult(startPoint, endPoint, cmlength);
  406. // // if (result != null) {
  407. // // app.onUpdateChart?.call(
  408. // // URMChartParams(
  409. // // cmlength: cmlength,
  410. // // minPointIndex: result.minPos,
  411. // // maxPointIndex: result.maxPos,
  412. // // points: convertPoints(result.outputPoints),
  413. // // ),
  414. // // );
  415. // // print(
  416. // // "URM Measure inMaxDensity: ${result.maxVessDiameter} inMeanDensity: ${result.meanVessDistacne}");
  417. // // final feature = ref.feature!;
  418. // // for (var output in ref.meta.outputs) {
  419. // // if (output.name == MeasureTerms.MaxVessDistance) {
  420. // // output.unit = VidUsUnit.mm;
  421. // // feature.updateFloatValue(
  422. // // output, result.maxVessDistance, VidUsUnit.mm);
  423. // // }
  424. // // if (output.name == MeasureTerms.MinVessDistance) {
  425. // // output.unit = VidUsUnit.mm;
  426. // // feature.updateFloatValue(
  427. // // output, result.minVessDistance, VidUsUnit.mm);
  428. // // }
  429. // // if (output.name == MeasureTerms.MeanVessDistacne) {
  430. // // output.unit = VidUsUnit.mm;
  431. // // feature.updateFloatValue(
  432. // // output, result.meanVessDistacne, VidUsUnit.mm);
  433. // // }
  434. // // if (output.name == MeasureTerms.StdVessDistance) {
  435. // // output.unit = VidUsUnit.mm;
  436. // // feature.updateFloatValue(
  437. // // output, sqrt(result.varianceVessDistance), VidUsUnit.mm);
  438. // // }
  439. // // if (output.name == MeasureTerms.MaxVessDiameter) {
  440. // // output.unit = VidUsUnit.mm;
  441. // // feature.updateFloatValue(
  442. // // output, result.maxVessDiameter, VidUsUnit.mm);
  443. // // }
  444. // // if (output.name == MeasureTerms.MinVessDiameter) {
  445. // // output.unit = VidUsUnit.mm;
  446. // // feature.updateFloatValue(
  447. // // output, result.minVessDiameter, VidUsUnit.mm);
  448. // // }
  449. // // if (output.name == MeasureTerms.MeanVessDiameter) {
  450. // // output.unit = VidUsUnit.mm;
  451. // // feature.updateFloatValue(
  452. // // output, result.meanVessDiameter, VidUsUnit.mm);
  453. // // }
  454. // // if (output.name == MeasureTerms.StdVessDiameter) {
  455. // // output.unit = VidUsUnit.mm;
  456. // // feature.updateFloatValue(
  457. // // output, sqrt(result.varianceVessDiameter), VidUsUnit.mm);
  458. // // }
  459. // // }
  460. // // } else {
  461. // // throw Exception("URM Measure API error");
  462. // // }
  463. // // } catch (e) {
  464. // // description = " ";
  465. // // updateStringValue(description);
  466. // // return;
  467. // // }
  468. // // ref.application.updateRenderReady.emit(this, null);
  469. // // }
  470. // List<DPoint> urmPointsToDPoints(List<UrmPoint>? points) {
  471. // if (points == null) return [];
  472. // List<DPoint> urmPoints = [];
  473. // for (var point in points) {
  474. // urmPoints.add(DPoint(point.x, point.y));
  475. // }
  476. // return urmPoints;
  477. // }
  478. // //
  479. // }
  480. class URMTraceCal extends Calculator<AreaItemAbstract, double> {
  481. URMTraceCal(
  482. AreaItemAbstract ref, {
  483. required this.type,
  484. }) : super(ref);
  485. final String type;
  486. @override
  487. void calculate() {}
  488. @override
  489. Future<void> calculateAsync() async {
  490. if (ref.feature == null) return;
  491. final feature = ref.feature!;
  492. try {
  493. if (ref.application is! URMApplication) {
  494. return;
  495. }
  496. Size urmResultSize = const Size(0, 0);
  497. final URMApplication urmApplication = ref.application as URMApplication;
  498. urmResultSize = Size(urmApplication.resultWidth.toDouble(),
  499. urmApplication.resultHeight.toDouble());
  500. final List<DPoint> points =
  501. feature.innerPoints.map((e) => e.scale2Size(urmResultSize)).toList();
  502. // switch (type) {
  503. // case MeasureTypes.SRTraceDensity:
  504. // await getSRTraceVelResult(urmApplication, convertPoints(points));
  505. // break;
  506. // case MeasureTypes.SRTraceFractalDim:
  507. // await getSRTraceFractalDimResult(
  508. // urmApplication, convertPoints(points));
  509. // break;
  510. // default:
  511. // }
  512. } catch (e) {
  513. logger.e('URM Measure error: $e');
  514. return;
  515. }
  516. }
  517. // //✅ URM 测量项 4
  518. // Future<void> getSRTraceVelResult(
  519. // URMApplication app, List<UrmPoint> points) async {
  520. // String description = "URM\n Measuring";
  521. // try {
  522. // GetSRTraceVelResult? result = await app.getSRTraceVelResult(points);
  523. // if (result != null) {
  524. // print("URM Measure output: ${result.output} ");
  525. // final feature = ref.feature!;
  526. // for (var output in ref.meta.outputs) {
  527. // if (output.name == MeasureTerms.URMDenROI) {
  528. // output.unit = VidUsUnit.percent;
  529. // feature.updateFloatValue(output, result.output, output.unit);
  530. // }
  531. // }
  532. // } else {
  533. // throw Exception("URM Measure API error");
  534. // }
  535. // } catch (e) {
  536. // description = " ";
  537. // updateStringValue(description);
  538. // return;
  539. // }
  540. // ref.application.updateRenderReady.emit(this, null);
  541. // }
  542. // //✅ URM 测量项 5
  543. // Future<void> getSRTraceFractalDimResult(
  544. // URMApplication app, List<UrmPoint> points) async {
  545. // String description = "URM\n Measuring";
  546. // try {
  547. // GetSRTraceFractalDimResult? result =
  548. // await app.getSRTraceFractalDimResult(points);
  549. // if (result != null) {
  550. // print("URM Measure output: ${result.output} ");
  551. // final feature = ref.feature!;
  552. // for (var output in ref.meta.outputs) {
  553. // if (output.name == MeasureTerms.URMDenFractalDim) {
  554. // output.unit = VidUsUnit.None;
  555. // feature.updateFloatValue(output, result.output, output.unit);
  556. // }
  557. // }
  558. // } else {
  559. // throw Exception("URM Measure API error");
  560. // }
  561. // } catch (e) {
  562. // description = " ";
  563. // updateStringValue(description);
  564. // return;
  565. // }
  566. // ref.application.updateRenderReady.emit(this, null);
  567. // }
  568. List<UrmPoint> convertPoints(List<DPoint> points) {
  569. List<UrmPoint> urmPoints = [];
  570. for (var point in points) {
  571. urmPoints.add(UrmPoint(x: point.x, y: point.y));
  572. }
  573. return urmPoints;
  574. }
  575. }
  576. class URMVelCal extends Calculator<URMVelAbstract, double> {
  577. URMVelCal(URMVelAbstract ref) : super(ref);
  578. @override
  579. void calculate() {
  580. if (ref.feature == null) return;
  581. final a1 = _pickChildValue(ref.child1);
  582. final a2 = _pickChildValue(ref.child2);
  583. final a3 = _pickChildValue(ref.child2);
  584. final feature = ref.feature!;
  585. final viewport = feature.hostVisualArea!.viewport!;
  586. // if (a1 != null && a2 != null) {
  587. // final value = GeneralFormulas.countStenosis(
  588. // a1,
  589. // a2,
  590. // );
  591. // updateFloatValue(value);
  592. // }
  593. }
  594. double? _pickChildValue(MeasureItem item) {
  595. if (item.calculator == null) return null;
  596. ValueBase? value;
  597. if (item.measuredFeatures.isNotEmpty) {
  598. value = item.measuredFeatures.first.value;
  599. } else if (item.feature != null) {
  600. value = item.feature!.value;
  601. }
  602. if (value != null && value is FloatValue) {
  603. return (value).value ?? 0;
  604. }
  605. return null;
  606. }
  607. }
  608. class URMSrDensityCal extends Calculator<URMTwoSRRoiRectAbstract, double> {
  609. URMSrDensityCal(URMTwoSRRoiRectAbstract ref) : super(ref);
  610. @override
  611. void calculate() {
  612. if (ref.feature == null) return;
  613. final a1 = _pickChildValue(ref.child1);
  614. final a2 = _pickChildValue(ref.child2);
  615. final a3 = _pickChildValue(ref.child2);
  616. final feature = ref.feature!;
  617. final viewport = feature.hostVisualArea!.viewport!;
  618. // if (a1 != null && a2 != null) {
  619. // final value = GeneralFormulas.countStenosis(
  620. // a1,
  621. // a2,
  622. // );
  623. // updateFloatValue(value);
  624. // }
  625. }
  626. double? _pickChildValue(MeasureItem item) {
  627. if (item.calculator == null) return null;
  628. ValueBase? value;
  629. if (item.measuredFeatures.isNotEmpty) {
  630. value = item.measuredFeatures.first.value;
  631. } else if (item.feature != null) {
  632. value = item.feature!.value;
  633. }
  634. if (value != null && value is FloatValue) {
  635. return (value).value ?? 0;
  636. }
  637. return null;
  638. }
  639. }