示例#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;
        }
示例#2
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);
        }
示例#3
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);
                }
            }
        }