Ejemplo n.º 1
0
        RayTracer currentModel;                        //Current ray tracer model

        public RayTracerRequestHandler(IScriptModuleComms _m_commsMod, Scene _m_scene)
        {
            isBusy = false;
            currentModel = new RayTracer();

            m_commsMod = _m_commsMod;
            m_scene = _m_scene;
        }//constructure
Ejemplo n.º 2
0
        }//constructure

        /// <summary>
        /// Handle all requests for ray tracing including generating new ray trace model, drawing rays from a model, or
        /// delete ray. 
        /// </summary>
        /// <param name="newRequest">All the parameter send from modSendCommand()</param>
        public void handleARequest(RayTraceRequest newRequest)
        {
            //If the command is to generating a new ray tracer model
            if (newRequest.command == "RayTrace0To1" || newRequest.command == "RayTrace0ToMax")
            {
                currentModel.deleteRays();
                currentModel = new RayTracer();

                if (newRequest.command == "RayTrace0To1")
                {
                    currentModel.RayTrace(true, m_scene, newRequest.input1, newRequest.scriptID);
                }
                else
                {
                    currentModel.RayTrace(false, m_scene, newRequest.input1, newRequest.scriptID);
                }
            }//if

            //If the command is to select from the existed model (reading a model from a file)
            //Input1 in the newRequest must contains file name. 
            else if(newRequest.command == "RayTraceFromModel")
            {
                string model = System.IO.File.ReadAllText(@EssentialPaths.getRTModelPath() + newRequest.input1 + ".txt");
                currentModel.deleteRays();
                currentModel = new RayTracer();
                currentModel.RayTraceFromModel(model, m_scene, newRequest.scriptID);
            }
            
            //If the command is to get all ray tracer model name
            else if(newRequest.command == "GetAllModelsName")
            {
                string allModels = System.IO.File.ReadAllText(@EssentialPaths.getModelListPath());
                m_commsMod.DispatchReply(newRequest.scriptID, 1, "AllModelsName//" + allModels, "");
            }

            //Else, it is other ray trace commands such as drawing, deleting, calculating power. 
            else
            {
                switch (newRequest.command)
                {
                    case "DeleteRayTrace":
                        currentModel.deleteRays();
                        break;

                    case "IDtype0": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(0, 0);
                        break;

                    case "IDtype1": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(1, 0);
                        break;

                    case "IDtype2": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(2, 0);
                        break;

                    case "IDtype3": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(3, 0);
                        break;

                    case "IDtype4": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(4, 0);
                        break;

                    case "IDtype5": 
                        currentModel.deleteRays();
                        currentModel.drawRayPath(5, 0);
                        break;

                    case "DrawNextPath":
                    case "DrawPrevPath":
                        currentModel.deleteRays();
                        //Get number of reflection and element index
                        string[] tokens = newRequest.input1.Split('_');
                        currentModel.drawRayPath(int.Parse(tokens[0]), int.Parse(tokens[1]));
                        break;



                    //This method can only be called after the ray tracer model has been initialised and post initialised
                    //Input1 contains no of reflection, pathID, and rayID (keys), Input2 contains the position of where 
                    //the ray was pressed;
                    case "getStrengthAt": 
                        double signalStrength = currentModel.getStrengthAt(newRequest.input1, newRequest.input2);
                        m_log.DebugFormat("[strength = ]" + signalStrength.ToString());
                        m_commsMod.DispatchReply(newRequest.scriptID, 1, "Strength: " + signalStrength.ToString(), "");
                        break;
                    default: break;
                }//switch
                
            }//else
        }
Ejemplo n.º 3
0
            }//getStrengthAt
            /// <summary>
            /// Calculate and return the left-over power after the reflection at the 
            /// end point of this ray.
            /// </summary>
            /// <param name="primMaterial">The material which reflecting this ray</param>
            /// <returns>Left over power in dBW</returns>
            public double getRefLoss(Vector3 intersectPoint, int primMaterial)
            {
                //To find the angle between 2 vectors
                //
                //    A.B
                //  ------  = cos(θ)
                //  |A||B|

                Vector3 ray1 = startPoint - endPoint;
                Vector3 ray2 = intersectPoint - endPoint;
                double airRefractiveIndex = RefrectiveIndex.AIR;
                double surfaceRefractiveIndex = RefrectiveIndex.getRefractiveIndex(primMaterial);

                //Calculate angle or incident, and reflection/refraction angle. 
                RayTracer rayTracerModel = new RayTracer();
                double incidentAngle = Math.Acos(Vector3.Dot(ray1, ray2) / (ray1.Length() * ray2.Length()));
                double reflectionAngle = rayTracerModel.getRefAngle(incidentAngle, airRefractiveIndex, surfaceRefractiveIndex);

                //Calculate and return reflection/refraction loss
                return RadioPower.ComputeRefloss(airRefractiveIndex, surfaceRefractiveIndex, incidentAngle, reflectionAngle);
            }
Ejemplo n.º 4
0
 public PathFromTxToRy(RayTracer parent, Vector3 _start, string _id)
 {
     rayTracerModel = parent;
     transmitterPos = _start;
     reachesReceiver = false;
     rayList = new Dictionary<string, RayAsPathSection>();
     id = _id;
 }
Ejemplo n.º 5
0
 public RayAsPathSection(Vector3 _startPoint, Vector3 _endPoint, double startPower, string _id, RayTracer _rayTracerModel)
 {
     rayTracerModel = _rayTracerModel;
     startPoint = _startPoint;
     endPoint = _endPoint;
     maxPower = startPower;
     minPower = maxPower - RadioPower.CalculatePathloss(Vector3.Distance(startPoint, endPoint), rayTracerModel.runningFreqRT, rayTracerModel.runningFreqRTUnit);
     id = _id;
 }//constructor