1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import 'dart:typed_data';
- import 'package:vid/us/vid_us_data_reader.dart';
- import 'package:vid/us/vid_us_data_writer.dart';
- import 'package:vid/us/vid_us_display_mode.dart';
- import 'package:vid/us/vid_us_mode.dart';
- import 'package:vid/us/vid_us_tissue_3d_area.dart';
- import 'package:vid/us/vid_us_visual.dart';
- import 'package:vid/us/vid_us_visual_indicator.dart';
- import 'package:vid/us/vid_us_visual_type.dart';
- class VidUs3DVisual extends VidUsVisual {
- late List<VidUsTissue3DArea> _tissue3DAreas;
- /// Gets the tissue 3d areas for this visual.
- List<VidUsTissue3DArea> get tissue3DAreas => _tissue3DAreas;
- VidUs3DVisual() {
- super.setVisualType(VidUsVisualType.V3D);
- _tissue3DAreas = [];
- }
- ///Convert VidUs3DVisual to binary data.
- @override
- Uint8List toBytes() {
- var baseData = super.toBytes();
- var writer = new VidUsDataWriter();
- writer.writeBytes(baseData);
- writer.writeByte(_tissue3DAreas.length);
- _tissue3DAreas.forEach((area) {
- writer.writeBytes(area.toBytes());
- });
- return writer.data;
- }
- ///Convert binary data to VidUs3DVisual.
- static VidUsVisual fromBytes(Uint8List bytes) {
- var reader = new VidUsDataReader(bytes);
- var visualType = VidUsVisualType.values[reader.readByte()];
- var displayMode = VidUsDisplayMode.values[reader.readByte()];
- if (visualType == VidUsVisualType.V3D) {
- var indicator = VidUsVisualIndicator.values[reader.readByte()];
- var visual = new VidUs3DVisual();
- visual.setIndicator(indicator);
- var activeModeType = VidUsModeType.values[reader.readByte()];
- var modeCount = reader.readByte();
- for (int i = 0; i < modeCount; i++) {
- var mode = VidUsMode.fromBytes(reader.readBytes());
- visual.modes.add(mode);
- }
- visual.setActiveModeType(activeModeType);
- var tissue3DAreaCount = reader.readByte();
- for (int i = 0; i < tissue3DAreaCount; i++) {
- var tissue3DArea = VidUsTissue3DArea.fromBytes(reader.readBytes());
- visual.tissue3DAreas.add(tissue3DArea);
- }
- visual.setDisplayMode(displayMode);
- return visual;
- }
- throw new Exception(
- "Can not restore visual data from $visualType to VidUs3DVisual.");
- }
- }
|