Esempio n. 1
0
        public static void ExportTile()
        {
            return;

            if (CTreeManager.Trees.Count == 0)
            {
                CDebug.Warning($"CDartTxt: no output created on tile {CProgramStarter.currentTileIndex}");
                return;
            }
            DateTime start     = DateTime.Now;
            DateTime lastDebug = DateTime.Now;

            StringBuilder output = new StringBuilder(HEADER_LINE + newLine);

            for (int i = 0; i < CTreeManager.Trees.Count; i++)
            {
                CDebug.Progress(i, CTreeManager.Trees.Count, DEBUG_FREQUENCY, ref lastDebug, start, "Export dart (trees)");
                CTree  tree = CTreeManager.Trees[i];
                string line = GetLine(tree);
                if (line != null)
                {
                    output.Append(line + newLine);
                }
            }

            //CDebug.WriteLine(output);
            WriteToFile(output.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Assigns vege poins to trees. Handled in TreeManager
        /// </summary>
        private void ProcessVegePoints()
        {
            vege.Sort((b, a) => a.Z.CompareTo(b.Z));             //sort descending by height

            const int debugFrequency = 10000;

            DateTime processVegePointsStart = DateTime.Now;

            CDebug.WriteLine("ProcessVegePoints", true);

            DateTime previousDebugStart = DateTime.Now;


            int pointsToAddCount = vege.Count;

            //pointsToAddCount = 12000;

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

                Vector3 point = vege[i];
                CTreeManager.AddPoint(point, i);

                CDebug.Progress(i, vege.Count, debugFrequency, ref previousDebugStart, processVegePointsStart, "added point");
            }
            CDebug.WriteLine("maxPossibleTreesAssignment = " + CTreeManager.maxPossibleTreesAssignment + " todo: investigate if too high");


            CAnalytics.processVegePointsDuration = CAnalytics.GetDuration(processVegePointsStart);
            CDebug.Duration("ProcessVegePoints", processVegePointsStart);
        }
Esempio n. 3
0
        /// <summary>
        /// Add all (valid/invalid) tree points to the output and main output
        /// </summary>
        private static void AddTreePointsTo(ref StringBuilder pOutput, bool pValid, ref DateTime start)
        {
            string   res;
            DateTime lastDebug = DateTime.Now;

            List <CTree> trees = pValid ? CTreeManager.Trees : CTreeManager.InvalidTrees;

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

                CDebug.Progress(i, trees.Count, DEBUG_FREQUENCY, ref lastDebug, start, "Export las (trees)");

                CTree t = trees[i];

                //without this there are always invalid trees in the main file at buffer zones
                if (t.isAtBufferZone)
                {
                    continue;
                }

                res = GetTreeLines(t);                 //already ends with "newLine"
                pOutput.Append(res);
            }
            //mainOutput.Append(pOutput);
        }
Esempio n. 4
0
        private void AddPointsFromLines(List <Tuple <EClass, Vector3> > pParsedLines)
        {
            DateTime addStartTime = DateTime.Now;

            CDebug.WriteLine("AddPointsFromLines " + pParsedLines.Count);
            int pointsToAddCount = pParsedLines.Count;

            pParsedLines.Sort((a, b) => b.Item2.Z.CompareTo(a.Item2.Z));
            //lines are sorted. first point is peak for sure
            Init(pParsedLines[0].Item2, treeIndex, treePointExtent);

            DateTime lineStartTime = DateTime.Now;

            for (int i = 1; i < Math.Min(pParsedLines.Count, pointsToAddCount); i++)
            {
                Tuple <EClass, Vector3> parsedLine = pParsedLines[i];
                Vector3 point = parsedLine.Item2;

                //all points belong to 1 tree. force add it
                AddPoint(point);

                CDebug.Progress(i, pParsedLines.Count, 100000, ref lineStartTime, addStartTime, "added point:");
            }
            CDebug.Duration("All points added", addStartTime);
        }
