Ejemplo n.º 1
0
 public channel(int index, Hare.Geometry.Vector Dir, channel_type c, double delay_ms)
 {
     _index = index;
     V      = Dir;
     Type   = c;
     delay  = delay_ms;
 }
Ejemplo n.º 2
0
 public WaveConduit(ParticleRays[] PR_in, Pach_Graphics.colorscale C_in, double[] V_Bounds_in, Scene S)
 {
     min = Utilities.RC_PachTools.HPttoRPt(S.Min());
     Hare.Geometry.Vector range = S.Max() - S.Min();
     nx     = (int)System.Math.Ceiling(range.x);
     ny     = (int)System.Math.Ceiling(range.y);
     nz     = (int)System.Math.Ceiling(range.z);
     ptgrid = new List <int> [nx, ny, nz];
     for (int x = 0; x < nx; x++)
     {
         for (int y = 0; y < ny; y++)
         {
             for (int z = 0; z < nz; z++)
             {
                 ptgrid[x, y, z] = new List <int>();
             }
         }
     }
     dx       = range.x / nx;
     dy       = range.y / ny;
     dz       = range.z / nz;
     C        = C_in;
     V_Bounds = V_Bounds_in;
     PR       = PR_in;
 }
            public override void Absorb(ref OctaveRay Ray, out double cos_theta, Hare.Geometry.Vector Normal)
            {
                cos_theta = Hare.Geometry.Hare_math.Dot(Ray.direction, Normal);
                int index = 18 - (int)Math.Round(Math.Acos(Math.Abs(cos_theta)) / angle_incr);

                Ray.Intensity *= (1 - Ang_Coef_Oct[Ray.Octave][index]);
            }
            public override void Absorb(ref OctaveRay Ray, out double cos_theta, Hare.Geometry.Vector Normal)
            {
                cos_theta = Hare.Geometry.Hare_math.Dot(Normal, Ray.direction);

                Ray.Intensity *= (Ref[Ray.Octave]);
                Ray.phase     += PD[Ray.Octave];
            }
