import 'dart:typed_data'; import 'package:vid/us/vid_us_data_reader.dart'; import 'package:vid/us/vid_us_data_writer.dart'; enum PhysicalCoordinateType { Tissue, TimeMotion, ConvexTissue, LinearTissue, ConvexTVTissue, LinearTVTissue, Doppler, TissueTimeMotion, MAM, PWV } class VidUsPhysicalCoordinate { late PhysicalCoordinateType _type; Uint8List toBytes() { var writer = new VidUsDataWriter(); writer.writeByte(_type.index); return writer.data; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; switch (type) { case PhysicalCoordinateType.ConvexTissue: return VidUsConvexTissuePhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.LinearTissue: return VidUsLinearTissuePhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.ConvexTVTissue: return VidUsConvexTVTissuePhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.LinearTVTissue: return VidUsLinearTVTissuePhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.Doppler: return VidUsDopplerPhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.TissueTimeMotion: return VidUsTissueTimeMotionPhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.MAM: return VidUsMAMPhysicalCoordinate.fromBytes(bytes); case PhysicalCoordinateType.PWV: return VidUsPWVPhysicalCoordinate.fromBytes(bytes); default: throw new Exception("Not supported CoordinateType $type"); } } } class VidUsTissuePhysicalCoordinate extends VidUsPhysicalCoordinate { late double _depthEnd; late double _depthStart; late double _width; late double _beamPosition; double get depthEnd => _depthEnd; double get depthStart => _depthStart; double get width => _width; double get beamPosition => _beamPosition; VidUsTissuePhysicalCoordinate( double depthEnd, double depthStart, double width, double beamPosition) { _type = PhysicalCoordinateType.Tissue; _beamPosition = beamPosition; _width = width; _depthStart = depthStart; _depthEnd = depthEnd; } @override Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_depthStart); writer.writeDouble(_depthEnd); writer.writeDouble(_width); writer.writeDouble(_beamPosition); return writer.data; } } class VidUsTimeMotionPhysicalCoordinate extends VidUsPhysicalCoordinate { late double _sweepSpeed; late double _max; late double _min; double get sweepSpeed => _sweepSpeed; double get max => _max; double get min => _min; VidUsTimeMotionPhysicalCoordinate(double sweepSpeed, double max, double min) { _type = PhysicalCoordinateType.TimeMotion; _min = min; _max = max; _sweepSpeed = sweepSpeed; } @override Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_min); writer.writeDouble(_max); writer.writeDouble(_sweepSpeed); return writer.data; } } class VidUsConvexTissuePhysicalCoordinate extends VidUsTissuePhysicalCoordinate { late double _zeroRadius; double get zeroRadius => _zeroRadius; VidUsConvexTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius) : super(depthEnd, depthStart, width, beamPosition) { _type = PhysicalCoordinateType.ConvexTissue; _zeroRadius = zeroRadius; } @override Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_zeroRadius); return writer.data; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.ConvexTissue) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.ConvexTissue)}, source type:{$type}"); } var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); var width = reader.readDouble(); var beamPosition = reader.readDouble(); var zeroRadius = reader.readDouble(); return new VidUsConvexTissuePhysicalCoordinate( depthEnd, depthStart, width, beamPosition, zeroRadius); } } class VidUsLinearTissuePhysicalCoordinate extends VidUsTissuePhysicalCoordinate { late double _steer; double get steer => _steer; VidUsLinearTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double steer) : super(depthEnd, depthStart, width, beamPosition) { _type = PhysicalCoordinateType.LinearTissue; _steer = steer; } @override Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_steer); return writer.data; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.LinearTissue) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.LinearTissue}, source type:{$type}"); } var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); var width = reader.readDouble(); var beamPosition = reader.readDouble(); var steer = reader.readDouble(); return new VidUsLinearTissuePhysicalCoordinate( depthEnd, depthStart, width, beamPosition, steer); } } class VidUsConvexTVTissuePhysicalCoordinate extends VidUsConvexTissuePhysicalCoordinate { late double _originalRocx; late double _originalZeroRadius; double get originalZeroRadius => _originalZeroRadius; double get originalRocx => _originalRocx; VidUsConvexTVTissuePhysicalCoordinate( double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius, double originalZeroRadius, double originalRocx) : super(depthEnd, depthStart, width, beamPosition, zeroRadius) { _type = PhysicalCoordinateType.ConvexTVTissue; _originalRocx = originalRocx; _originalZeroRadius = originalZeroRadius; } Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_originalZeroRadius); writer.writeDouble(_originalRocx); return writer.data; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.ConvexTVTissue) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.ConvexTVTissue}, source type:{$type}"); } var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); var width = reader.readDouble(); var beamPosition = reader.readDouble(); var zeroRadius = reader.readDouble(); var originalZeroRadius = reader.readDouble(); var originalRocx = reader.readDouble(); return new VidUsConvexTVTissuePhysicalCoordinate(depthEnd, depthStart, width, beamPosition, zeroRadius, originalZeroRadius, originalRocx); } } class VidUsLinearTVTissuePhysicalCoordinate extends VidUsConvexTissuePhysicalCoordinate { VidUsLinearTVTissuePhysicalCoordinate(double depthEnd, double depthStart, double width, double beamPosition, double zeroRadius) : super(depthEnd, depthStart, width, beamPosition, zeroRadius) { _type = PhysicalCoordinateType.LinearTVTissue; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.LinearTVTissue) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.LinearTVTissue}, source type:{$type}"); } var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); var width = reader.readDouble(); var beamPosition = reader.readDouble(); var zeroRadius = reader.readDouble(); return new VidUsLinearTVTissuePhysicalCoordinate( depthEnd, depthStart, width, beamPosition, zeroRadius); } } class VidUsDopplerPhysicalCoordinate extends VidUsTimeMotionPhysicalCoordinate { late double _baseLine; double get baseLine => _baseLine; VidUsDopplerPhysicalCoordinate( double sweepSpeed, double max, double min, double baseLine) : super(sweepSpeed, max, min) { _type = PhysicalCoordinateType.Doppler; _baseLine = baseLine; } @override Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_baseLine); return writer.data; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.Doppler) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.Doppler}, source type:{$type}"); } var min = reader.readDouble(); var max = reader.readDouble(); var sweepSpeed = reader.readDouble(); var baseLine = reader.readDouble(); return new VidUsDopplerPhysicalCoordinate(sweepSpeed, max, min, baseLine); } } class VidUsTissueTimeMotionPhysicalCoordinate extends VidUsTimeMotionPhysicalCoordinate { late double _depthStart; late double _depthEnd; double get depthStart => _depthStart; double get depthEnd => _depthEnd; VidUsTissueTimeMotionPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd) : super(sweepSpeed, max, min) { _type = PhysicalCoordinateType.TissueTimeMotion; _depthEnd = depthEnd; _depthStart = depthStart; } Uint8List toBytes() { var writer = new VidUsDataWriter(); var baseData = super.toBytes(); writer.writeBytes(baseData); writer.writeDouble(_depthStart); writer.writeDouble(_depthEnd); return writer.data; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.TissueTimeMotion) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.TissueTimeMotion}, source type:{$type}"); } var min = reader.readDouble(); var max = reader.readDouble(); var sweepSpeed = reader.readDouble(); var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); return new VidUsTissueTimeMotionPhysicalCoordinate( sweepSpeed, max, min, depthStart, depthEnd); } } class VidUsMAMPhysicalCoordinate extends VidUsTissueTimeMotionPhysicalCoordinate { VidUsMAMPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd) : super(sweepSpeed, max, min, depthStart, depthEnd) { _type = PhysicalCoordinateType.MAM; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.MAM) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.MAM}, source type:{$type}"); } var min = reader.readDouble(); var max = reader.readDouble(); var sweepSpeed = reader.readDouble(); var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); return new VidUsMAMPhysicalCoordinate( sweepSpeed, max, min, depthStart, depthEnd); } } class VidUsPWVPhysicalCoordinate extends VidUsTissueTimeMotionPhysicalCoordinate { VidUsPWVPhysicalCoordinate(double sweepSpeed, double max, double min, double depthStart, double depthEnd) : super(sweepSpeed, max, min, depthStart, depthEnd) { _type = PhysicalCoordinateType.PWV; } static VidUsPhysicalCoordinate fromBytes(Uint8List bytes) { var reader = new VidUsDataReader(bytes); var type = PhysicalCoordinateType.values[reader.readByte()]; if (type != PhysicalCoordinateType.PWV) { throw new Exception( "Type not matched, target type:{$PhysicalCoordinateType.PWV}, source type:{$type}"); } var min = reader.readDouble(); var max = reader.readDouble(); var sweepSpeed = reader.readDouble(); var depthStart = reader.readDouble(); var depthEnd = reader.readDouble(); return new VidUsPWVPhysicalCoordinate( sweepSpeed, max, min, depthStart, depthEnd); } }