コード例 #1
0
        public static Task Execute(SliceCommand command, ILogger logger)
        {
            if (File.Exists(command.Input) == false)
            {
                logger.Fatal("Provided cloud point data file does not exist!");
                Environment.Exit(0);
            }

            using var streamReader = FileFormatDetector.GetCloudStreamReader(command.Input);
            if (streamReader == null)
            {
                logger.Fatal("Not supported data format.");
                Environment.Exit(0);
            }

            if (File.Exists(command.TerrainPath) == false)
            {
                logger.Fatal("Terrain file does not exist!");
                Environment.Exit(0);
            }

            var cloud   = new Cloud(streamReader);
            var terrain = Terrain.Import(command.TerrainPath);


            var slices = cloud.Slice(command.SliceHeight).Where(slice => slice != null).OrderBy(slice => slice.Height).ToList();

            foreach (var pointSlice in slices)
            {
                foreach (var pointSet in pointSlice.PointSets)
                {
                    foreach (var point in pointSet)
                    {
                        point.Z -= terrain.GetHeight(point);
                    }
                }
            }
            using var writer = new GpdWriter(command.Output, null, (float)command.SliceHeight);
            writer.WriteSlices(slices);

            return(Task.CompletedTask);
        }
コード例 #2
0
        public static void ExportTrees(DetectTreesCommand command, IList <Tree> trees)
        {
            var x = 0;

            foreach (var tree in trees)
            {
                using var writer = new GpdWriter(
                          Path.Join(command.OutputDirectory, $"T{x++}.gpd"), null, command.SliceHeight.GetValueOrDefault(0.1)
                          );
                var nodes          = tree.GetAllNodesAsVector();
                var nodeDictionary = nodes
                                     .Select((n, i) => new Tuple <Tree.Node, int>(n, i))
                                     .ToDictionary(t => t.Item1, t => t.Item2);
                foreach (var node in nodeDictionary.Keys)
                {
                    var parentId = node.Parent is null ? -1 : nodeDictionary[node.Parent];
                    var id       = nodeDictionary[node];
                    writer.WritePointSet(node.PointSet, 0, $"Id+{id};Parent+{parentId};");
                }
            }
        }