예제 #1
0
        /// <summary>
        /// Split preprocessed file into tiles and converto to txt
        /// </summary>
        internal static List <string> GetTxtFilesPaths(string pPreprocessedFilePath)
        {
            List <string> result   = new List <string>();
            int           tileSize = CParameterSetter.GetIntSettings(ESettings.tileSize);

            string outputFolderPath = GetTiledFilesFolder(
                CUtils.GetFileName(pPreprocessedFilePath), tileSize);

            FileInfo[] tiles;
            //lastile splits file into tiles even if tileSize is bigger
            //todo: WHY?
            //=> dont split to tiles
            if (CProjectData.mainHeader.Width <= tileSize &&
                CProjectData.mainHeader.Height <= tileSize)
            {
                tiles = new FileInfo[] { new FileInfo(pPreprocessedFilePath) };
            }
            else
            {
                tiles = GetTiledFiles(pPreprocessedFilePath,
                                      outputFolderPath, tileSize, CProjectData.bufferSize);
            }

            for (int i = 0; i < tiles.Length; i++)
            {
                string txtFile = Las2Txt(tiles[i].FullName, outputFolderPath);
                result.Add(txtFile);
            }
            return(result);
        }
예제 #2
0
        public void UpdateRangeBounds()
        {
            //X
            //range has to match file coordinates
            //in project are used coordinates moved by offset
            Vector3 min = (Vector3)CProjectData.sourceFileHeader.Min_orig;
            Vector3 max = (Vector3)CProjectData.sourceFileHeader.Max_orig;

            form.trackBarRangeXmin.SetRange((int)min.X * 10, (int)max.X * 10);
            form.trackBarRangeXmax.SetRange((int)min.X * 10, (int)max.X * 10);

            int minValue = CParameterSetter.GetIntSettings(ESettings.rangeXmin);
            int maxValue = CParameterSetter.GetIntSettings(ESettings.rangeXmax);

            //if last values were out of slider bounds, update them
            if (minValue >= form.trackBarRangeXmax.Maximum)
            {
                minValue = form.trackBarRangeXmax.Minimum;
            }
            if (maxValue <= form.trackBarRangeXmax.Minimum)
            {
                maxValue = form.trackBarRangeXmax.Maximum;
            }

            TrySetTrackBarValue(form.trackBarRangeXmin, minValue);
            TrySetTrackBarValue(form.trackBarRangeXmax, maxValue);
            //form.trackBarRangeXmin.Value =
            //	minValue.LimitToRange(form.trackBarRangeXmin.Minimum, form.trackBarRangeXmin.Maximum);
            //form.trackBarRangeXmax.Value = CUtils.LimitToRange(maxValue,
            //	form.trackBarRangeXmax.Minimum, form.trackBarRangeXmax.Maximum);

            SetRangeX();

            //Y
            form.trackBarRangeYmin.SetRange((int)min.Y * 10, (int)max.Y * 10);
            form.trackBarRangeYmax.SetRange((int)min.Y * 10, (int)max.Y * 10);

            minValue = CParameterSetter.GetIntSettings(ESettings.rangeYmin);
            maxValue = CParameterSetter.GetIntSettings(ESettings.rangeYmax);

            //if last values were out of slider bounds, update them
            if (minValue >= form.trackBarRangeYmax.Maximum)
            {
                minValue = form.trackBarRangeYmax.Minimum;
            }
            if (maxValue <= form.trackBarRangeYmax.Minimum)
            {
                maxValue = form.trackBarRangeYmax.Maximum;
            }

            //WARNING: when float is used there is a possible value overflow
            //form.trackBarRangeYmin.Value = CUtils.LimitToRange(minValue,
            //	form.trackBarRangeYmin.Minimum, form.trackBarRangeYmin.Maximum);
            //form.trackBarRangeYmax.Value = CUtils.LimitToRange(maxValue,
            //	form.trackBarRangeYmax.Minimum, form.trackBarRangeYmax.Maximum);
            TrySetTrackBarValue(form.trackBarRangeYmin, minValue);
            TrySetTrackBarValue(form.trackBarRangeYmax, maxValue);

            SetRangeY();
        }
예제 #3
0
        /// <summary>
        /// Calculate partition step size in proportion to used ground array step
        /// </summary>
        private static void SetPartitionStepSize()
        {
            float scaledPartitionStep =
                CParameterSetter.GetIntSettings(ESettings.partitionStep) /
                CParameterSetter.GetFloatSettings(ESettings.groundArrayStep);

            partitionStepSize = Math.Max(1, (int)scaledPartitionStep);
        }
예제 #4
0
        private static float GetPartitionSize(float size)
        {
            int partitionStep = CParameterSetter.GetIntSettings(ESettings.partitionStep);
            int xParts        = (int)Math.Ceiling(arrayWidth / partitionStep);
            int zParts        = (int)Math.Ceiling(arrayHeight / partitionStep);
            int parts         = xParts * zParts;

            return(size / Math.Max(1, parts));
        }
