| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.IO; |
| | 4 | | using System.Linq; |
| | 5 | | using Morpho25.Utility; |
| | 6 | | using MorphoGeometry; |
| | 7 | |
|
| | 8 | | namespace MorphoReader |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Building output of envimet. |
| | 12 | | /// </summary> |
| | 13 | | public class BuildingOutput : BinaryOutput |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Create a new building output object. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="edx">EDX file.</param> |
| | 19 | | public BuildingOutput(string edx) |
| 0 | 20 | | : base(edx) |
| 0 | 21 | | { |
| 0 | 22 | | _offset = 4 * _numX * _numY * _numZ; |
| 0 | 23 | | _buffer = 4 * _numX * _numY * _numZ * 3; |
| | 24 | |
|
| 0 | 25 | | BasePoint = new Vector(0, 0, 0); |
| 0 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Create a new building output object. |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="edx">EDX file.</param> |
| | 32 | | /// <param name="basePoint">Base point.</param> |
| | 33 | | public BuildingOutput(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="facades">Facades to map.</param> |
| | 44 | | /// <param name="variable">Variable to read.</param> |
| | 45 | | public override void SetValuesFromBinary(string edt, |
| | 46 | | List<Voxel> facades, int variable) |
| 0 | 47 | | { |
| 0 | 48 | | using (FileStream SourceStream = File.Open(edt, FileMode.Open)) |
| 0 | 49 | | { |
| 0 | 50 | | BinaryReader binReader = new BinaryReader(SourceStream); |
| | 51 | |
|
| 0 | 52 | | binReader.BaseStream.Position = _buffer * variable + _offset; |
| 0 | 53 | | byte[] dateArray = binReader.ReadBytes(_buffer); |
| | 54 | |
|
| | 55 | | /* |
| | 56 | | * |----|----|----| |
| | 57 | | */ |
| | 58 | |
|
| 0 | 59 | | int facadeLength = 12; |
| | 60 | |
|
| 0 | 61 | | for (int f = 0; f < facades.Count; f++) |
| 0 | 62 | | { |
| 0 | 63 | | int count = 0; |
| 0 | 64 | | int start = f * facadeLength; |
| | 65 | |
|
| 0 | 66 | | for (int i = start; i < start + facadeLength; i += 4) |
| 0 | 67 | | { |
| 0 | 68 | | float number = BitConverter.ToSingle(dateArray, i); |
| 0 | 69 | | if (count == 0) |
| 0 | 70 | | facades[f].ValueX = number; |
| 0 | 71 | | else if (count == 1) |
| 0 | 72 | | facades[f].ValueY = number; |
| | 73 | | else |
| 0 | 74 | | facades[f].ValueZ = number; |
| | 75 | |
|
| 0 | 76 | | count++; |
| | 77 | |
|
| 0 | 78 | | if (count == 3) |
| 0 | 79 | | count = 0; |
| 0 | 80 | | } |
| | 81 | |
|
| 0 | 82 | | } |
| 0 | 83 | | } |
| 0 | 84 | | } |
| | 85 | | } |
| | 86 | | } |