Example #1
0
        //TODO: not practical since it can only return CField and the caller
        // has to cast it to more specific type. Find out more general approach?
        //public CField GetFieldContaining(EArray pClass, bool pNormal, Vector3 pPoint)
        //{
        //	switch(pClass)
        //	{
        //		case EArray.Ground:
        //			if(!pNormal)
        //				break;
        //			return groundArray.GetFieldContainingPoint(pPoint);
        //		case EArray.Vege:
        //			if(pNormal)
        //				break;
        //			return vegeDetailArray.GetFieldContainingPoint(pPoint);
        //		case EArray.Tree:
        //			return pNormal ?
        //				treeNormalArray.GetFieldContainingPoint(pPoint) :
        //				treeDetailArray.GetFieldContainingPoint(pPoint);
        //	}
        //	CDebug.Error($"GetFieldContaining() for class {pClass} - {pNormal} not defined");
        //	return null;
        //}

        private void InitArrays()
        {
            unassignedArray = new CUnassignedArray(NORMAL_STEP, false);

            ballArray       = new CBallArray(NORMAL_STEP, false);
            ballDetailArray = new CBallArray(DETAIL_STEP_BALLS, true);

            groundArray   = new CGroundArray(NORMAL_STEP, false);
            buildingArray = new CVegeArray(NORMAL_STEP, false);
            vegeArray     = new CVegeArray(NORMAL_STEP, false);

            vegeDetailArray = new CVegeArray(DETAIL_STEP, true);

            preprocessDetailArray = new CVegeArray(DETAIL_STEP, true);
            preprocessNormalArray = new CVegeArray(NORMAL_STEP, false);

            treeDetailArray = new CTreeArray(DETAIL_STEP, true);
            treeNormalArray = new CTreeArray(NORMAL_STEP, false);

            CObjPartition.Init();
        }
Example #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);
        }
Example #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);
                }
            }
        }