Example #1
0
 /// <summary>
 /// Initializes new, empty tree based on data stored under given path.
 /// </summary>
 /// <param name="pathOnDisk">Path under which data for this tree is stored. Must exist.</param>
 /// <param name="loadedPointsLimit">Maximum amount of points that can be loaded into memory at once.</param>
 /// <param name="zipData">Environment archive metadata (only applicable to ZIP files).</param>
 protected NodeTree(string pathOnDisk, int loadedPointsLimit, ZipTreeData zipData = null)
 {
     this.pathOnDisk = pathOnDisk;
     ZipData         = zipData;
     NodeLoader      = new NodeLoader(this, loadedPointsLimit);
 }
Example #2
0
        /// <summary>
        /// Attempts to load index file with tree meta data from disk and create appropriate instance of node tree.
        /// </summary>
        /// <param name="path">Directory under which tree data is stored.</param>
        /// <param name="pointLimit">Maximum amount of points that tree can store in memory at once.</param>
        /// <param name="dataHash">Hash of the point cloud data (only applicable to ZIP files).</param>
        /// <param name="instance">Newly created instance of the node tree.</param>
        /// <returns>True if load was successful, false otherwise.</returns>
        public static bool TryLoadFromDisk(string path, int pointLimit, string dataHash, out NodeTree instance)
        {
            var         fullPath = Utility.GetFullPath(path);
            string      indexPath;
            long        offset, size;
            ZipTreeData zipData = null;

            if (!string.IsNullOrEmpty(dataHash))
            {
                indexPath = fullPath;
                zipData   = new ZipTreeData(indexPath, dataHash);
                const string indexName = "index" + TreeUtility.IndexFileExtension;
                size   = zipData.GetEntrySize(indexName);
                offset = zipData.GetEntryOffset(indexName);
            }
            else
            {
                indexPath = Path.Combine(fullPath, "index" + TreeUtility.IndexFileExtension);

                if (!File.Exists(indexPath))
                {
                    instance = null;
                    return(false);
                }

                size   = new FileInfo(indexPath).Length;
                offset = 0;
            }

            NodeTree result = null;

            try
            {
                var indexData = IndexData.ReadFromFile(indexPath, offset, size);

                if (indexData.TreeType == TreeType.Octree)
                {
                    result = new Octree(fullPath, pointLimit, zipData);
                }
                else
                {
                    result = new Quadtree(fullPath, pointLimit, zipData);
                }

                foreach (var nodeMetaData in indexData.Data)
                {
                    var nodeRecord = result.CreateNodeRecord(nodeMetaData);
                    result.NodeRecords.Add(nodeRecord.Identifier, nodeRecord);
                }

                result.RebuildHierarchy();
                instance = result;
                return(true);
            }
            catch (Exception e)
            {
                Debug.LogError($"{e.Message}\n{e.StackTrace}");
                result?.Dispose();
                instance = null;
                return(false);
            }
        }
Example #3
0
 /// <summary>
 /// Initializes new, empty quadtree based on data stored under given path.
 /// </summary>
 /// <param name="pathOnDisk">Path under which data for this tree is stored. Must exist.</param>
 /// <param name="loadedPointsLimit">Maximum amount of points that can be loaded into memory at once.</param>
 /// <param name="zipData">Data about environment zip file (if applicable).</param>
 public Quadtree(string pathOnDisk, int loadedPointsLimit, ZipTreeData zipData = null) : base(pathOnDisk, loadedPointsLimit, zipData)
 {
 }