convex_tissue.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'dart:math' as math;
  2. import 'package:fis_measure/interfaces/date_types/point.dart';
  3. import 'package:fis_measure/interfaces/date_types/skew_transform.dart';
  4. import 'package:fis_measure/interfaces/process/physical_coordinates/physical_coordinate.dart';
  5. import 'package:flutter/foundation.dart';
  6. import 'package:vid/us/vid_us_physical_coordinate.dart';
  7. import 'package:vid/us/vid_us_visual_area_type.dart';
  8. class ConvexTissuePhysicalCoordinate implements ITissuePhysicalCoordinate {
  9. late final double _depthStart;
  10. late final double _depthEnd;
  11. late final double _width;
  12. late final double _beamPosition;
  13. late final double _zeroRadius;
  14. late final double _zeroY;
  15. ConvexTissuePhysicalCoordinate(
  16. VidUsConvexTissuePhysicalCoordinate vidData,
  17. ) {
  18. _depthStart = vidData.depthStart;
  19. _depthEnd = vidData.depthEnd;
  20. _width = vidData.width;
  21. _beamPosition = vidData.beamPosition;
  22. _zeroRadius = vidData.zeroRadius;
  23. _zeroY = -math.cos((_width / 2) / 180 * math.pi) * _zeroRadius;
  24. }
  25. @override
  26. VidUsVisualAreaType get areaType => VidUsVisualAreaType.Tissue;
  27. @override
  28. double get depthEnd => _depthEnd;
  29. @override
  30. double get depthStart => _depthStart;
  31. @override
  32. double get width => _width;
  33. @override
  34. double get beamPosition => _beamPosition;
  35. /// 可见扇形边到圆点的距离
  36. double get zeroRadius => _zeroRadius;
  37. /// 圆心点Y轴位置
  38. double get zeroY => _zeroY;
  39. @override
  40. DPoint convert(DPoint pointInLogical) {
  41. double depth = math.sqrt(math.pow(pointInLogical.x, 2) +
  42. math.pow(pointInLogical.y + zeroRadius, 2)) -
  43. zeroRadius;
  44. double tilt =
  45. toDegrees(math.atan2(pointInLogical.x, pointInLogical.y + zeroRadius));
  46. return DPoint(tilt, depth);
  47. }
  48. @override
  49. DPoint convertBack(DPoint pointInPhysical) {
  50. int ratio = pointInPhysical.x >= 0 ? 1 : -1;
  51. var angle = pointInPhysical.x.abs();
  52. double radian = (math.pi / 180) * angle.abs();
  53. double x = ratio * math.sin(radian) * (pointInPhysical.y + zeroRadius);
  54. double y = math.cos(radian) * (pointInPhysical.y + zeroRadius) - zeroRadius;
  55. return DPoint(x, y);
  56. }
  57. @protected
  58. double toDegrees(double angle) {
  59. return angle / math.pi * 180;
  60. }
  61. }