Exemple #1
0
        public static void ExportExamples()
        {
            // Example 1: export point cloud to folder
            {
                using (var storeSource = new SimpleDiskStore(@"T:\Vgm\Stores\copytest1").ToPointCloudStore())
                    using (var storeTarget = new SimpleFolderStore(@"T:\Vgm\Stores\exportFolder").ToPointCloudStore())
                    {
                        storeSource.ExportPointSet("097358dc-d89a-434c-8a4e-fe03c063d886", storeTarget, true);
                    }
            }

            // Example 2: export point cloud to another store
            {
                using (var storeSource = new SimpleDiskStore(@"T:\Vgm\Stores\copytest1").ToPointCloudStore())
                    using (var storeTarget = new SimpleDiskStore(@"T:\Vgm\Stores\exportStore").ToPointCloudStore())
                    {
                        storeSource.ExportPointSet("097358dc-d89a-434c-8a4e-fe03c063d886", storeTarget, true);
                        storeTarget.Flush();
                    }
            }

            // Example 3: inline point cloud nodes
            {
                using (var storeSource = new SimpleDiskStore(@"T:\Vgm\Stores\copytest1").ToPointCloudStore())
                    using (var storeTarget = new SimpleFolderStore(@"T:\Vgm\Stores\exportInlined").ToPointCloudStore())
                    {
                        storeSource.InlinePointSet("097358dc-d89a-434c-8a4e-fe03c063d886", storeTarget, false);
                        storeTarget.Flush();
                    }
            }
        }
Exemple #2
0
        internal static void DumpPointSetKeys()
        {
            var storeFolder = @"T:\Vgm\Pinter_Dachboden_3Dworx_Store\Pinter_Dachboden_store";

            var sds   = new SimpleDiskStore(storeFolder);
            var keys  = sds.SnapshotKeys();
            var store = sds.ToPointCloudStore(cache: default);
Exemple #3
0
        internal static Storage CreateDiskStorage(string dbDiskLocation)
        {
            var x = new SimpleDiskStore(dbDiskLocation);

            return(new Storage(
                       (a, b, c, _) => x.Add(a, b, c), (a, _) => x.Get(a), (a, _) => x.Remove(a),
                       (a, _) => x.TryGetFromCache(a), x.Dispose, x.Flush
                       ));
        }
        /// <summary>
        /// Opens or creates a store at the specified location.
        /// </summary>
        public static Storage OpenStore(string storePath, LruDictionary <string, object> cache)
        {
            lock (s_stores)
            {
                if (s_stores.TryGetValue(storePath, out WeakReference <Storage> x) && x.TryGetTarget(out Storage cached))
                {
                    if (!cached.IsDisposed)
                    {
                        return(cached);
                    }
                }

                var store = new SimpleDiskStore(storePath).ToPointCloudStore(cache);
                s_stores[storePath] = new WeakReference <Storage>(store);
                return(store);
            }
        }
Exemple #5
0
        internal static void TestImport()
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
            var filename = @"test.e57";

            var store = new SimpleDiskStore(@"./store").ToPointCloudStore(new LruDictionary <string, object>(1024 * 1024 * 1024));

            var config = ImportConfig.Default
                         .WithStorage(store)
                         .WithKey("mykey")
                         .WithVerbose(true)
            ;

            Report.BeginTimed("importing");
            var pointcloud = PointCloud.Import(filename, config);

            Report.EndTimed();
            store.Flush();
        }
        static object ImportFile(string path, params string[] filenames)
        {
            var tsStart = DateTimeOffset.UtcNow;

            try
            {
                var storePath = path + "_STORE";

                if (Directory.Exists(storePath))
                {
                    Directory.Delete(storePath, true);
                    Thread.Sleep(1000);
                }

                var store = new SimpleDiskStore(storePath).ToPointCloudStore();

                Report.BeginTimed($"importing");
                var sw         = new Stopwatch(); sw.Start();
                var keys       = new List <string>();
                var pointCount = 0L;
                foreach (var filename in filenames)
                {
                    var key = Path.GetFileName(filename);
                    keys.Add(key);
                    var config = ImportConfig.Default
                                 .WithStorage(store)
                                 .WithKey(key)
                                 .WithVerbose(false)
                                 .WithMaxDegreeOfParallelism(0)
                                 .WithMinDist(0.005)
                                 .WithNormalizePointDensityGlobal(true)
                    ;
                    var pc = PointCloud.Import(filename, config);
                    pointCount += pc.PointCount;
                }
                store.Flush();
                sw.Stop();
                Report.EndTimed();
                var tsEnd = DateTimeOffset.UtcNow;

                var storeDataSizeInBytes  = new FileInfo(Path.Combine(storePath, "data.bin")).Length;
                var storeIndexSizeInBytes = new FileInfo(Path.Combine(storePath, "index.bin")).Length;

                var stats = new
                {
                    tsStart,
                    tsEnd,
                    path,
                    filenames,
                    keys,
                    pointCount,
                    durationInSeconds = Math.Round(sw.Elapsed.TotalSeconds, 2),
                    storeDataSizeInBytes,
                    storeDataSizeInGb = Math.Round(storeDataSizeInBytes / (1024.0 * 1024 * 1024), 3),
                    storeIndexSizeInBytes,
                    storeIndexSizeInMb = Math.Round(storeIndexSizeInBytes / (1024.0 * 1024), 3),
                };

                var json = JsonConvert.SerializeObject(stats, Formatting.Indented);
                Console.WriteLine(json);
                var n = DateTimeOffset.Now;

                var statsFileName = path + $"_{n.Year:0000}{n.Month:00}{n.Day:00}_{n.Hour:00}{n.Minute:00}{n.Second:00}_stats.json";
                File.WriteAllText(statsFileName, json);

                return(stats);
            }
            catch (Exception e)
            {
                var tsEnd = DateTimeOffset.UtcNow;
                var stats = new
                {
                    tsStart,
                    tsEnd,
                    path,
                    filenames,
                    error = e.ToString()
                };
                return(stats);
            }
        }
