public static SolveResults ComputeBetweenExit(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeExitBetweenAccess(); result.Value = plan; return result; }
private static SolveResults ComputeFibonacci(int n) { SolveResults result = new SolveResults(); if (n == 0) { result.Value = 0; } else if (n == 1) { result.Value = 1; } else { int x = 0, y = 1, rc = 0; for (int i = 2; i <= n; i++) { rc = x + y; x = y; y = rc; } result.Value = rc; } return(result); }
/// <summary> /// static Method create lines for recursive process /// Create a compute function the takes the input retrieve from IGH_DataAccess /// and returns an instance of SolveResults. /// </summary> private static SolveResults ComputeRecursiveLines(double length, double branchAngle, double branchScale, int num) { var result = new SolveResults(); //Set the branch angle by converting it from degrees to radians double bAngleRad = (Math.PI / 100) * branchAngle; //Create a new line in the yDirection from the origin and add it to the list. var lines = new List <Line>(); var stPt = new Point3d(0, 0, 0); var unitYvect = new Vector3d(0, 1, 0); var ln0 = new Line(stPt, unitYvect, length); lines.Add(ln0); //Create two temporary lists and set the first equal to the lines list. var tempList01 = new List <Line>(); var tempList02 = new List <Line>(); tempList01 = lines; int i = 0; while (i < num) { tempList02 = CreateBranch(tempList01, branchScale, bAngleRad); tempList01 = tempList02; lines.AddRange(tempList02); i++; } result.Value = lines; return(result); }
/// <summary> /// This is the method that create circle for recursive process /// Create a Compute function that takes the input retrieve from IGH_DataAccess /// and returns an instance of SolveResults /// </summary> private static SolveResults ComputeReCursiveCircles(double radius, int level) { var result = new SolveResults(); //Set (initial) List of circles var circles = new List <Circle>(); //Creat new circle and add a (intial) list var circle01 = new Circle(new Point3d(0, 0, 0), radius); circles.Add(circle01); //Set two list for recursive process var tempList01 = new List <Circle>(); var tempList02 = new List <Circle>(); tempList01 = circles; //Recursive loop int i = 0; while (i < level) { tempList02 = CreateRecursiveCircle(radius, tempList01); tempList01 = tempList02; circles.AddRange(tempList01); i++; } result.Value = circles; return(result); }
public static SolveResults ComputeSunVecs(PBSun sun) { SolveResults result = new SolveResults(); sun.ComputeVectors(); result.Value = sun; return(result); }
public static SolveResults ComputeAttractions(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeAttractionViz(); result.Value = plan; return(result); }
public static SolveResults ComputeExit(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeBetweenPaths(); result.Value = plan; return(result); }
public static SolveResults ComputeIsovistClustering(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeIsovist(); result.Value = plan; return(result); }
public static SolveResults ComputeSolar(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeSolarAccess(); result.Value = plan; return(result); }
public static SolveResults ComputeMSP(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeSampleMeanShortestPath(); result.Value = plan; return(result); }
public static SolveResults ComputeNeighborhoodSize(SmartPlan plan) { SolveResults result = new SolveResults(); plan.ComputeNeighSize(); result.Value = plan; return(result); }
private SolveResults ListRecordsSolve(AirtableBase airtableBase, IGH_DataAccess DA) { SolveResults result = new SolveResults(); string offset = "0"; Task OutResponse = this.ListRecordsMethodAsync(airtableBase, offset, DA); result.Value = 1; return(result); }
public static SolveResults ComputeSOM(KMap _som) { SolveResults result = new SolveResults(); _som.trainNodes(); _som.outputNodeWeights(); _som.iter++; result.Value = _som; return(result); }
/// <summary> /// This is the method that create points list for recursive process /// Create a Compute function that takes the input retrieve from IGH_DataAccess /// and returns an instance of SolveResults /// </summary> private static SolveResults ComputeDragonPts(double length, int num) { //Declare start and rule string(example) string startString = "FX"; string ruleX = "X+YF+"; string ruleY = "-FX-Y"; var result = new SolveResults(); var dragonString = startString; GrowString(ref num, ref dragonString, ruleX, ruleY); var dragonPts = new List <Point3d>(); ParceDragonString(dragonString, length, ref dragonPts); result.Value = dragonPts; return(result); }
/// <summary> /// This is the method that create points list for recursive process /// Create a Compute function that takes the input retrieve from IGH_DataAccess /// and returns an instance of SolveResults /// </summary> private static SolveResults ComputePenroseLines(double length, int num) { //Declare start and rule strings (example) string finalString = "[7]++[7]++[7]++[7]++[7]"; string rule6 = "81++91----71[-81----61]++"; string rule7 = "+81--91[---61--71]+"; string rule8 = "-61++71[+++81++91]-"; string rule9 = "--81++++61[+91++++71]--71"; var result = new SolveResults(); var penroseString = finalString; GrowString(ref num, ref penroseString, rule6, rule7, rule8, rule9); var penroseLines = new List <Line>(); ParsePenroseString(penroseString, length, ref penroseLines); result.Value = penroseLines; return(result); }
private SolveResults ComputeDivs(Curve crv, ConcurrentDictionary <int, List <double> > distanceList) { distanceList.Values[1] if (distanceList.Count == 0) { return(null); } if (crv.PointAtStart.DistanceTo(crv.PointAtEnd) < distanceList.Max()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, " Distance between start and end points of curve(s) may be too small." + " If it yields undesirable results, consider increasing distance between them to max value in the supplied distances."); } // if parameter is within region A, use items from dictionary list A ) // SolveResults result = new SolveResults(); crv.Domain = new Interval(0, crv.GetLength()); double t1 = crv.Domain.T1; double tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; int i, j; i = j = -1; List <Curve> crvList = new List <Curve>(); List <Point3d> ptList = new List <Point3d>() { crv.PointAtStart }; List <double> paramList = new List <double>() { 0.0 }; //List<double> div2 = distanceList2; // TODO: Fix intersection issues with curves that have their start and End points too close to each other; eg:closed curves. while (true) { //reset i if distance list end reached and curve still exists. if (i >= distanceList.Count - 1) { i = -1; } // increment i++; j++; if (distanceList[i] < tol) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, " Distances less than or equal to rhino model tolerance will be ignored"); distanceList.RemoveAt(i); } // sphere-curve intersection // using overload with curve domain to limit intersection area- allows to break while-loop when curve reaches the end. CurveIntersections events = Intersection.CurveSurface(crv, new Interval(paramList[j], t1), new Sphere(crv.PointAt(paramList[j]), distanceList[i]).ToNurbsSurface(), tol, tol); if (events != null && events.Count > 0) { paramList.Add(events.Last().ParameterA); ptList.Add(events.Last().PointA); } else { break; } } crvList.Add(crv); ptList.Add(crv.PointAtEnd); paramList.Add(crv.Domain.Max); result.Curves = crvList; result.Points = ptList; result.Parameters = paramList; //result.div2 = div2; return(result); }
SolveResults Compute(List <Curve> closedCrvs, double tol) { var rc = new SolveResults(); List <Point3d> centers = new List <Point3d>(); List <Rectangle3d> boxes = new List <Rectangle3d>(); Brep[] srfs = Brep.CreatePlanarBreps(closedCrvs, tol); if (srfs != null) { ///Pick the srf with the biggest area in order to discard smaller islands ///TODO: Add option to include islands with a foreach in srfs Brep srf = srfs[0]; double area = AreaMassProperties.Compute(srf).Area; foreach (var b in srfs) { if (AreaMassProperties.Compute(b).Area > area) { area = AreaMassProperties.Compute(b).Area; srf = b; } } /// Based on javascript code from: https://github.com/mapbox/polylabel/blob/master/polylabel.js Point3d vc = new Point3d(); /// Find bounding box of the outer ring BoundingBox bb = srf.GetBoundingBox(true); var minX = bb.Min.X; var minY = bb.Min.Y; var maxX = bb.Max.X; var maxY = bb.Max.Y; var width = maxX - minX; var height = maxY - minY; var cellSize = Math.Min(width, height); var h = cellSize / 2; /// A priority queue of cells in order of their "potential" (max distance to polygon) List <Cell> cellList = new List <Cell>(); //List<Cell> cellArchive = new List<Cell>(); if (cellSize == 0) { vc = bb.Min; } /// Cover polygon with initial cells for (var x = minX; x < maxX; x += cellSize) { for (var y = minY; y < maxY; y += cellSize) { cellList.Add(new Cell(x + h, y + h, h, srf)); //cellList.Sort((a, b) => a.max.CompareTo(b.max)); //cellArchive.AddRange(cellList); //if (showBoxes) cellArchive.AddRange(cellList); } } cellList.Sort((a, b) => a.max.CompareTo(b.max)); /// Take centroid as the first best guess Cell bestCell = GetCentroidCell(srf); /// Special case for rectangular polygons Cell bboxCell = new Cell(minX + width / 2, minY + height / 2, 0, srf); if (bboxCell.d > bestCell.d) { bestCell = bboxCell; } /// Do the work while (cellList.Count > 0) { /// Pick the most promising cell from the queue Cell cell = cellList[cellList.Count - 1]; cellList.RemoveAt(cellList.Count - 1); /// Update the best cell if we found a better one if (cell.d > bestCell.d) { bestCell = cell; } /// Do not drill down further if there's no chance of a better solution if (cell.max - bestCell.d <= tol) { continue; } /// Split the cell into four cells h = cell.h / 2; cellList.Add(new Cell(cell.x - h, cell.y - h, h, srf)); cellList.Add(new Cell(cell.x + h, cell.y - h, h, srf)); cellList.Add(new Cell(cell.x - h, cell.y + h, h, srf)); cellList.Add(new Cell(cell.x + h, cell.y + h, h, srf)); cellList.Sort((a, b) => a.max.CompareTo(b.max)); //if (cellArchive.Count < 1000) cellArchive.AddRange(cellList); } centers.Add(new Point3d(bestCell.x, bestCell.y, 0)); //boxes.AddRange(cellArchive.Select(x => x.box)); } rc.centers = centers; return(rc); }
SolveResults Compute(string fileLoc, int numColors) { var rc = new SolveResults(); Dictionary <Color, int> dictColors = new Dictionary <Color, int>(); Dictionary <Color, List <GH_Point> > dictColorLocation = new Dictionary <Color, List <GH_Point> >(); List <GH_Colour> topCols = new List <GH_Colour>(); List <GH_Integer> colCount = new List <GH_Integer>(); GH_Structure <GH_Point> colLocation = new GH_Structure <GH_Point>(); try { using (Bitmap bitmap = new Bitmap(fileLoc)) { GH_Integer pixCount = new GH_Integer(); GH_Convert.ToGHInteger(bitmap.Height * bitmap.Width, 0, ref pixCount); rc.PixCount = pixCount; ///https://www.grasshopper3d.com/forum/topics/unsafe?page=1&commentId=2985220%3AComment%3A808291&x=1#2985220Comment808291 GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmap); Color col = Color.Transparent; for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { ///GH_MemoryBitmap Sample is faster than GetPixel //col = bitmap.GetPixel(x, y); if (sampler.Sample(x, y, ref col)) { if (!dictColors.ContainsKey(col)) { dictColors.Add(col, 1); //dictColorLocation.Add(col, new List<GH_Point> { new GH_Point(new Point3d(x,y,0)) }); } else { dictColors[col]++; //dictColorLocation[col].Add(new GH_Point(new Point3d(x,y,0))); } } } } if (numColors > dictColors.Count || numColors <= 0) { numColors = dictColors.Count; } var sortedColorDict = (from entry in dictColors orderby entry.Value descending select entry) .Take(numColors) .ToDictionary(pair => pair.Key, pair => pair.Value); //var sortedColorLocation = (from entry in dictColorLocation orderby entry.Value.Count descending select entry) // .Take(numColors) // .ToDictionary(pair => pair.Key, pair => pair.Value); foreach (var clr in sortedColorDict) { GH_Colour gh_Col = new GH_Colour(); GH_Convert.ToGHColour(clr.Key, 0, ref gh_Col); topCols.Add(gh_Col); GH_Integer gh_Count = new GH_Integer(); GH_Convert.ToGHInteger(clr.Value, 0, ref gh_Count); colCount.Add(gh_Count); } /*int i = 0; * foreach (var clr in sortedColorLocation) * { * GH_Path path = new GH_Path(i); * colLocation.AppendRange(clr.Value, path); * i++; * } */ sampler.Release(false); bitmap.Dispose(); } } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Could not load image from file path: " + fileLoc); } rc.TopColors = topCols; rc.ColorCount = colCount; //rc.ColorLocation = colLocation; return(rc); }
SolveResults Compute(string fileLoc, List <Color> colors, int tskId) { var rc = new SolveResults(); bool filterColors = colors.Any(); List <GH_Colour> topCols = new List <GH_Colour>(); List <GH_Integer> colCount = new List <GH_Integer>(); GH_Structure <GH_Point> colLocation = new GH_Structure <GH_Point>(); try { using (Bitmap bitmap = new Bitmap(fileLoc)) { GH_Integer pixCount = new GH_Integer(); GH_Convert.ToGHInteger(bitmap.Height * bitmap.Width, 0, ref pixCount); rc.PixCount = pixCount; ///https://www.grasshopper3d.com/forum/topics/unsafe?page=1&commentId=2985220%3AComment%3A808291&x=1#2985220Comment808291 GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmap); Color col = Color.Transparent; for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { ///GH_MemoryBitmap Sample is faster than GetPixel //col = bitmap.GetPixel(x, y); if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(tskId, colors.IndexOf(col)); colLocation.Append(new GH_Point(new Point3d(x, y, 0)), path); } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(tskId, colors.IndexOf(col)); colLocation.Append(new GH_Point(new Point3d(x, y, 0)), path); } } } } sampler.Release(false); bitmap.Dispose(); } } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Could not load image from file path: " + fileLoc); } List <GH_Colour> ghColors = new List <GH_Colour>(); foreach (var c in colors) { ghColors.Add(new GH_Colour(c)); } rc.TopColors = ghColors; rc.ColorLocation = colLocation; return(rc); }
SolveResults Compute(string cubeMap, string equiMap, int w) { var rc = new SolveResults(); Boolean converted = false; string equiFileLoc = string.Empty; if (!File.Exists(cubeMap)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cubemap file path does not exist."); rc.Converted = converted; rc.EquiFileLoc = equiFileLoc; return(rc); } else if (cubeMap == equiMap) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cubemap file path and equirectangular file path are the same. Cubemap not converted."); rc.Converted = converted; rc.EquiFileLoc = equiFileLoc; return(rc); } else { if (File.Exists(equiMap)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Existing file overwritten: " + equiMap); } if (!Directory.Exists(Path.GetDirectoryName(equiMap))) { Directory.CreateDirectory(Path.GetDirectoryName(equiMap)); } try { using (Bitmap bm = new Bitmap(cubeMap)) { Bitmap equi = new Bitmap(bm.Width, bm.Height, bm.PixelFormat); if ((w < 1) || (w.Equals(null))) { w = bm.Width; } equi = ConvertCubicToEquirectangular(bm, w); equi.Save(equiMap); equi.Dispose(); bm.Dispose(); equiFileLoc = equiMap; converted = true; } } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Could not load image from file path: " + cubeMap); } rc.Converted = converted; rc.EquiFileLoc = equiFileLoc; return(rc); } }
SolveResults Compute(Curve crv, List <double> pattern) { var rc = new SolveResults(); if (pattern.Count == 0) { return(null); } var pattern_length = 0.0; for (var i = 0; i < pattern.Count; i++) { if (pattern[i] < 0.0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dash patterns cannot have negative length segments"); pattern[i] = 0.0; } pattern_length += pattern[i]; } if (pattern_length <= 1e-12) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Total pattern length is too short."); return(rc); } crv = crv.DuplicateCurve(); var dashes = new List <Curve>(); var gaps = new List <Curve>(); var index = -1; var dash = false; while (true) { //toggle gap/dash flag dash = !dash; //increment index++; //limit if (index >= pattern.Count) { index = 0; } //get pattern length if (Math.Abs(pattern[index]) < 1e-32) { if (dash) { dashes.Add(null); } else { gaps.Add(null); } } else { //measure length double length = crv.GetLength(); if (!RhinoMath.IsValidDouble(length)) { break; } //cut short if we're at the end of the curve if (length <= pattern[index]) { if (dash) { dashes.Add(crv); } else { gaps.Add(crv); } break; } //compute normalised arc-length parameter. if (!crv.LengthParameter(pattern[index], out var t)) { break; } var segment = crv.Trim(crv.Domain.Min, t); if (segment != null && segment.IsValid) { if (dash) { dashes.Add(segment); } else { gaps.Add(segment); } } crv = crv.Trim(t, crv.Domain.Max); if (crv == null) { break; } } } rc.Dashes = dashes; rc.Gaps = gaps; return(rc); }