Пример #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
         *
         * build 2 main classes:
         * . Particle System (and a class Particle)
         * . Environment (Mesh with scalar and optional vector field)
         *
         * RunScript function structure at the end:
         *
         * . check inputs & eventually bypass execution
         * . initialise Environment
         * . initialise Paeticle 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 (PS == null || M.Vertices.Count != scalarField.Length)
        {
            // initialize particle system
            PS = new ParticleSystem(P, M);

            // populate scalar field from mesh and array to restore it
            scalarField = PopulateScalarField(M);
            initVal     = scalarField;

            // populate point cloud from mesh (speeds up neighbour search)
            MeshPoints = PopulatePointCloud(M);

            // build neighbours indexes map & diffusion weights
            NeighbourMap     = BuildNeighboursMap(M);
            DiffusionWeights = CalculateDiffusionWeights();
        }

        // restore initial values on reset
        if (reset)
        {
            // initialize particle system
            PS = new ParticleSystem(P, M);

            // restore scalar field values
            scalarField = RestoreScalarField(initVal);
        }

        if (go)
        {
            // update runtime variables
            PS.seekRadius    = sR;
            PS.seekIntensity = sI;
            PS.sensDist      = sensDist; // old value 3.0
            PS.sensAng       = sensAng * 2;

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

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

            // diffusion
            Diffusion((float)dR);

            // evaporate scalar field
            EvaporateField(scalarField, eR);

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

        // . . . . . . .  extract geometries

        // particles positions and velocites
        PS.GetPointsVectors(out pts, out vecs);
        points  = pts;
        vectors = vecs;
        // colored mesh
        outMCol = GetColoredMesh(M, scalarField);
        // debug mode
        if (debug)
        {
            switch (method)
            {
            case 0:
                neigh    = PS.GetNeighPts();
                neighCol = PS.GetNeighBrightness();
                break;

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

        // ............................................................................
        // </Custom code>
    }
Пример #2
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 (PS == null || M.Vertices.Count != ME.scalarField.Length)
        {
            // initialize particle system
            ME = new MeshEnvironment(M, dR, eR);
            PS = new ParticleSystem(P, ME);
        }

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

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

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

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

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

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

        // . . . . . . .  extract geometries

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

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

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

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

        // ............................................................................
        // </Custom code>
    }
Пример #3
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, Mesh M, List <Point3d> P, List <Vector3d> Vf, double sR, double sI, ref object points, ref object vectors, ref object tr, ref object cols, ref object neigh, ref object neighCol, ref object outMCol)
    {
        // <Custom code>
        // Stigmergy - advanced
        // ............................................................................

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

        // initialize on reset
        if (reset || PS == null)
        {
            PS          = new ParticleSystem(P, M);
            scalarField = PopulateScalarField(M);
            vectorField = Vf.ToArray();
            MeshPoints  = PopulatePointCloud(M);

            debug = "";
        }

        if (go)
        {
            PS.seekRadius    = sR;
            PS.seekIntensity = sI;
            PS.futPosMult    = 3.0f;
            PS.UpdateRTree(M);
            Component.ExpireSolution(true);
            //EvaporateMesh(M, 0.65);
            EvaporateField(scalarField, 0.98);
        }

        // extract geometries

        PS.GetPointsVectors(out pts, out vecs);

        // Print(debug);

        debug    = "";
        points   = pts;
        vectors  = vecs;
        neigh    = PS.GetNeighPts();
        neighCol = PS.GetNeighBrightness();
        //if (!go)
        outMCol = GetScalarField(scalarField);
        //tr = PS.GetTrails();

        /* see this line above and the one after this commentary?
         *
         * This made me bleed:
         *
         * trails are Polylines, but I initialize them with a single point (so that's not a Polyline... yet)
         * This causes a 'reference not set to an instance' exception (when something is declared but not instanced)
         * the problem is that everything below this line does not compile anymore BUT THE SCRIPT EXECUTES
         * so I coudn't understand why neighPts contained data but nothig was outputting.... GROAN!!!
         *
         */
        //neigh = neighPts;


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