Exemple #7
0
        internal static Storage CreateDiskStorage(string dbDiskLocation)
        {
            var x = new SimpleDiskStore(dbDiskLocation);

            return(new Storage(x.Add, x.Get, x.Remove, x.Dispose, x.Flush, cache: default));
        }
Exemple #8
0
        internal static void CopyTest()
        {
            var filename   = @"T:\Vgm\Data\JBs_Haus.pts";
            var rootKey    = "097358dc-d89a-434c-8a4e-fe03c063d886";
            var splitLimit = 65536;
            var minDist    = 0.001;

            var store1Path = @"T:\Vgm\Stores\copytest1";
            var store2Path = @"T:\Vgm\Stores\copytest2";
            var store3Path = @"T:\Vgm\Stores\copytest3";
            var store4Path = @"T:\Vgm\Stores\JBs_Haus.pts";

            // create stores
            var store1 = new SimpleDiskStore(store1Path).ToPointCloudStore();
            var store2 = new SimpleDiskStore(store2Path).ToPointCloudStore();

            // import point cloud into store1
            Report.BeginTimed("importing");
            var config = ImportConfig.Default
                         .WithStorage(store1)
                         .WithKey(rootKey)
                         .WithOctreeSplitLimit(splitLimit)
                         .WithMinDist(minDist)
                         .WithNormalizePointDensityGlobal(true)
                         .WithVerbose(true)
            ;
            var pointcloud = PointCloud.Import(filename, config);

            Report.EndTimed();
            store1.Flush();

            return;

            if (!Directory.Exists(store3Path))
            {
                Directory.CreateDirectory(store3Path); Thread.Sleep(1000);
            }
            if (!Directory.Exists(store4Path))
            {
                Directory.CreateDirectory(store4Path); Thread.Sleep(1000);
            }

            // copy point cloud from store1 to store2
            var pc1        = store1.GetPointSet(rootKey);
            var root1      = pc1.Root.Value;
            var totalNodes = root1.CountNodes(outOfCore: true);

            store2.Add(rootKey, pc1);
            Report.BeginTimed("copy");
            var totalBytes = 0L;

            //pc1.Root.Value.ForEachNode(outOfCore: true, n => Report.Line($"{n.Id} {n.PointCountCell,12:N0}"));
            Convert(root1.Id);
            Report.Line($"{totalNodes}");
            Report.EndTimed();
            store2.Flush();

            // meta
            var rootJson = JObject.FromObject(new
            {
                rootId         = root1.Id.ToString(),
                splitLimit     = splitLimit,
                minDist        = minDist,
                pointCount     = root1.PointCountTree,
                bounds         = root1.BoundingBoxExactGlobal,
                centroid       = (V3d)root1.CentroidLocal + root1.Center,
                centroidStdDev = root1.CentroidLocalStdDev,
                cell           = root1.Cell,
                totalNodes     = totalNodes,
                totalBytes     = totalBytes,
                gzipped        = false
            });

            File.WriteAllText(Path.Combine(store3Path, "root.json"), rootJson.ToString(Formatting.Indented));

            rootJson["gzipped"] = true;
            File.WriteAllText(Path.Combine(store4Path, "root.json"), rootJson.ToString(Formatting.Indented));

            void Convert(Guid key)
            {
                if (key == Guid.Empty)
                {
                    return;
                }

                var(def, raw) = store1.GetDurable(key);
                var node = raw as IDictionary <Durable.Def, object>;

                node.TryGetValue(Durable.Octree.SubnodesGuids, out var subnodeGuids);

                // write inlined node to store
                var inlinedNode = store1.ConvertToInline(node);
                var inlinedBlob = store2.Add(key, Durable.Octree.Node, inlinedNode, false);

                totalBytes += inlinedBlob.Length;
                //Report.Line($"stored node {key}");

                // write blob as file
                File.WriteAllBytes(Path.Combine(store3Path, key.ToString()), inlinedBlob);

                // write blob as file (gzipped)
                using (var fs = File.OpenWrite(Path.Combine(store4Path, key.ToString())))
                    using (var zs = new GZipStream(fs, CompressionLevel.Fastest))
                    {
                        zs.Write(inlinedBlob, 0, inlinedBlob.Length);
                    }

                // children
                if (subnodeGuids != null)
                {
                    foreach (var x in (Guid[])subnodeGuids)
                    {
                        Convert(x);
                    }
                }
            }
        }