예제 #1
0
        public async Task <ACADIAHeatMapOutputs> Handler(ACADIAHeatMapInputs args, ILambdaContext context)
        {
            if (this.store == null)
            {
                // Preload the dependencies (if they exist),
                // so that they are available during model deserialization.
                var asmLocation = this.GetType().Assembly.Location;
                var asmDir      = Path.GetDirectoryName(asmLocation);
                var asmName     = Path.GetFileNameWithoutExtension(asmLocation);
                var depPath     = Path.Combine(asmDir, $"{asmName}.Dependencies.dll");

                if (File.Exists(depPath))
                {
                    Console.WriteLine($"Loading dependencies from assembly: {depPath}...");
                    Assembly.LoadFrom(depPath);
                    Console.WriteLine("Dependencies assembly loaded.");
                }

                this.store = new S3ModelStore <ACADIAHeatMapInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <ACADIAHeatMapInputs, ACADIAHeatMapOutputs>(store, ACADIAHeatMap.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
예제 #2
0
        /// <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);
        }