public void Place(Plant plant, Point position) { plant.Position = position; plant.PositionOrder = PlacedPlantCount++; Garden.DrawPlant(plant, this); UpdateErodes(plant); }
public Packing(PlantList plantList, Garden garden) { //First placement Garden = garden; PlantList = plantList; BasePlacement = new Placement(plantList, garden); PossiblePlacements.Insert(0, BasePlacement); FinalPlacement = ComputePacking(BasePlacement); }
//Create base placement public Placement(PlantList plants, Garden garden) { //Plants Plants = plants; ComputeDimInfos(plants); garden.SetGardenMaps(MinDim, MaxDim); Garden = garden; }
public static void Test1() { //SoilMap var soilMap = new Mat(new Size(500, 500), DepthType.Cv8U, 1); soilMap.SetTo(new MCvScalar(0)); for (int i = 1; i < 25; i++) { for (int j = 1; j < 25; j++) { soilMap.SetValue(i, j, (byte)255); } } //Garden var garden = new Garden(soilMap); //Plants //p1 var model1 = new List <KeyValuePair <int, Mat> >(); var k = 1; var plantMap1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(2 * k + 1, 2 * k + 1), new Point(k, k)); model1.Add(new KeyValuePair <int, Mat>(0, plantMap1)); model1.Add(new KeyValuePair <int, Mat>(-1, plantMap1)); model1.Add(new KeyValuePair <int, Mat>(1, plantMap1)); model1 = model1.OrderBy(o => o.Key).ToList(); var plant1 = new Plant(1, model1); //p2 var model2 = new List <KeyValuePair <int, Mat> >(); k = 2; var plantMap2 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(2 * k + 1, 2 * k + 1), new Point(k, k)); model2.Add(new KeyValuePair <int, Mat>(0, plantMap2)); model2.Add(new KeyValuePair <int, Mat>(-1, plantMap2)); model2.Add(new KeyValuePair <int, Mat>(1, plantMap2)); model2 = model2.OrderBy(o => o.Key).ToList(); var plant2 = new Plant(2, model2); var plantList = new PlantList() { plant1, plant2 }; //Packing var packing = new Packing(plantList, garden); }
public Erosion(Plant plant, Garden garden) { Erode3D = new List <KeyValuePair <int, Mat> >(); ErodePoints = new List <Point>(); ErodeMap = new Mat(garden.SoilMap.Rows, garden.SoilMap.Cols, DepthType.Cv8U, 1); ErodeMap.SetTo(new MCvScalar(255)); foreach (var level in garden.Model) { var erode = new Mat( new Size(level.Value.Cols, level.Value.Rows), DepthType.Cv8U, 1 ); erode.SetTo(new MCvScalar(0)); //tresh CvInvoke.Erode(level.Value, erode, plant.Model.Where(x => x.Key == level.Key).Select(x => x.Value).FirstOrDefault(), new Point(1, 1), 1, BorderType.Constant, new MCvScalar(0)); //Compute points for (int i = 0; i < erode.Cols; i++) { for (int j = 0; j < erode.Rows; j++) { if (erode.GetValue(i, j) == 255) { ErodePoints.Add(new Point(i, j)); } } } Erode3D.Add(new KeyValuePair <int, Mat>(level.Key, erode)); } foreach (var erode in Erode3D) { CvInvoke.BitwiseAnd(ErodeMap, erode.Value, ErodeMap); } }