public float GetDefinedFactor() { List <CTreePoint> topTreePoints = TreePoints; if (topTreePoints.Count == 0) { return(0); } if (TreePoints.Count < CTreeManager.MIN_BRANCH_POINT_COUNT) { int allTreePointsCount = tree.GetAllPoints().Count; if (allTreePointsCount < CTreeManager.MIN_TREE_POINT_COUNT) { return(0); } } float height = tree.GetTreeHeight(); float distLowestToPeak = Vector3.Distance(TreePoints.Last().Center, tree.peak.Center); float lowestPointRatio = (distLowestToPeak + GetMinDefinedHeightOffset(height)) / height; int treePointCount = TreePoints.Count; const int minPointsPerMeter = 3; //float pointCountRatio = treePointCount / (height * minPointsPerMeter); float pointCountRatio = treePointCount / (distLowestToPeak * minPointsPerMeter); pointCountRatio = Math.Min(pointCountRatio, 1); float factor = (lowestPointRatio + pointCountRatio) / 2; return(factor); }
/// <summary> /// Use this only in deserialization /// </summary> /// <param name="pTreepointsOnBranch"></param> public void SetTreePoints(List <CTreePoint> pTreepointsOnBranch) { foreach (CTreePoint tp in pTreepointsOnBranch) { TreePoints.Add(tp); OnAddPoint(tp.minBB); OnAddPoint(tp.maxBB); } }
public void AddPoint(Vector3 pPoint) { if (CTreeManager.DEBUG) { CDebug.WriteLine("--- AddPoint " + pPoint.ToString("#+0.00#;-0.00") + " to " + this); } RefreshFurthestPoint(pPoint); OnAddPoint(pPoint); int insertAtIndex = 0; //find appropriate insert at index if (TreePoints.Count > 0) { for (int i = TreePoints.Count - 1; i >= -1; i--) { insertAtIndex = i + 1; if (insertAtIndex == 0) { break; } CTreePoint pointOnBranch = TreePoints[i]; if (pointOnBranch.Includes(pPoint)) { pointOnBranch.AddPoint(pPoint); //boundaries of points are changed, check if the order has to be changed if (i > 0) { CTreePoint previousPoint = TreePoints[i - 1]; //if(previousPoint.Contains(pointOnBranch.Center)) if (pointOnBranch.Z > previousPoint.Z) { TreePoints.RemoveAt(i); TreePoints.Insert(i - 1, pointOnBranch); } } if (i < TreePoints.Count - 1) { CTreePoint nextPoint = TreePoints[i + 1]; if (pointOnBranch.Z < nextPoint.Z) { TreePoints.RemoveAt(i); TreePoints.Insert(i + 1, pointOnBranch); } } CheckAddedPoint(); return; } if (pPoint.Z < pointOnBranch.Z) { if (i == TreePoints.Count - 1 || TreePoints[i + 1].Z <= pPoint.Z) { break; } } } } CTreePoint newPoint = new CTreePoint(pPoint, tree.treePointExtent); TreePoints.Insert(insertAtIndex, newPoint); CheckAddedPoint(); if (CTreeManager.DEBUG) { CDebug.WriteLine("---- new point"); } }
private Vector3 GetLastPoint() { return(TreePoints.Count == 0 ? tree.peak.Center : TreePoints.Last().Center); }