예제 #5
0
        /// <summary>
        /// Assigns all vege points in preprocess arrays.
        /// Then it calculates the expected average tree height.
        /// </summary>
        private void PreprocessVegePoints()
        {
            const int debugFrequency = 10000;

            DateTime PreprocessVegePointsStart = DateTime.Now;

            CDebug.WriteLine("PreprocessVegePoints", true);

            DateTime preprocessVegePointsStart = DateTime.Now;
            DateTime previousDebugStart        = DateTime.Now;

            for (int i = 0; i < vege.Count; i++)
            {
                if (CProjectData.backgroundWorker.CancellationPending)
                {
                    return;
                }

                Vector3 point = vege[i];
                preprocessDetailArray.AddPointInField(point);
                preprocessNormalArray.AddPointInField(point);

                CDebug.Progress(i, vege.Count, debugFrequency, ref previousDebugStart, preprocessVegePointsStart, "preprocessed point");
            }

            //fill missing heigh - will be used in detection process
            //rank 2 - rank 1 (max) extends local maximas -> unwanted effect
            preprocessDetailArray.FillMissingHeights(2);
            preprocessDetailArray.FillMissingHeights(2);

            CDebug.Duration("PreprocessVegePoints", PreprocessVegePointsStart);

            //determine average tree height
            if (CParameterSetter.GetBoolSettings(ESettings.autoAverageTreeHeight))
            {
                //not valid anymore //why not valid??...seems to work fine
                CTreeManager.AVERAGE_TREE_HEIGHT = preprocessNormalArray.GetAverageZ();

                if (float.IsNaN(CTreeManager.AVERAGE_TREE_HEIGHT))
                {
                    CDebug.Error("AVERAGE_TREE_HEIGHT = NaN. using input value");
                    CTreeManager.AVERAGE_TREE_HEIGHT = CParameterSetter.GetIntSettings(ESettings.avgTreeHeigh);
                }
            }
            else
            {
                CTreeManager.AVERAGE_TREE_HEIGHT = CParameterSetter.GetIntSettings(ESettings.avgTreeHeigh);
            }
        }
예제 #6
0
        public static void Init()
        {
            treeIndex  = 0;
            debugcalls = 0;
            maxPossibleTreesAssignment = 0;

            detectMethod    = GetDetectMethod();
            AllowedDescend  = CParameterSetter.GetFloatSettings(ESettings.allowedDescend);
            MinAscendSteps  = CParameterSetter.GetIntSettings(ESettings.minAscendSteps);
            MinDescendSteps = CParameterSetter.GetIntSettings(ESettings.minDescendSteps);

            LocalMaxHeight = CParameterSetter.GetFloatSettings(ESettings.localMaxHeight);

            Reinit();
        }
예제 #7
0
        /// <summary>
        /// Calculates estimated file size
        /// </summary>
        private static float GetResultFileSize()
        {
            CHeaderInfo header = CProjectData.sourceFileHeader;

            if (header == null)
            {
                return(0);
            }

            arrayHeight = header.Height;
            arrayWidth  = header.Width;
            if ((ESplitMode)CParameterSetter.GetIntSettings(ESettings.currentSplitMode) == ESplitMode.Manual)
            {
                SSplitRange range = CParameterSetter.GetSplitRange();
                arrayWidth  = range.RangeX;
                arrayHeight = range.RangeY;
            }

            float area = arrayWidth * arrayHeight;

            const float treeStructure = .05f;
            const float reftreeSize   = 1;
            const float treeBoxSize   = .01f;

            const float treeDensity = .1f;    //1 tree per 10 squared meters
            float       groundSize  = 5;      //its just small, no reason to count it in

            float totalSize = groundSize;


            if (CParameterSetter.GetBoolSettings(ESettings.exportTreeStructures))
            {
                totalSize += area * treeDensity * treeStructure;
            }
            if (CParameterSetter.GetBoolSettings(ESettings.exportTreeBoxes))
            {
                totalSize += area * treeDensity * treeBoxSize;
            }
            if (CParameterSetter.GetBoolSettings(ESettings.exportRefTrees))
            {
                totalSize += area * treeDensity * reftreeSize;
            }
            return(totalSize);
        }
예제 #8
0
        private static void CheckRange()
        {
            switch ((ESplitMode)CParameterSetter.GetIntSettings(ESettings.currentSplitMode))
            {
            case ESplitMode.Manual:
                SSplitRange range = CParameterSetter.GetSplitRange();
                if (!range.IsValid())
                {
                    problems.Add($"range {range} is not valid");
                }
                break;

            case ESplitMode.Shapefile:
                string shapefilePath = CParameterSetter.GetStringSettings(ESettings.shapeFilePath);
                if (!File.Exists(shapefilePath))
                {
                    problems.Add($"shapefile not defined. {shapefilePath}");
                }
                break;
            }
        }
