Exemplo n.º 1
0
        public static void ExportTile()
        {
            if (!export)
            {
                return;
            }
            DateTime exportStart = DateTime.Now;

            StringBuilder output = new StringBuilder();
            string        res;

            DateTime start     = DateTime.Now;
            DateTime lastDebug = DateTime.Now;

            AddPointsTo(ref output, EClass.Unassigned, ref start);
            AddPointsTo(ref output, EClass.Ground, ref start);
            AddPointsTo(ref output, EClass.Building, ref start);

            if (CTreeManager.GetDetectMethod() == EDetectionMethod.Balls)
            {
                AddPointsTo(ref output, EClass.BallsSurface, ref start);
                AddPointsTo(ref output, EClass.Balls, ref start);
                AddPointsTo(ref output, EClass.BallsMainPoints, ref start);
                AddPointsTo(ref output, EClass.BallsCenters, ref start);
            }

            //tree points
            AddTreePointsTo(ref output, true, ref start);
            //invalid tree points
            AddTreePointsTo(ref output, false, ref start);

            if (output.Length == 0)
            {
                CDebug.Warning($"CLasExporter: no output created on tile {CProgramStarter.currentTileIndex}");
                return;
            }

            //1. Create the text file
            string txtOutputPath = tileFilePath + ".txt";

            WriteToFile(output, txtOutputPath);
            //2. save output path for the main file export
            exportedTiles.Add(txtOutputPath);

            //3. Convert the txt to las using LasTools
            //format: x, y, z, class, user comment (id), R, G, B
            string cmd = $"{txt2lasCmd} {txtOutputPath}";

            CCmdController.RunLasToolsCmd(cmd, tileFilePath + ".las");

            CAnalytics.lasExportDuration = CAnalytics.GetDuration(exportStart);
        }
Exemplo n.º 2
0
        public static void Init()
        {
            saveFileName = CUtils.GetFileName(
                CParameterSetter.GetStringSettings(ESettings.forestFileFullName));
            string outputFolderSettings = CParameterSetter.GetStringSettings(ESettings.outputFolderPath);

            //include the method alias into the main folder name
            EDetectionMethod method = CTreeManager.GetDetectMethod();
            string           suffix = CUtils.GetMethodSuffix(method);

            saveFileName += suffix;

            outputFolder = CObjExporter.CreateFolderIn(saveFileName, outputFolderSettings);

            Points = new CPointsHolder();
        }
Exemplo n.º 3
0
        public List <Vector3> GetPoints(EClass pClass)
        {
            switch (pClass)
            {
            case EClass.Unassigned:
                //points has been filtered out in fields only
                if (CTreeManager.GetDetectMethod() == EDetectionMethod.Balls)
                {
                    return(ballArray.GetPoints());
                }
                return(unassigned);

            case EClass.Balls:
                return(ballPoints);

            case EClass.BallsMainPoints:
                return(ballsMainPoints);

            case EClass.BallsCenters:
                return(ballsCenters);

            case EClass.BallsSurface:
                return(ballsSurface);

            case EClass.Ground:
                return(ground);

            case EClass.Vege:
                return(vege);

            case EClass.Building:
                return(building);
            }
            CDebug.Error($"Points of class {pClass} not defined");
            return(null);
        }
Exemplo n.º 4
0
        private void ProcessUnassignedPoints()
        {
            DateTime debugStart         = DateTime.Now;
            DateTime previousDebugStart = DateTime.Now;

            for (int i = 0; i < unassigned.Count; i++)
            {
                if (CProjectData.backgroundWorker.CancellationPending)
                {
                    return;
                }
                CDebug.Progress(i, unassigned.Count, 100000, ref previousDebugStart, debugStart, "ProcessUnassignedPoints");

                if (CProjectData.backgroundWorker.CancellationPending)
                {
                    return;
                }

                Vector3 point = unassigned[i];
                unassignedArray.AddPointInField(point);
                if (CTreeManager.GetDetectMethod() == EDetectionMethod.Balls)
                {
                    ballArray.AddPointInField(point);
                }
            }

            if (CTreeManager.GetDetectMethod() == EDetectionMethod.Balls)
            {
                //unassignedArray.FillArray(); //doesnt make sense

                const bool filterBasedOnheight = false;
                //balls are expected to be in this height above ground
                if (filterBasedOnheight)
                {
                    ballArray.FilterPointsAtHeight(1.8f, 2.7f);
                }

                //add filtered points to detail array
                List <Vector3> filteredPoints = ballArray.GetPoints();
                foreach (Vector3 point in filteredPoints)
                {
                    if (CProjectData.backgroundWorker.CancellationPending)
                    {
                        return;
                    }

                    ballDetailArray.AddPointInField(point);
                }

                List <CBallField> ballFields = new List <CBallField>();

                //vege.Sort((b, a) => a.Z.CompareTo(b.Z)); //sort descending by height

                List <CBallField> sortedFields = ballDetailArray.fields;
                //sortedFields.Sort((a, b) => a.indexInField.Item1.CompareTo(b.indexInField.Item1));
                //sortedFields.Sort((a, b) => a.indexInField.Item2.CompareTo(b.indexInField.Item2));

                sortedFields.OrderBy(a => a.indexInField.Item1).ThenBy(a => a.indexInField.Item2);

                //List<Vector3> mainPoints = new List<Vector3>();

                debugStart         = DateTime.Now;
                previousDebugStart = DateTime.Now;
                //process
                for (int i = 0; i < sortedFields.Count; i++)
                {
                    if (CProjectData.backgroundWorker.CancellationPending)
                    {
                        return;
                    }
                    CDebug.Progress(i, sortedFields.Count, 100000, ref previousDebugStart, debugStart, "Detecting balls");

                    CBallField field = (CBallField)sortedFields[i];
                    field.Detect();
                    if (field.ball != null && field.ball.isValid)
                    {
                        ballFields.Add(field);
                        ballsMainPoints.AddRange(field.ball.GetMainPoints(true));

                        ballsCenters.Add(field.ball.center);
                        ballsCenters.AddRange(CUtils.GetPointCross(field.ball.center));
                        //return;
                        ballsSurface.AddRange(field.ball.GetSurfacePoints());
                    }
                }

                foreach (CBallField field in ballFields)
                {
                    ballPoints.AddRange(field.points);
                }
            }
        }
