Exemplo n.º 1
0
        public static void RunWateryScenario()
        {
            Bitmap          jranjana = new Bitmap("C:\\Users\\Justin Murray\\Desktop\\maps\\input\\rivers_lr.png");
            Field2d <float> field    = new Utils.FieldFromBitmap(jranjana);
            BrownianTree    tree     = BrownianTree.CreateFromOther(field, (x) => x > 0.5f ? BrownianTree.Availability.Available : BrownianTree.Availability.Unavailable);

            tree.RunDefaultTree();
            HydrologicalField hydro = new HydrologicalField(tree);
            var sets = hydro.FindContiguousSets();
            List <TreeNode <Point2d> > riverForest = new List <TreeNode <Point2d> >();

            foreach (var river in sets[HydrologicalField.LandType.Shore])
            {
                riverForest.Add(river.MakeTreeFromContiguousSet(pt =>
                {
                    // Warning: naive non-boundary-checking test-only implementation.  This will probably CRASH THE PROGRAM
                    // if a river happens to border the edge of the map.
                    return
                    (hydro[pt.y + 1, pt.x + 1] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y + 1, pt.x + 0] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y + 1, pt.x - 1] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y + 0, pt.x - 1] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y - 1, pt.x - 1] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y - 1, pt.x + 0] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y - 1, pt.x + 1] == HydrologicalField.LandType.Ocean ||
                     hydro[pt.y + 0, pt.x + 1] == HydrologicalField.LandType.Ocean);
                }));
            }
            DrainageField draino = new DrainageField(hydro, riverForest);
            List <TreeNode <TreeNode <Point2d> > > riverSets = new List <TreeNode <TreeNode <Point2d> > >();

            foreach (var river in riverForest)
            {
                riverSets.Add(river.GetMajorSubtrees(node => node.Depth() > 15));
            }

            using (var file = System.IO.File.OpenWrite("C:\\Users\\Justin Murray\\Desktop\\maps\\output\\report.txt"))
                using (var writer = new System.IO.StreamWriter(file))
                {
                    riverSets.OrderByDescending(set => set.Size()).Select(riverSet =>
                    {
                        writer.WriteLine("River of size " + riverSet.value.Size() + " with " + riverSet.Size() + " separate sub-rivers.");
                        foreach (var river in riverSet.ToArray().OrderByDescending(t => t.Depth()))
                        {
                            writer.WriteLine("\tPart of river with " + river.value.Depth() + " depth and " + (river.Size() - 1) + " tributaries.");
                        }
                        writer.WriteLine();
                        return(0);
                    }).ToArray();
                }

            Utils.OutputAsTributaryMap(sets, riverSets, draino, jranjana, "C:\\Users\\Justin Murray\\Desktop\\maps\\output\\tree.png");
        }