Ejemplo n.º 1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("The Urban Simulator has begun.");

            urbanModel theUrbanModel = new urbanModel();

            if (!getPrecinct(theUrbanModel))                                //Ask user to select a surface representing the Precinct
            {
                return(Result.Failure);
            }

            if (!generateRoadNetwork(theUrbanModel))                        //Using the precinct, Generate a Road Network
            {
                return(Result.Failure);
            }

            createBlocks(theUrbanModel);                 //Using the road network, create blocks

            subdivideBlocks(theUrbanModel, 30, 20);      //This dimension here 30,50 is the plot dimensions                                         //Subdivide the blocks in Plots

            //initiateBuildings()                                           //Place buildings on each plot

            RhinoApp.WriteLine("The Urban Simulator in complete.");

            RhinoDoc.ActiveDoc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 2
0
        public bool generateRoadNetwork(urbanModel model)
        {
            var iterationcount = 5;

            Random roadRand = new Random();

            var obstCrvs  = model.precinctSrf.ToBrep().DuplicateNakedEdgeCurves(true, false).ToList();
            var borderNum = obstCrvs.Count;

            if (borderNum > 0)
            {
                Random rnd    = new Random();
                Curve  theCrv = obstCrvs[roadRand.Next(borderNum)];

                recursiveLine(theCrv, ref obstCrvs, roadRand, 1, iterationcount);
            }

            model.roadNetwork = obstCrvs;

            if (obstCrvs.Count < borderNum)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 3
0
        public bool createBlocks(urbanModel model)
        {
            var multiFace = model.precinctSrf.ToBrep().Faces[0].Split(model.roadNetwork, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

            var blocks = new List <Brep>();

            foreach (var faces in multiFace.Faces)
            {
                var face = faces.DuplicateFace(false);
                face.Faces.ShrinkFaces();
                blocks.Add(face);
                RhinoDoc.ActiveDoc.Objects.AddBrep(face);
            }

            if (blocks.Count > 0)
            {
                model.blocks = blocks;
                return(true);
            }
            else
            {
                RhinoApp.WriteLine("Blocks failed.");
                return(false);
            }
        }
Ejemplo n.º 4
0
        public bool getPrecinct(urbanModel model)
        {
            GetObject obj = new GetObject();

            obj.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            obj.SetCommandPrompt("Please select a surface representing your Precinct");

            GetResult res = obj.Get();

            if (res != GetResult.Object)
            {
                RhinoApp.WriteLine("User failed to select a surface");
                return(false);
            }

            if (obj.ObjectCount == 1)
            {
                model.precinctSrf = obj.Object(0).Surface();
            }

            return(true);
        }
Ejemplo n.º 5
0
        public bool generateRoadNetwork(urbanModel model)
        {
            int noIterations = 4;

            Random rndRoadT = new Random();

            List <Curve> obstCrvs = new List <Curve>();

            //extract the border from the precint surface
            Curve[] borderCrvs = model.precintSrf.ToBrep().DuplicateNakedEdgeCurves(true, false);

            foreach (Curve itCrv in borderCrvs)
            {
                obstCrvs.Add(itCrv);
            }

            if (borderCrvs.Length > 0)
            {
                int noBorders = borderCrvs.Length;

                Random rnd    = new Random();
                Curve  theCrv = borderCrvs[rnd.Next(noBorders)];

                recursivePerpLine(theCrv, ref obstCrvs, rndRoadT, 1, noIterations);
            }

            model.roadNetwork = obstCrvs;


            if (obstCrvs.Count > borderCrvs.Length)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("The Urban Simulator has begun.");

            urbanModel theUrbanModel = new urbanModel();

            if (!getPrecinct(theUrbanModel))               //Ask user to select a surface representing the Precinct
            {
                return(Result.Failure);
            }

            if (!generateRoadNetwork(theUrbanModel))       //Using the precint, Generate a road network
            {
                return(Result.Failure);
            }

            //createBlocks()                              //Using the road network, create block
            //subdivideBlock()                            //Subdivide the block into Plots
            //instantiateBuildings()                      //Place buildings on each plot

            RhinoApp.WriteLine("The Urban Simulator is complete.");

            return(Result.Success);
        }
Ejemplo n.º 7
0
        public bool createBlocks(urbanModel model)
        {
            Brep precinctPolySurface = model.precinctSrf.ToBrep().Faces[0].Split(model.roadNetwork, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

            List <Brep> blocks = new List <Brep>();

            foreach (BrepFace itBF in precinctPolySurface.Faces)
            {
                Brep itBlock = itBF.DuplicateFace(false);
                itBlock.Faces.ShrinkFaces();
                blocks.Add(itBlock);
                RhinoDoc.ActiveDoc.Objects.AddBrep(itBlock);
            }

            if (blocks.Count > 0)
            {
                model.blocks = blocks;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoApp.WriteLine("The Urban Simulator has begun.");

            urbanModel theUrbanModel = new urbanModel();

            if (!getPrecinct(theUrbanModel))               //ask user to select surface
            {
                return(Result.Failure);
            }

            RhinoDoc.ActiveDoc.Views.RedrawEnabled.Equals(false);

            generateRoadNetwork(theUrbanModel);                  //generate road
            createBlocks(theUrbanModel);                         //create blocks using road
            subdivideBlocks(theUrbanModel, 30, 30, 50, 30);      //subdivide blocks into
            //instantiateBuildings(theUrbanModel);                 //place buildings on each block

            RhinoDoc.ActiveDoc.Views.RedrawEnabled.Equals(true);

            RhinoApp.WriteLine("The Urban Simulator is complete.");

            return(Result.Success);
        }
Ejemplo n.º 9
0
        public bool subdivideBlocks(urbanModel model, int minPlotDepth, int maxPlotWidth)
        {
            model.plots = new List <Brep>();



            foreach (Brep itBlock in model.blocks)
            {
                Curve[] borderCrvs = itBlock.DuplicateNakedEdgeCurves(true, false);

                List <Curve> splitLines = new List <Curve>();

                itBlock.Faces[0].SetDomain(0, new Interval(0, 1));
                itBlock.Faces[0].SetDomain(1, new Interval(0, 1));

                Point3d pt1 = itBlock.Faces[0].PointAt(0, 0);
                Point3d pt2 = itBlock.Faces[0].PointAt(0, 1);
                Point3d pt3 = itBlock.Faces[0].PointAt(1, 1);
                Point3d pt4 = itBlock.Faces[0].PointAt(1, 0);

                double length = pt1.DistanceTo(pt2);
                double width  = pt1.DistanceTo(pt4);

                Point3d sdPt1 = new Point3d();
                Point3d sdPt2 = new Point3d();

                if (length > width)                 //length is wider
                {
                    if (width > (minPlotDepth * 2)) //suitable for subdivision
                    {
                        //create a dubdiving line
                        sdPt1 = itBlock.Surfaces[0].PointAt(0.5, 0);
                        sdPt2 = itBlock.Surfaces[0].PointAt(0.5, 1);
                    }
                }
                else //length is wider
                {
                    if (length > (minPlotDepth * 2)) //suitable for subdivision
                    {
                        //create a dubdiving line
                        sdPt1 = itBlock.Surfaces[0].PointAt(0, 0.5);
                        sdPt2 = itBlock.Surfaces[0].PointAt(1, 0.5);
                    }
                }


                Line  subDLine = new Line(sdPt1, sdPt2);
                Curve subDCrv  = subDLine.ToNurbsCurve();

                splitLines.Add(subDCrv);

                double crvLength = subDCrv.GetLength();
                double noPlots   = Math.Floor(crvLength / maxPlotWidth);

                for (int t = 0; t < noPlots; t++)
                {
                    double tVal = t * (1 / noPlots);

                    Plane perpFrm;

                    Point3d evalPt = subDCrv.PointAtNormalizedLength(tVal);
                    subDCrv.PerpendicularFrameAt(tVal, out perpFrm);

                    Point3d ptPer2Up   = Point3d.Add(evalPt, perpFrm.XAxis);
                    Point3d ptPer2Down = Point3d.Add(evalPt, -perpFrm.XAxis);

                    //Draw a line perpendicular
                    Line ln1 = new Line(evalPt, ptPer2Up);
                    Line ln2 = new Line(evalPt, ptPer2Down);

                    Curve lnExt1 = ln1.ToNurbsCurve().ExtendByLine(CurveEnd.End, borderCrvs);
                    Curve lnExt2 = ln2.ToNurbsCurve().ExtendByLine(CurveEnd.End, borderCrvs);

                    splitLines.Add(lnExt1);
                    splitLines.Add(lnExt2);
                }

                Brep plotPolySurface = itBlock.Faces[0].Split(splitLines, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

                foreach (BrepFace itBF in plotPolySurface.Faces)
                {
                    Brep itPlot = itBF.DuplicateFace(false);
                    itPlot.Faces.ShrinkFaces();
                    model.plots.Add(itPlot);
                    RhinoDoc.ActiveDoc.Objects.AddBrep(itPlot);
                }

                RhinoDoc.ActiveDoc.Views.Redraw();
            }

            return(true);
        }
Ejemplo n.º 10
0
 public void instantiateBuildings(urbanModel model)
 {
 }
Ejemplo n.º 11
0
        public bool subdivideBlocks(urbanModel model, double minLength, double minWidth, double maxLength, double maxWidth)
        {
            model.plots = new List <Brep>();

            foreach (var block in model.blocks)
            {
                Point3d        subPt1     = new Point3d();
                Point3d        subPt2     = new Point3d();
                List <Curve>   splitLines = new List <Curve>();
                List <Point3d> evalPoints = new List <Point3d>();

                var obstCrvs = block.DuplicateNakedEdgeCurves(true, false).ToList();

                block.Faces[0].SetDomain(0, new Interval(0, 1));
                block.Faces[0].SetDomain(1, new Interval(0, 1));

                var pt1 = block.Surfaces[0].PointAt(0, 0);
                var pt2 = block.Surfaces[0].PointAt(0, 1);
                var pt3 = block.Surfaces[0].PointAt(1, 1);
                var pt4 = block.Surfaces[0].PointAt(1, 0);

                var length = pt1.DistanceTo(pt2);
                var width  = pt1.DistanceTo(pt4);

                if (length > width)
                {
                    if (width > (minLength * 2))
                    {
                        subPt1 = block.Surfaces[0].PointAt(0.5, 0);
                        subPt2 = block.Surfaces[0].PointAt(0.5, 1);
                    }
                }
                else
                {
                    if (length > (minLength * 2))
                    {
                        subPt1 = block.Surfaces[0].PointAt(0, 0.5);
                        subPt2 = block.Surfaces[0].PointAt(1, 0.5);
                    }
                }

                var subCrv = new Line(subPt1, subPt2).ToNurbsCurve();
                splitLines.Add(subCrv);

                var crvLength = subCrv.GetLength();
                var plotNum   = Math.Ceiling(crvLength / maxWidth);

                for (int i = 1; i < plotNum; i++)
                {
                    var val    = i * (1 / plotNum);
                    var evalPt = subCrv.PointAtNormalizedLength(val);

                    Plane perpFrame;

                    subCrv.PerpendicularFrameAt(val, out perpFrame);
                    var evalPtUp = Point3d.Add(evalPt, perpFrame.XAxis);
                    var evalPtDn = Point3d.Add(evalPt, -perpFrame.XAxis);

                    var ln1 = new Line(evalPt, evalPtUp);
                    var ln2 = new Line(evalPt, evalPtDn);

                    var lnExt1 = ln1.ToNurbsCurve().ExtendByLine(CurveEnd.End, obstCrvs);
                    var lnExt2 = ln2.ToNurbsCurve().ExtendByLine(CurveEnd.End, obstCrvs);

                    splitLines.Add(lnExt1);
                    splitLines.Add(lnExt2);
                }

                var plotMultiFace = block.Faces[0].Split(splitLines, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

                foreach (var faces in plotMultiFace.Faces)
                {
                    var face = faces.DuplicateFace(false);
                    face.Faces.ShrinkFaces();
                    model.plots.Add(face);
                    RhinoDoc.ActiveDoc.Objects.AddBrep(face);
                }
            }
            return(true);
        }