public static void ExportMain() { if (!exportMain || !exportBitmap) { return; } if (!CParameterSetter.GetBoolSettings(ESettings.ExportBMTreePositions)) { return; } if (CProgramStarter.tilesCount < 2) { return; } //mainMap.SetPixel(0, 0, treeColor); //main bitmap has a lot of missing fields - apply filter //todo: make radius dependent on bitmap width? if (FILTER_MAIN_MAP) { //looks good enough on .3f, higher npt necessary, just slows down rapidly const float kernelRadius = .3f; int kernelSize = GetKernelSize(mainMapStepSize, kernelRadius); FilterBitmap(ref mainMap, kernelSize, EFilter.ColorOrMax); } ExportBitmap(mainMap, "tree_positions_main", -1); }
public static void Init() { useTreeMaterial = CParameterSetter.GetBoolSettings(ESettings.colorTrees); materialSet = new Dictionary <EMaterial, List <int> >(); materials = new Mtl("colors"); AddMaterial("invalid", .3f, EMaterial.Invalid); AddMaterial("alarm", 1, 0, 0, EMaterial.Alarm); AddMaterial("fake", 1, 0, 1, EMaterial.Fake); AddMaterial("checkTree", 0, 0, 1, EMaterial.CheckTree); //https://www.december.com/html/spec/colorper.html AddMaterial("unassignedGold", .6f, .8f, .1f, EMaterial.UnassignedPoint); AddMaterial("groundBrown", .62f, .44f, .23f, EMaterial.GroundPoint); AddMaterial("vegeGreen", .6f, 1, .6f, EMaterial.VegePoint); AddMaterial("buildingRed", .63f, .32f, .18f, EMaterial.BuildingPoint); AddTreeMaterial("red", 1, 0, 0); AddTreeMaterial("orange", 1, .5f, 0); AddTreeMaterial("lightOrange", 1, .2f, 0); AddTreeMaterial("pink", 1, 0, .5f); AddTreeMaterial("purple", .5f, 0, .5f); AddTreeMaterial("green", 0, 1, 0); AddTreeMaterial("yellow", 1, 1, 0); AddTreeMaterial("azure", 0, 1, 1); AddTreeMaterial("lightBlue", 0, .5f, 1); AddTreeMaterial("darkBlue", 0, 0, .3f); AddTreeMaterial("mediumBlue", 0, 0, .7f); }
private void LoadObj(string pFileName) { Obj = new Obj(pFileName); string refTreePath = GetRefTreeFilePath(pFileName, pFileName + ".obj"); bool useReducedReftreeModels = CParameterSetter.GetBoolSettings(ESettings.useReducedReftreeModels); if (useReducedReftreeModels || !File.Exists(refTreePath)) { Obj.Name += "_reduced"; string reducedObjFileName = pFileName + "_reduced.obj"; if (!useReducedReftreeModels) { CDebug.WriteLine("Reftree " + refTreePath + " OBJ does not exist."); CDebug.WriteLine("Try reduced file: " + reducedObjFileName); } refTreePath = GetRefTreeFilePath(pFileName, reducedObjFileName); if (!File.Exists(refTreePath)) { CDebug.Error("No ref tree OBJ found!"); return; } } Obj.LoadObj(refTreePath); }
/// <summary> /// Generates point feature representing position of the tree. /// Attributes: /// id, X, Y, height, DBH, AGB, type /// </summary> private static Feature GetTreePosition(CTree pTree, ref StringBuilder pString) { CVector3D globalTreepos = CUtils.GetGlobalPosition(pTree.peak.Center); IPoint myPoint = factory.CreatePoint(new Coordinate(globalTreepos.X, globalTreepos.Y)); AttributesTable attributesTable = new AttributesTable(); attributesTable.Add(ATTR_ID, pTree.treeIndex); pString.Append(pTree.treeIndex + SEP); shpInfoMain.Append(pTree.treeIndex + SEP); attributesTable.Add(ATTR_X, globalTreepos.X.ToString(NUM_FORMAT)); attributesTable.Add(ATTR_Y, globalTreepos.Y.ToString(NUM_FORMAT)); pString.Append(globalTreepos.X.ToString(NUM_FORMAT) + SEP); shpInfoMain.Append(globalTreepos.X.ToString(NUM_FORMAT) + SEP); pString.Append(globalTreepos.Y.ToString(NUM_FORMAT) + SEP); shpInfoMain.Append(globalTreepos.Y.ToString(NUM_FORMAT) + SEP); float treeHeight = pTree.GetTreeHeight(); attributesTable.Add(ATTR_HEIGHT, treeHeight.ToString(NUM_FORMAT)); pString.Append(treeHeight.ToString(NUM_FORMAT) + SEP); shpInfoMain.Append(treeHeight.ToString(NUM_FORMAT) + SEP); if (CParameterSetter.GetBoolSettings(ESettings.calculateDBH)) { double stemDiameter = CBiomassController.GetTreeStemDiameter(treeHeight); attributesTable.Add(ATTR_DBG, stemDiameter.ToString(NUM_FORMAT)); pString.Append(stemDiameter.ToString(NUM_FORMAT) + SEP); shpInfoMain.Append(stemDiameter.ToString(NUM_FORMAT) + SEP); if (CParameterSetter.GetBoolSettings(ESettings.calculateAGB)) { double biomass = CBiomassController.GetTreeBiomass(stemDiameter, treeHeight); attributesTable.Add(ATTR_AGB, biomass.ToString(NUM_FORMAT)); pString.Append(biomass.ToString(NUM_FORMAT) + SEP); shpInfoMain.Append(biomass.ToString(NUM_FORMAT) + SEP); } } //251 - Finalizace produktu //attributesTable.Add(ATTR_TYPE, pTree.assignedRefTree.RefTreeTypeName); //pString.Append(pTree.assignedRefTree.RefTreeTypeName + SEP); Feature feature = new Feature(myPoint, attributesTable); pString.AppendLine(); shpInfoMain.AppendLine(); return(feature); }
/// <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); } }
/// <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); }
public static void ExportPartition(string pFileSuffix = "", string pIndexPrefix = "") { //folderPath = CObjExporter.CreateFolderIn( // CProjectData.saveFileName, CProjectData.outputTileSubfolder); //just creates a folder (for analytics etc) if (!CParameterSetter.GetBoolSettings(ESettings.export3d) || CRxpParser.IsRxp) { CDebug.WriteLine("Skipping export"); return; } int counter = 0; DateTime exportPartitionStart = DateTime.Now; DateTime previousDebugStart = DateTime.Now; int partsCount = partitionXRange * partitionYRange; int debugFrequency = 1; for (int x = 0; x < partitionXRange; x++) { for (int y = 0; y < partitionYRange; y++) { if (CProjectData.backgroundWorker.CancellationPending) { return; } counter++; List <Obj> objsInPartition = objPartition[x, y]; //export only if partition contains some objects (doesn't have to) if (objsInPartition.Count > 0) { CObjExporter.ExportObjs(objsInPartition, $"{CProjectData.saveFileName}_{pIndexPrefix}[{x},{y}]{pFileSuffix}", CProjectData.outputTileSubfolder); } CDebug.Progress(counter, partsCount, debugFrequency, ref previousDebugStart, exportPartitionStart, "Export of part"); } } }
/// <summary> /// True = everything ok /// </summary> public static bool CheckProblems() { Reset(); CheckPath("Forest", CParameterSetter.GetStringSettings(ESettings.forestFileFullName), true); //if(!CRxpParser.IsRxp) //{ // CheckPath("Reftree", CParameterSetter.GetStringSettings(ESettings.reftreeFolderPath), false); //} CheckPath("Output", CParameterSetter.GetStringSettings(ESettings.outputFolderPath), false); if (CParameterSetter.GetBoolSettings(ESettings.useCheckTreeFile)) { CheckPath("Checktree", CParameterSetter.GetStringSettings(ESettings.checkTreeFilePath), true); } CheckRange(); CheckExport(); if (CShpController.exportShape) { if (CParameterSetter.GetBoolSettings(ESettings.calculateDBH)) { CheckDBH(); } if (CParameterSetter.GetBoolSettings(ESettings.calculateAGB)) { CheckAGB(); } CheckTreeRadius(); } bool hasProblems = problems.Count > 0; if (hasProblems) { CDebug.WriteProblems(problems); problems.Clear(); } return(!hasProblems); }
private static void CheckExport() { bool willExportAny3D = CParameterSetter.GetBoolSettings(ESettings.export3d); if (willExportAny3D) { bool exportTreeStructures = CParameterSetter.GetBoolSettings(ESettings.exportTreeStructures); bool exportReftrees = CParameterSetter.GetBoolSettings(ESettings.exportRefTrees); bool exportTreeBoxes = CParameterSetter.GetBoolSettings(ESettings.exportTreeBoxes); willExportAny3D = exportTreeStructures || exportReftrees || exportTreeBoxes; } bool willExportSomeportBitmap = CParameterSetter.GetBoolSettings(ESettings.exportBitmap); if (willExportSomeportBitmap) { bool exportBMHeightmap = CParameterSetter.GetBoolSettings(ESettings.ExportBMHeightmap); bool exportBMTreeBorders = CParameterSetter.GetBoolSettings(ESettings.ExportBMTreeBorders); bool exportBMTreePositions = CParameterSetter.GetBoolSettings(ESettings.ExportBMTreePositions); willExportSomeportBitmap = exportBMHeightmap || exportBMTreeBorders || exportBMTreePositions; } bool willExportAnyShp = CParameterSetter.GetBoolSettings(ESettings.exportShape); if (willExportAnyShp) { bool exportShapeTreeAreas = CParameterSetter.GetBoolSettings(ESettings.exportShapeTreeAreas); bool exportShapeTreePositions = CParameterSetter.GetBoolSettings(ESettings.exportShapeTreePositions); willExportAnyShp = exportShapeTreeAreas || exportShapeTreePositions; } bool willExportAnyLas = CParameterSetter.GetBoolSettings(ESettings.exportLas); if (!willExportAny3D && !willExportSomeportBitmap && !willExportAnyShp && !willExportAnyLas) { problems.Add($"No reason to process when no 3D-obj, bitmap, SHP-file or LAS-file will be exported."); return; } }
public static void AddTrees(bool pValid) //, bool pFake) { List <Tuple <Tuple <int, int>, CTree> > treesToExport = new List <Tuple <Tuple <int, int>, CTree> >(); bool exportTreeStrucure = CParameterSetter.GetBoolSettings(ESettings.exportTreeStructures); bool exportBoxes = CParameterSetter.GetBoolSettings(ESettings.exportTreeBoxes); if (!exportBoxes && !exportTreeStrucure) { return; } foreach (CTree tree in pValid ? CTreeManager.Trees : CTreeManager.InvalidTrees) { treesToExport.Add(new Tuple <Tuple <int, int>, CTree>(tree.peakNormalField.indexInField, tree)); } //special: add not-trees if (!pValid) { foreach (CTree tree in CTreeManager.NotTrees) { treesToExport.Add(new Tuple <Tuple <int, int>, CTree>(tree.peakNormalField.indexInField, tree)); } } treesToExport.Sort((x, y) => x.Item2.treeIndex.CompareTo(y.Item2.treeIndex)); foreach (Tuple <Tuple <int, int>, CTree> exportTree in treesToExport) { Obj obj = exportTree.Item2.GetObj(exportTreeStrucure, false, exportBoxes); if (!pValid) { obj.UseMtl = CMaterialManager.GetInvalidMaterial().Name; } AddObj(exportTree.Item1, obj); } }
public static void Export(int pTileIndex) { if (!exportBitmap) { return; } //init for each tile treeMarkerSize = GetTreeBrushSize(false); DateTime bitmapStart = DateTime.Now; CVegeArray array = CProjectData.Points.vegeDetailArray; Bitmap bitmap = new Bitmap(array.arrayXRange, array.arrayYRange); int maxValue = 0; for (int x = 0; x < array.arrayXRange; x++) { for (int y = 0; y < array.arrayYRange; y++) { CVegeField element = array.GetField(x, y); int? colorVal = element.GetColorValue(); //from detailed array if (colorVal == null) { continue; } int colorVaInt = (int)colorVal; if (colorVaInt > maxValue) { maxValue = colorVaInt; } int rVal = colorVaInt; //highlight buffer zone bool isAtBufferZone = CTreeMath.IsAtBufferZone(element.Center); if (isAtBufferZone) { rVal = Math.Min(rVal + 30, 255); } Color color = Color.FromArgb(rVal, colorVaInt, colorVaInt); //CDebug.WriteLine($"{x},{y} = {color}"); bitmap.SetPixel(x, y, color); if (exportMain && !isAtBufferZone) { Tuple <int, int> posInMain = GetIndexInMainBitmap(element.Center); if (posInMain == null) { continue; } if (color.R > 255) { CDebug.Error("color.R = " + color.R); } mainMap.SetPixel(posInMain.Item1, posInMain.Item2, color); } } } //StretchColorRange(ref bitmap, maxValue); //FilterBitmap(ref bitmap, GetKernelSize(array.stepSize, .2f), EFilter.Max); if (exportHeightmap) { ExportBitmap(bitmap, "heightmap", pTileIndex); } int bitmapsCount = 3; bool useCheckTree = CParameterSetter.GetBoolSettings(ESettings.useCheckTreeFile); if (useCheckTree) { bitmapsCount++; } CDebug.Progress(1, bitmapsCount, 1, ref bitmapStart, bitmapStart, "bitmap: "); if (exportPositions) { Bitmap bitmapTreePos = new Bitmap(bitmap); AddTreesToBitmap(array, bitmapTreePos, true, false); ExportBitmap(bitmapTreePos, "tree_positions", pTileIndex); if (useCheckTree) { Bitmap bitmapChecktree = new Bitmap(bitmapTreePos); ExportBitmap(bitmapChecktree, "tree_check", pTileIndex); CDebug.Progress(bitmapsCount - 1, bitmapsCount, 1, ref bitmapStart, bitmapStart, "bitmap: "); } } CDebug.Progress(2, bitmapsCount, 1, ref bitmapStart, bitmapStart, "bitmap: "); if (exportBorders) { Bitmap bitmapTreeBorder = new Bitmap(bitmap); AddTreesToBitmap(array, bitmapTreeBorder, true, true); ExportBitmap(bitmapTreeBorder, "tree_borders", pTileIndex); } CDebug.Progress(bitmapsCount, bitmapsCount, 1, ref bitmapStart, bitmapStart, "bitmap: "); CAnalytics.bitmapExportDuration = CAnalytics.GetDuration(bitmapStart); CDebug.Duration("bitmap export", bitmapStart); }
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); } }
public static void Write(bool pToFile) { string output = " - ANALYTICS - " + newLine2; output += $"treeExtent = {CParameterSetter.GetFloatSettings(ESettings.treeExtent)} " + newLine; output += $"treeExtentMultiply = {CParameterSetter.GetFloatSettings(ESettings.treeExtentMultiply)} " + newLine2; output += $"loadedPoints = {loadedPoints} " + newLine; output += $"vegePoints = {vegePoints} " + newLine; output += $"groundPoints = {groundPoints} " + newLine; output += $"unassignedPoints = {unassignedPoints} " + newLine; output += $"buildingPoints = {buildingPoints} " + newLine; output += $"filteredPoints = {filteredPoints}" + newLine2; output += $"arrayWidth = {arrayWidth} m" + newLine; output += $"arrayHeight = {arrayHeight} m" + newLine2; output += $"firstDetectedTrees = {firstDetectedTrees} " + newLine; output += $"firstMergedCount = {GetFirstMergedCount()} " + newLine; output += $"secondMergedCount = {GetSecondMergedCount()} " + newLine; output += $"detectedTrees = {detectedTrees} " + newLine; output += $"trees density = 1 per {GetTreesDensity():0.00} m\xB2 " + newLine; output += $"invalidTrees = {invalidTrees} ({invalidTreesAtBorder} of them at border)\n" + newLine; output += $"inputAverageTreeHeight = {inputAverageTreeHeight} " + newLine; output += $"averageTreeHeight = {averageTreeHeight} " + newLine; output += $"maxTreeHeight = {maxTreeHeight} " + newLine; output += $"minTreeHeight = {minTreeHeight}" + newLine2; output += $"loadedReftrees = {loadedReftrees} " + newLine; output += $"averageReftreeSimilarity = {averageReftreeSimilarity} " + newLine2; output += "Duration" + newLine; output += $"load reftrees = {loadReftreesDuration} " + newLine; output += $"fill missing ground = {fillAllHeightsDuration} " + newLine; output += $"add vege points = {processVegePointsDuration} " + newLine; output += $"first merge = {firstMergeDuration} " + newLine; output += $"second merge = {secondMergeDuration} " + newLine; output += $"reftree assignment = {reftreeAssignDuration} " + newLine; output += $"bitmap export = {bitmapExportDuration} " + newLine; output += $"las export = {lasExportDuration} " + newLine; output += $"-------------------" + newLine; output += $"total = {totalDuration} " + newLine; if (CParameterSetter.GetBoolSettings(ESettings.useCheckTreeFile)) { output += "Checktree" + newLine; output += $"loadedCheckTrees = {loadedCheckTrees} " + newLine; output += $"assignedCheckTrees = {assignedCheckTrees} " + newLine; output += $"invalidCheckTrees = {invalidCheckTrees} " + newLine; } output += $"\nERRORS" + newLine; int counter = 0; const int MAX_ERROR_DEBUG = 100; foreach (string error in errors) { output += $"- {error} " + newLine; counter++; if (counter > MAX_ERROR_DEBUG) { break; } } //before WriteToFile (it can fail there too) errors.Clear(); //reset, so errors dont stack with previous error CDebug.WriteLine(output); if (pToFile) { WriteToFile(output); //ExportCsv(ECsvAnalytics.InputParams); //ExportCsv(ECsvAnalytics.ComputationTime); ExportCsv(ECsvAnalytics.Summary); //probably enough } }
/// <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); }
private static Tuple <CRefTree, STreeSimilarity> GetMostSuitableRefTree(CTree pTree) { if (Trees.Count == 0) { CDebug.Error("no reftrees defined!"); return(null); } CRefTree mostSuitableTree = Trees[0]; STreeSimilarity treeSimilarity = new STreeSimilarity(); STreeSimilarity bestSimilarity = new STreeSimilarity(); if (Trees.Count == 1 && !forceAlgorithm) { return(new Tuple <CRefTree, STreeSimilarity>(mostSuitableTree, treeSimilarity)); } bool forceRandom = false; //pTree.treeIndex != debugTree; bool randomReftree = CParameterSetter.GetBoolSettings(ESettings.assignRefTreesRandom) && pTree.treeIndex != debugTree; if (forceRandom || randomReftree) { //int random = new Random().Next(0, Trees.Count); int rnd = random.Next(0, Trees.Count); //if (debugSimilarites) { CDebug.WriteLine($"random = {random}"); } return(new Tuple <CRefTree, STreeSimilarity>(Trees[rnd], treeSimilarity)); } if (debugSimilarites) { CDebug.WriteLine("\n" + pTree.treeIndex + " similarities = "); } foreach (CRefTree refTree in Trees) { if (CProjectData.backgroundWorker.CancellationPending) { break; } treeSimilarity = CTreeMath.GetSimilarityWith(refTree, pTree); //float similarity = treeSimilarity.similarity; if (debugSimilarites) { CDebug.WriteLine($"{refTree.fileName} similarity = {treeSimilarity.similarity}"); } if (treeSimilarity.similarity > bestSimilarity.similarity) { mostSuitableTree = refTree; bestSimilarity = treeSimilarity; } if (bestSimilarity.similarity > 0.9f && !forceAlgorithm) { break; } } if (debugSimilarites) { CDebug.WriteLine("Most suitable reftree = " + mostSuitableTree.Obj.Name + ". similarity = " + bestSimilarity.similarity); CDebug.WriteLine($"tree height = {pTree.GetTreeHeight()}"); CDebug.WriteLine($"reftree height = {mostSuitableTree.GetTreeHeight()}"); CDebug.WriteLine($"angle offset = {bestSimilarity.angleOffset}"); } return(new Tuple <CRefTree, STreeSimilarity>(mostSuitableTree, bestSimilarity)); }