/// <summary> /// Classify each point into its according points list. /// Then adds it to its array. /// </summary> public void AddPointsFromLines(List <Tuple <EClass, Vector3> > pParsedLines) { ClassifyPoints(pParsedLines); DateTime processStartTime = DateTime.Now; CDebug.Count("ProcessParsedLines", pParsedLines.Count); //TODO: unite processing all points CDebug.Step(EProgramStep.ProcessUnassignedPoints); ProcessUnassignedPoints(); CDebug.Step(EProgramStep.ProcessBuildingPoints); ProcessBuildingPoints(); CDebug.Step(EProgramStep.ProcessGroundPoints); ProcessGroundPoints(); CDebug.Step(EProgramStep.PreprocessVegePoints); PreprocessVegePoints(); CDebug.Step(EProgramStep.ProcessVegePoints); ProcessVegePoints(); SetAnalytics(); CDebug.Duration("All points added", processStartTime); }
public static string[] GetFileLines(string pPreprocessedFilePath) { CDebug.Step(EProgramStep.LoadLines); string[] lines = File.ReadAllLines(pPreprocessedFilePath); CDebug.Action("load", pPreprocessedFilePath); return(lines); }
/// <summary> /// Reads parsed lines and loads class and point list. /// Result is sorted in descending order. /// </summary> public static List <Tuple <EClass, Vector3> > ParseLines(string[] lines, bool pUseHeader) { CDebug.Step(EProgramStep.ParseLines); //store coordinates to corresponding data strucures based on their class const int DEFAULT_START_LINE = 19; int startLine = pUseHeader && CProjectData.mainHeader != null ? DEFAULT_START_LINE : 0; CDebug.Warning("loading " + lines.Length + " lines!"); int linesToRead = lines.Length; //todo: check that "classic" processed files work correctly without using default class //bool classesCorect = true; List <Tuple <EClass, Vector3> > parsedLines = new List <Tuple <EClass, Vector3> >(); if (useDebugData) { parsedLines = CDebugData.GetStandartTree(); //CDebugData.DefineArray(true, 0); } else { for (int i = startLine; i < linesToRead; i++) { // <class, coordinate> Tuple <EClass, Vector3> c = CLazTxtParser.ParseLine(lines[i], pUseHeader); if (c == null) { continue; } //some files have different class counting. we are interested only in classes in EClass //if(c.Item1 == EClass.Other) //{ // c = new Tuple<EClass, Vector3>(EClass.Vege, c.Item2); // classesCorect = false; //} parsedLines.Add(c); } } //if(!classesCorect) //{ // CDebug.WriteLine("classes not correct. using default class"); //} CDebug.Count("parsedLines", parsedLines.Count); return(parsedLines); }
public static void Init() { CDebug.Step(EProgramStep.LoadReftrees); return; Trees = new List <CRefTree>(); if (CRxpParser.IsRxp) { return; } List <string> treeFileNames = GetTreeFileNames(); LoadTrees(treeFileNames); }
public static List <string> GetTiledPreprocessedFilePaths() { string preprocessedFilePath = GetPreprocessedFilePath(); SetMainHeader(preprocessedFilePath); if (CRxpParser.IsRxp) { return(new List <string>() { preprocessedFilePath }); } CDebug.Step(EProgramStep.Pre_LasToTxt); //split into tiles and convert to txt return(CPreprocessController.GetTxtFilesPaths(preprocessedFilePath)); }
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); }
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()); }
public static void OnException() { CDebug.Step(EProgramStep.Exception); }
private static EProcessResult ProcessTile(string pTilePath, int pTileIndex) { //has to reinit first for the correct progress output CDebug.ReInit(); DateTime startTime = DateTime.Now; currentTileIndex = pTileIndex; List <Tuple <EClass, Vector3> > parsedLines; if (CRxpParser.IsRxp) { CRxpInfo rxpInfo = CRxpParser.ParseFile(pTilePath); parsedLines = rxpInfo.ParsedLines; //for now we expect only one tile in rxp processing CProjectData.currentTileHeader = rxpInfo.Header; CProjectData.mainHeader = rxpInfo.Header; } else { string[] lines = CProgramLoader.GetFileLines(pTilePath); bool linesOk = lines != null && lines.Length > 0 && !string.IsNullOrEmpty(lines[0]); if (linesOk && CHeaderInfo.HasHeader(lines[0])) { //todo: where to init header? CProjectData.currentTileHeader = new CHeaderInfo(lines); } else { const string noHeaderMsg = "Processed tile has no header"; CDebug.Error(noHeaderMsg); throw new Exception(noHeaderMsg); } parsedLines = CProgramLoader.ParseLines(lines, true); } //has to be called after currentTileHeader is assigned CProjectData.ReInit(pTileIndex); //has to reinit after each tile is processed CTreeManager.Reinit(); if (CProjectData.backgroundWorker.CancellationPending) { return(EProcessResult.Cancelled); } CProgramLoader.ProcessParsedLines(parsedLines); if (CProjectData.backgroundWorker.CancellationPending) { return(EProcessResult.Cancelled); } CTreeManager.DebugTrees(); CDebug.Step(EProgramStep.Export3D); CObjPartition.ExportPartition("", "tile" + pTileIndex); if (CProjectData.backgroundWorker.CancellationPending) { return(EProcessResult.Cancelled); } //has to be called after ExportPartition where final folder location is determined try { CDebug.Step(EProgramStep.Bitmap); CBitmapExporter.Export(pTileIndex); } catch (Exception e) { CDebug.Error("exception: " + e.Message); } CAnalytics.totalDuration = CAnalytics.GetDuration(startTime); CDebug.Duration("total time", startTime); CDebug.Step(EProgramStep.Dart); CDartTxt.ExportTile(); CDebug.Step(EProgramStep.Shp); CShpController.ExportCurrent(); CDebug.Step(EProgramStep.Las); CLasExporter.ExportTile(); CDebug.Step(EProgramStep.Analytics); CAnalytics.Write(true); return(EProcessResult.Done); }
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); } }
/// <summary> /// Returns path to the classified forest file. /// If it is not created it runs: /// - lasground /// - lasheight /// - lasclassify /// commands /// </summary> internal static string GetClassifiedFilePath() { DateTime getClassifiedFilePathStart = DateTime.Now; DateTime start = DateTime.Now; if (File.Exists(preprocessedFilePath)) { return(preprocessedFilePath); } //forest file is already processed bool preprocess = CParameterSetter.GetBoolSettings(ESettings.preprocess); if (!preprocess || CRxpParser.IsRxp) { return(forestFilePath); } /////// lastile ////////// CDebug.Step(EProgramStep.Pre_Tile); //takes long time for large files but cant meassure process FileInfo[] tiledFiles = GetTiledFiles(forestFilePath, tmpTiledFilesFolder, PREPROCESS_TILE_SIZE, CProjectData.bufferSize); List <string> classifyFilePaths = new List <string>(); tilesCount = tiledFiles.Length; for (int i = 0; i < tiledFiles.Length; i++) { currentTileIndex = i; CDebug.Progress(i, tiledFiles.Length, 1, ref start, getClassifiedFilePathStart, "GetClassifiedFilePath", true); FileInfo fi = tiledFiles[i]; /////// lasnoise ////////// CDebug.Step(EProgramStep.Pre_Noise); string noiseFilePath = LasNoise(fi.FullName); /////// lasground ////////// CDebug.Step(EProgramStep.Pre_LasGround); string groundFilePath = LasGround(noiseFilePath); /////// lasheight ////////// CDebug.Step(EProgramStep.Pre_LasHeight); string heightFilePath = LasHeight(groundFilePath); /////// lasclassify ////////// CDebug.Step(EProgramStep.Pre_LasClassify); string classifyFilePath = LasClassify(heightFilePath); classifyFilePaths.Add(classifyFilePath); } /////// lasmerge ////////// //LasMerge(classifyFilePaths); CDebug.Step(EProgramStep.Pre_LasReverseTile); /////// reverse lastile ////////// LasReverseTiles(classifyFilePaths); /////// delete unnecessary tmp files ////////// if (CParameterSetter.GetBoolSettings(ESettings.deleteTmp)) { CDebug.Step(EProgramStep.Pre_DeleteTmp); DirectoryInfo di = new DirectoryInfo(currentTmpFolder); FileInfo[] fileInfos = di.GetFiles(); for (int i = 0; i < fileInfos.Length; i++) { FileInfo fi = fileInfos[i]; if (IsTmpFile(fi)) { CDebug.WriteLine($"delete tmp file {fi.Name}"); fi.Delete(); } } //delete tiles folder new DirectoryInfo(tmpTiledFilesFolder).Delete(true); } return(preprocessedFilePath); }