示例#1
0
        public static Dictionary <string, object> Execute(
            DynaShape.Solver solver,
            List <Goal> goals,
            [DefaultArgument("null")] List <GeometryBinder> geometryBinders,
            [DefaultArgument("0")] int iterations,
            [DefaultArgument("true")] bool reset,
            [DefaultArgument("true")] bool execute,
            [DefaultArgument("true")] bool enableMomentum,
            [DefaultArgument("true")] bool enableFastDisplay,
            [DefaultArgument("false")] bool enableManipulation)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            if (reset)
            {
                solver.StopBackgroundExecution();
                solver.Clear();
                solver.AddGoals(goals);
                if (geometryBinders != null)
                {
                    solver.AddGeometryBinders(geometryBinders);
                }
                solver.Display.Render();
            }
            else
            {
                solver.EnableMouseInteraction = enableManipulation;
                solver.EnableMomentum         = enableMomentum;
                solver.EnableFastDisplay      = enableFastDisplay;
                solver.IterationCount         = iterations;

                if (execute)
                {
                    solver.StartBackgroundExecution();
                }
                else
                {
                    solver.StopBackgroundExecution();
                    if (!enableFastDisplay)
                    {
                        solver.Iterate();
                    }
                }
            }

            return(enableFastDisplay
               ? new Dictionary <string, object> {
                { "nodePositions", null },
                { "goalOutputs", null },
                { "geometries", null }
            }
               : new Dictionary <string, object> {
                { "nodePositions", solver.GetNodePositionsAsPoints() },
                { "goalOutputs", solver.GetGoalOutputs() },
                { "geometries", solver.GetGeometries() }
            });
        }
示例#2
0
        public static Dictionary <string, object> ExecuteSilently(
            List <Goal> goals,
            [DefaultArgument("null")] List <GeometryBinder> geometryBinders,
            [DefaultArgument("10000")] int iterations,
            [DefaultArgument("0.001")] double threshold,
            [DefaultArgument("true")] bool execute,
            [DefaultArgument("true")] bool enableMomentum)
        {
            if (!execute)
            {
                return new Dictionary <string, object> {
                           { "nodePositions", null },
                           { "goalOutputs", null },
                           { "geometries", null },
                           { "stats", null }
                }
            }
            ;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            DynaShape.Solver solver = new DynaShape.Solver();
            solver.AddGoals(goals);
            if (geometryBinders != null)
            {
                solver.AddGeometryBinders(geometryBinders);
            }
            solver.EnableMomentum = enableMomentum;
            solver.Execute(iterations, threshold);

            TimeSpan computationTime = stopwatch.Elapsed;

            stopwatch.Restart();

            return(new Dictionary <string, object> {
                { "nodePositions", solver.GetNodePositionsAsPoints() },
                { "goalOutputs", solver.GetGoalOutputs() },
                { "geometries", solver.GetGeometries() },
                { "stats", String.Concat(
                      "Computation Time: " + computationTime,
                      "\nData Output Time: " + stopwatch.Elapsed,
                      "\nIterations      : " + solver.CurrentIteration,
                      "\nMovement        : " + solver.GetKineticEnergy()) }
            });
        }
    }