| | 1 | | using MorphoGeometry; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.IO; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Text; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | |
|
| | 9 | | namespace MorphoReader |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Grid output of envimet. |
| | 13 | | /// </summary> |
| | 14 | | public class GridOutput : BinaryOutput |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Create a new grid output object. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="edx">EDX file.</param> |
| | 20 | | public GridOutput(string edx) |
| 1 | 21 | | : base(edx) |
| 1 | 22 | | { |
| 1 | 23 | | _offset = _buffer = 4 * _numX * _numY * _numZ; |
| | 24 | |
|
| 1 | 25 | | BasePoint = new Vector(0, 0, 0); |
| 1 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Create a new grid output object. |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="edx">EDX file.</param> |
| | 32 | | /// <param name="basePoint">Base point.</param> |
| | 33 | | public GridOutput(string edx, Vector basePoint) |
| 0 | 34 | | : this(edx) |
| 0 | 35 | | { |
| 0 | 36 | | BasePoint = basePoint; |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Set values from a binary file. |
| | 41 | | /// </summary> |
| | 42 | | /// <param name="edt">EDT file.</param> |
| | 43 | | /// <param name="voxels">Voxels to map.</param> |
| | 44 | | /// <param name="variable">Variable to read.</param> |
| | 45 | | public override void SetValuesFromBinary(string edt, |
| | 46 | | List<Voxel> voxels, int variable) |
| 1 | 47 | | { |
| 1 | 48 | | using (FileStream SourceStream = File.Open(edt, FileMode.Open)) |
| 1 | 49 | | { |
| 1 | 50 | | BinaryReader binReader = new BinaryReader(SourceStream); |
| | 51 | |
|
| 1 | 52 | | binReader.BaseStream.Position = _buffer * variable; |
| 1 | 53 | | byte[] dateArray = binReader.ReadBytes(_buffer); |
| | 54 | |
|
| | 55 | | /* |
| | 56 | | * |----| |
| | 57 | | */ |
| | 58 | |
|
| 1 | 59 | | int count = 0; |
| | 60 | | float number; |
| 178294 | 61 | | for (int i = 0; i < dateArray.Length; i += 4) |
| 89146 | 62 | | { |
| 89146 | 63 | | number = BitConverter.ToSingle(dateArray, i); |
| 89146 | 64 | | voxels[count].ValueZ = number; |
| 89146 | 65 | | count++; |
| 89146 | 66 | | } |
| 1 | 67 | | } |
| 1 | 68 | | } |
| | 69 | | } |
| | 70 | | } |