Ejemplo n.º 5
0
        public Sphere_Plot(List <Hare.Geometry.Point> pts, Hare.Geometry.Point Center, double max_dist)
        {
            Ctr   = Center;
            Faces = new List <int[]>();
            //Put data set in spherical coordinates...
            Vertices = new Hare.Geometry.Vector[pts.Count];
            for (int i = 0; i < pts.Count; i++)
            {
                Vertices[i] = pts[i] - Center;
                Vertices[i].Normalize();
            }

            double md2 = max_dist * max_dist * 25;

            for (int i = 0; i < Vertices.Length; i++)
            {
                for (int j = i + 1; j < Vertices.Length; j++)
                {
                    Hare.Geometry.Vector vd = Vertices[i] - Vertices[j];
                    //if (i == j) continue;
                    if (vd.x * vd.x + vd.y * vd.y + vd.z * vd.z > md2)
                    {
                        continue;
                    }
                    for (int k = j + 1; k < Vertices.Length; k++)
                    {
                        vd = Vertices[i] - Vertices[k];
                        if (vd.x * vd.x + vd.y * vd.y + vd.z * vd.z < md2)
                        {
                            Hare.Geometry.Point ctr;
                            double r2;
                            Utilities.PachTools.CircumCircleRadius(Vertices[i], Vertices[j], Vertices[k], out r2, out ctr);
                            if (r2 < max_dist * 10)
                            {
                                r2 *= r2;
                                int[] f = new int[3] {
                                    i, j, k
                                };
                                //Parallel.For(0, Vertices.Length, i =>
                                for (int x = 0; x < Vertices.Length; x++)
                                {
                                    if (x != f[0] && x != f[1] && x != f[2])
                                    {
                                        if (Utilities.PachTools.check_circumsphere(ctr, Vertices[x], r2))
                                        {
                                            Faces.Add(f);
                                        }
                                    }
                                }//) ;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < pts.Count; i++)
            {
                Vertices[i].Normalize();
            }
        }
 public void add_Speakers(IEnumerable <Hare.Geometry.Point> pts, IEnumerable <Rhino.Geometry.Vector3d> vec)
 {
     this.Enabled = true;
     Speakers     = new List <Line>();
     for (int i = 0; i < pts.Count <Hare.Geometry.Point>(); i++)
     {
         Hare.Geometry.Vector V = new Hare.Geometry.Vector(vec.ElementAt <Vector3d>(i).X, vec.ElementAt <Vector3d>(i).Y, vec.ElementAt <Vector3d>(i).Z);
         Speakers.Add(new Line(Utilities.RC_PachTools.HPttoRPt(pts.ElementAt(i)), Utilities.RC_PachTools.HPttoRPt(pts.ElementAt(i) + V)));
     }
 }
            public override void Absorb(ref BroadRay Ray, out double cos_theta, Hare.Geometry.Vector Normal)
            {
                cos_theta = Hare.Geometry.Hare_math.Dot(Ray.direction, Normal);
                int index = 18 - (int)Math.Round(Math.Acos(Math.Abs(cos_theta)) / angle_incr);

                for (int oct = 0; oct < 8; oct++)
                {
                    Ray.Energy[oct] *= (1 - Ang_Coef_Oct[oct][index]);
                }
            }
            public override void Scatter_VeryLate(ref OctaveRay Ray, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta)
            {
                if (rand.NextDouble() < Scattering_Coefficient[Ray.Octave, 1])
                {
                    Hare.Geometry.Vector diffx;
                    Hare.Geometry.Vector diffy;
                    Hare.Geometry.Vector diffz;
                    double proj;
                    //Check that the ray and the normal are both on the same side...
                    if (Cos_Theta > 0)
                    {
                        Normal *= -1;
                    }
                    diffz = Normal;
                    diffx = new Hare.Geometry.Vector(0, 0, 1);
                    proj  = Math.Abs(Hare.Geometry.Hare_math.Dot(diffz, diffx));

                    if (0.99 < proj && 1.01 > proj)
                    {
                        diffx = new Hare.Geometry.Vector(1, 0, 0);
                    }
                    diffy = Hare.Geometry.Hare_math.Cross(diffz, diffx);
                    diffx = Hare.Geometry.Hare_math.Cross(diffy, diffz);
                    diffx.Normalize();
                    diffy.Normalize();
                    diffz.Normalize();

                    double u1;
                    double u2;
                    double x;
                    double y;
                    double z;
                    Hare.Geometry.Vector vect;
                    u1 = 2.0 * Math.PI * rand.NextDouble();
                    // random azimuth
                    double Scat_Mod = rand.NextDouble();
                    u2 = Math.Acos(Scat_Mod);
                    // random zenith (elevation)
                    x = Math.Cos(u1) * Math.Sin(u2);
                    y = Math.Sin(u1) * Math.Sin(u2);
                    z = Math.Cos(u2);

                    vect = (diffx * x) + (diffy * y) + (diffz * z);
                    vect.Normalize();

                    //Return the new direction
                    Ray.direction = vect;
                }
                else
                {
                    //Specular Reflection
                    Ray.direction -= Normal * Cos_Theta * 2;
                }
            }
            public override void Absorb(ref OctaveRay Ray, Hare.Geometry.Vector Normal)
            {
                Ray.direction.Normalize();
                int Alt = (int)Math.Floor((Math.Acos(Hare.Geometry.Hare_math.Dot(Ray.direction, new Hare.Geometry.Vector(0, 0, -1))) * Altitude.Length) / (Math.PI / 2));

                if (Alt >= Altitude.Length / 2)
                {
                    Alt = Altitude.Length - 1;
                }
                int Azi = (int)Math.Round((Math.Atan2(Ray.direction.y, Ray.direction.x) * Azimuth.Length) / Math.PI);

                if (Ray.direction.y < 0 && Azi < Azimuth.Length / 2)
                {
                    Azi = Azimuth.Length - Math.Abs(Azi);
                }
                Ray.Intensity *= alpha[Alt][Azi][Ray.Octave];
            }
 public override void Absorb(ref BroadRay Ray, Hare.Geometry.Vector Normal)
 {
     Ray.Energy[0] *= (Ref[0]);
     Ray.phase[0]  += PD[0];
     Ray.Energy[1] *= (Ref[1]);
     Ray.phase[1]  += PD[1];
     Ray.Energy[2] *= (Ref[2]);
     Ray.phase[2]  += PD[2];
     Ray.Energy[3] *= (Ref[3]);
     Ray.phase[3]  += PD[3];
     Ray.Energy[4] *= (Ref[4]);
     Ray.phase[4]  += PD[4];
     Ray.Energy[5] *= (Ref[5]);
     Ray.phase[5]  += PD[5];
     Ray.Energy[6] *= (Ref[6]);
     Ray.phase[6]  += PD[6];
     Ray.Energy[7] *= (Ref[7]);
     Ray.phase[7]  += PD[7];
 }
            public override void Absorb(ref BroadRay Ray, out double cos_theta, Hare.Geometry.Vector Normal)
            {
                cos_theta = Hare.Geometry.Hare_math.Dot(Normal, Ray.direction);

                Ray.Energy[0] *= (Ref[0]);
                Ray.phase[0]  += PD[0];
                Ray.Energy[1] *= (Ref[1]);
                Ray.phase[1]  += PD[1];
                Ray.Energy[2] *= (Ref[2]);
                Ray.phase[2]  += PD[2];
                Ray.Energy[3] *= (Ref[3]);
                Ray.phase[3]  += PD[3];
                Ray.Energy[4] *= (Ref[4]);
                Ray.phase[4]  += PD[4];
                Ray.Energy[5] *= (Ref[5]);
                Ray.phase[5]  += PD[5];
                Ray.Energy[6] *= (Ref[6]);
                Ray.phase[6]  += PD[6];
                Ray.Energy[7] *= (Ref[7]);
                Ray.phase[7]  += PD[7];
            }
            public override void Absorb(ref BroadRay Ray, Hare.Geometry.Vector Normal)
            {
                //Simplified for sample laid on floor...
                Ray.direction.Normalize();
                int Alt = (int)Math.Floor((Math.Acos(Hare.Geometry.Hare_math.Dot(Ray.direction, new Hare.Geometry.Vector(0, 0, -1))) * Altitude.Length) / (Math.PI / 2));

                if (Alt >= Altitude.Length / 2)
                {
                    Alt = Altitude.Length - 1;
                }
                int Azi = (int)Math.Round((Math.Atan2(Ray.direction.y, Ray.direction.x) * Azimuth.Length) / Math.PI);

                if (Ray.direction.y < 0 && Azi < Azimuth.Length / 2)
                {
                    Azi = Azimuth.Length - Math.Abs(Azi);
                }
                for (int oct = 0; oct < 8; oct++)
                {
                    Ray.Energy[oct] *= alpha[Alt][Azi][oct];
                }
            }
 public abstract void Scatter_VeryLate(ref OctaveRay Ray, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta);
 public abstract void Scatter_Early(ref BroadRay Ray, ref Queue <OctaveRay> Rays, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta);
                public override double[] DirPower(int threadid, int random, Vector Direction, double position, ref Curve Curves, ref double[] DomainPower)
                {
                    X_Event X = new X_Event();
                    double[] RayPower = new double[8];

                    Interval t = Curves.Domain;
                    Point3d P = Curves.PointAt((position/t.Length) + t.Min);
                    Vector3d f = Curves.TangentAt(position);
                    Vector fore = new Hare.Geometry.Vector(f.X, f.Y, f.Z);

                    double cosphi = Hare.Geometry.Hare_math.Dot(Direction, fore);
                    double sinphi = Math.Sqrt(1 - cosphi * cosphi);
                    double tanphi = sinphi / cosphi;
                    double F_r = sinphi * sinphi * Math.Pow((tanphi * tanphi + 1) / (tanphi * tanphi + (1 + tanphi * Math.Tan(delta))), 1.5);

                    for (int oct = 0; oct < 8; oct++)
                    {
                        if (DomainPower[oct] == 0)
                        {
                            RayPower[oct] = 0;
                        }
                        else
                        {
                            RayPower[oct] = DomainPower[oct] * reciprocal_velocity * dLinf * F_r;
                        }
                    }
                    return RayPower;
                }
            public static double[] ETCurve_Directional(Direct_Sound Direct, ImageSourceData ISData, Receiver_Bank RTData, double CO_Time_ms, int Sampling_Frequency, int Octave, int Rec_ID, bool Start_at_Zero, double alt, double azi, bool degrees)
            {
                double[] Histogram = new double[(int)(CO_Time_ms * 0.001 * Sampling_Frequency)];
                    if (RTData != null)
                    {
                        for (int i = 0; i < Histogram.Length; i++)
                        {
                            Hare.Geometry.Vector Vpos = RTData.Directions_Pos(Octave, i, Rec_ID, alt, azi, degrees);
                            Hare.Geometry.Vector Vneg = RTData.Directions_Neg(Octave, i, Rec_ID, alt, azi, degrees);

                            double E = RTData.Rec_List[Rec_ID].Energy(i, Octave);
                            Hare.Geometry.Vector VTot = new Hare.Geometry.Vector(Math.Abs(Vpos.x) - Math.Abs(Vneg.x), Math.Abs(Vpos.y) - Math.Abs(Vneg.y), Math.Abs(Vpos.z) - Math.Abs(Vneg.z));

                            if (Vpos.x > 0)
                            {
                                Histogram[i] += Math.Abs(Vpos.x);
                            }
                            if (Vneg.x > 0)
                            {
                                Histogram[i] += Math.Abs(Vneg.x);
                            }

                            double L = VTot.Length();
                            if (L > 0) Histogram[i] *= E / L;

                            if (AcousticalMath.SPL_Intensity(Histogram[i]) > 200)
                            {
                                Rhino.RhinoApp.Write("Super high SPLs... what's going on, man?");
                            }
                        }
                    }

                    if (Direct != null && Direct.IsOccluded(Rec_ID))
                    {
                        int D_Start = 0;
                        if (!Start_at_Zero) D_Start = (int)Math.Ceiling(Direct.Time(Rec_ID) * Sampling_Frequency);

                        Hare.Geometry.Vector[] DirectValue;
                        switch (Octave)
                        {
                            case 8:
                                DirectValue = Direct.Dir_Energy_Sum(Rec_ID, alt, azi, degrees);
                                break;
                            default:
                                DirectValue = Direct.Dir_Energy(Octave, Rec_ID, alt, azi, degrees);
                                break;
                        }

                        for (int i = 0; i < DirectValue.Length; i++)
                        {
                            if (DirectValue[i].x > 0) Histogram[D_Start + i] += Math.Abs(DirectValue[i].x);
                        }
                    }

                    if (ISData != null)
                    {
                        switch (Octave)
                        {
                            case 8:
                                foreach (Deterministic_Reflection value in ISData.Paths[Rec_ID])
                                {
                                    if (Math.Ceiling(Sampling_Frequency * value.TravelTime) < Histogram.Length - 1)
                                    {
                                        Hare.Geometry.Vector[] E_Sum = value.Dir_EnergySum(alt, azi, degrees);
                                        for (int i = 0; i < E_Sum.Length; i++)
                                        {
                                            if (E_Sum[i].x > 0) Histogram[(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i)] += Math.Abs(E_Sum[i].x);
                                        }
                                    }
                                }
                                break;
                            default:
                                foreach (Deterministic_Reflection value in ISData.Paths[Rec_ID])
                                {
                                    if (Math.Ceiling(Sampling_Frequency * value.TravelTime) < Histogram.Length - 1)
                                    {
                                        Hare.Geometry.Vector[] E_Dir = value.Dir_Energy(Octave, alt, azi, degrees);
                                        for (int i = 0; i < E_Dir.Length; i++)
                                        {
                                            if (E_Dir[i].x > 0) Histogram[(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i)] += Math.Abs(E_Dir[i].x);
                                        }
                                    }
                                }
                                break;
                        }
                    }
                    return Histogram;
            }
            public override void Scatter_Early(ref BroadRay Ray, ref Queue <OctaveRay> Rays, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta)
            {
                double roughness_chance = rand.NextDouble();

                if (Cos_Theta > 0)
                {
                    Normal    *= -1;
                    Cos_Theta *= -1;
                }

                foreach (int oct in Ray.Octaves)
                {
                    // 3. Apply Scattering.
                    //// a. Create new source for scattered energy (E * Scattering).
                    //// b. Modify E (E * 1 - Scattering).
                    OctaveRay R = Ray.SplitRay(oct, Scattering_Coefficient[oct, 1]);

                    Hare.Geometry.Vector diffx;
                    Hare.Geometry.Vector diffy;
                    Hare.Geometry.Vector diffz;
                    double proj;
                    //Check that the ray and the normal are both on the same side...
                    diffz = Normal;
                    diffx = new Hare.Geometry.Vector(0, 0, 1);
                    proj  = Math.Abs(Hare.Geometry.Hare_math.Dot(diffz, diffx));

                    if (0.99 < proj && 1.01 > proj)
                    {
                        diffx = new Hare.Geometry.Vector(1, 0, 0);
                    }
                    diffy = Hare.Geometry.Hare_math.Cross(diffz, diffx);
                    diffx = Hare.Geometry.Hare_math.Cross(diffy, diffz);
                    diffx.Normalize();
                    diffy.Normalize();
                    diffz.Normalize();

                    double u1;
                    double u2;
                    double x;
                    double y;
                    double z;
                    Hare.Geometry.Vector vect;
                    u1 = 2.0 * Math.PI * rand.NextDouble();
                    // random azimuth
                    double Scat_Mod = rand.NextDouble();
                    u2 = Math.Acos(Scat_Mod);
                    // random zenith (elevation)
                    x = Math.Cos(u1) * Math.Sin(u2);
                    y = Math.Sin(u1) * Math.Sin(u2);
                    z = Math.Cos(u2);

                    vect = (diffx * x) + (diffy * y) + (diffz * z);
                    vect.Normalize();

                    //Return the new direction
                    R.direction = vect;

                    if (R.t_sum == 0)
                    {
                        Rhino.RhinoApp.Write("Something's up!");
                    }

                    Rays.Enqueue(R);
                }
                Ray.direction -= Normal * Cos_Theta * 2;
            }
            public override System.Numerics.Complex Reflection_Narrow(double frequency, Hare.Geometry.Vector Dir, Hare.Geometry.Vector Normal)
            {
                int a = (int)(Math.Abs(Hare.Geometry.Hare_math.Dot(Dir, Normal)) * 180 / Math.PI / 18);

                return(new System.Numerics.Complex(Transfer_FunctionR[a].Interpolate(frequency), Transfer_FunctionI[a].Interpolate(frequency)));
            }
 public channel(int index, Hare.Geometry.Vector Dir, channel_type c, double delay_ms)
 {
     _index = index;
     V = Dir;
     Type = c;
     delay = delay_ms;
 }
 public abstract void Absorb(ref BroadRay Ray, Hare.Geometry.Vector Normal);
 public abstract void Absorb(ref OctaveRay Ray, Hare.Geometry.Vector Normal);
 public override System.Numerics.Complex Reflection_Narrow(double frequency, Hare.Geometry.Vector Dir, Hare.Geometry.Vector Normal)
 {
     return(new System.Numerics.Complex(Transfer_Function.Interpolate(frequency), 0));
 }
            public static double[][] ETCurve_1d(Direct_Sound Direct, ImageSourceData ISData, Receiver_Bank RTData, double CO_Time_ms, int Sampling_Frequency, int Octave, int Rec_ID, bool Start_at_Zero, double alt, double azi, bool degrees)
            {
                double[][] Histogram = new double[3][];
                    Histogram[0] = new double[(int)(CO_Time_ms * 0.001 * Sampling_Frequency)];
                    Histogram[1] = new double[(int)(CO_Time_ms * 0.001 * Sampling_Frequency)];
                    Histogram[2] = new double[(int)(CO_Time_ms * 0.001 * Sampling_Frequency)];
                    if (RTData != null)
                    {
                        for (int i = 0; i < Histogram[0].Length; i++)
                        {
                            Hare.Geometry.Vector Vpos = RTData.Directions_Pos(Octave, i, Rec_ID, alt, azi, degrees);
                            Hare.Geometry.Vector Vneg = RTData.Directions_Neg(Octave, i, Rec_ID, alt, azi, degrees);

                            double E = RTData.Rec_List[Rec_ID].Energy(i, Octave);
                            Hare.Geometry.Vector VTot = new Hare.Geometry.Vector(Math.Abs(Vpos.x) - Math.Abs(Vneg.x), Math.Abs(Vpos.y) - Math.Abs(Vneg.y), Math.Abs(Vpos.z) - Math.Abs(Vneg.z));
                            VTot.Normalize();
                            VTot *= E;

                            Histogram[0][i] = VTot.x;
                            Histogram[1][i] = VTot.y;
                            Histogram[2][i] = VTot.z;
                        }
                    }

                    if (Direct != null && Direct.IsOccluded(Rec_ID))
                    {
                        int D_Start = 0;
                        if (!Start_at_Zero) D_Start = (int)Math.Ceiling(Direct.Time(Rec_ID) * Sampling_Frequency);

                        Hare.Geometry.Vector[] DirectValue;
                        switch (Octave)
                        {
                            case 8:
                                DirectValue = Direct.Dir_Energy_Sum(Rec_ID, alt, azi, degrees);
                                break;
                            default:
                                DirectValue = Direct.Dir_Energy(Octave, Rec_ID, alt, azi, degrees);
                                break;
                        }

                        for (int i = 0; i < DirectValue.Length; i++)
                        {
                            Histogram[0][D_Start + i] += Math.Abs(DirectValue[i].x);
                            Histogram[1][D_Start + i] += Math.Abs(DirectValue[i].y);
                            Histogram[2][D_Start + i] += Math.Abs(DirectValue[i].z);
                        }
                    }

                    if (ISData != null)
                    {
                        switch (Octave)
                        {
                            case 8:
                                foreach (Deterministic_Reflection value in ISData.Paths[Rec_ID])
                                {
                                    if (Math.Ceiling(Sampling_Frequency * value.TravelTime) < Histogram[0].Length - 1)
                                    {
                                        Hare.Geometry.Vector[] E_Sum = value.Dir_EnergySum(alt, azi, degrees);
                                        for (int i = 0; i < E_Sum.Length; i++)
                                        {
                                            Histogram[0][(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i / Sampling_Frequency)] += Math.Abs(E_Sum[i].x);
                                            Histogram[1][(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i / Sampling_Frequency)] += Math.Abs(E_Sum[i].y);
                                            Histogram[2][(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i / Sampling_Frequency)] += Math.Abs(E_Sum[i].z);
                                        }
                                    }
                                }
                                break;
                            default:
                                foreach (Deterministic_Reflection value in ISData.Paths[Rec_ID])
                                {
                                    if (Math.Ceiling(Sampling_Frequency * value.TravelTime) < Histogram[0].Length - 1)
                                    {
                                        Hare.Geometry.Vector[] E_Dir = value.Dir_Energy(Octave, alt, azi, degrees);
                                        for (int i = 0; i < E_Dir.Length; i++)
                                        {
                                            Histogram[0][(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i / Sampling_Frequency)] += Math.Abs(E_Dir[i].x);
                                            Histogram[1][(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i / Sampling_Frequency)] += Math.Abs(E_Dir[i].y);
                                            Histogram[2][(int)Math.Ceiling(Sampling_Frequency * value.TravelTime + i / Sampling_Frequency)] += Math.Abs(E_Dir[i].z);
                                        }
                                    }
                                }
                                break;
                        }
                    }
                    return Histogram;
            }
 /// <summary>
 /// Calculates the direction of a specular reflection.
 /// </summary>
 /// <param name="R"></param>
 /// <param name="u"></param>
 /// <param name="v"></param>
 /// <param name="Face_ID"></param>
 public static void SpecularReflection(ref Hare.Geometry.Vector R, ref Environment.Scene Room, ref double u, ref double v, ref int Face_ID)
 {
     Hare.Geometry.Vector local_N = Room.Normal(Face_ID, u, v);
     R -= local_N * Hare.Geometry.Hare_math.Dot(R, local_N) * 2;
 }
            public static Hare.Geometry.Vector Rotate_Vector(Hare.Geometry.Vector V, double azi, double alt, bool degrees)
            {
                double yaw, pitch;
                if (degrees)
                {
                    yaw = Math.PI * alt / 180.0;
                    pitch = Math.PI * azi / 180.0;
                }
                else
                {
                    yaw = alt;
                    pitch = azi;
                }

                ///Implicit Sparse Rotation Matrix
                double[] r1 = new double[3] { Math.Cos(pitch) * Math.Cos(yaw) , Math.Sin(pitch) * Math.Cos(yaw) , Math.Sin(yaw) };
                Hare.Geometry.Vector fwd = new Hare.Geometry.Vector(r1[0], r1[1], r1[2]);
                Hare.Geometry.Vector up = new Hare.Geometry.Vector(0, 0, 1) - Hare.Geometry.Hare_math.Dot(new Hare.Geometry.Vector(0, 0, 1), fwd) * fwd;
                up.Normalize();
                double[] r3 = new double[3] { up.x, up.y, up.z };
                Hare.Geometry.Vector right = Hare.Geometry.Hare_math.Cross(up, fwd);
                double[] r2 = new double[3] { right.x, right.y, right.z };

                return (new Hare.Geometry.Vector(r1[0] * V.x + r1[1] * V.y + r1[2] * V.z, r2[0] * V.x + r2[1] * V.y + r2[2] * V.z, r3[0] * V.x + r3[1] * V.y + r3[2] * V.z));
            }
 public void add_Speakers(IEnumerable<Rhino.Geometry.Point3d> pts, IEnumerable<Rhino.Geometry.Vector3d> vec)
 {
     this.Enabled = true;
     Speakers = new List<Line>();
     for (int i = 0; i < pts.Count<Rhino.Geometry.Point3d>(); i++)
     {
         Hare.Geometry.Vector V = new Hare.Geometry.Vector(vec.ElementAt<Vector3d>(i).X, vec.ElementAt<Vector3d>(i).Y, vec.ElementAt<Vector3d>(i).Z);
         Speakers.Add(new Line(pts.ElementAt<Point3d>(i), pts.ElementAt<Point3d>(i) + Utilities.PachTools.HPttoRPt(V)));
     }
 }
            public override System.Numerics.Complex[] Reflection_Spectrum(int sample_frequency, int length, Hare.Geometry.Vector Normal, Hare.Geometry.Vector Dir, int threadid)
            {
                int a = (int)(Math.Abs(Hare.Geometry.Hare_math.Dot(Dir, Normal)) * 180 / Math.PI / 18);

                System.Numerics.Complex[] Ref_trns = new System.Numerics.Complex[length];

                for (int j = 0; j < length; j++)
                {
                    double freq = j * (sample_frequency / 2) / length;
                    Ref_trns[j] = new System.Numerics.Complex(Transfer_FunctionR[a].Interpolate(freq), Transfer_FunctionI[a].Interpolate(freq));
                }

                return(Ref_trns);
            }
            protected override void DrawForeground(DrawEventArgs e)
            {
                int index = 0;
                foreach (Guid G in m_id_list)
                {
                    Rhino.DocObjects.RhinoObject rhobj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(G);
                    if (rhobj == null)
                    {
                        m_id_list.Remove(G);
                        m_Balloons.RemoveAt(index);
                        continue;
                    }

                    if (rhobj.Attributes.ObjectId == G)
                    {
                        if (rhobj.ObjectType == Rhino.DocObjects.ObjectType.Point)
                        {
                            string mode = rhobj.Geometry.GetUserString("SourceType");
                            // Draw our own representation of the object
                            //m_pChannelAttrs.m_bDrawObject = false;
                            Rhino.Geometry.Point3d pt = rhobj.Geometry.GetBoundingBox(true).Min;
                            // this is a point object so the bounding box will be wee sized
                            Rhino.Geometry.Point2d screen_pt = e.Display.Viewport.WorldToClient(pt);
                            if (mode == "2" && m_Balloons[index] != null)
                            {
                                if ((rhobj.IsSelected(false) != 0))
                                {
                                    //Display the balloon for 1khz.
                                    e.Display.DrawSprite(LS, pt, 0.25f, true);// screen_pt, 32.0f);
                                    e.Display.DrawMeshWires(this.m_Balloons[index].m_DisplayMesh, Color.Blue);
                                    e.Display.Draw2dText(index.ToString(), Color.Yellow, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                                    double Theta = (m_Balloons[index].CurrentAlt + 270) * System.Math.PI / 180;
                                    double Phi = (m_Balloons[index].CurrentAzi - 90) * System.Math.PI / 180;
                                    Hare.Geometry.Vector Direction = new Hare.Geometry.Vector(Math.Sin(Theta) * Math.Cos(Phi), Math.Sin(Theta) * Math.Sin(Phi), Math.Cos(Theta));
                                    e.Display.DrawLine(pt, new Rhino.Geometry.Point3d(Direction.x * 1000, Direction.y * 1000, Direction.z * 1000) + pt, Color.Red, 1);
                                }
                                else
                                {
                                    //Display the Icon for a loudspeaker.
                                    e.Display.DrawSprite(LU, pt, 0.5f, true);// screen_pt, 32.0f);
                                    //e.Display.DrawMeshVertices(this.m_Balloons[i].m_DisplayMesh, R);
                                    e.Display.Draw2dText(index.ToString(), Color.Black, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                                }
                            }
                            else
                            {
                                if ((rhobj.IsSelected(false) != 0))
                                {
                                    e.Display.DrawSprite(SS, pt, 0.5f, true);// screen_pt, 32.0f);
                                    e.Display.Draw2dText(index.ToString(), Color.Yellow, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                                }
                                else
                                {
                                    e.Display.DrawSprite(SU, pt, 0.5f, true);// screen_pt, 32.0f, Color.Black);
                                    e.Display.Draw2dText(index.ToString(), Color.Black, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                                }
                            }
                        }
                        else if (rhobj.ObjectType == Rhino.DocObjects.ObjectType.Brep)
                        {
                            Rhino.Geometry.Point3d pt = (rhobj.Geometry as Rhino.Geometry.Brep).GetBoundingBox(false).Center;
                            Rhino.Geometry.Point2d screen_pt = e.Display.Viewport.WorldToClient(pt);
                            if ((rhobj.IsSelected(false) != 0))
                            {
                                e.Display.DrawSprite(SS, pt, 0.5f, true);// screen_pt, 32.0f);
                                e.Display.Draw2dText(index.ToString(), Color.Yellow, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                            }
                            else
                            {
                                e.Display.DrawSprite(SU, pt, 0.5f, true);// screen_pt, 32.0f, Color.Black);
                                e.Display.Draw2dText(index.ToString(), Color.Black, new Rhino.Geometry.Point2d((int)screen_pt.X, (int)screen_pt.Y + 40), false, 12, "Arial");
                            }
                        }
                        else if (rhobj.ObjectType == Rhino.DocObjects.ObjectType.Curve)
                        {
                            Rhino.Geometry.Curve crv = (rhobj.Geometry as Rhino.Geometry.Curve);
                            Rhino.Geometry.Point3d[] pts;
                            double[] par = crv.DivideByLength(10, true, out pts);

                            for(int i = 0; i < par.Length; i++)
                            {
                                Rhino.Geometry.Vector3d V = crv.TangentAt(par[i]);
                                e.Display.DrawCircle(new Rhino.Geometry.Circle(new Rhino.Geometry.Plane(pts[i], V), .5), System.Drawing.Color.Red);
                                e.Display.DrawCircle(new Rhino.Geometry.Circle(new Rhino.Geometry.Plane(pts[i], V), .7), System.Drawing.Color.Red);
                                e.Display.DrawCircle(new Rhino.Geometry.Circle(new Rhino.Geometry.Plane(pts[i], V), 1.2), System.Drawing.Color.Red);
                                e.Display.DrawCircle(new Rhino.Geometry.Circle(new Rhino.Geometry.Plane(pts[i], V), 1.4), System.Drawing.Color.Red);
                                e.Display.DrawCircle(new Rhino.Geometry.Circle(new Rhino.Geometry.Plane(pts[i], V), 1.9), System.Drawing.Color.Red);
                                e.Display.DrawCircle(new Rhino.Geometry.Circle(new Rhino.Geometry.Plane(pts[i], V), 2.1), System.Drawing.Color.Red);
                            }

                            Rhino.Geometry.Point2d screen_pt0 = e.Display.Viewport.WorldToClient(pts[0]);
                            Rhino.Geometry.Point2d screen_pt1 = e.Display.Viewport.WorldToClient(pts[pts.Length-1]);
                            if ((rhobj.IsSelected(false) != 0))
                            {
                                e.Display.Draw2dText(index.ToString(), Color.Yellow, new Rhino.Geometry.Point2d((int)screen_pt0.X, (int)screen_pt0.Y + 40), false, 12, "Arial");
                                e.Display.Draw2dText(index.ToString(), Color.Yellow, new Rhino.Geometry.Point2d((int)screen_pt1.X, (int)screen_pt1.Y + 40), false, 12, "Arial");
                            }
                            else
                            {
                                e.Display.Draw2dText(index.ToString(), Color.Black, new Rhino.Geometry.Point2d((int)screen_pt0.X, (int)screen_pt0.Y + 40), false, 12, "Arial");
                                e.Display.Draw2dText(index.ToString(), Color.Black, new Rhino.Geometry.Point2d((int)screen_pt1.X, (int)screen_pt1.Y + 40), false, 12, "Arial");
                            }

                        }
                    }
                    index++;
                }
            }
 public abstract void Absorb(ref BroadRay Ray, out double cos_theta, Hare.Geometry.Vector Normal);
 public override void Absorb(ref OctaveRay Ray, Hare.Geometry.Vector Normal)
 {
     Ray.Intensity *= (Ref[Ray.Octave]);
     Ray.phase     += PD[Ray.Octave];
 }
 public static Vector3d HPttoRPt(Hare.Geometry.Vector Point)
 {
     return(new Vector3d(Point.x, Point.y, Point.z));
 }
Ejemplo n.º 32
0
 private void Draw_Feedback()
 {
     if (Hybrid_Select.Checked)
     {
         if (Pach_Hybrid_Control.Instance != null && !Pach_Hybrid_Control.Instance.Auralisation_Ready() || Receiver_Choice.SelectedIndex < 0)
         {
             return;
         }
         Point3d[] rec = new Point3d[Recs.Length];
         for (int i = 0; i < Recs.Length; i++)
         {
             rec[i] = Utilities.PachTools.HPttoRPt(Recs[i]);
         }
         AuralisationConduit.Instance.add_Receivers(rec);
         List <Point3d> pts = new List <Point3d>();
         foreach (Direct_Sound D in Direct_Data)
         {
             pts.Add(D.Src_Origin);
         }
         AuralisationConduit.Instance.add_Sources(pts);
         List <Deterministic_Reflection> Paths = new List <Deterministic_Reflection>();
         List <Polyline> Lines = new List <Polyline>();
         foreach (ImageSourceData I in IS_Data)
         {
             if (I != null)
             {
                 Paths.AddRange(I.Paths[Receiver_Choice.SelectedIndex]);
             }
         }
         foreach (Deterministic_Reflection p in Paths)
         {
             foreach (Polyline P in p.PolyLine)
             {
                 Lines.Add(P);
             }
         }
         AuralisationConduit.Instance.add_Reflections(Lines);
         pts.Clear();
         List <Vector3d> Dirs = new List <Vector3d>();
         for (int i = 0; i < this.Channel_View.Items.Count; i++)
         {
             Hare.Geometry.Vector TempDir = Utilities.PachTools.Rotate_Vector(Utilities.PachTools.Rotate_Vector(((channel)Channel_View.Items[i]).V, 0, -(double)Alt_Choice.Value, true), -(double)Azi_Choice.Value, 0, true);//new Hare.Geometry.Vector(Speaker_Directions[i].X, Speaker_Directions[i].Y, Speaker_Directions[i].Z)
             //Hare.Geometry.Vector TempDir = Utilities.PachTools.Rotate_Vector(((channel)Channel_View.Items[i]).V, -(double)Azi_Choice.Value, -(double)Alt_Choice.Value, true);
             TempDir.Normalize();
             pts.Add(Utilities.PachTools.HPttoRPt(Recs[0]) + (Utilities.PachTools.HPttoRPt(TempDir) * -.343 * Math.Max(5, ((channel)Channel_View.Items[i]).delay)));
             Dirs.Add(new Vector3d(TempDir.x, TempDir.y, TempDir.z));
         }
         AuralisationConduit.Instance.add_Speakers(pts, Dirs);
         AuralisationConduit.Instance.set_direction(Utilities.PachTools.HPttoRPt(Recs[Receiver_Choice.SelectedIndex]), Utilities.PachTools.HPttoRPt(Utilities.PachTools.Rotate_Vector(Utilities.PachTools.Rotate_Vector(new Hare.Geometry.Vector(1, 0, 0), 0, -(double)Alt_Choice.Value, true), -(double)Azi_Choice.Value, 0, true)));
         //AuralisationConduit.Instance.set_direction(Utilities.PachTools.HPttoRPt(Recs[Receiver_Choice.SelectedIndex]), Utilities.PachTools.HPttoRPt(Utilities.PachTools.Rotate_Vector(new Hare.Geometry.Vector(1, 0, 0), -(double)Azi_Choice.Value, -(double)Alt_Choice.Value, true)));
     }
     else if (Mapping_Select.Checked)
     {
         if (Pach_Mapping_Control.Instance != null && !Pach_Mapping_Control.Instance.Auralisation_Ready() && Receiver_Choice.SelectedIndex < 0)
         {
             return;
         }
         if (Maps == null || Maps[0] == null)
         {
             return;
         }
         AuralisationConduit.Instance.add_Receivers(Maps[0].Origins());
         List <Point3d> pts = new List <Point3d>();
         foreach (Mapping.PachMapReceiver m in Maps)
         {
             pts.Add(m.Src);
         }
         AuralisationConduit.Instance.add_Sources(pts);
     }
     else
     {
         AuralisationConduit.Instance.Enabled = false;
     }
     Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();
 }
            public override void Scatter_VeryLate(ref OctaveRay Ray, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta)
            {
                if (rand.NextDouble() < Scattering_Coefficient[Ray.Octave, 1])
                {
                    Hare.Geometry.Vector diffx;
                    Hare.Geometry.Vector diffy;
                    Hare.Geometry.Vector diffz;
                    double proj;
                    //Check that the ray and the normal are both on the same side...
                    if (Cos_Theta > 0) Normal *= -1;
                    diffz = Normal;
                    diffx = new Hare.Geometry.Vector(0, 0, 1);
                    proj = Math.Abs(Hare.Geometry.Hare_math.Dot(diffz, diffx));

                    if (0.99 < proj && 1.01 > proj) diffx = new Hare.Geometry.Vector(1, 0, 0);
                    diffy = Hare.Geometry.Hare_math.Cross(diffz, diffx);
                    diffx = Hare.Geometry.Hare_math.Cross(diffy, diffz);
                    diffx.Normalize();
                    diffy.Normalize();
                    diffz.Normalize();

                    double u1;
                    double u2;
                    double x;
                    double y;
                    double z;
                    Hare.Geometry.Vector vect;
                    u1 = 2.0 * Math.PI * rand.NextDouble();
                    // random azimuth
                    double Scat_Mod = rand.NextDouble();
                    u2 = Math.Acos(Scat_Mod);
                    // random zenith (elevation)
                    x = Math.Cos(u1) * Math.Sin(u2);
                    y = Math.Sin(u1) * Math.Sin(u2);
                    z = Math.Cos(u2);

                    vect = (diffx * x) + (diffy * y) + (diffz * z);
                    vect.Normalize();

                    //Return the new direction
                    Ray.direction = vect;
                }
                else
                {
                    //Specular Reflection
                    Ray.direction -= Normal * Cos_Theta * 2;
                }
            }
                public override BroadRay Directions(int index, int thread, ref Random random, ref Curve Curves, ref double[] DomainPower, ref double Delay, ref Phase_Regime ph, ref int S_ID)
                {
                    double pos = random.NextDouble();
                    int i;

                    Interval t = Curves.Domain;
                    double x = random.NextDouble() * (t[1] - t[0]) + t[0];
                    Point3d P = Curves.PointAt(x);
                    Vector3d f = Curves.TangentAt(x);
                    Vector fore = new Hare.Geometry.Vector(f.X, f.Y, f.Z);

                    double Theta = random.NextDouble() * 2 * System.Math.PI;
                    double Phi = random.NextDouble() * 2 * System.Math.PI;
                    Vector Direction = new Hare.Geometry.Vector(Math.Sin(Theta) * Math.Cos(Phi), Math.Sin(Theta) * Math.Sin(Phi), Math.Cos(Theta));

                    double cosphi = Hare.Geometry.Hare_math.Dot(Direction, fore);
                    double sinphi = Math.Sqrt(1 - cosphi * cosphi);
                    double tanphi =  sinphi/cosphi;
                    double F_r = sinphi * sinphi * Math.Pow((tanphi * tanphi + 1) / (tanphi * tanphi + (1 + tanphi * Math.Tan(delta))), 1.5);

                    double[] power = new double[8];
                    for (int oct = 0; oct < 8; oct++) power[oct] = DomainPower[oct] * reciprocal_velocity * dLinf * F_r;
                    double[] phase = new double[8];
                    if (ph == Phase_Regime.Random) for (int o = 0; o < 8; o++) phase[o] = random.Next() * 2 * Math.PI;
                    else for (int o = 0; o < 8; o++) phase[o] = 0 - Delay * Utilities.Numerics.angularFrequency[o];

                    return new BroadRay(Utilities.PachTools.RPttoHPt(P), Direction, random.Next(), thread, DomainPower, phase, Delay, S_ID);
                }
            public override void Scatter_Early(ref BroadRay Ray, ref Queue<OctaveRay> Rays, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta)
            {
                double roughness_chance = rand.NextDouble();
                if (Cos_Theta > 0)
                {
                    Normal *= -1;
                    Cos_Theta *= -1;
                }

                foreach (int oct in Ray.Octaves)
                {
                    // 3. Apply Scattering.
                    //// a. Create new source for scattered energy (E * Scattering).
                    //// b. Modify E (E * 1 - Scattering).
                    OctaveRay R = Ray.SplitRay(oct, Scattering_Coefficient[oct, 1]);

                    Hare.Geometry.Vector diffx;
                    Hare.Geometry.Vector diffy;
                    Hare.Geometry.Vector diffz;
                    double proj;
                    //Check that the ray and the normal are both on the same side...
                    diffz = Normal;
                    diffx = new Hare.Geometry.Vector(0, 0, 1);
                    proj = Math.Abs(Hare.Geometry.Hare_math.Dot(diffz, diffx));

                    if (0.99 < proj && 1.01 > proj) diffx = new Hare.Geometry.Vector(1, 0, 0);
                    diffy = Hare.Geometry.Hare_math.Cross(diffz, diffx);
                    diffx = Hare.Geometry.Hare_math.Cross(diffy, diffz);
                    diffx.Normalize();
                    diffy.Normalize();
                    diffz.Normalize();

                    double u1;
                    double u2;
                    double x;
                    double y;
                    double z;
                    Hare.Geometry.Vector vect;
                    u1 = 2.0 * Math.PI * rand.NextDouble();
                    // random azimuth
                    double Scat_Mod = rand.NextDouble();
                    u2 = Math.Acos(Scat_Mod);
                    // random zenith (elevation)
                    x = Math.Cos(u1) * Math.Sin(u2);
                    y = Math.Sin(u1) * Math.Sin(u2);
                    z = Math.Cos(u2);

                    vect = (diffx * x) + (diffy * y) + (diffz * z);
                    vect.Normalize();

                    //Return the new direction
                    R.direction = vect;

                    if (R.t_sum == 0)
                    {
                        Rhino.RhinoApp.Write("Something's up!");
                    }

                    Rays.Enqueue(R);

                }
                Ray.direction -= Normal * Cos_Theta * 2;
            }
 public abstract System.Numerics.Complex Reflection_Narrow(double frequency, Hare.Geometry.Vector Dir, Hare.Geometry.Vector Normal);
            public override void Scatter_Late(ref OctaveRay Ray, ref Queue<OctaveRay> Rays, ref Random rand, Hare.Geometry.Vector Normal, double Cos_Theta)
            {
                double scat_sel = rand.NextDouble();
                if (scat_sel > Scattering_Coefficient[Ray.Octave, 2])
                {
                    // Specular Reflection
                    Ray.direction -= Normal * Cos_Theta * 2;
                    return;
                }
                else if (scat_sel > Scattering_Coefficient[Ray.Octave, 0])
                {
                    //Only for a certain portion of high benefit cases--
                    //// a. Create new source for scattered energy (E * Scattering).
                    //// b. Modify E (E * 1 - Scattering).
                    //Create a new ray...
                    OctaveRay tr = Ray.SplitRay(1 - Scattering_Coefficient[Ray.Octave,1]);
                    // this is the specular reflection. Save it for later.
                    tr.direction -= Normal * Cos_Theta * 2;

                    if (tr.t_sum == 0)
                    {
                        Rhino.RhinoApp.Write("Something's up!");
                    }

                    Rays.Enqueue(tr);
                }

                //If we are here, the original ray needs a scattered direction:
                Hare.Geometry.Vector diffx;
                Hare.Geometry.Vector diffy;
                Hare.Geometry.Vector diffz;
                double proj;
                //Check that the ray and the normal are both on the same side...
                if (Cos_Theta > 0) Normal *= -1;
                diffz = Normal;
                diffx = new Hare.Geometry.Vector(0, 0, 1);
                proj = Math.Abs(Hare.Geometry.Hare_math.Dot(diffz, diffx));

                if (0.99 < proj && 1.01 > proj) diffx = new Hare.Geometry.Vector(1, 0, 0);
                diffy = Hare.Geometry.Hare_math.Cross(diffz, diffx);
                diffx = Hare.Geometry.Hare_math.Cross(diffy, diffz);
                diffx.Normalize();
                diffy.Normalize();
                diffz.Normalize();

                double u1;
                double u2;
                double x;
                double y;
                double z;
                Hare.Geometry.Vector vect;
                u1 = 2.0 * Math.PI * rand.NextDouble();
                // random azimuth
                double Scat_Mod = rand.NextDouble();
                u2 = Math.Acos(Scat_Mod);
                // random zenith (elevation)
                x = Math.Cos(u1) * Math.Sin(u2);
                y = Math.Sin(u1) * Math.Sin(u2);
                z = Math.Cos(u2);

                vect = (diffx * x) + (diffy * y) + (diffz * z);
                vect.Normalize();

                //Return the new direction
                Ray.direction = vect;
            }
 public override System.Numerics.Complex Reflection_Narrow(double frequency, Hare.Geometry.Vector Dir, Hare.Geometry.Vector Normal)
 {
     return(Inf_Mat.Reflection_Narrow(frequency, Dir, Normal));
 }
 public override System.Numerics.Complex[] Reflection_Spectrum(int sample_frequency, int length, Hare.Geometry.Vector Normal, Hare.Geometry.Vector Dir, int threadid)
 {
     return(Inf_Mat.Reflection_Spectrum(sample_frequency, length, Normal, Dir, threadid));
 }
 public abstract System.Numerics.Complex[] Reflection_Spectrum(int sample_frequency, int length, Hare.Geometry.Vector Normal, Hare.Geometry.Vector Dir, int threadid);
Ejemplo n.º 41
0
            /// <summary>
            /// Writes pachyderm mapping file.
            /// </summary>
            /// <param name="filename">The location the new file is to be written to.</param>
            /// <param name="Rec_List">The list of receivers to be written.</param>
            public static void Write_pachm(string filename, PachMapReceiver[] Rec_List)
            {
                System.IO.BinaryWriter sw = new System.IO.BinaryWriter(System.IO.File.Open(filename, System.IO.FileMode.Create));
                //1. Write calculation type. (string)
                sw.Write(Rec_List[0].Data_Type());
                Boolean Directional = Rec_List[0].Data_Type() == "Type;Map_Data";

                //2. Write the number of samples in each histogram. (int)
                sw.Write((UInt32)Rec_List[0].SampleCT);
                //3. Write the sample rate. (int)
                sw.Write((UInt32)Rec_List[0].SampleRate);
                //4. Write the number of Receivers (int)
                int Rec_Ct = Rec_List[0].Rec_List.Length;

                sw.Write((UInt32)Rec_Ct);
                //4.5 Announce the Version
                sw.Write("Version");
                sw.Write(PachTools.Version());
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                sw.Write("Mesh Information");
                //6. Announce Mesh Vertices (string)
                sw.Write("Mesh Vertices");
                //Write the number of vertices & faces (int) (int)
                sw.Write((UInt32)Rec_List[0].Map_Mesh.Vertex_Count);
                sw.Write((UInt32)Rec_List[0].Map_Mesh.Polygon_Count);

                for (int i = 0; i < Rec_List[0].Map_Mesh.Vertex_Count; i++)
                {
                    //Write Vertex: (double) (double) (double)
                    sw.Write(Rec_List[0].Map_Mesh[i].x);
                    sw.Write(Rec_List[0].Map_Mesh[i].y);
                    sw.Write(Rec_List[0].Map_Mesh[i].z);
                }
                //7. Announce Mesh Faces (string)
                sw.Write("Mesh Faces");
                for (int i = 0; i < Rec_List[0].Map_Mesh.Polygon_Count; i++)
                {
                    // Write mesh vertex indices: (int) (int) (int) (int)
                    sw.Write((UInt32)Rec_List[0].Map_Mesh.Polys[i].Points[0].index);
                    sw.Write((UInt32)Rec_List[0].Map_Mesh.Polys[i].Points[1].index);
                    sw.Write((UInt32)Rec_List[0].Map_Mesh.Polys[i].Points[2].index);
                    if (Rec_List[0].Map_Mesh.Polys[i].VertextCT > 3)
                    {
                        sw.Write((UInt32)Rec_List[0].Map_Mesh.Polys[i].Points[3].index);
                    }
                    else
                    {
                        sw.Write((UInt32)Rec_List[0].Map_Mesh.Polys[i].Points[2].index);
                    }
                }
                //7.5: Announce the number of sources.
                //sw.Write("Sources");
                sw.Write("SourceswLoc");
                sw.Write(Rec_List.Length);
                //7.5a: Announce the Type of Source
                for (int i = 0; i < Rec_List.Length; i++)
                {
                    ///////////////////////
                    sw.Write(Rec_List[i].Src.x);
                    sw.Write(Rec_List[i].Src.y);
                    sw.Write(Rec_List[i].Src.z);
                    ///////////////////////
                    sw.Write(Rec_List[i].SrcType);
                    sw.Write(Rec_List[i].delay_ms);//v.2.0.0.1
                }

                //8. Announce that the following data pertains to the receiver histograms (string)
                sw.Write("Receiver Hit Data");
                //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                sw.Write(Rec_List[0].Rec_Vertex);

                for (int s = 0; s < Rec_List.Length; s++)
                {
                    for (int i = 0; i < Rec_Ct; i++)
                    {
                        //Write Receiver Index (int)
                        sw.Write((UInt32)i);
                        //Write the direct sound arrival time.
                        sw.Write((Rec_List[s].Rec_List[i] as PachMapReceiver.Map_Receiver).Direct_Time);
                        //Write Impedance of Air
                        sw.Write(Rec_List[0].Rec_List[i].Rho_C);

                        for (int Octave = 0; Octave < 8; Octave++)
                        {
                            //Write Octave (int)
                            sw.Write((UInt32)Octave);
                            double[] Hist = Rec_List[s].Rec_List[i].GetEnergyHistogram(Octave);
                            for (int e = 0; e < Rec_List[s].SampleCT; e++)
                            {
                                //Write each energy value in the histogram (double)...
                                sw.Write(Hist[e]);
                                //Write each directional value in the histogram (double) (double) (double);
                                if (Directional)
                                {
                                    Hare.Geometry.Vector DirPos = Rec_List[s].Directions_Pos(Octave, e, i);
                                    Hare.Geometry.Vector DirNeg = Rec_List[s].Directions_Neg(Octave, e, i);
                                    sw.Write(DirPos.x);
                                    sw.Write(DirPos.y);
                                    sw.Write(DirPos.z);
                                    sw.Write(DirNeg.x);
                                    sw.Write(DirNeg.y);
                                    sw.Write(DirNeg.z);
                                }
                            }
                        }
                        sw.Write("End_Receiver_Hits");
                    }
                }
                sw.Write("End_of_File");
                sw.Close();
            }
                public override BroadRay Directions(int index, int thread, ref Random random, ref Curve Curves, ref double[] DomainPower, ref double Delay, ref Phase_Regime ph, ref int S_ID)
                {
                    double pos = random.NextDouble();
                    int i;

                    Interval t = Curves.Domain;
                    double x = random.NextDouble() * (t[1] - t[0]) + t[0];
                    Point3d P = Curves.PointAt(x);

                    double Theta = random.NextDouble() * 2 * System.Math.PI;
                    double Phi = random.NextDouble() * 2 * System.Math.PI;
                    Vector Direction = new Hare.Geometry.Vector(Math.Sin(Theta) * Math.Cos(Phi), Math.Sin(Theta) * Math.Sin(Phi), Math.Cos(Theta));
                    double[] phase = new double[8];
                    if (ph == Phase_Regime.Random) for (int o = 0; o < 8; o++) phase[o] = random.Next() * 2 * Math.PI;
                    else for (int o = 0; o < 8; o++) phase[o] = 0 - Delay * Utilities.Numerics.angularFrequency[o];

                    return new BroadRay(Utilities.PachTools.RPttoHPt(P), Direction, random.Next(), thread, DomainPower, phase, Delay, S_ID);
                }