/// <summary> /// The ACADIAHeatMap function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A ACADIAHeatMapOutputs instance containing computed results and the model with any new elements.</returns> public static ACADIAHeatMapOutputs Execute(Dictionary <string, Model> inputModels, ACADIAHeatMapInputs input) { if (!inputModels.TryGetValue("Envelope", out var envelopeModel)) { throw new Exception("womp womp envelope"); } var env = envelopeModel.AllElementsOfType <Envelope>().ToArray()[0]; var profile = env.Profile.Perimeter; if (!inputModels.TryGetValue("BlobData", out var internalPtsModel)) { throw new Exception("womp womp model points"); } var pts = internalPtsModel.AllElementsOfType <ModelPoints>().Where(n => n.Name == "BlobCentroids"); var modelPts = pts.ToArray()[0]; var distances = "fake distances"; var output = new ACADIAHeatMapOutputs(distances); // The analyze function computes the distance // to the attractor. var analyze = new Func <Vector3, double>((v) => { var dist = ClosestPointDist(v, modelPts); distances += dist.ToString(); distances += ","; return(dist); }); // Construct a color scale from a small number // of colors. var colorScale = new ColorScale(new List <Color>() { Colors.Cyan, Colors.Purple, Colors.Orange }, 10); var analysisMesh = new AnalysisMesh(profile, input.CellSize, input.CellSize, colorScale, analyze); var zDelta = analysisMesh.Transform.ZAxis.Z - profile.Centroid().Z; analysisMesh.Analyze(); analysisMesh.Transform.Move(zDelta); output.Model.AddElement(analysisMesh); return(output); }
public void SingleValueAnalysisMesh() { this.Name = "SingleValueAnalysis"; var perimeter = Polygon.Ngon(5, 5); var colorScale = new ColorScale(new List <Color>() { Colors.Cyan, Colors.Orange }, 10); var analysisMesh = new AnalysisMesh(perimeter, 0.2, 0.2, colorScale, (Vector3 vector) => { return(1); }); analysisMesh.Analyze(); this.Model.AddElement(analysisMesh); }
public void RayShadowTest() { this.Name = "RayShadowTest"; var outer = Polygon.Rectangle(3, 3); var inner = Polygon.Rectangle(1.5, 1.5); var mass = new Mass(new Profile(outer, inner.Reversed()), 2); mass.Transform.Move(new Vector3(0, 0, 1)); mass.Transform.Rotate(Vector3.ZAxis, 45); mass.UpdateRepresentations(); var light = new Vector3(4, 4, 10); var colorScale = new ColorScale(new List <Color> { Colors.White, Colors.Darkgray }); var analyze = new Func <Vector3, double>((v) => { var ray = new Ray(v, (light - v).Unitized()); if (ray.Intersects(mass, out List <Vector3> results)) { var hit = results[results.Count - 1]; if (!v.Equals(hit)) { var hitLine = new ModelCurve(new Line(light, hit), BuiltInMaterials.XAxis); this.Model.AddElement(hitLine); } return(1.0); } return(0.0); }); var sw = new Stopwatch(); sw.Start(); var analysisMesh = new AnalysisMesh(Polygon.Rectangle(10, 10), 0.5, 0.5, colorScale, analyze); sw.Stop(); this._output.WriteLine($"Analysis mesh constructed in {sw.Elapsed.TotalMilliseconds}ms."); sw.Reset(); sw.Start(); analysisMesh.Analyze(); sw.Stop(); this._output.WriteLine($"Shot {analysisMesh.TotalAnalysisLocations} rays in {sw.Elapsed.TotalMilliseconds}ms."); this.Model.AddElements(new Element[] { mass, analysisMesh }); }
public void AnalysisMesh() { this.Name = "Elements_Analysis_AnalysisMesh"; // <example> var perimeter1 = Polygon.L(10, 10, 3); var perimeter2 = Polygon.Ngon(5, 5); var move = new Transform(3, 7, 0); var perimeter = perimeter1.Union(move.OfPolygon(perimeter2)); var mc = new ModelCurve(perimeter); this.Model.AddElement(mc); // Construct a mass from which we will measure // distance to the analysis mesh's cells. var center = perimeter.Centroid(); var mass = new Mass(Polygon.Rectangle(1, 1)); mass.Transform.Move(center); this.Model.AddElement(mass); // The analyze function computes the distance // to the attractor. var analyze = new Func <Vector3, double>((v) => { return(center.DistanceTo(v)); }); // Construct a color scale from a small number // of colors. var colorScale = new ColorScale(new List <Color>() { Colors.Cyan, Colors.Purple, Colors.Orange }, 10); var analysisMesh = new AnalysisMesh(perimeter, 0.2, 0.2, colorScale, analyze); analysisMesh.Analyze(); // </example> this.Model.AddElement(analysisMesh); }
/// <summary> /// The ProceduralMassGen function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A ProceduralMassGenOutputs instance containing computed results and the model with any new elements.</returns> public static ProceduralMassGenOutputs Execute(Dictionary <string, Model> inputModels, ProceduralMassGenInputs input) { var boundaries = input.Perimeter.Offset(5.0, EndType.Butt); var boundary = boundaries[0]; var volume = input.MinBuildHeight * input.MaxBuildHeight; var output = new ProceduralMassGenOutputs(volume); var mc = new ModelCurve(boundary); output.Model.AddElement(mc); /////////////// analysis mesh code // Construct a mass from which we will measure // distance to the analysis mesh's cells. var center = boundary.Centroid(); var mass = new Mass(Polygon.Rectangle(1, 1)); mass.Transform.Move(center); output.Model.AddElement(mass); // The analyze function computes the distance // to the attractor. var analyze = new Func <Vector3, double>((v) => { return(center.DistanceTo(v)); }); // Construct a color scale from a small number // of colors. var colorScale = new ColorScale(new List <Color>() { Colors.Cyan, Colors.Purple, Colors.Orange }, 10); var analysisMesh = new AnalysisMesh(boundary, 2.0, 2.0, colorScale, analyze); analysisMesh.Analyze(); output.Model.AddElement(analysisMesh); /////////////// analysis mesh code // var height = 1.0;dotnet bui // var mass = new Mass(boundary, height); // //var profile = new Profile(boundaries); // //var cG = new CoordinateGrid(input.Perimeter, 10.0, 10.0, 10.0); // //var modelCurves = grid.GetCells().Select(c => new ModelCurve(c.GetCellGeometry())); // //var pts = cG.Available; // /// Your code here. // //var height = 1.0; // var volume = input.MinBuildHeight * input.MaxBuildHeight; // var output = new ProceduralMassGenOutputs(volume); // output.Model.AddElement(mass); // var grid = new Grid2d(boundary, null); // grid.U.DivideByApproximateLength(1.0); // grid.V.DivideByApproximateLength(1.0); // //var cells = grid.GetCells(); // var newCells = grid.GetCells().Select(c=>c).ToArray(); // var cellsBelonging = new List<Grid2d>(); // foreach(var c in newCells) // { // var vertices = from n in c.GetCellGeometry().ToPolyline().Vertices group n by n into nGroup where nGroup.Count() ==1 select nGroup.Key; // var vertArray = vertices.ToArray(); // var poly = new Polygon(vertArray); // if(boundary.Contains(poly.Centroid())) // { // cellsBelonging.Add(c); // } // } // var modelCurves = cellsBelonging.Select(c => new ModelCurve(c.GetCellGeometry())); // foreach (var m in modelCurves) // output.Model.AddElement(m); //for (int i = 0; i < pts.Count; i++) //{ // var rectangle = Polygon.Rectangle(8, 8); // var mass = new Mass(rectangle, height); // output.Model.AddElement(mass); //} return(output); }