示例#1
0
        /// <inheritdoc/>
        protected override NodeRecord CreateNodeRecord(NodeMetaData data)
        {
            var nodeRecord = new OctreeNodeRecord(data.Identifier,
                                                  new Bounds(data.BoundsCenter, data.BoundsSize), data.PointCount);

            return(nodeRecord);
        }
示例#2
0
        public static IndexData ReadFromFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"Index file under {filePath} not found.");
            }

            var size = new FileInfo(filePath).Length;

            int treeType;

            NodeMetaData[] data;

            using (var mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open))
            {
                using (var accessor = mmf.CreateViewAccessor(0, size))
                {
                    accessor.Read(0, out treeType);
                    accessor.Read(sizeof(int), out int itemCount);

                    data = new NodeMetaData[itemCount];
                    long pos = sizeof(int) * 2;

                    for (var i = 0; i < itemCount; ++i)
                    {
                        data[i] = NodeMetaData.Read(accessor, ref pos);
                    }
                }
            }

            return(new IndexData((TreeType)treeType, data));
        }
示例#3
0
        public static IndexData ReadFromFile(string filePath, long offset, long size)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"Index file under {filePath} not found.");
            }

            int treeType;

            NodeMetaData[] data;

            using (var mmf = MemoryMappedFile.CreateFromFile(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read), null, 0L, MemoryMappedFileAccess.Read, HandleInheritability.None, false))
            {
                using (var accessor = mmf.CreateViewAccessor(offset, size, MemoryMappedFileAccess.Read))
                {
                    accessor.Read(0, out treeType);
                    accessor.Read(sizeof(int), out int itemCount);

                    data = new NodeMetaData[itemCount];
                    long pos = sizeof(int) * 2;

                    for (var i = 0; i < itemCount; ++i)
                    {
                        data[i] = NodeMetaData.Read(accessor, ref pos);
                    }
                }
            }

            return(new IndexData((TreeType)treeType, data));
        }
示例#4
0
        public IndexData(TreeType treeType, List <NodeRecord> records)
        {
            TreeType = treeType;
            Data     = new NodeMetaData[records.Count];

            for (var i = 0; i < records.Count; ++i)
            {
                var record = records[i];
                Data[i] = new NodeMetaData
                {
                    Identifier   = record.Identifier,
                    PointCount   = record.PointCount,
                    BoundsCenter = record.Bounds.center,
                    BoundsSize   = record.Bounds.size
                };
            }
        }
示例#5
0
        public static NodeMetaData Read(MemoryMappedViewAccessor accessor, ref long position)
        {
            accessor.Read(position, out byte idLength);
            position += sizeof(byte);

            var idBytes = new byte[idLength];

            accessor.ReadArray(position, idBytes, 0, idLength);
            var identifier = Encoding.ASCII.GetString(idBytes);

            position += idLength;
            accessor.Read(position, out int pointCount);
            position += sizeof(int);

            accessor.Read(position, out float cX);
            position += sizeof(float);
            accessor.Read(position, out float cY);
            position += sizeof(float);
            accessor.Read(position, out float cZ);
            position += sizeof(float);

            accessor.Read(position, out float sX);
            position += sizeof(float);
            accessor.Read(position, out float sY);
            position += sizeof(float);
            accessor.Read(position, out float sZ);
            position += sizeof(float);

            var result = new NodeMetaData
            {
                Identifier   = identifier,
                PointCount   = pointCount,
                BoundsCenter = new Vector3(cX, cY, cZ),
                BoundsSize   = new Vector3(sX, sY, sZ)
            };

            return(result);
        }
示例#6
0
 /// <summary>
 /// Creates and returns new node record associated with tree type.
 /// </summary>
 /// <param name="data">Metadata of the node.</param>
 protected abstract NodeRecord CreateNodeRecord(NodeMetaData data);