Ejemplo n.º 1
0
 // constructor
 public AgentPlane(Point3d O, Vector3d dirX, AgentPlaneSystem agentSim)
 {
     this.O = O;
     dirX.Unitize();
     this.X        = dirX;
     this.agentSim = agentSim;
     neighbours    = new List <Point3d>();
     neighTens     = new List <TensorPoint>();
 }
Ejemplo n.º 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, List <Point3d> P, List <Vector3d> V, Mesh Ms, Mesh Mv, double pR, double nR, double cS, double aS, double sS, double fS, double meR, double meS, double coS, double mF, ref object iter, ref object Planes, ref object MeshPlanes)
    {
        // <Custom code>

        /*
         * align planes with mesh field - C#
         * code by Alessio Erioli - (c) Co-de-iT 2019
         *
         * NOTE ON CUSTOM BEHAVIORS
         *
         * If you feel like implementing your custom behaviors:
         * . hit CTRL+F and search for "DBD2020" - you should find 2 more locations (apart from this line)
         * . . one location is in the Update() method of the AgentPlaneSimulationClass - uncomment the line to call the CustomBehavior method
         * . . the other location is in the CustomAgentBehavior() method of the AgentPlane class - here is where you can write your code
         *
         * Keep in mind that you are writing a behavior for the single agent, that then will be executed by all agents in the system
         */

        if (P == null || P.Count == 0)
        {
            return;
        }

        if (reset || aPS == null)
        {
            // passing the essential parameters to the new simulation
            aPS          = new AgentPlaneSystem(P, V);
            MEnvironment = Ms;                            // the environment mesh can be either Ms or Mv (color is ignored)
            MeshRTree    = RTreeFromMesh(Ms);
            TensorField  = TensorFieldFromMeshes(Ms, Mv); // passing scalar and vector data to the Tensor Field

            // initializing arrays for export
            gP = new GH_Plane[aPS.agentPlanes.Length];

            //initialize iterations counter
            iterationsCount = 0;
        }

        if (go)
        {
            // update parameters
            aPS.PlaneRadius        = pR;
            aPS.NeighborhoodRadius = nR;
            aPS.CohesionStrength   = cS;
            aPS.AlignmentStrength  = aS;
            aPS.SeparationStrength = sS;
            aPS.FieldStrength      = fS;
            aPS.MeshSeekRadius     = meR;
            aPS.MeshStrength       = meS;
            aPS.SeekColorStrength  = coS;
            aPS.MaxForce           = mF;

            // update system
            aPS.Update();

            iterationsCount++;

            Component.ExpireSolution(true);
        }

        // extract output geometries and information

        Parallel.For(0, aPS.agentPlanes.Length, i =>
        {
            // extract planes
            gP[i] = new GH_Plane(aPS.agentPlanes[i].PlaneOut());
        });

        iter   = iterationsCount;
        Planes = gP;


        // </Custom code>
    }