Exemple #1
0
        public bool createBlocks(UrbanModel model)
        {
            Random blockType       = Random();
            Brep   precinctPolySrf = model.PrecinctSrf.ToBrep().Faces[0].Split(model.roadNetworks, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

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

            foreach (BrepFace itBF in precinctPolySrf.Faces)
            {
                Brep ItBlock = itBF.DuplicateFace(false);
                ItBlock.Faces.ShrinkFaces();
                int theBlockType = blockType.Next(4);

                blocks.Add(new block(ItBlock, theBlockType));
                RhinoDoc.ActiveDoc.Objects.AddBrep(ItBlock);
            }
            if (blocks.Count > 0)
            {
                model.blocks = blocks;
                return(true);
            }

            else
            {
                return(false);
            }
        }
Exemple #2
0
        public bool getPrecinct(UrbanModel model)
        {
            GetObject obj = new GetObject();

            obj.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            obj.SetCommandPrompt("Please set surface for precinct");

            GetResult res = obj.Get();

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

            if (obj.ObjectCount == 1)
            {
                model.PrecinctSrf = obj.Object(0).Surface();
            }
            return(true);
        }
Exemple #3
0
        public bool generateRoadNetwork(UrbanModel model)

        {
            int noIterations = 6;

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

            //extract edges from the precinct- temp geometry
            Curve[] borderCrvs = model.PrecinctSrf.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.roadNetworks = obstCrvs;
            if (obstCrvs.Count > borderCrvs.Length)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
Exemple #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoDoc.ActiveDoc.Views.RedrawEnabled = false;
            RhinoApp.WriteLine("The Urban Simulator has begun.");

            UrbanModel TheUrbanModel = new UrbanModel();



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

            if (!generateRoadNetwork(TheUrbanModel))
            {
                ;                                                       // Using precinct generate road network
            }
            return(Result.Failure);

            createBlocks(TheUrbanModel);                                // Using road network generates blocks

            if (!subdivideBlocks(TheUrbanModel, 30, 20))
            {
                ;                                                           // subdivide block into plots
            }
            return(Result.Failure);

            RhinoDoc.ActiveDoc.Views.RedrawEnabled = true;

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

            RhinoDoc.ActiveDoc.Views.Redraw();

            return(Result.Success);
        }
Exemple #5
0
        public bool subdivideBlocks(UrbanModel model, int minPlotDepth, int maxPlotWidth)
        {
            foreach (block itBlock in model.blocks)
            {
                Brep itSrf = itBlock.blockSrf;
                itBlock.plot = new List <plot>();
                Curve[] borderCrvs = itSrf.DuplicateNakedEdgeCurves(true, false);

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

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

                Point3d pt1 = itSrf.Faces[0].PointAt(0, 0);
                Point3d pt2 = itSrf.Faces[0].PointAt(0, 1);
                Point3d pt3 = itSrf.Faces[0].PointAt(1, 1);
                Point3d pt4 = itSrf.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)
                {
                    if (width > (minPlotDepth * 2))
                    {
                        sdPt1 = itSrf.Surfaces[0].PointAt(0.5, 0);
                        sdPt2 = itSrf.Surfaces[0].PointAt(0.5, 1);
                    }
                    else
                    {
                        if (length > (minPlotDepth * 2))
                        {
                            sdPt1 = itSrf.Surfaces[0].PointAt(0, 0.5);
                            sdPt2 = itSrf.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 perpindicular
                        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 plotPolySrf = itSrf.Faces[0].Split(splitLines, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);



                    foreach (BrepFace itBF in plotPolySrf.Faces)
                    {
                        Brep itPlot = itBF.DuplicateFace(false);
                        itPlot.Faces.ShrinkFaces();
                        itBlock.plot.Add(new plot(itPlot, itBlock.type));
                        RhinoDoc.ActiveDoc.Objects.AddBrep(itPlot);
                    }


                    RhinoDoc.ActiveDoc.Views.Redraw();
                }
                //check the dimensions
                //find the shorter dimensions
                //validate if should be subdivide
                //if so subdidivde half way
                //hten si=ubdivide into smaller plots based on minim plot width
            }



            return(true);
        }