|
@@ -0,0 +1,142 @@
|
|
|
+import 'dart:math';
|
|
|
+
|
|
|
+import 'package:fis_common/logger/logger.dart';
|
|
|
+import 'package:fis_jsonrpc/rpc.dart';
|
|
|
+import 'package:fis_measure/interfaces/process/items/terms.dart';
|
|
|
+import 'package:fis_measure/process/primitives/urm_measure/urm_vessel_measure.dart';
|
|
|
+
|
|
|
+
|
|
|
+import 'package:fis_measure/process/workspace/urm/application.dart';
|
|
|
+
|
|
|
+import 'dart:math' as math;
|
|
|
+import '../calculator.dart';
|
|
|
+
|
|
|
+class URMVesselMeasureCal extends Calculator<URMVesselMeasure, double> {
|
|
|
+ URMVesselMeasureCal(
|
|
|
+ URMVesselMeasure ref,
|
|
|
+ ) : super(ref);
|
|
|
+ URMSimpleMeasureParams? param;
|
|
|
+ @override
|
|
|
+ void calculate() {}
|
|
|
+
|
|
|
+ @override
|
|
|
+ Future<void> calculateAsync() async {
|
|
|
+ handleURMSimpleMeasureParams();
|
|
|
+ try {
|
|
|
+ if (ref.feature == null) return;
|
|
|
+ if (ref.application is! URMApplication) return;
|
|
|
+ final URMApplication urmApplication = ref.application as URMApplication;
|
|
|
+
|
|
|
+ URMMeasureProcessResult? outresult =
|
|
|
+ await urmApplication.getURMMeasureResult(
|
|
|
+ urmMeasureType: URMMeasureType.URMVesselMeasure,
|
|
|
+ rOIType: URMROIType.placeHolder_0,
|
|
|
+ srcDPoints: param!.srcDPoints,
|
|
|
+ );
|
|
|
+ if (outresult == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ URMVessMeasureResult? vessMeasureResult = outresult.vessMeasureResult;
|
|
|
+ if (vessMeasureResult == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ref.meta.outputs.isNotEmpty) {
|
|
|
+ final feature = ref.feature!;
|
|
|
+ if (feature == null) return;
|
|
|
+ final viewport = feature.hostVisualArea!.viewport!;
|
|
|
+ final p1 = feature.startPoint;
|
|
|
+ final p2 = feature.endPoint;
|
|
|
+ final pp1 = viewport.convert(p1);
|
|
|
+ final pp2 = viewport.convert(p2);
|
|
|
+ final cmlength = (pp2 - pp1).length.abs();
|
|
|
+
|
|
|
+ for (var output in ref.meta.outputs) {
|
|
|
+ if (output.name == MeasureTerms.MaxVessDistance) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.maxVessDistance, output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.MinVessDistance) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.minVessDistance, output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.MeanVessDistacne) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.meanVessDistacne, output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.StdVessDistance) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(output,
|
|
|
+ math.sqrt(vessMeasureResult.varianceVessDistance), output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.MaxVessDiameter) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.maxVessDiameter, output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.MinVessDiameter) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.minVessDiameter, output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.MeanVessDiameter) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.meanVessDiameter, output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.StdVessDiameter) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(output,
|
|
|
+ math.sqrt(vessMeasureResult.varianceVessDiameter), output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.VesselCount) {
|
|
|
+
|
|
|
+ feature.updateFloatValue(
|
|
|
+ output, vessMeasureResult.vesselCount.toDouble(), output.unit);
|
|
|
+ } else if (output.name == MeasureTerms.Distance) {
|
|
|
+
|
|
|
+
|
|
|
+ feature.updateFloatValue(output, cmlength, output.unit);
|
|
|
+ }
|
|
|
+ List<Point<num>> points = [];
|
|
|
+ outresult.resultDPoints?.forEach((element) {
|
|
|
+ points.add(Point(element.x, element.y));
|
|
|
+ });
|
|
|
+
|
|
|
+ urmApplication.onUpdateChart?.call(
|
|
|
+ URMChartParams(
|
|
|
+ cmlength: cmlength,
|
|
|
+ minPointIndex: vessMeasureResult.minPos,
|
|
|
+ maxPointIndex: vessMeasureResult.maxPos,
|
|
|
+ points: points,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ logger.e('URM Measure error: $e');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ref.application.updateRenderReady.emit(this, null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void handleURMSimpleMeasureParams() {
|
|
|
+ if (ref.feature == null) return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (ref.application is! URMApplication) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final URMApplication urmApplication = ref.application as URMApplication;
|
|
|
+
|
|
|
+ final p1 = ref.feature!.startPoint;
|
|
|
+ final p2 = ref.feature!.endPoint;
|
|
|
+
|
|
|
+ param = URMSimpleMeasureParams(
|
|
|
+ urmMeasureType: URMMeasureType.URMVesselMeasure,
|
|
|
+ rOIType: URMROIType.placeHolder_0,
|
|
|
+ srcDPoints: [
|
|
|
+ urmApplication.localToView(p1),
|
|
|
+ urmApplication.localToView(p2)
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ } catch (e) {
|
|
|
+ logger.e('URM handleURMSimpleMeasureParams error: $e');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|