< Summary

Information
Class: MorphoReader.BinaryOutput
Assembly: MorphoReader
File(s): D:\a\Morpho\Morpho\project\Morpho\MorphoReader\BinaryOutput.cs
Line coverage
76%
Covered lines: 87
Uncovered lines: 27
Coverable lines: 114
Total lines: 273
Line coverage: 76.3%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_NumX()100%1100%
get_NumY()100%1100%
get_NumZ()100%10%
get_VariableName()100%1100%
get_BasePoint()100%1100%
get_DataContent()100%1100%
get_ProjectName()100%1100%
get_LocationName()100%1100%
get_SimulationDate()100%1100%
get_SimulationTime()100%1100%
.ctor(...)100%1100%
SetVariableName(...)100%1100%
SetSpacing(...)100%1100%
Setsequence(...)100%1100%
SetNumberOfCells(...)100%1100%
SetGeneralInfo(...)100%1100%
GetFacadesFromBinary(...)100%6100%
FaceX(...)100%10%
FaceY(...)100%10%
FaceZ(...)100%1100%
GetVoxels(...)50%460%

File(s)

D:\a\Morpho\Morpho\project\Morpho\MorphoReader\BinaryOutput.cs

#LineLine coverage
 1using Morpho25.Utility;
 2using MorphoGeometry;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Text;
 7using System.Threading.Tasks;
 8
 9
 10namespace MorphoReader
 11{
 12    /// <summary>
 13    /// Direction enum.
 14    /// </summary>
 15    public enum Direction
 16    {
 17        X,
 18        Y,
 19        Z
 20    }
 21
 22    /// <summary>
 23    /// Binary output of envimet.
 24    /// </summary>
 25    public abstract class BinaryOutput
 26    {
 27        protected int _numX;
 28        protected int _numY;
 29        protected int _numZ;
 30
 31        protected List<double> _sequenceX;
 32        protected List<double> _sequenceY;
 33        protected List<double> _sequenceZ;
 34
 35        protected List<double> _spacingX;
 36        protected List<double> _spacingY;
 37        protected List<double> _spacingZ;
 38
 39        protected int _offset;
 40        protected int _buffer;
 41
 142        public int NumX => _numX;
 143        public int NumY => _numY;
 044        public int NumZ => _numZ;
 45
 246        public string[] VariableName { get; private set; }
 26743947        public Vector BasePoint { get; protected set; }
 48
 149        public int DataContent { get; protected set; }
 150        public string ProjectName { get; protected set; }
 151        public string LocationName { get; protected set; }
 152        public string SimulationDate { get; protected set; }
 153        public string SimulationTime { get; protected set; }
 54
 55        public delegate Face FaceByDirection(float spacingX, float spacingY,
 56            float spacingZ, Vector centroid);
 57
 58        /// <summary>
 59        /// Create new binary output object.
 60        /// </summary>
 61        /// <param name="edx">EDX file.</param>
 162        public BinaryOutput(string edx)
 163        {
 164            Read edxFile = new Read(edx);
 165            var outputKeys = edxFile.Information;
 66
 167            SetNumberOfCells(outputKeys);
 168            SetSpacing(outputKeys);
 169            Setsequence(outputKeys);
 170            SetVariableName(outputKeys);
 171            SetGeneralInfo(outputKeys);
 172        }
 73
 74        /// <summary>
 75        /// Set variable names
 76        /// </summary>
 77        /// <param name="outputKeys">Keys.</param>
 78        protected void SetVariableName(Dictionary<string, string> outputKeys)
 179        {
 180            VariableName = outputKeys["name_variables"].Split(',');
 181        }
 82
 83        /// <summary>
 84        /// Set X Y Z axis.
 85        /// </summary>
 86        /// <param name="outputKeys">Keys.</param>
 87        protected void SetSpacing(Dictionary<string, string> outputKeys)
 188        {
 189            _spacingX = outputKeys["spacing_x"]
 190                .Split(',')
 5391                .Select(_ => Convert.ToDouble(_))
 192                .ToList();
 193            _spacingY = outputKeys["spacing_y"]
 194                .Split(',')
 5895                .Select(_ => Convert.ToDouble(_))
 196                .ToList();
 197            _spacingZ = outputKeys["spacing_z"]
 198                .Split(',')
 2999                .Select(_ => Convert.ToDouble(_))
 1100                .ToList();
 1101        }
 102
 103        /// <summary>
 104        /// Set X Y Z sequences.
 105        /// </summary>
 106        /// <param name="outputKeys">Keys.</param>
 107        protected void Setsequence(Dictionary<string, string> outputKeys)
 1108        {
 1109            _sequenceX = Util.Accumulate(_spacingX).ToList();
 1110            _sequenceY = Util.Accumulate(_spacingY).ToList();
 1111            _sequenceZ = Util.Accumulate(_spacingZ).ToList();
 1112        }
 113
 114        /// <summary>
 115        /// Set number of cells X Y Z.
 116        /// </summary>
 117        /// <param name="outputKeys">Keys.</param>
 118        protected void SetNumberOfCells(Dictionary<string, string> outputKeys)
 1119        {
 1120            _numX = Convert.ToInt32(outputKeys["nr_xdata"]);
 1121            _numY = Convert.ToInt32(outputKeys["nr_ydata"]);
 1122            _numZ = Convert.ToInt32(outputKeys["nr_zdata"]);
 1123        }
 124
 125        /// <summary>
 126        /// Set generic information.
 127        /// </summary>
 128        /// <param name="outputKeys">Keys.</param>
 129        protected void SetGeneralInfo(Dictionary<string, string> outputKeys)
 1130        {
 1131            ProjectName = outputKeys["projectname"];
 1132            DataContent = Convert.ToInt32(outputKeys["data_content"]);
 1133            LocationName = outputKeys["locationname"];
 1134            SimulationDate = outputKeys["simulation_date"];
 1135            SimulationTime = outputKeys["simulation_time"];
 1136        }
 137
 138        /// <summary>
 139        /// Get building voxels from EDT EDX.
 140        /// </summary>
 141        /// <param name="faceByDirection">Facade direction.</param>
 142        /// <returns></returns>
 143        protected List<Voxel> GetFacadesFromBinary(FaceByDirection faceByDirection)
 1144        {
 145
 1146            List<Voxel> voxels = new List<Voxel>();
 147
 148            Vector vector;
 149            Face face;
 150            Voxel facade;
 151
 60152            for (int k = 0; k < _numZ; k++)
 29153            {
 3422154                for (int j = 0; j < _numY; j++)
 1682155                {
 181656156                    for (int i = 0; i < _numX; i++)
 89146157                    {
 89146158                        vector = new Vector((float)_sequenceX[i] + BasePoint.x - (float)_spacingX[i], (float)_sequenceY[
 89146159                        face = faceByDirection((float)_spacingX[i], (float)_spacingY[j], (float)_spacingZ[k], vector);
 160
 89146161                        facade = new Voxel(new Pixel(i, j, k), face);
 89146162                        voxels.Add(facade);
 89146163                    }
 1682164                }
 29165            }
 166
 1167            return voxels;
 1168        }
 169
 170        /// <summary>
 171        /// Facade in X.
 172        /// </summary>
 173        /// <param name="spacingX">Spacing value in X.</param>
 174        /// <param name="spacingY">Spacing value in Y.</param>
 175        /// <param name="spacingZ">Spacing value in Z.</param>
 176        /// <param name="centroid">Centroid.</param>
 177        /// <returns>Selected face.</returns>
 178        protected Face FaceX(float spacingX, float spacingY, float spacingZ, Vector centroid)
 0179        {
 0180            var points = new Vector[]
 0181            {
 0182                new Vector(centroid.x - (spacingX / 2), centroid.y - (spacingY / 2), centroid.z - spacingZ),
 0183                new Vector(centroid.x - (spacingX / 2), centroid.y + (spacingY / 2), centroid.z - spacingZ),
 0184                new Vector(centroid.x - (spacingX / 2), centroid.y + (spacingY / 2), centroid.z),
 0185                new Vector(centroid.x - (spacingX / 2), centroid.y - (spacingY / 2), centroid.z)
 0186            };
 187
 0188            Face face = new Face(points);
 189
 0190            return face;
 0191        }
 192
 193        /// <summary>
 194        /// Facade in Y.
 195        /// </summary>
 196        /// <param name="spacingX">Spacing value in X.</param>
 197        /// <param name="spacingY">Spacing value in Y.</param>
 198        /// <param name="spacingZ">Spacing value in Z.</param>
 199        /// <param name="centroid">Centroid.</param>
 200        /// <returns>Selected face.</returns>
 201        protected Face FaceY(float spacingX, float spacingY, float spacingZ, Vector centroid)
 0202        {
 203
 0204            var points = new Vector[]
 0205            {
 0206                new Vector(centroid.x - (spacingX / 2), centroid.y - (spacingY / 2), centroid.z - spacingZ),
 0207                new Vector(centroid.x + (spacingX / 2), centroid.y - (spacingY / 2), centroid.z - spacingZ),
 0208                new Vector(centroid.x + (spacingX / 2), centroid.y - (spacingY / 2), centroid.z),
 0209                new Vector(centroid.x - (spacingX / 2), centroid.y - (spacingY / 2), centroid.z)
 0210            };
 211
 0212            Face face = new Face(points);
 213
 0214            return face;
 0215        }
 216
 217        /// <summary>
 218        /// Facade in Z.
 219        /// </summary>
 220        /// <param name="spacingX">Spacing value in X.</param>
 221        /// <param name="spacingY">Spacing value in Y.</param>
 222        /// <param name="spacingZ">Spacing value in Z.</param>
 223        /// <param name="centroid">Centroid.</param>
 224        /// <returns>Selected face.</returns>
 225        protected Face FaceZ(float spacingX, float spacingY, float spacingZ, Vector centroid)
 89146226        {
 227
 89146228            var points = new Vector[]
 89146229            {
 89146230                new Vector(centroid.x - (spacingX / 2), centroid.y - (spacingY / 2), centroid.z - spacingZ),
 89146231                new Vector(centroid.x + (spacingX / 2), centroid.y - (spacingY / 2), centroid.z - spacingZ),
 89146232                new Vector(centroid.x + (spacingX / 2), centroid.y + (spacingY / 2), centroid.z - spacingZ),
 89146233                new Vector(centroid.x - (spacingX / 2), centroid.y + (spacingY / 2), centroid.z - spacingZ)
 89146234            };
 235
 89146236            Face face = new Face(points);
 237
 89146238            return face;
 89146239        }
 240
 241        /// <summary>
 242        /// Get voxels by direction.
 243        /// </summary>
 244        /// <param name="direction">Direction.</param>
 245        /// <returns>Collection of voxels.</returns>
 246        public List<Voxel> GetVoxels(Direction direction)
 1247        {
 248
 1249            if (direction == Direction.X)
 0250            {
 0251                return GetFacadesFromBinary(FaceX);
 252            }
 1253            else if (direction == Direction.Y)
 0254            {
 0255                return GetFacadesFromBinary(FaceY);
 256            }
 257            else
 1258            {
 1259                return GetFacadesFromBinary(FaceZ);
 260            }
 261
 1262        }
 263
 264        /// <summary>
 265        /// Set values reading EDX file.
 266        /// </summary>
 267        /// <param name="edt">EDT file.</param>
 268        /// <param name="voxels">Facades.</param>
 269        /// <param name="variable">Index of the variable to read.</param>
 270        public abstract void SetValuesFromBinary(string edt,
 271            List<Voxel> voxels, int variable);
 272    }
 273}