Esempio n. 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);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Export file using data from currently loaded trees
        /// </summary>
        public static void ExportCurrent()
        {
            if (!exportShape)
            {
                return;
            }

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

            List <IFeature> treePositions = new List <IFeature>();
            List <IFeature> treeBorders   = new List <IFeature>();
            StringBuilder   shpInfo       = new StringBuilder();

            shpInfo.Append(ATTR_ID + SEP);
            shpInfo.Append(ATTR_X + SEP);
            shpInfo.Append(ATTR_Y + SEP);
            //shpInfo.Append(ATTR_AREA + SEP);
            shpInfo.Append(ATTR_HEIGHT + SEP);
            shpInfo.Append(ATTR_DBG + SEP);
            shpInfo.Append(ATTR_AGB);
            shpInfo.AppendLine();

            for (int i = 0; i < CTreeManager.Trees.Count; i++)
            {
                CDebug.Progress(i, CTreeManager.Trees.Count, DEBUG_FREQUENCY, ref lastDebug, start, "Export shp (trees)");
                CTree tree = CTreeManager.Trees[i];
                //tree positions
                Feature f = GetTreePosition(tree, ref shpInfo);
                treePositions.Add(f);
                treePositionsAll.Add(f);

                //tree borders
                f = GetTreeBorder(tree);
                treeBorders.Add(f);
                treeAreasAll.Add(f);
            }
            CLasExporter.WriteToFile(shpInfo, CProjectData.outputTileSubfolder + "shape_info.csv");

            if (exportShapeTreePos)
            {
                ExportFeatures(treePositions, TREE_POS_FILE, false);
            }
            if (exportShapeTreeAreas)
            {
                ExportFeatures(treeBorders, TREE_BORDER_FILE, false);
            }
        }
Esempio n. 7
0
        private static void LoadTrees(List <string> pFileNames)
        {
            DateTime loadTreesStartTime = DateTime.Now;
            DateTime lastDebugTime      = DateTime.Now;

            CDebug.WriteLine("Load reftrees: ");
            foreach (string fileName in pFileNames)
            {
                CDebug.WriteLine(" - " + fileName);
            }

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

                string fileName = pFileNames[i];
                CDebug.Progress(i, pFileNames.Count, 1, ref lastDebugTime, loadTreesStartTime, "load reftree");

                CRefTree deserializedRefTree     = CRefTree.Deserialize(fileName);
                bool     isDeserializedTreeValid = deserializedRefTree != null &&
                                                   deserializedRefTree.IsCurrentVersion();
                CRefTree refTree = isDeserializedTreeValid ?
                                   deserializedRefTree : new CRefTree(fileName, i, TREE_POINT_EXTENT, true);

                refTree.RefTreeTypeName = fileName;                 //GetTypeName(fileName);

                if (!refTree.isValid)
                {
                    //this reftree is not valid. case for reftrees in 'ignore' folder
                    CDebug.Warning($"Skipping reftree {fileName}");
                    continue;
                }
                //material set durring assigning to tree
                //refTree.Obj.UseMtl = CMaterialManager.GetRefTreeMaterial(counter);

                Trees.Add(refTree);
                CDebug.WriteLine($"Loaded tree: {fileName}. height = {refTree.GetTreeHeight()}");
            }
            CAnalytics.loadReftreesDuration = CAnalytics.GetDuration(loadTreesStartTime);
            CDebug.Duration("Load reftrees", loadTreesStartTime);

            CAnalytics.loadedReftrees = Trees.Count;

            DebugReftrees();
        }
Esempio n. 8
0
        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");
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Add points from given class to the output and main output
        /// </summary>
        private static void AddPointsTo(ref StringBuilder pOutput, EClass pClass, ref DateTime start)
        {
            List <Vector3> points = CProjectData.Points.GetPoints(pClass);
            string         res;
            DateTime       lastDebug = DateTime.Now;

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

                CDebug.Progress(i, points.Count, DEBUG_FREQUENCY, ref lastDebug, start, "Export las (ground points)");

                Vector3   p       = points[i];
                CVector3D globalP = CUtils.GetGlobalPosition(p);
                res = GetPointLine(globalP, 1, 0, GetClassColor(pClass)) + newLine;
                pOutput.Append(res);
            }
            //mainOutput.Append(pOutput);
        }
Esempio n. 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);
        }
