Exemple #1
0
        public static Dictionary <string, object> ExecuteSilently(
            List <Goal> goals,
            [DefaultArgument("null")] List <GeometryBinder> geometryBinders,
            [DefaultArgument("0.001")] float nodeMergeThreshold,
            [DefaultArgument("10000")] int iterations,
            [DefaultArgument("0.001")] float terminationThreshold,
            [DefaultArgument("true")] bool execute,
            [DefaultArgument("true")] bool enableMomentum,
            [DefaultArgument("0.98")] float dampingFactor)
        {
            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, nodeMergeThreshold);
            if (geometryBinders != null)
            {
                solver.AddGeometryBinders(geometryBinders, nodeMergeThreshold);
            }
            solver.EnableMomentum = enableMomentum;
            solver.DampingFactor  = dampingFactor;
            solver.Execute(iterations, terminationThreshold);

            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,
                      "\nNo. of Iterations Spent  : " + solver.CurrentIteration,
                      "\nLargest Movement Sqr.    : " + solver.GetKineticEnergy()) }
            });
        }
    }
Exemple #2
0
        public static Dictionary <string, object> Execute(
            DynaShape.Solver solver,
            List <Goal> goals,
            [DefaultArgument("null")] List <GeometryBinder> geometryBinders,
            [DefaultArgument("0.001")] float nodeMergeThreshold,
            [DefaultArgument("0")] int iterations,
            [DefaultArgument("true")] bool reset,
            [DefaultArgument("true")] bool execute,
            [DefaultArgument("true")] bool enableMomentum,
            [DefaultArgument("true")] bool enableFastDisplay,
            [DefaultArgument("false")] bool enableManipulation,
            [DefaultArgument("0.98")] float dampingFactor)
        {
#if CLI
            throw new Exception("This node will not work as you are currently using the CLI-compatible verison of DynaShape. " +
                                "You can use the DynaShape.ExecuteSilently node instead");
#else
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

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

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

            return(execute || enableFastDisplay
               ? new Dictionary <string, object> {
                { "nodePositions", null },
                { "goalOutputs", null },
                { "geometries", null }
            }
               : new Dictionary <string, object> {
                { "nodePositions", solver.GetNodePositionsAsPoints() },
                { "goalOutputs", solver.GetGoalOutputs() },
                { "geometries", solver.GetGeometries() }
            });
#endif
        }