예제 #9
0
        /// <summary>
        /// When user sets range in textBox manually, update the value after the focus of
        /// textbox is lost, otherwise it always changes the selection
        /// </summary>
        internal void textRange_LostFocus(TrackBar pTrackBar, ESettings pOppositeRange, string textRangeValue)
        {
            float value = 0;

            if (textRangeValue.Length == 0)
            {
                return;
            }

            bool parsed;


            bool hasSign = textRangeValue[0] == '+' || textRangeValue[0] == '-';

            if (hasSign)
            {
                int sign = textRangeValue[0] == '-' ? -1 : +1;

                parsed = float.TryParse(textRangeValue.Substring(1, textRangeValue.Length - 1), out value);
                if (!parsed)
                {
                    return;
                }

                float newValue = CParameterSetter.GetIntSettings(pOppositeRange) / 10 + sign * value;
                TrySetTrackBarValue(pTrackBar, (int)newValue * 10);
            }
            else
            {
                parsed = float.TryParse(textRangeValue, out value);
                if (!parsed)
                {
                    return;
                }
                TrySetTrackBarValue(pTrackBar, (int)value * 10);
            }
            SetRangeX();
            SetRangeY();
        }
예제 #10
0
        private static string GetPreprocessedFilePath()
        {
            DateTime getPreprocessedFilePathStart = DateTime.Now;
            DateTime start = DateTime.Now;

            CDebug.Progress(1, 3, 1, ref start, getPreprocessedFilePathStart, "classifyFilePath", true);

            string classifyFilePath = CPreprocessController.GetClassifiedFilePath();

            if (CRxpParser.IsRxp)
            {
                return(classifyFilePath);
            }

            /////// lassplit //////////

            CDebug.Step(EProgramStep.Pre_Split);

            CDebug.Progress(2, 3, 1, ref start, getPreprocessedFilePathStart, "splitFilePath", true);

            //split mode = NONE => split file is same as classified file
            string splitFilePath = classifyFilePath;

            switch ((ESplitMode)CParameterSetter.GetIntSettings(ESettings.currentSplitMode))
            {
            case ESplitMode.Manual:
                splitFilePath = CPreprocessController.LasSplit(classifyFilePath);
                break;

            case ESplitMode.Shapefile:
                splitFilePath = CPreprocessController.LasClip(classifyFilePath);
                break;
            }

            return(splitFilePath);
        }
예제 #11
0
        public static EProcessResult Start()
        {
            CSequenceController.SetValues();

            DateTime startTime = DateTime.Now;

            CProjectData.Init();
            CTreeManager.Init();
            CAnalytics.Init();

            CDartTxt.Init();
            CLasExporter.Init();
            CBiomassController.Init(
                CParameterSetter.GetStringSettings(ESettings.dbh),
                CParameterSetter.GetStringSettings(ESettings.agb));
            CTreeRadiusCalculator.Init();
            CShpController.Init();
            CReftreeManager.Init();

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en");

            //GENERAL
            CProjectData.useMaterial     = true;
            CObjExporter.simplePointsObj = false;

            CMaterialManager.Init();

            string[] workerResult = new string[2];
            workerResult[0] = "this string";
            workerResult[1] = "some other string";
            CProjectData.backgroundWorker.ReportProgress(10, workerResult);

            try
            {
                List <string> tiledFiles = CProgramLoader.GetTiledPreprocessedFilePaths();

                tilesCount = tiledFiles.Count;
                int startTile = CParameterSetter.GetIntSettings(ESettings.startIndex);
                if (startTile < 0 || startTile >= tiledFiles.Count)
                {
                    throw new Exception($"Parameter startTile = {startTile}, tiledFiles.Count = {tiledFiles.Count}");
                }

                for (int i = startTile; i < tiledFiles.Count; i++)
                {
                    string         tiledFilePath = tiledFiles[i];
                    EProcessResult tileProcess   = ProcessTile(tiledFilePath, i);
                    if (CProjectData.backgroundWorker.CancellationPending)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                CDebug.Error(
                    $"{Environment.NewLine}exception: {e.Message} {Environment.NewLine}{Environment.NewLine}" +
                    $"StackTrace: {e.StackTrace}{Environment.NewLine}");
                OnException();
                return(EProcessResult.Exception);
            }

            if (CProjectData.backgroundWorker.CancellationPending)
            {
                CDebug.Step(EProgramStep.Cancelled);
                return(EProcessResult.Cancelled);
            }

            CDebug.Step(EProgramStep.ExportMainFiles);
            //TODO: implement this in super class for all controllers
            //dont create the main file if not needed
            if (tilesCount > 1)
            {
                CDartTxt.ExportMain();
                CLasExporter.ExportMain();
                CShpController.ExportMain();
            }
            CBitmapExporter.ExportMain();

            CDebug.Step(EProgramStep.Done);

            if (CSequenceController.IsLastSequence())
            {
                CSequenceController.OnLastSequenceEnd();
                return(EProcessResult.Done);
            }

            CSequenceController.currentConfigIndex++;
            return(Start());
        }