vid_us_3d_visual.dart 2.2 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_display_mode.dart';
  5. import 'package:vid/us/vid_us_mode.dart';
  6. import 'package:vid/us/vid_us_tissue_3d_area.dart';
  7. import 'package:vid/us/vid_us_visual.dart';
  8. import 'package:vid/us/vid_us_visual_indicator.dart';
  9. import 'package:vid/us/vid_us_visual_type.dart';
  10. class VidUs3DVisual extends VidUsVisual {
  11. late List<VidUsTissue3DArea> _tissue3DAreas;
  12. /// Gets the tissue 3d areas for this visual.
  13. List<VidUsTissue3DArea> get tissue3DAreas => _tissue3DAreas;
  14. VidUs3DVisual() {
  15. super.setVisualType(VidUsVisualType.V3D);
  16. _tissue3DAreas = [];
  17. }
  18. ///Convert VidUs3DVisual to binary data.
  19. @override
  20. Uint8List toBytes() {
  21. var baseData = super.toBytes();
  22. var writer = new VidUsDataWriter();
  23. writer.writeBytes(baseData);
  24. writer.writeByte(_tissue3DAreas.length);
  25. _tissue3DAreas.forEach((area) {
  26. writer.writeBytes(area.toBytes());
  27. });
  28. return writer.data;
  29. }
  30. ///Convert binary data to VidUs3DVisual.
  31. static VidUsVisual fromBytes(Uint8List bytes) {
  32. var reader = new VidUsDataReader(bytes);
  33. var visualType = VidUsVisualType.values[reader.readByte()];
  34. var displayMode = VidUsDisplayMode.values[reader.readByte()];
  35. if (visualType == VidUsVisualType.V3D) {
  36. var indicator = VidUsVisualIndicator.values[reader.readByte()];
  37. var visual = new VidUs3DVisual();
  38. visual.setIndicator(indicator);
  39. var activeModeType = VidUsModeType.values[reader.readByte()];
  40. var modeCount = reader.readByte();
  41. for (int i = 0; i < modeCount; i++) {
  42. var mode = VidUsMode.fromBytes(reader.readBytes());
  43. visual.modes.add(mode);
  44. }
  45. visual.setActiveModeType(activeModeType);
  46. var tissue3DAreaCount = reader.readByte();
  47. for (int i = 0; i < tissue3DAreaCount; i++) {
  48. var tissue3DArea = VidUsTissue3DArea.fromBytes(reader.readBytes());
  49. visual.tissue3DAreas.add(tissue3DArea);
  50. }
  51. visual.setDisplayMode(displayMode);
  52. return visual;
  53. }
  54. throw new Exception(
  55. "Can not restore visual data from $visualType to VidUs3DVisual.");
  56. }
  57. }