Exemplo n.º 5
0
        public static void ProcessParsedLines(List <Tuple <EClass, Vector3> > parsedLines)
        {
            CAnalytics.loadedPoints = parsedLines.Count;
            CProjectData.Points.AddPointsFromLines(parsedLines);

            CObjPartition.AddGroundArrayObj();

            if (CParameterSetter.GetBoolSettings(ESettings.exportPoints))
            {
                CObjPartition.AddPoints(EClass.Unassigned);
                CObjPartition.AddPoints(EClass.Ground);
                CObjPartition.AddPoints(EClass.Vege);
                CObjPartition.AddPoints(EClass.Building);
            }

            CDebug.Count("Trees", CTreeManager.Trees.Count);

            CTreeManager.CheckAllTrees();

            CDebug.Step(EProgramStep.ValidateTrees1);
            //dont move invalid trees to invalid list yet, some invalid trees will be merged
            CTreeManager.ValidateTrees(false, false);

            //export before merge
            if (CProjectData.exportBeforeMerge)
            {
                CTreeManager.AssignMaterials();                 //call before export

                CObjPartition.AddTrees(true);
                CObjPartition.AddTrees(false);
                CObjPartition.ExportPartition("_noMerge");
                CObjPartition.Init();
                //CObjPartition.AddArray();
            }

            CAnalytics.firstDetectedTrees = CTreeManager.Trees.Count;

            CDebug.Step(EProgramStep.MergeNotTrees1);
            CTreeManager.TryMergeNotTrees();


            CDebug.Step(EProgramStep.MergeTrees1);
            //try merge all (even valid)
            EDetectionMethod detectionMethod = CTreeManager.GetDetectMethod();

            if ((detectionMethod == EDetectionMethod.AddFactor ||
                 detectionMethod == EDetectionMethod.Detection2D
                 ) &&
                CProjectData.tryMergeTrees)
            {
                CTreeManager.TryMergeAllTrees(false);
            }
            CAnalytics.afterFirstMergedTrees = CTreeManager.Trees.Count;

            //validate restrictive
            bool cathegorize = false;

            if (detectionMethod == EDetectionMethod.Detection2D)
            {
                cathegorize = true;
            }

            CDebug.Step(EProgramStep.ValidateTrees2);
            CTreeManager.ValidateTrees(cathegorize, true);

            CDebug.Step(EProgramStep.MergeTrees2);
            if (detectionMethod == EDetectionMethod.AddFactor)
            {
                //merge only invalid
                if (CProjectData.tryMergeTrees2)
                {
                    CTreeManager.TryMergeAllTrees(true);
                }
            }

            //try merging not-trees again after trees were merged
            CDebug.Step(EProgramStep.MergeNotTrees2);
            CTreeManager.TryMergeNotTrees();

            CDebug.Step(EProgramStep.ValidateTrees3);
            if (detectionMethod == EDetectionMethod.AddFactor)
            {
                //validate restrictive
                //cathegorize invalid trees
                CTreeManager.ValidateTrees(true, true, true);
            }

            //todo: just debug
            //CTreeManager.CheckAllTrees();

            CAnalytics.detectedTrees        = CTreeManager.Trees.Count;
            CAnalytics.invalidTrees         = CTreeManager.InvalidTrees.Count;
            CAnalytics.invalidTreesAtBorder = CTreeManager.GetInvalidTreesAtBorderCount();

            CAnalytics.inputAverageTreeHeight = CTreeManager.AVERAGE_TREE_HEIGHT;
            CAnalytics.averageTreeHeight      = CTreeManager.GetAverageTreeHeight();
            CAnalytics.maxTreeHeight          = CTreeManager.MaxTreeHeight;
            CAnalytics.minTreeHeight          = CTreeManager.GetMinTreeHeight();

            CDebug.Count("Trees", CTreeManager.Trees.Count);
            CDebug.Count("InvalidTrees", CTreeManager.InvalidTrees.Count);
            //CProjectData.array.DebugDetectedTrees();

            CTreeManager.AssignMaterials();

            CDebug.Step(EProgramStep.AssignReftrees);
            CReftreeManager.AssignRefTrees();
            if (CParameterSetter.GetBoolSettings(ESettings.exportRefTrees))            //no reason to export when no refTrees were assigned
            {
                //CRefTreeManager.ExportTrees();
                CObjPartition.AddRefTrees();
            }

            CObjPartition.AddTrees(true);
            if (CParameterSetter.GetBoolSettings(ESettings.exportInvalidTrees))
            {
                CObjPartition.AddTrees(false);
            }
        }