示例#1
0
        private static void IndexFile(string file, bool drawPoints)
        {
            var sw = Stopwatch.StartNew();

            var tree = new QuadTree();

            using (var stream = new FileStreamUnbufferedSequentialRead(file))
            {
                var source = Path.GetExtension(file) == ".las"
                    ? (IPointSource) new LasFile(stream)
                    : new XyzFile(stream);

                foreach (var point in source.IndexedPoints())
                {
                    tree.Add(point);
                }

                tree.CollapseSmallNodes();

                Console.WriteLine($"{tree._root.Count} in {sw.ElapsedMilliseconds}");

                var leafNodes     = tree.GetLeaves().ToList();
                var leafDensities = leafNodes.Select(x => x.Count / Math.Pow(x.Dimension, 2)).OrderBy(x => x).ToList();

                Console.WriteLine($"{leafNodes.Count} leaf nodes");
                Console.WriteLine($"{tree.GetDepth()} depth");

                Console.WriteLine("density (points per unit area)");
                Console.WriteLine($"  naive  : {tree._root.Count / ((tree._maxX - tree._minX) * (tree._maxY - tree._minY)):N6}");
                Console.WriteLine($"  median : {leafDensities[leafDensities.Count / 2]:N6}");
                Console.WriteLine($"  mean   : {leafDensities.Average():N6}");
                Console.WriteLine($"  min    : {leafDensities.First():N6}");
                Console.WriteLine($"  max    : {leafDensities.Last():N6}");

                if (drawPoints)
                {
                    DrawDensityMap(tree, source);
                    //DrawTreeDepthMap(tree);
                    //DrawTreeIndexChunkDensityMap(tree);

                    Console.WriteLine($"{tree.GetLeaves().Sum(x => x.Chunks.Count)}");

                    var hashset = new HashSet <long>();
                    foreach (var node in tree.GetLeaves())
                    {
                        hashset.UnionWith(node.Chunks);
                    }

                    Console.WriteLine($"chunks: {hashset.Count}");
                    //foreach (var chunk in hashset.OrderBy(x => x))
                    //{
                    //    Console.WriteLine(chunk);
                    //}
                }
            }
        }
示例#2
0
        private static void ScanFileIndexed(string file)
        {
            var sw = Stopwatch.StartNew();

            using (var stream = new FileStreamUnbufferedSequentialRead(file))
            {
                var source = Path.GetExtension(file) == ".las"
                    ? (IPointSource) new LasFile(stream)
                    : new XyzFile(stream);

                var max   = 0.0;
                var count = 0L;
                foreach (var point in source.Points())
                {
                    ++count;
                    max = Math.Max(point.Z, max);
                }

                Console.WriteLine($"read {count} indexed in {sw.ElapsedMilliseconds}");
            }
        }