/// <inheritdoc/> protected override NodeRecord CreateNodeRecord(NodeMetaData data) { var nodeRecord = new OctreeNodeRecord(data.Identifier, new Bounds(data.BoundsCenter, data.BoundsSize), data.PointCount); return(nodeRecord); }
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)); }
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)); }
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 }; } }
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); }
/// <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);