コード例 #1
0
 public static IArray <int> FindStringColumn(this SerializableEntityTable table, string name)
 {
     foreach (var col in table.StringColumns)
     {
         if (col.Name == name)
         {
             return(col.GetTypedData().ToIArray());
         }
     }
     return(null);
 }
コード例 #2
0
ファイル: Serializer.cs プロジェクト: dmk-rib/Open.Vim.Sdk
        public static List <INamedBuffer> ToBuffers(this SerializableEntityTable table)
        {
            var r = new List <INamedBuffer>();

            r.AddRange(table.NumericColumns.Select(b
                                                   => b.ToNamedBuffer(VimConstants.NumberColumnNamePrefix + b.Name)));
            r.AddRange(table.IndexColumns.Select(b
                                                 => b.ToNamedBuffer(VimConstants.IndexColumnNamePrefix + b.Name)));
            r.AddRange(table.StringColumns.Select(b
                                                  => b.ToNamedBuffer(VimConstants.StringColumnNamePrefix + b.Name)));
            r.Add(table.Properties.ToNamedBuffer(VimConstants.PropertiesBufferName));
            return(r);
        }
コード例 #3
0
ファイル: EntityTable.cs プロジェクト: dmk-rib/Open.Vim.Sdk
        public EntityTable(Document document, SerializableEntityTable entityTable)
        {
            Document      = document;
            _EntityTable  = entityTable;
            Name          = _EntityTable.Name;
            PropertyLists = new DictionaryOfLists <int, Property>();
            foreach (var p in _EntityTable.Properties)
            {
                PropertyLists.Add(p.EntityIndex, new Property(Document, p));
            }
            NumericColumns = LinqArray.LinqArray.ToLookup(_EntityTable.NumericColumns, c => c.Name, c => c);
            // We access our indices using simplified names "Element" rather than what gets serialized "Rvt.Element:Element"
            IndexColumns  = LinqArray.LinqArray.ToLookup(_EntityTable.IndexColumns, c => c.Name.SimplifiedName(), c => c);
            StringColumns = LinqArray.LinqArray.ToLookup(_EntityTable.StringColumns, c => c.Name, c => c);
            NumRows       = Columns.FirstOrDefault()?.NumElements() ?? 0;

            if (!Columns.All(x => x.NumElements() == NumRows))
            {
                Debug.Fail("All columns in an entity table must be the same length");
            }
        }
コード例 #4
0
ファイル: Serializer.cs プロジェクト: dmk-rib/Open.Vim.Sdk
        public static SerializableEntityTable ReadEntityTable(this Stream stream)
        {
            var et = new SerializableEntityTable();

            stream.ReadBFast((_stream, name, size) =>
            {
                // Strip prefix
                var simpName = name.SimplifiedName();

                // Switch based on the name
                if (name.StartsWith(VimConstants.IndexColumnNamePrefix))
                {
                    var buffer = stream.ReadBufferFromNumberOfBytes <int>(size);
                    et.IndexColumns.Add(buffer.ToNamedBuffer(simpName));
                }
                else if (name.StartsWith(VimConstants.NumberColumnNamePrefix))
                {
                    var buffer = stream.ReadBufferFromNumberOfBytes <double>(size);
                    et.NumericColumns.Add(buffer.ToNamedBuffer(simpName));
                }
                else if (name.StartsWith(VimConstants.StringColumnNamePrefix))
                {
                    var buffer = stream.ReadBufferFromNumberOfBytes <int>(size);
                    et.StringColumns.Add(buffer.ToNamedBuffer(simpName));
                }
                else if (name == VimConstants.PropertiesBufferName)
                {
                    et.Properties = stream.ReadArrayFromNumberOfBytes <SerializableProperty>(size);
                }
                else
                {
                    Debug.Assert(false, $"{name} is not a recognized entity table buffer");
                }
                return(et);
            });
            return(et);
        }
コード例 #5
0
        public List <SerializableEntityTable> ComputeEntityTables(Dictionary <string, int> stringLookup)
        {
            // Create the new Entity tables
            var tableList = new List <SerializableEntityTable>();

            // Create the geometry table
            {
                var tb = GetTableBuilderOrCreate(TableNames.Geometry);
                tb.Clear();
                // We have to force evaluation because as an enumerable the bounding box could be evaluated 6 times more
                tb.AddField(Geometries.Select(g => AABox.Create(g.Vertices)).ToArray(), "Box");
                tb.AddField(Geometries.Select(g => g.Vertices.Count), "VertexCount");
                tb.AddField(Geometries.Select(g => g.Indices.Count / 3), "FaceCount");
            }

            // TODO: add bounding box information to the nodes

            foreach (var tb in Tables.Values)
            {
                var table = new SerializableEntityTable
                {
                    // Set the table name
                    Name = tb.Name,

                    // Convert the columns to named buffers
                    IndexColumns = tb.IndexColumns
                                   .Select(kv => kv.Value.ToNamedBuffer(kv.Key))
                                   .ToList(),
                    NumericColumns = tb.NumericColumns
                                     .Select(kv => kv.Value.ToNamedBuffer(kv.Key))
                                     .ToList(),
                    StringColumns = tb.StringColumns
                                    .Select(kv => kv.Value
                                            .Select(s => stringLookup[s ?? string.Empty])
                                            .ToArray()
                                            .ToNamedBuffer(kv.Key))
                                    .ToList()
                };

                // Assure that all columns are the same length
                var nRows = -1;
                foreach (var c in table.IndexColumns)
                {
                    var n = c.NumElements();
                    if (nRows < 0)
                    {
                        nRows = n;
                    }
                    else if (nRows != n)
                    {
                        throw new Exception($"Invalid number of rows {n} expected {nRows}");
                    }
                }
                foreach (var c in table.NumericColumns)
                {
                    var n = c.NumElements();
                    if (nRows < 0)
                    {
                        nRows = n;
                    }
                    else if (nRows != n)
                    {
                        throw new Exception($"Invalid number of rows {n} expected {nRows}");
                    }
                }
                foreach (var c in table.StringColumns)
                {
                    var n = c.NumElements();
                    if (nRows < 0)
                    {
                        nRows = n;
                    }
                    else if (nRows != n)
                    {
                        throw new Exception($"Invalid number of rows {n} expected {nRows}");
                    }
                }

                // Properties
                table.Properties = tb.Properties.Select(p => new SerializableProperty
                {
                    EntityIndex = p.EntityId,
                    Name        = stringLookup[p.Name],
                    Value       = stringLookup[p.Value]
                }).ToArray();

                tableList.Add(table);
            }


            return(tableList);
        }
コード例 #6
0
 public static EntityTable ToEntityTable(this SerializableEntityTable entityTable, Document document)
 => new EntityTable(document, entityTable);