public IActionResult Index() { SingleFamily sf = new SingleFamily(); HomeFactory homeFactory = new Homes.HomeFactory(sf); Home singleFamily=homeFactory.BuildTheHome(); Ranch ranch = new Ranch(); homeFactory = new HomeFactory(ranch); Home ranchHome = homeFactory.BuildTheHome(); //Logger l = new Logger(); //LoggerFactory lf = new LoggerFactory(l); //lf.NotifyLog(""); //l.Number = 5; //var test = l.total; //l.Number = 4; //var t = l.total; return View(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //define instances SingleFamily house = new SingleFamily(); Vector3d vec = new Vector3d(); Point3d pt = new Point3d(); //Get data if (!DA.GetData(0, ref house)) { return; } if (!DA.GetData(1, ref vec)) { return; } if (!DA.GetData(2, ref pt)) { return; } //Calculate Vector3d tan = Engine.Geometry.Compute.CrossProduct(vec, Vector3d.ZAxis); SingleFamily movedHouse = Adjust.Translate(house, pt, tan); //Set data DA.SetData(0, movedHouse); }
public static SingleFamily Move(SingleFamily house, Vector3d vector) { SingleFamily movedHouse = house.Clone(); Transform t = Transform.Translation(vector); movedHouse.GardenBound.Transform(t); movedHouse.HouseGeom.Transform(t); movedHouse.AccessPoint += new Point3d(vector); movedHouse.MidPoint += new Point3d(vector); return(movedHouse); }
//============ //Test for curves public static List <Point3d> PossiblePoints(Curve crv, SingleFamily house) { Polyline houseGardenBoundary = house.GardenBound; Point3d houseAccessPt = house.AccessPoint; double crvLength = crv.GetLength(); double houseWidth = Query.ClosestSegmentToPoint(houseAccessPt, houseGardenBoundary).Length; List <Point3d> pointPos = new List <Point3d>(); Point3d currPt = crv.PointAtStart; double currLength = houseWidth; int i = 0; while (currLength < crvLength) { double[] tParam = crv.DivideByLength(houseWidth, true); currPt = crv.PointAt(tParam[i]); pointPos.Add(currPt); currLength += houseWidth; //if the garden overlaps the previous garden the loop will break. if (i != 0) { Polyline prevGarden = Methods.Adjust.Translate(house, pointPos[i - 1], crv.TangentAt(tParam[i - 1])).GardenBound; Polyline currGarden = Methods.Adjust.Translate(house, pointPos[i], crv.TangentAt(tParam[i])).GardenBound; Curve[] overlap = Curve.CreateBooleanIntersection(prevGarden.ToPolylineCurve(), currGarden.ToPolylineCurve(), ObjectModel.Tolerance.Distance); if (overlap != null && overlap.Length != 0 && AreaMassProperties.Compute(overlap[0]).Area >= 10) { break; } } i++; if (i == house.MaxAmount) { break; } } return(pointPos); }
public static Dictionary <string, double> MassBalance(SingleFamily house, Surface site, int divisions) { double tol = Tolerance.Distance; Brep gardenBrep = Brep.CreatePlanarBreps(new[] { house.GardenBound.ToPolylineCurve() }, tol)[0]; Surface gardenSrf = gardenBrep.Surfaces[0]; double stackArea = AreaMassProperties.Compute(gardenSrf, true, false, false, false).Area / (divisions * divisions); double cut = 0; double fill = 0; Point3d[,] srfPts = Query.SurfaceGrid(gardenSrf, divisions, divisions); foreach (Point3d pt in srfPts) { Ray3d ray = new Ray3d(pt, Vector3d.ZAxis); Point3d[] projectedPt = Intersection.RayShoot(ray, new Surface[] { site }, 1); if (projectedPt == null) { ray = new Ray3d(pt, -Vector3d.ZAxis); projectedPt = Intersection.RayShoot(ray, new Surface[] { site }, 1); if (projectedPt != null) { fill += (pt.Z - projectedPt[0].Z); } } else { cut += (projectedPt[0].Z - pt.Z); } } fill *= stackArea; cut *= stackArea; double massBalance = cut - fill; Dictionary <string, double> values = new Dictionary <string, double>(); values.Add("cut", cut); values.Add("fill", fill); values.Add("massBalance", massBalance); return(values); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //define instances SingleFamily house = new SingleFamily(); Vector3d vec = new Vector3d(); //Get data if (!DA.GetData(0, ref house)) { return; } if (!DA.GetData(1, ref vec)) { return; } //Calculate SingleFamily movedHouse = Adjust.Move(house, vec); //Set data DA.SetData(0, movedHouse); }
//====================================================================// public static ObjectModel.SingleFamily Translate(SingleFamily house, Point3d boundPt, Vector3d tan) { Point3d basePt = house.AccessPoint; Line accessLine = Query.ClosestSegmentToPoint(basePt, house.GardenBound); Vector3d accessVec = Compute.CreateVector(accessLine.To, accessLine.From); SingleFamily movedHouse = house.Clone(); Transform t = Transform.Translation(Compute.CreateVector(basePt, boundPt)); Transform r = Transform.Rotation(accessVec, tan, boundPt); movedHouse.GardenBound.Transform(t); movedHouse.GardenBound.Transform(r); movedHouse.HouseGeom.Transform(t); movedHouse.HouseGeom.Transform(r); movedHouse.Orientation = Compute.CrossProduct(Vector3d.ZAxis, tan); movedHouse.MidPoint = movedHouse.GardenBound.CenterPoint(); // add a real translation here maybe? movedHouse.AccessPoint = boundPt; return(movedHouse); }
public static List <Point3d> PossiblePoints(Line line, SingleFamily house, Random random, Carport carport) //TODO: we want to have carport as an optional parameter later { Polyline houseGardenBoundary = house.GardenBound; Point3d houseAccessPt = house.AccessPoint; bool hasCarPort = house.HasCarPort; double lineLength = line.Length; double houseWidth = Query.ClosestSegmentToPoint(houseAccessPt, houseGardenBoundary).Length; Point3d startPt = line.From; Vector3d vec = (line.Direction) / lineLength; Vector3d husVec = vec * houseWidth; Vector3d cpVec = new Vector3d(); double cpWidth = 0; if (hasCarPort) { cpWidth = Query.ClosestSegmentToPoint(carport.AccessPoint, carport.GardenBound).Length; cpVec = vec * cpWidth; } List <Point3d> pointPos = new List <Point3d>(); Point3d currPt = startPt; double currLength = houseWidth; Line currLine = new Line(); int i = 0; while (currLength < lineLength) { currLine = new Line(currPt, husVec); currPt = currLine.To; pointPos.Add(currPt); currLength += houseWidth; i++; if (hasCarPort) { currLine = new Line(currPt, cpVec); currPt = currLine.To; pointPos.Add(currPt); currLength += cpWidth; } if (i == house.MaxAmount) { break; } } Vector3d move_vec = random.NextDouble() * (lineLength - currLength) * vec.Normalise(); List <Point3d> move_pts = new List <Point3d>(); foreach (Point3d p in pointPos) { move_pts.Add(Point3d.Add(p, move_vec)); } return(move_pts); }
//====================================================================// public static (List <IHouse>, List <PolylineCurve>, List <Carport>) PlaceHouseRow(List <SingleFamily> baseHouses, Curve bound, Curve originalBound, List <Curve> roads, Random random, string method, Carport carport) { List <SingleFamily> houseList = new List <SingleFamily>(); List <Carport> carportList = new List <Carport>(); List <PolylineCurve> cutBound = new List <PolylineCurve>(); SingleFamily baseHouse = baseHouses[random.Next(baseHouses.Count)]; //1. pick house type to place //2. Get boundaries. bound.TryGetPolyline(out Polyline boundPL); List <Line> lines = SegmentBounds(boundPL.ClosePolyline(), baseHouse); if (lines.Count == 0) { goto end; } Line currLine = lines.PickLine(method, random, roads, originalBound); currLine.Extend(-Tolerance.FilletOffset, -Tolerance.FilletOffset); List <Point3d> possiblePts = PossiblePoints(currLine, baseHouse, random, carport); //3. Place houses for each position for (int i = 0; i < possiblePts.Count; i++) { SingleFamily movedHouse = Adjust.Translate(baseHouse, possiblePts[i], currLine.Direction); if (i == 0) { movedHouse.RowPosition = "left"; } if (Query.IsInside(movedHouse, bound)) //TODO: Include carport { houseList.Add(movedHouse); } else if (houseList.Count != 0) //already places houses { break; } if (movedHouse.HasCarPort) { i++; Carport movedCarport = Adjust.Translate(carport, possiblePts[i], currLine.Direction); carportList.Add(movedCarport); } } end: if (houseList.Count >= baseHouse.MinAmount) { cutBound = UpdateBoundaries(houseList, baseHouse, bound); //TODO: Include carport } else { cutBound = new List <PolylineCurve>() { bound.ToPolylineCurve() }; houseList = new List <SingleFamily>(); carportList = new List <Carport>(); } houseList.AddRowPos(); List <IHouse> IHouseList = houseList.Cast <IHouse>().ToList(); return(IHouseList, cutBound, carportList); }
public static List <PolylineCurve> UpdateBoundaries(List <SingleFamily> houseList, SingleFamily baseHouse, Curve bound) { if (houseList.Count == 0) { return(new List <PolylineCurve>()); } Polyline cutRegion = Compute.ConvexHull(houseList.Select(x => x.GardenBound).ToList()); Curve cutCrv = Curve.CreateControlPointCurve(cutRegion.ToList(), 1); Curve offsetRegion = cutCrv.OffsetOut(baseHouse.Offset, Plane.WorldXY); List <Curve> cutRegions = Curve.CreateBooleanDifference(bound, offsetRegion, Tolerance.Distance).ToList(); double cellSize = AreaMassProperties.Compute(baseHouse.GardenBound.ToPolylineCurve()).Area * 2; cutRegions = cutRegions.Where(x => AreaMassProperties.Compute(x).Area >= cellSize).ToList(); return(cutRegions.ToPolylineCurves()); }