12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System.Collections.Generic;
- using System.IO;
- namespace fis.Vid.Visuals
- {
- public class Vinno3DVisual:VinnoVisual
- {
- /// <summary>
- /// Gets the tissue 3d areas for this visual.
- /// </summary>
- public IList<VinnoTissue3DArea> Tissue3DAreas { get; }
- public Vinno3DVisual()
- {
- VisualType = VinnoVisualType.V3D;
- Tissue3DAreas = new List<VinnoTissue3DArea>();
- }
- public override byte[] ToBytes()
- {
- var baseData = base.ToBytes();
- byte[] result;
- using (var stream = new MemoryStream())
- {
- stream.Write(baseData, 0, baseData.Length);
- var writer = new VinnoStreamWriter(stream);
- writer.WriteByte((byte)Tissue3DAreas.Count);
- foreach (var tissue3DArea in Tissue3DAreas)
- {
- writer.WriteBytes(tissue3DArea.ToBytes());
- }
- result = stream.ToArray();
- }
- return result;
- }
- public new static VinnoVisual FromBytes(byte[] bytes)
- {
- Vinno3DVisual result = null;
- using (var stream = new MemoryStream(bytes))
- {
- stream.Position = 0;
- var reader = new VinnoStreamReader(stream);
- var visualType = (VinnoVisualType)reader.ReadByte();
- var displayMode = (VinnoDisplayMode)reader.ReadByte();
- if (visualType == VinnoVisualType.V3D)
- {
- var indicator = (VinnoVisualIndicator)reader.ReadByte();
- result = new Vinno3DVisual {Indicator = indicator};
- var activeModeType = (VinnoModeType)reader.ReadByte();
- var modeCount = reader.ReadByte();
- var modes = new List<VinnoMode>();
- for (int i = 0; i < modeCount; i++)
- {
- var mode = VinnoMode.FromBytes(reader.ReadBytes());
- modes.Add(mode);
- }
- foreach (var mode in modes)
- {
- result.Modes.Add(mode);
- }
- result.ActiveModeType = activeModeType;
- var tissue3DAreaCount = reader.ReadByte();
- var tissue3DAreas = new List<VinnoTissue3DArea>();
- for (int i = 0; i < tissue3DAreaCount; i++)
- {
- var tissue3DArea = VinnoTissue3DArea.FromBytes(reader.ReadBytes());
- tissue3DAreas.Add(tissue3DArea);
- }
- foreach (var tissue3DArea in tissue3DAreas)
- {
- result.Tissue3DAreas.Add(tissue3DArea);
- }
- result.DisplayMode = displayMode;
- }
- }
- return result;
- }
- }
- }
|