# File Operations

- Import a point cloud. Supports asc format (x,y,z - coordinates of a point per line, whitespace separator, non mandatory per line are in addition intensity or rgb values). PCL format pcd is also supported.
- Exports a point cloud. Only PCL format pcd is supported.
- Generates various csv output files. The output file names contain the tree id derived from input cloud file name. File ending with dist gives a distance for each point to the computed model. File ending with stats contains parameters like DBH, volume, height and several more. File ending with detailed contains complete information of the model. One cylinder per line including the parent child information. Files are stored in the output folder of your project folder.
- Creates a ply model for detected tree and stem model. Files are stored in the output/Ply folder of your project folder.

# Cylinder detection

The left Button segments main branch + stem points from the twig points. No input needed.

The middle button runs the method for an already imported point cloud. After tree detection visualization can be validated. Output has to be generated manually with File Operations button 3 and 4.

### Threshold description Spherefollowing - basic understanding of the method is needed.

The method is used to fit cylinders into a de-noised point cloud and to build the tree model. Stem points should be detected before running this method. Spheres are utilized to follow the branching structure of the tree from the root to its tips.
A sphere with a center point on a skeleton axis cuts the point cloud. All points within a distance of epsSphere **(6)** to the
sphere-surface are considered to be used to detect the next sphere and are put into a sub point cloud *Psub*. *Psub* is
subdivided into PStem and PBranch.

*PStem* (*PBranch* is processed in same manner) is clustered then with Euclidean Clustering.
At most five clusters *P_i* are generated in a distance minimum epsClusterStem **(4)**, each containing minimum minPtsClusterStem **(9)** points.
The number of returned clusters is set to five, as this is the maximum expected number of cross
sectional areas located on a sphere surface. Each cluster represents a cross-sectional area of the stem/branch.
A circle is fitted with the Random Sample Consensus (RANSAC) algorithm into *P_i*, if the number of points
in *P_i* exceeds minPtsRansacStem **(7)** , and with the more robust but less accurate median method proposed in
Hackenberg et al. (2014) otherwise.

The center point of the circle, the center point of the sphere and the circle radius are chosen as cylinder parameters. The circle is
enlarged with sphereMultiplier **(3)** and transformed to a three dimensional sphere. A minimum radius can be given for
the search spheres **(11,12)** The procedure is repeated recursively until no more cross sectional areas can be found.
Taken from Hackenberg et al 2015b.

- Lets you choose from predefined threshold sets - those cannot be overwritten
- Gives a name for a new threshold set
- The factor to multiply a detected circle for generating a new sphere. Must be larger than 1. For lower quality scans this number can be raised, but you will loose some details.
- A clustering threshold. Two groups of different stem points detected by one sphere cut are put in two clusters if their distance is larger than this number. Only needs to be enlarged if a lot of occlusion is expected. Should never be larger than the expected minimum distance between two main branches. Can most likely be ignored.
**Same as above, but for twig points. Depending on the tree species you might have twigs whose distance is smaller than the predifined value. Can be lowered in this case.**- During sphere cut all points within a distance less than this parameter are considered in the sphere neighborhood. Only enlarge if heavy occlusion occurs.
- Ransac cylinder fit tends to fail sometimes if not enough points are used. 100 should be fine, can be ignored in most cases. Only enlarge this, when you see unexpected large cylinders.
- Just a high number to prevent any RANSAC fit for twigs. Always fails at twig points to my experience. Should be left like it is.
- A circle is fitted only if more points than this numbers are in a cluster. Can be ignored if clouds contain not much noise.
- Same as above, but for twig points.
- If a sphere generated from the detected circle is smaller than this threshold, its radius is set to this value
- Same as above for twig points
- Closes the dialog
- Deletes the selcted setting
- Saves the settings (available also in next start under the given name) and starts computation

### Threshold description Allometric approach - basic understanding of the method is needed.

**Allometric improvement** (a, b, fac, minRad):
A new parameter named GrowthVolume is generated for each cylinder. The GrowthVolume of **a** cylinder is the cylinderâ€™s volume plus the GrowthVolume of all the cylinderâ€™s child cylinders. If analysed against radius of the cylinder,an allometric model of the form
y=**a** x^**b**
can be fitted via NLS fit. Compute **a** and **b** outside within R as proposed on the Statistics and Allometry section. Set **fac** to a large value, if you do not want to apply this function.
If **minRad** does not equal 0.0025, an automatic radius will be found during parameter optimization. Taken from Hackenberg et al 2015b.

**Parameter Optimization** (iterations, seeds, criterion)
The SpherefollowingMethod needs ten input parameters. To enable an automatic search for optimal parameters, initial parameters have to be set by the user. Then a multi-threaded parameter search starts.
In each iteration step **seeds** new parameter sets are created. For one creation each parameter is chosen from a normal distribution centred around the parameter value from the last iteration. For each set a tree
model is build. The average euclidean distance from the point cloud to the model is computed. If this distance is smaller than the last found optimal distance, the method stores the distance and the parameter
set. If after one iteration the distance improvement is smaller than **criterion**, the search is stopped. If the number of iterations exceeds **iterations**, the search stops. The best parameter set is printed out after
completion. Taken from Hackenberg et al 2015b.

The right button runs the method with same threshold set for all point clouds contained in data folder in a loop. More automatism, also output (csv and ply files) is generated, but no direct visual validation possible.