Exemple #1
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="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, out NodeTree instance)
        {
            var fullPath  = Utility.GetFullPath(path);
            var indexPath = Path.Combine(fullPath, "index" + TreeUtility.IndexFileExtension);

            if (!File.Exists(indexPath))
            {
                Debug.LogError("Index file not found.");
                instance = null;
                return(false);
            }

            NodeTree result = null;

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

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

                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);
            }
        }
Exemple #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);
            }
        }