Esempio n. 1
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(bool reset, bool go, bool debug, int method, Mesh M, List <Point3d> P, double sR, double sI, double dR, double eR, double sensDist, double sensAng, ref object points, ref object vectors, ref object outMCol, ref object neigh, ref object neighCol, ref object sensors)
    {
        // <Custom code>
        // ............................................................................
        // Stigmergy system

        /*
         * notes on code refactoring
         *
         * 2 main classes:
         * . Particle System (and a class Particle)
         * . Environment (Mesh with scalar and optional vector field)
         *
         * RunScript function structure:
         *
         * . check inputs & eventually bypass execution
         * . initialise Environment
         * . initialise Particle System
         * . Update live variables
         * . Update Particle System
         * . Update Environment
         * . Extract Output Geometries and Data
         *
         */

        // return on null input
        if (M == null || P == null)
        {
            return;
        }


        // initialize on first execution or mesh change
        if (AS == null || M.Vertices.Count != ME.scalarField.Length)
        {
            // initialize particle system
            ME = new MeshEnvironment(M, dR, eR);
            AS = new AgentSystem(P, ME);
        }

        // restore initial values on reset
        if (reset)
        {
            // initialize particle system
            ME.RestoreScalarField();
            AS = new AgentSystem(P, ME);
        }

        if (go)
        {
            // update runtime variables
            AS.seekRadius      = sR;
            AS.seekIntensity   = sI;
            AS.sensDist        = sensDist; // old value 3.0
            AS.sensAng         = sensAng;
            ME.diffusionRate   = (float)dR;
            ME.evaporationRate = (float)eR;

            // update simulation
            switch (method)
            {
            case 0:
                AS.UpdateRTree();
                break;

            case 1:
                AS.UpdateJones();
                break;
            }

            // update environment (diffusion + evaporation)
            ME.Update();

            // update component
            Component.ExpireSolution(true);
        }

        // . . . . . . .  extract geometries

        // particles positions and velocites
        AS.GetPointsVectors(out pts, out vecs);
        points  = pts;
        vectors = vecs;

        // colored mesh
        outMCol = ME.GetColoredMesh();

        // debug mode
        if (debug)
        {
            switch (method)
            {
            case 0:
                neigh    = AS.GetNeighPts();
                neighCol = AS.GetNeighBrightness();
                break;

            case 1:
                sensors = AS.SensorsOut();
                break;
            }
        }

        // ............................................................................
        // </Custom code>
    }