vid_us_tissue_3d_area.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'dart:typed_data';
  2. import 'package:vid/us/vid_us_data_reader.dart';
  3. import 'package:vid/us/vid_us_data_writer.dart';
  4. import 'package:vid/us/vid_us_point.dart';
  5. import 'package:vid/us/vid_us_rect.dart';
  6. enum VidUs3DAreaIndicator { Global, A, B, C, ThreeD }
  7. class VidUsTissue3DArea {
  8. late VidUsRect _bounds;
  9. late double _cmPerPixel;
  10. late VidUsPoint _globalOffset;
  11. late VidUs3DAreaIndicator _indicator;
  12. VidUsRect get bounds => _bounds;
  13. double get cmPerPixel => _cmPerPixel;
  14. VidUsPoint get globalOffset => _globalOffset;
  15. VidUs3DAreaIndicator get indicator => _indicator;
  16. VidUsTissue3DArea(VidUsRect bounds, double cmPerPixel,
  17. VidUsPoint globalOffset, VidUs3DAreaIndicator indicator) {
  18. _indicator = indicator;
  19. _globalOffset = globalOffset;
  20. _cmPerPixel = cmPerPixel;
  21. _bounds = bounds;
  22. }
  23. Uint8List toBytes() {
  24. var writer = new VidUsDataWriter();
  25. writer.writeByte(_indicator.index);
  26. writer.writeDouble(_cmPerPixel);
  27. writer.writeDouble(_globalOffset.x);
  28. writer.writeDouble(_globalOffset.y);
  29. writer.writeDouble(_bounds.left);
  30. writer.writeDouble(_bounds.top);
  31. writer.writeDouble(_bounds.right);
  32. writer.writeDouble(_bounds.bottom);
  33. return writer.data;
  34. }
  35. static VidUsTissue3DArea fromBytes(Uint8List tissue3DAreaData) {
  36. var reader = new VidUsDataReader(tissue3DAreaData);
  37. var indicator = VidUs3DAreaIndicator.values[reader.readByte()];
  38. var cmPerPixel = reader.readDouble();
  39. var x = reader.readDouble();
  40. var y = reader.readDouble();
  41. var globalOffset = new VidUsPoint(x, y);
  42. var left = reader.readDouble();
  43. var top = reader.readDouble();
  44. var right = reader.readDouble();
  45. var bottom = reader.readDouble();
  46. var bounds = new VidUsRect.tlbr(
  47. new VidUsPoint(left, top), new VidUsPoint(right, bottom));
  48. return new VidUsTissue3DArea(bounds, cmPerPixel, globalOffset, indicator);
  49. }
  50. }