Esempio n. 1
0
        private MphtxtMesh ReadMeshObj()
        {
            var objectVersion = ReadInt();
            var dimension     = ReadInt();

            if (dimension != 2 && dimension != 3)
            {
                throw new InvalidDataException(Strings.MphtxtReader_ReadMeshObj_NotSupportedDimension);
            }

            var meshPointCount       = ReadInt();
            var lowestMeshPointIndex = ReadInt();

            var coordinates = new CoordinateCollection(dimension, meshPointCount);

            for (int i = 0; i < meshPointCount; i++)
            {
                ReadDoubles(coordinates[i].Storage.Span);
            }

            var elementTypeCount = ReadInt();
            var geometryElements = new Dictionary <string, GeometryElementCollection>();

            for (int typeId = 0; typeId < elementTypeCount; typeId++)
            {
                var typeName = ReadString();

                var nodePerEle   = ReadInt();
                var elementCount = ReadInt();
                var elements     = new GeometryElementCollection(elementCount, nodePerEle);
                geometryElements[typeName] = elements;
                for (int i = 0; i < elementCount; i++)
                {
                    ReadInts(elements[i].AsSpan());
                    for (int j = 0; j < nodePerEle; ++j)
                    {
                        elements[i][j] -= lowestMeshPointIndex;
                    }
                }

                var indexCount = ReadInt();
                if (indexCount != elementCount)
                {
                    throw new InvalidDataException(
                              $"Type {typeName} has different element count ({elementCount}) and index count ({indexCount}).");
                }

                for (int i = 0; i < indexCount; i++)
                {
                    elements[i].EntityIndex = ReadInt();
                }
            }

            return(new MphtxtMesh(coordinates, geometryElements));
        }
 /// <summary>
 /// Initializes an enumerator.
 /// </summary>
 /// <param name="container">The collection to be enumerated.</param>
 public Enumerator(GeometryElementCollection container)
 {
     this.container = container ?? throw new ArgumentNullException(nameof(container));
     index          = -1;
 }