Esempio n. 11
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);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Merges all trees, whose peak has good AddFactor to another tree
        /// </summary>
        private static void MergeGoodAddFactorTrees(bool pOnlyInvalid)
        {
            DateTime mergeStart         = DateTime.Now;
            DateTime previousMergeStart = DateTime.Now;
            int      iteration          = 0;
            int      maxIterations      = Trees.Count;

            for (int i = Trees.Count - 1; i >= 0; i--)
            {
                if (CProjectData.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (i >= Trees.Count)
                {
                    //CDebug.WriteLine("Tree was deleted");
                    continue;
                }
                CTree treeToMerge = Trees[i];
                if (treeToMerge.treeIndex == 48 || treeToMerge.treeIndex == 1001)
                {
                    CDebug.WriteLine("");
                }

                if (pOnlyInvalid && !treeToMerge.isValid && treeToMerge.IsAtBorder())
                {
                    //CDebug.Warning(treeToMerge + " is at border");
                    continue;
                }

                //dont merge tree if it is local maximum
                //if some tree is very close (in neighbouring detail field)
                //merge it with the highest one
                if (detectMethod == EDetectionMethod.AddFactor2D)
                {
                    if (treeToMerge.Equals(22))
                    {
                        CDebug.WriteLine();
                    }

                    if (treeToMerge.IsLocalMaximum())
                    {
                        continue;
                    }

                    CTreeField   f           = CProjectData.Points.treeDetailArray.GetFieldContainingPoint(treeToMerge.peak.Center);
                    List <CTree> treesInHood = f.GetDetectedTreesFromNeighbourhood();
                    foreach (CTree tree in treesInHood)
                    {
                        if (tree.Equals(treeToMerge))
                        {
                            continue;
                        }

                        MergeTrees(tree, treeToMerge);
                        break;
                    }
                    continue;
                }


                List <CTree> possibleTrees      = GetPossibleTreesToMergeWith(treeToMerge, EPossibleTreesMethod.ClosestHigher);
                Vector3      pPoint             = treeToMerge.peak.Center;
                float        bestAddPointFactor = 0;
                CTree        selectedTree       = null;

                foreach (CTree possibleTree in possibleTrees)
                {
                    bool isFar           = false;
                    bool isSimilarHeight = false;

                    if (possibleTree.isValid && treeToMerge.isValid)
                    {
                        float mergeFactor = GetMergeValidFacor(treeToMerge, possibleTree);
                        if (mergeFactor > 0.9f)
                        {
                            selectedTree = possibleTree;
                            break;
                        }
                    }
                    if (pOnlyInvalid && possibleTree.isValid && treeToMerge.isValid)
                    {
                        continue;
                    }

                    if (treeToMerge.isValid)
                    {
                        //treeToMerge is always lower
                        float possibleTreeHeight = possibleTree.GetTreeHeight();
                        float treeToMergeHeight  = treeToMerge.GetTreeHeight();

                        const float maxPeaksDistance = 1;
                        float       peaksDist        = CUtils.Get2DDistance(treeToMerge.peak, possibleTree.peak);
                        if (peaksDist > maxPeaksDistance)
                        {
                            isFar = true;
                        }

                        const float maxPeakHeightDiff = 1;
                        if (possibleTreeHeight - treeToMergeHeight < maxPeakHeightDiff)
                        {
                            isSimilarHeight = true;
                        }
                    }

                    float addPointFactor = possibleTree.GetAddPointFactor(pPoint, treeToMerge);
                    float requiredFactor = 0.5f;
                    if (isFar)
                    {
                        requiredFactor += 0.1f;
                    }
                    if (isSimilarHeight)
                    {
                        requiredFactor += 0.1f;
                    }
                    if (pOnlyInvalid)
                    {
                        requiredFactor -= 0.2f;
                    }

                    if (addPointFactor > requiredFactor && addPointFactor > bestAddPointFactor)
                    {
                        selectedTree       = possibleTree;
                        bestAddPointFactor = addPointFactor;
                        if (bestAddPointFactor > 0.9f)
                        {
                            break;
                        }
                    }
                }
                if (selectedTree != null)
                {
                    float dist = CUtils.Get2DDistance(treeToMerge.peak.Center, selectedTree.peak.Center);
                    treeToMerge = MergeTrees(ref treeToMerge, ref selectedTree, pOnlyInvalid);
                }

                CDebug.Progress(iteration, maxIterations, 50, ref previousMergeStart, mergeStart, "merge");
                iteration++;
            }
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        /// <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);
        }
Esempio n. 15
0
        //public static string[] GetDebugHeaderLines()
        //{
        //	string[] result = new string[19];
        //	for(int i = 0; i <= 14; i++)
        //	{
        //		result[i] = "%";
        //	}

        //	result[15] = "% scale factor x y z         1 1 1";
        //	result[16] = "% offset x y z               0 0 0";
        //	result[17] = "% min x y z               0 0 0";
        //	result[18] = "% max x y z               0 0 0";
        //	//result[19] = "-20.10000	-3.21350	631.06150	0";
        //	return result;
        //}

        public static CRxpInfo ParseFile(string pFile)
        {
            int    sync_to_pps = 0;
            IntPtr h3ds        = IntPtr.Zero;

            int opened = scanifc_point3dstream_open(pFile, ref sync_to_pps, ref h3ds);

            Console.WriteLine($"opened = {opened}, h3ds = {h3ds}");

            uint       PointCount = 1;
            int        EndOfFrame = 1;
            const uint BLOCK_SIZE = 1000;

            scanifc_xyz32[]      BufferXYZ  = new scanifc_xyz32[BLOCK_SIZE];
            scanifc_attributes[] BufferMISC = new scanifc_attributes[BLOCK_SIZE];
            ulong[] BufferTIME = new ulong[BLOCK_SIZE];

            List <Tuple <EClass, Vector3> > fileLines = new List <Tuple <EClass, Vector3> >();

            //fileLines.AddRange(GetDebugHeaderLines().ToList<string>());

            Vector3 min = new Vector3(int.MaxValue, int.MaxValue, int.MaxValue);
            Vector3 max = new Vector3(int.MinValue, int.MinValue, int.MinValue);

            int      readIteration      = 0;
            DateTime debugStart         = DateTime.Now;
            DateTime previousDebugStart = DateTime.Now;

            int maxLinesToLoad = int.MaxValue;             //5000000

            while (PointCount != 0 || EndOfFrame != 0)
            {
                //debug smaller batch
                if (fileLines.Count >= maxLinesToLoad)
                {
                    break;
                }

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

                readIteration++;
                CDebug.Progress(readIteration, int.MaxValue, 1000, ref previousDebugStart, debugStart, "Parsing Rxp file (size unknown)");
                int read = scanifc_point3dstream_read(
                    h3ds, BLOCK_SIZE,
                    BufferXYZ, BufferMISC, BufferTIME,
                    ref PointCount, ref EndOfFrame);
                for (int i = 0; i < PointCount; i++)
                {
                    scanifc_xyz32 xyz = BufferXYZ[i];
                    //Console.WriteLine($"BufferXYZ = {xyz.x},{xyz.y},{xyz.z}");

                    RefreshMinMax(xyz, ref min, ref max);

                    fileLines.Add(new Tuple <EClass, Vector3>(EClass.Undefined, xyz.ToVector()));
                }
            }

            CHeaderInfo header = new CHeaderInfo(new Vector3(1, 1, 1), new Vector3(0, 0, 0), min, max);

            CRxpInfo rxpInfo = new CRxpInfo(fileLines, header);

            return(rxpInfo);
        }
Esempio n. 16
0
        /// <summary>
        /// Assigns to each of detected trees the most suitable refTree
        /// </summary>
        public static void AssignRefTrees()
        {
            if (Trees.Count == 0)
            {
                //CDebug.Error("no reftrees loaded");
                return;
            }

            DateTime addTreeObjModelsStart = DateTime.Now;

            CDebug.WriteLine("Get reftree models");

            const int debugFrequency = 10;

            DateTime assignRefTreesStart = DateTime.Now;

            CDebug.WriteLine("AssignRefTrees");

            DateTime previousDebugStart = DateTime.Now;

            int   counter       = 0;
            float similaritySum = 0;

            foreach (CTree t in CTreeManager.Trees)
            {
                if (CProjectData.backgroundWorker.CancellationPending)
                {
                    break;
                }

                Tuple <CRefTree, STreeSimilarity> suitableRefTree = GetMostSuitableRefTree(t);
                CRefTree mostSuitableRefTree = suitableRefTree.Item1;
                if (mostSuitableRefTree == null)
                {
                    CDebug.Error("no reftrees assigned!");
                    continue;
                }

                SetRefTreeObjTransform(ref mostSuitableRefTree, t, suitableRefTree.Item2.angleOffset);
                similaritySum += suitableRefTree.Item2.similarity;
                //CDebug.WriteLine($"similaritySum += {suitableRefTree.Item2.similarity}");

                Obj suitableTreeObj = mostSuitableRefTree.Obj.Clone();
                suitableTreeObj.Name += "_" + t.treeIndex;
                t.assignedRefTreeObj  = suitableTreeObj;
                t.assignedRefTree     = mostSuitableRefTree;
                //t.RefTreeTypeName = mostSuitableRefTree.RefTreeTypeName; //copy the type name

                suitableTreeObj.UseMtl = t.assignedMaterial.Name;

                CDebug.Progress(counter, CTreeManager.Trees.Count, debugFrequency, ref previousDebugStart, assignRefTreesStart, "Assigned reftree");
                counter++;


                //CDebug.WriteLine("\n mostSuitableRefTree = " + mostSuitableRefTree);
            }


            CAnalytics.averageReftreeSimilarity = similaritySum / CTreeManager.Trees.Count;

            CAnalytics.reftreeAssignDuration = CAnalytics.GetDuration(addTreeObjModelsStart);
            CDebug.Duration("Assign reftree models", addTreeObjModelsStart);
        }