Exemple #1
0
        /// <summary>
        /// Add new tree to tree arrays
        /// </summary>
        public void OnTreeCreated(CTree pNewTree, Vector3 pFirstPoint)
        {
            CVegeField vegeField       = vegeDetailArray.GetFieldContainingPoint(pFirstPoint);
            CTreeField treeDetailField = treeDetailArray.GetFieldContainingPoint(pFirstPoint);
            CTreeField treeNormalField = treeNormalArray.GetFieldContainingPoint(pFirstPoint);

            if (vegeField == null)
            {
                CDebug.Error($"Cant create tree. point {pFirstPoint} is OOB!");
                return;
            }

            treeDetailField.AddDetectedTree(pNewTree, true);
            treeNormalField.AddDetectedTree(pNewTree, true);

            pNewTree.peakDetailField = treeDetailField;
            pNewTree.peakNormalField = treeNormalField;
        }
Exemple #2
0
        private static void AddTreesToBitmap(CVegeArray pArray, Bitmap pBitmap, bool pTreePostition, bool pTreeBorder)
        {
            List <CTree> allTrees = new List <CTree>();

            allTrees.AddRange(CTreeManager.Trees);
            allTrees.AddRange(CTreeManager.InvalidTrees);

            foreach (CTree tree in allTrees)
            {
                try
                {
                    CVegeField fieldWithTree = pArray.GetFieldContainingPoint(tree.peak.Center);
                    if (fieldWithTree == null)
                    {
                        CDebug.Error($"tree {tree.treeIndex} field = null");
                        continue;
                    }

                    int x = fieldWithTree.indexInField.Item1;
                    int y = fieldWithTree.indexInField.Item2;

                    if (IsOOB(x, y, pBitmap))
                    {
                        CDebug.Error($"{x},{y} is OOB {pBitmap.Width}x{pBitmap.Height}");
                        continue;
                    }

                    //draw branch extents
                    if (pTreeBorder && tree.isValid)
                    {
                        List <Vector3> furthestPoints = tree.GetFurthestPoints();
                        //	new List<Vector3>();
                        //foreach(CBranch branch in tree.Branches)
                        //{
                        //	furthestPoints.Add(branch.furthestPoint);
                        //}
                        for (int i = 0; i < furthestPoints.Count; i++)
                        {
                            Vector3 furthestPoint     = furthestPoints[i];
                            Vector3 nextFurthestPoint = furthestPoints[(i + 1) % furthestPoints.Count];

                            CVegeField fieldWithFP1 = pArray.GetFieldContainingPoint(furthestPoint);
                            CVegeField fieldWithFP2 = pArray.GetFieldContainingPoint(nextFurthestPoint);
                            if (fieldWithFP1 == null || fieldWithFP2 == null)
                            {
                                CDebug.Error($"futhest points {furthestPoint} + {nextFurthestPoint} - no field assigned");
                                continue;
                            }

                            int x1 = fieldWithFP1.indexInField.Item1;
                            int y1 = fieldWithFP1.indexInField.Item2;
                            int x2 = fieldWithFP2.indexInField.Item1;
                            int y2 = fieldWithFP2.indexInField.Item2;

                            using (Graphics g = Graphics.FromImage(pBitmap))
                            {
                                g.DrawLine(treeBorderPen, x1, y1, x2, y2);
                            }
                        }

                        foreach (CBranch branch in tree.Branches)
                        {
                            CVegeField fieldWithBranch = pArray.GetFieldContainingPoint(branch.furthestPoint);
                            if (fieldWithBranch == null)
                            {
                                CDebug.Error($"branch {branch} is OOB");
                                continue;
                            }

                            int _x = fieldWithBranch.indexInField.Item1;
                            int _y = fieldWithBranch.indexInField.Item2;

                            using (Graphics g = Graphics.FromImage(pBitmap))
                            {
                                g.DrawLine(branchPen, x, y, _x, _y);
                            }
                        }
                    }
                    //mark tree position
                    if (pTreePostition)
                    {
                        DrawTreeOnBitmap(pBitmap, tree, x, y);

                        bool isAtBufferZone = CTreeMath.IsAtBufferZone(tree);
                        if (exportMain && !isAtBufferZone)
                        {
                            //Tuple<int, int> posInMain = CGroundArray.GetPositionInArray(
                            //	tree.peak.Center, CProjectData.mainHeader.TopLeftCorner, mainMapStepSize);

                            //CUtils.TransformArrayIndexToBitmapIndex(ref posInMain,
                            //	CProjectData.mainHeader, mainMapStepSize, mainMap);
                            Tuple <int, int> posInMain = GetIndexInMainBitmap(tree.peak.Center);
                            x = posInMain.Item1;
                            y = posInMain.Item2;
                            if (posInMain == null)
                            {
                                continue;
                            }

                            Color color = mainMap.GetPixel(x, y);
                            if (!IsTreeColoured(color))
                            {
                                DrawTreeOnBitmap(mainMap, tree, x, y);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    CDebug.Error(e.Message);
                }
            }
        }