Exemple #1
0
            public HSV_colorscale(int Ht, int Wd, double H_OFFSETin, double H_BREADTHin, double S_OFFSETin, double S_BREADTHin, double V_OFFSETin, double V_BREADTHin, bool Discretize, int Stepsin)
            {
                H_OFFSET    = H_OFFSETin;
                H_BREADTH   = H_BREADTHin;
                S_OFFSET    = S_OFFSETin;
                S_BREADTH   = S_BREADTHin;
                V_OFFSET    = V_OFFSETin;
                V_BREADTH   = V_BREADTHin;
                Discretized = Discretize;
                Steps       = Stepsin;
                PIC         = new Bitmap(Wd, Ht);
                Graphics g = Graphics.FromImage(PIC);

                if (Discretized)
                {
                    for (int y = 0; y < Ht; y++)
                    {
                        double loc = System.Math.Floor(Steps * (double)y / (double)Ht);
                        Color  c   = PachTools.HsvColor((((loc / Steps) * System.Math.PI) * H_BREADTH) + H_OFFSET, (loc / Steps * S_BREADTH) + S_OFFSET, (loc / Steps * V_BREADTH) + V_OFFSET);
                        g.DrawLine(new Pen(c, 1), 0, y, Ht, y);
                    }
                }
                else
                {
                    for (int y = 0; y < Ht; y++)
                    {
                        double loc = y / (double)Ht;
                        Color  c   = PachTools.HsvColor(((loc * System.Math.PI) * H_BREADTH) + H_OFFSET, (loc * S_BREADTH) + S_OFFSET, (loc * V_BREADTH) + V_OFFSET);
                        g.DrawLine(new Pen(c, 1), 0, y, Ht, y);
                    }
                }
                g.Dispose();
            }
Exemple #2
0
            private void Source_Aim_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (Receiver_Choice.SelectedIndex < 0 || Source_Aim.SelectedIndex < 0)
                {
                    return;
                }
                double azi, alt;

                PachTools.World_Angles(Direct_Data[Source_Aim.SelectedIndex].Src.Origin(), Utilities.PachTools.HPttoRPt(Recs[Receiver_Choice.SelectedIndex]), true, out alt, out azi);

                Alt_Choice.Value = (decimal)alt;
                Azi_Choice.Value = (decimal)azi;
            }
Exemple #3
0
            private void Step_Forward()
            {
                t_lo = t * (double)Step_Select.Value;
                t_hi = t * (double)Step_Select.Value + (double)Integration_select.Value;
                if (t_hi > Map[0].CutOffTime)
                {
                    t_lo = t = 0;
                    t_hi = t + (double)Integration_select.Value;
                }

                this.Invoke((MethodInvoker) delegate { oct = PachTools.OctaveStr2Int(Octave.Text); });
                this.Invoke((MethodInvoker) delegate { Update_T(); });

                Mesh Mesh_Map = PachMapReceiver.Get_SPL_Map(Map, new double[] { Current_SPLMin, Current_SPLMax }, new double[] { t_hi, t_lo }, c_scale, oct, SelectedSources(), Coherent.Checked, ZeroAtDirect.Checked, false);

                if (WC == null)
                {
                    return;
                }
                WC.Populate(Mesh_Map);

                //////////////////////////////
                if (Folder_Status.Text != "")
                {
                    string number;
                    if (t < 100)
                    {
                        if (t < 10)
                        {
                            number = "00" + t.ToString();
                        }
                        else
                        {
                            number = "0" + t.ToString();
                        }
                    }
                    else
                    {
                        number = t.ToString();
                    }

                    this.Invoke((MethodInvoker) delegate { Rhino.RhinoApp.RunScript("-ViewCaptureToFile " + Folder_Status.Text + "\\"[0] + "frame" + number + ".jpg Width=1280 Height=720 DrawGrid=No Enter", true); });
                }
                //////////////////////////////
                t++;

                Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            }
Exemple #4
0
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);

                if (!Rm.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);
                double fs = 137.8125 * Math.Pow(2, Selected_Extent.SelectedIndex);

                samplefrequency = fs;
                double df = 1d / ((double)CO_TIME.Value / 1000);

                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, df, 1, PachTools.GetSource());
                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, (double)CO_TIME.Value);

                for (double f = df; f < fs; f += df)
                {
                    FDTD.reset(f, Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse);
                    FDTD.RuntoCompletion();

                    Frequencies.Items.Add(string.Format("{0} Hz.", f), true);
                }

                Receiver_Choice.Text = "0";

                result_signals = Mic.Recordings;
            }
Exemple #5
0
            /// <summary>
            /// Assigns a color based on the value's location in the color scale.
            /// </summary>
            /// <param name="Value">the value</param>
            /// <param name="VMin">scale min</param>
            /// <param name="VMax">scale max</param>
            /// <returns></returns>
            public override Color GetValue(double Value, double VMin, double VMax)
            {
                Color c;

                if (Discretized)
                {
                    if (Value < VMin)
                    {
                        c = PachTools.HsvColor(H_BREADTH * System.Math.PI + H_OFFSET, S_BREADTH + S_OFFSET, V_OFFSET + V_BREADTH);
                    }
                    else if (Value > VMax)
                    {
                        c = PachTools.HsvColor(H_OFFSET, S_OFFSET, V_OFFSET);
                    }
                    else
                    {
                        double loc = System.Math.Floor(Steps * (1 - (Value - VMin) / (VMax - VMin)));
                        c = PachTools.HsvColor((loc / Steps * System.Math.PI) * H_BREADTH + H_OFFSET, loc * S_BREADTH + S_OFFSET, loc * V_BREADTH + V_OFFSET);
                    }
                }
                else
                {
                    if (Value < VMin)
                    {
                        c = PachTools.HsvColor(H_BREADTH * System.Math.PI + H_OFFSET, S_BREADTH + S_OFFSET, V_OFFSET + V_BREADTH);
                    }
                    else if (Value > VMax)
                    {
                        c = PachTools.HsvColor(H_OFFSET, S_OFFSET, V_OFFSET);
                    }
                    else
                    {
                        double loc = (1 - (Value - VMin) / (VMax - VMin));
                        c = PachTools.HsvColor((loc * System.Math.PI) * H_BREADTH + H_OFFSET, loc * S_BREADTH + S_OFFSET, loc * V_BREADTH + V_OFFSET);
                    }
                }
                return(c);
            }
            public void Plot_PTB_Results()
            {
                if (Direct_Data == null && IS_Data == null && Receiver == null && Parameter_Choice.Text != "Sabine RT" && Parameter_Choice.Text != "Eyring RT")
                {
                    return;
                }
                double[] Schroeder;
                string[] paramtype    = new string [] { "T30/s", "EDT/s", "D/%", "C/dB", "TS/ms", "G/dB", "LF%", "LFC%", "IACC" };//LF/% LFC/% IACC
                string   ReceiverLine = "Receiver{0};";

                double[, , ,] ParamValues = new double[SourceList.Items.Count, Recs.Length, 8, paramtype.Length];

                for (int s = 0; s < Direct_Data.Length; s++)
                {
                    for (int r = 0; r < Recs.Length; r++)
                    {
                        ReceiverLine += r.ToString() + ";";
                        for (int oct = 0; oct < 8; oct++)
                        {
                            double[] ETC = AcousticalMath.ETCurve(Direct_Data, IS_Data, Receiver, (int)(CO_TIME.Value / 1000), SampleRate, oct, r, s, false);
                            Schroeder = AcousticalMath.Schroeder_Integral(ETC);
                            ParamValues[s, r, oct, 0] = AcousticalMath.T_X(Schroeder, 30, SampleRate);
                            ParamValues[s, r, oct, 1] = AcousticalMath.EarlyDecayTime(Schroeder, SampleRate);
                            ParamValues[s, r, oct, 2] = AcousticalMath.Definition(ETC, SampleRate, 0.05, Direct_Data[s].Min_Time(r), false);
                            ParamValues[s, r, oct, 3] = AcousticalMath.Clarity(ETC, SampleRate, 0.08, Direct_Data[s].Min_Time(r), false);
                            ParamValues[s, r, oct, 4] = AcousticalMath.Center_Time(ETC, SampleRate, Direct_Data[s].Min_Time(r)) * 1000;
                            ParamValues[s, r, oct, 5] = AcousticalMath.Strength(ETC, Direct_Data[s].SWL[oct], false);
                            double azi, alt;
                            PachTools.World_Angles(Direct_Data[s].Src.Origin(), Utilities.PachTools.HPttoRPt(Recs[r]), true, out alt, out azi);
                            double[][] Lateral_ETC = AcousticalMath.ETCurve_1d(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, oct, r, new System.Collections.Generic.List <int> {
                                s
                            }, false, alt, azi, true);
                            ParamValues[s, r, oct, 6] = AcousticalMath.Lateral_Fraction(ETC, Lateral_ETC, SampleRate, Direct_Data[s].Min_Time(r), false);
                        }
                    }
                }

                System.Windows.Forms.SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog();
                sf.DefaultExt   = ".txt";
                sf.AddExtension = true;
                sf.Filter       = "Text File (*.txt)|*.txt|" + "All Files|";

                if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        System.IO.StreamWriter SW = new System.IO.StreamWriter(System.IO.File.Open(sf.FileName, System.IO.FileMode.Create));
                        SW.WriteLine("Pachyderm Acoustic Simulation Results");
                        SW.WriteLine("Saved {0}", System.DateTime.Now.ToString());
                        SW.WriteLine("Filename:{0}", Rhino.RhinoDoc.ActiveDoc.Name);

                        for (int oct = 0; oct < 8; oct++)
                        {
                            SW.WriteLine(string.Format(ReceiverLine, oct));
                            for (int param = 0; param < paramtype.Length; param++)
                            {
                                SW.Write(paramtype[param] + ";");
                                for (int i = 0; i < Direct_Data.Length; i++)
                                {
                                    for (int q = 0; q < Recs.Length; q++)
                                    {
                                        SW.Write(ParamValues[i, q, oct, param].ToString() + ";");
                                    }
                                }
                                SW.WriteLine("");
                            }
                        }
                        SW.Close();
                    }
                    catch (System.Exception)
                    {
                        Rhino.RhinoApp.WriteLine("File is open, and cannot be written over.");
                        return;
                    }
                }
            }
            public void Begin()
            {
                Random Rnd = new Random();

                for (int q = 0; q < RayCount; q++)
                {
                    Rhino.RhinoApp.SetCommandPrompt(string.Format("Finding Ray {0} of {1}", q, RayCount));
                    double SumLength = 0;
                    Pachyderm_Acoustic.Environment.OctaveRay R = Source.Directions(q, 0, ref Rnd).SplitRay(5);
                    double        u           = 0;
                    double        v           = 0;
                    int           ChosenIndex = 0;
                    Polyline      Ray         = new Polyline();
                    List <double> leg         = new List <double> {
                        0
                    };
                    List <int> code = new List <int> {
                        0
                    };
                    List <Hare.Geometry.Point> Start;
                    //List<int> IDs = new List<int>();
                    Ray.Add(PachTools.HPttoRPt(R.origin));
                    List <double> P = new List <double> {
                        R.Intensity
                    };
                    do
                    {
                        R.Ray_ID = Rnd.Next();
                        if (Room.shoot(R, out u, out v, out ChosenIndex, out Start, out leg, out code))
                        {
                            double cos_theta;


                            for (int i = 0; i < Start.Count; i++)
                            {
                                Ray.Add(PachTools.HPttoRPt(Start[i]));
                                //IDs.Add(-1);
                                R.Intensity *= Math.Pow(10, -.1 * Room.Attenuation(code[i])[5] * leg[i]);
                                SumLength   += leg[i];
                            }

                            R.origin  = Start[Start.Count - 1];
                            R.Surf_ID = ChosenIndex;
                            bool trans = (Rnd.NextDouble() < Room.TransmissionValue[ChosenIndex][5]);

                            Room.Absorb(ref R, out cos_theta, u, v);
                            Room.Scatter_Simple(ref R, ref Rnd, cos_theta, u, v);

                            if (trans)
                            {
                                R.direction *= -1;
                                R.Intensity *= Room.TransmissionValue[ChosenIndex][5];
                            }
                            else
                            {
                                R.Intensity *= (1 - Room.TransmissionValue[ChosenIndex][5]);
                            }

                            P.Add((double)R.Intensity);

                            //if (Rnd.NextDouble() < Room.ScatteringValue[ChosenIndex].Coefficient(5))
                            //{
                            //    Room.Scatter_Simple(ref R, ref Rnd);
                            //    //Utilities.PachTools.Ray_Acoustics.LambertianReflection_Stoch(ref R.direction, ref Rnd, Room.Normal(ChosenIndex, u, v));

                            //    if (trans)
                            //    {
                            //        R.direction *= -1;
                            //        R.Intensity *= Room.TransmissionValue[ChosenIndex][5];
                            //    }
                            //    else
                            //    {
                            //        R.Intensity *= Room.AbsorptionValue[ChosenIndex].Coefficient_A_Broad()[5];
                            //    }

                            //}
                            //else
                            //{
                            //    if (!trans)
                            //    {
                            //        Utilities.PachTools.Ray_Acoustics.SpecularReflection(ref R.direction, ref Room, ref u, ref v, ref ChosenIndex);
                            //        R.Intensity *= Room.AbsorptionValue[ChosenIndex].Coefficient_A_Broad()[5];
                            //    }
                            //    else
                            //    {
                            //        R.Intensity *= Room.TransmissionValue[ChosenIndex][5];
                            //    }
                            //}
                        }
                        else
                        {
                            //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(PachTools.HPttoRPt(R.origin), PachTools.HPttoRPt(R.origin + R.direction));
                            break;
                        }
                    }while (SumLength < CutoffLength);
                    //Poly_ID.Add(IDs);
                    if (SumLength > CutoffLength)
                    {
                        Ray.Add(PachTools.HPttoRPt(R.origin));
                    }
                    RayList.Add(Ray);
                    Power.Add(P);
                }
            }
            private void Calculate_Click(object sender, System.EventArgs e)
            {
                Pach_GetModel_Command Model = new Pach_GetModel_Command();

                Source[] Source;


                if (PachydermAc_PlugIn.Instance.Source(out Source) && !object.ReferenceEquals(FileLocation.SelectedPath, ""))
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }
                ParticleRays[] RTParticles = new ParticleRays[Source.Length];

                Calculate.Enabled = false;
                PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance;
                Scene Sc;

                if (PachydermAc_PlugIn.Instance.Geometry_Spec() == 0)
                {
                    Sc = PachTools.Get_NURBS_Scene(0, (double)Air_Temp.Value, 0, 0, false);
                }
                else
                {
                    Sc = PachTools.Get_Poly_Scene(0, (double)Air_Temp.Value, 0, 0, false);
                }

                for (int i = 0; i < Source.Length; i++)
                {
                    if (Source != null)
                    {
                        List <Point3d> L = new List <Point3d>();
                        List <Rhino.Geometry.Point3d> L_RC = new List <Rhino.Geometry.Point3d>();
                        for (int j = 0; j < Source.Length; j++)
                        {
                            L.Add(Source[j].Origin());
                            L_RC.Add(new Rhino.Geometry.Point3d(Source[j].Origin().X, Source[j].Origin().Y, Source[j].Origin().Z));
                        }

                        if (plugin.Geometry_Spec() == 0)
                        {
                            Sc.partition(L_RC, 15);
                            RTParticles[i] = new ParticleRays(Source[i], Sc, (int)RT_Count.Value, CutOffLength());
                        }
                        else if (plugin.Geometry_Spec() == 1)
                        {
                            Sc.partition(L, 15);
                            RTParticles[i] = new ParticleRays(Source[i], Sc, (int)RT_Count.Value, CutOffLength());
                        }
                        RTParticles[i].Begin();
                    }
                    else
                    {
                        Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                    }

                    Pachyderm_Acoustic.Visualization.Phonon P;
                    if (ParticleChoice.SelectedIndex == 0)
                    {
                        P = new Tetrahedron();
                    }
                    else if (ParticleChoice.SelectedIndex == 1)
                    {
                        P = new Icosahedron();
                    }
                    else
                    {
                        P = new Geodesic_sphere();
                    }
                    RenderParticles(RTParticles, (double)(Frame_Rate.Value * Seconds.Value), P);
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                }
                Calculate.Enabled = true;
            }
Exemple #9
0
            /// <summary>
            /// Writes a Pac1 file. [Useable by scripts and interface components alike.]
            /// </summary>
            /// <param name="filename">The location of the final saved file...</param>
            /// <param name="Direct_Data">Array of Completed Direct Sound Simulations Required</param>
            /// <param name="IS_Data">Array of Completed Image Source Simulations. Enter null if opted out.</param>
            /// <param name="Receiver">Array of Completed Ray-Tracing Simulation Receivers. Enter null if opted out.</param>
            public static void Write_Pac1(string filename, Direct_Sound[] Direct_Data, ImageSourceData[] IS_Data = null, Environment.Receiver_Bank[] Receiver = null)
            {
                if (Direct_Data == null && IS_Data == null && IS_Data == null && Receiver != null)
                {
                    System.Windows.Forms.MessageBox.Show("There is no simulated data to save.");
                    return;
                }

                System.IO.BinaryWriter sw = new System.IO.BinaryWriter(System.IO.File.Open(filename, System.IO.FileMode.Create));

                //1. Date & Time
                sw.Write(System.DateTime.Now.ToString());
                //2. Library Version... if less than 1.1, assume only 1 source.
                sw.Write(PachTools.Version());
                //3. Cut off Time (seconds) and SampleRate
                sw.Write((double)Receiver[0].CO_Time);//CO_TIME.Value);
                sw.Write(Receiver[0].SampleRate);
                //4.0 Source Count(int)
                Hare.Geometry.Point[] SRC = new Hare.Geometry.Point[Direct_Data.Length];
                for (int i = 0; i < Direct_Data.Length; i++)
                {
                    SRC[i] = Direct_Data[i].Src_Origin;
                }

                sw.Write(SRC.Length);
                for (int i = 0; i < SRC.Length; i++)
                {
                    //4.1 Source Location x (double)
                    sw.Write(SRC[i].x);
                    //4.2 Source Location y (double)
                    sw.Write(SRC[i].y);
                    //4.3 Source Location z (double)
                    sw.Write(SRC[i].z);
                }
                //5. No of Receivers
                sw.Write(Receiver[0].Rec_List.Length);

                //6. Write the coordinates of each receiver point
                //6b. Write the environmental characteristics at each receiver point (Rho * C); V2.0 only...
                for (int q = 0; q < Receiver[0].Rec_List.Length; q++)
                {
                    sw.Write(Receiver[0].Rec_List[q].Origin.x);
                    sw.Write(Receiver[0].Rec_List[q].Origin.y);
                    sw.Write(Receiver[0].Rec_List[q].Origin.z);
                    sw.Write(Receiver[0].Rec_List[q].Rho_C);
                }

                for (int s = 0; s < SRC.Length; s++)
                {
                    if (Direct_Data != null)
                    {
                        //7. Write Direct Sound Data
                        Direct_Data[s].Write_Data(ref sw);
                    }

                    if (IS_Data[0] != null)
                    {
                        //8. Write Image Source Sound Data
                        IS_Data[s].Write_Data(ref sw);
                    }

                    if (Receiver != null)
                    {
                        //9. Write Ray Traced Sound Data
                        Receiver[s].Write_Data(ref sw);
                    }
                }
                sw.Write("End");
                sw.Close();
            }
Exemple #10
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();
            }
Exemple #11
0
            private void Calculate_Click(object sender, System.EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);

                if (!Rm.Complete)
                {
                    return;
                }

                if (P == null)
                {
                    P = new WaveConduit(scale, new double[2] {
                        (double)this.Param_Min.Value, (double)this.Param_Max.Value
                    });
                }
                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

                Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Dirac_Pulse;

                switch (SourceSelect.Text)
                {
                case "Dirac Pulse":
                    s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Dirac_Pulse;
                    break;

                case "Sine Wave":
                    s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Tone;
                    break;

                case "Sine Pulse":
                    s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse;
                    break;
                }

                Numeric.TimeDomain.Signal_Driver_Compact SD  = new Numeric.TimeDomain.Signal_Driver_Compact(s_type, (double)Frequency_Selection.Value, 1, PachTools.GetSource());
                Numeric.TimeDomain.Microphone_Compact    Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);

                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, (double)Freq_Max.Value, (double)CO_TIME.Value);
                M    = new Rhino.Geometry.Mesh[3][] { FDTD.m_templateX, FDTD.m_templateY, FDTD.m_templateZ };

                P.SetColorScale(new Pach_Graphics.HSV_colorscale(Param_Scale.Height, Param_Scale.Width, 0, 4.0 / 3.0, 1, 0, 1, 1, false, 12), new double[] { (double)Param_Min.Value, (double)Param_Max.Value });
                P.Enabled = true;

                if (AxisSelect.SelectedIndex == 0)
                {
                    Pos_Select.Maximum = FDTD.xDim - 1;
                }
                else if (AxisSelect.SelectedIndex == 1)
                {
                    Pos_Select.Maximum = FDTD.yDim - 1;
                }
                else if (AxisSelect.SelectedIndex == 2)
                {
                    Pos_Select.Maximum = FDTD.zDim - 1;
                }

                if (Map_Planes.Items.Count == 0)
                {
                    Pos_Select.Value = Pos_Select.Maximum / 2;
                    AddPlane_Click(new object(), new EventArgs());
                }
            }
Exemple #12
0
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                EigenFrequencies.Items.Clear();
                Chosenfreq = 0;
                FC         = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);

                if (!Rm.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);
                double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Selected_Extent.SelectedIndex);

                //samplefrequency = fs;
                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, 1000, 1, PachTools.GetSource());
                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, (double)CO_TIME.Value);
                FDTD.RuntoCompletion();

                samplefrequency = FDTD.SampleFrequency;

                Mic.reset();
                result_signals = Mic.Recordings[0];
                //System.Numerics.Complex[] source_response = SD.Frequency_Response(result_signals[0].Length);

                //double f_limit = 0.8 * fs / samplefrequency * result_signals[0].Length;
                //double f_top = 1.3 * f_limit;
                //double dpi = Utilities.Numerics.PiX2 / (f_top - f_limit);

                //for (int c = 0; c < result_signals.Length; c++)
                //{
                //    System.Numerics.Complex[] result_response = Audio.Pach_SP.FFT_General(result_signals[c],0);
                //    Array.Resize(ref result_response, result_response.Length / 2);
                //    for (int s = 0; s < result_response.Length; s++)
                //    {
                //        System.Numerics.Complex mod = source_response[s].Magnitude;
                //        if (s > f_limit) mod /= System.Numerics.Complex.Pow(source_response[s], (.5 * Math.Tanh((s-f_limit) * dpi) + 0.5));
                //        result_response[s] /= mod.Magnitude;
                //    }
                //    result_signals[c] = Audio.Pach_SP.IFFT_Real_General(Audio.Pach_SP.Mirror_Spectrum(result_response), 0);
                //}
                //Find Eigenfrequencies
                if (EigenFrequencies.Items.Count > 0)
                {
                    return;
                }
                EigenFrequencies.Items.Clear();
                Find_EigenFrequencies();

                Receiver_Choice.Items.Clear();
                for (int i = 0; i < result_signals.Length; i++)
                {
                    Receiver_Choice.Items.Add(i);
                }
                Time = new double[result_signals[0].Length];
                for (int i = 0; i < Time.Length; i++)
                {
                    Time[i] = (double)i / samplefrequency;
                }
                Receiver_Choice.SelectedIndex = 0;
                Receiver_Choice.Update();
            }
Exemple #13
0
            private void Update_Graph(object sender, EventArgs e)
            {
                Analysis_View.GraphPane.CurveList.Clear();

                int REC_ID = 0;

                try
                {
                    REC_ID = int.Parse(Receiver_Choice.Text);

                    int OCT_ID = PachTools.OctaveStr2Int(Graph_Octave.Text);
                    Analysis_View.GraphPane.Title.Text       = "Logarithmic Energy Time Curve";
                    Analysis_View.GraphPane.XAxis.Title.Text = "Time (seconds)";
                    Analysis_View.GraphPane.YAxis.Title.Text = "Sound Pressure Level (dB)";

                    List <int> SrcIDs = new List <int>();
                    foreach (int i in SourceList.CheckedIndices)
                    {
                        SrcIDs.Add(i);
                    }

                    //List<double[]> Filter = new List<double[]>();
                    List <System.Drawing.Color> C = new List <System.Drawing.Color> {
                        System.Drawing.Color.Red, System.Drawing.Color.OrangeRed, System.Drawing.Color.Orange, System.Drawing.Color.DarkGoldenrod, System.Drawing.Color.Olive, System.Drawing.Color.Green, System.Drawing.Color.Aquamarine, System.Drawing.Color.Azure, System.Drawing.Color.Blue, System.Drawing.Color.Indigo, System.Drawing.Color.Violet
                    };

                    double[][] Temp;

                    switch (DistributionType.Text)
                    {
                    case "Monaural":
                        Response    = new double[1][];
                        Response[0] = (AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false));
                        break;

                    case "First Order Ambisonics":
                        Response    = new double[4][];
                        Temp        = AcousticalMath.PTCurve_Fig8_3Axis(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[0] = AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false);
                        Response[1] = Temp[0];
                        Response[2] = Temp[1];
                        Response[3] = Temp[2];
                        break;

                    case "Second Order Ambisonics":
                        Response    = new double[9][];
                        Temp        = AcousticalMath.PTCurve_Fig8_3Axis(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[0] = AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false);
                        Response[1] = Temp[0];
                        Response[2] = Temp[1];
                        Response[3] = Temp[2];
                        Temp        = AcousticalMath.PTCurve_Ambisonics2(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[4] = Temp[0];
                        Response[5] = Temp[1];
                        Response[6] = Temp[2];
                        Response[7] = Temp[3];
                        Response[8] = Temp[4];
                        break;

                    case "Third Order Ambisonics":
                        Response     = new double[16][];
                        Temp         = AcousticalMath.PTCurve_Fig8_3Axis(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[0]  = AcousticalMath.PTCurve(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, REC_ID, SrcIDs, false);
                        Response[1]  = Temp[0];
                        Response[2]  = Temp[1];
                        Response[3]  = Temp[2];
                        Temp         = AcousticalMath.PTCurve_Ambisonics2(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[4]  = Temp[0];
                        Response[5]  = Temp[1];
                        Response[6]  = Temp[2];
                        Response[7]  = Temp[3];
                        Response[8]  = Temp[4];
                        Temp         = AcousticalMath.PTCurve_Ambisonics3(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, Receiver_Choice.SelectedIndex, SelectedSources(), false, (double)Alt_Choice.Value, (double)Azi_Choice.Value, true);
                        Response[9]  = Temp[0];
                        Response[10] = Temp[1];
                        Response[11] = Temp[2];
                        Response[12] = Temp[3];
                        Response[13] = Temp[4];
                        Response[14] = Temp[5];
                        Response[15] = Temp[6];
                        break;

                    default:
                        Response = new double[Channel_View.Items.Count][];
                        for (int i = 0; i < Channel_View.Items.Count; i++)
                        {
                            double alt = -(double)Alt_Choice.Value + 180 * Math.Asin((Channel_View.Items[i] as channel).V.z) / Math.PI;
                            double azi = (double)Azi_Choice.Value + 180 * Math.Atan2((Channel_View.Items[i] as channel).V.y, (Channel_View.Items[i] as channel).V.x) / Math.PI;
                            if (alt > 90)
                            {
                                alt -= 180;
                            }
                            if (alt < -90)
                            {
                                alt += 180;
                            }
                            if (azi > 360)
                            {
                                azi -= 360;
                            }
                            if (azi < 0)
                            {
                                azi += 360;
                            }
                            Response[i] = AcousticalMath.PTCurve_Directional(Direct_Data, IS_Data, Receiver, CutoffTime, SampleRate, PachTools.OctaveStr2Int(Graph_Octave.Text), REC_ID, SrcIDs, false, alt, azi, true);
                        }
                        break;
                    }

                    //Get the maximum value of the Direct Sound
                    double DirectMagnitude = 0;
                    foreach (int i in SourceList.CheckedIndices)
                    {
                        double[] E = Direct_Data[i].EnergyValue(OCT_ID, REC_ID);
                        for (int j = 0; j < E.Length; j++)
                        {
                            double D = AcousticalMath.SPL_Intensity(E[j]);
                            if (D > DirectMagnitude)
                            {
                                DirectMagnitude = D;
                            }
                        }
                    }

                    double[] time = new double[Response[0].Length];
                    for (int i = 0; i < Response[0].Length; i++)
                    {
                        time[i] = (double)i / SampleRate - 1024f / SampleRate;
                    }

                    for (int i = 0; i < Response.Length; i++)
                    {
                        double[] filter = Audio.Pach_SP.FIR_Bandpass(Response[i], OCT_ID, SampleRate, 0);
                        Analysis_View.GraphPane.AddCurve(String.Format("Channel {0}", i), time, AcousticalMath.SPL_Pressure_Signal(filter), C[i % 10], ZedGraph.SymbolType.None);
                    }
                    Analysis_View.GraphPane.XAxis.Scale.Max = time[time.Length - 1];
                    Analysis_View.GraphPane.XAxis.Scale.Min = time[0];
                    Analysis_View.GraphPane.YAxis.Scale.Max = DirectMagnitude + 15;
                    Analysis_View.GraphPane.YAxis.Scale.Min = 0;

                    //AuralisationConduit.Instance.set_direction(Receiver[0].Origin(Receiver_Choice.SelectedIndex), new Rhino.Geometry.Vector3d(Math.Cos((float)Azi_Choice.Value * Math.PI / 180.0f) * Math.Cos((float)Alt_Choice.Value * Math.PI / 180.0f), Math.Sin((float)Azi_Choice.Value * Math.PI / 180.0f) * Math.Cos((float)Alt_Choice.Value * Math.PI / 180.0f), Math.Sin((float)Alt_Choice.Value * Math.PI / 180.0f)));
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                }
                catch { return; }
                Analysis_View.AxisChange();
                Analysis_View.Invalidate();
                Draw_Feedback();
            }
Exemple #14
0
            private void Step_Backward()
            {
                t--;
                if (t < 0)
                {
                    t = 0;
                }
                t_lo = t * (double)Step_Select.Value;
                t_hi = t * (double)Step_Select.Value + (double)Increment.Value;
                Min_Time_out.Text = t_lo.ToString();
                Max_Time_out.Text = t_hi.ToString();
                Mesh Mesh_Map = PachMapReceiver.Get_SPL_Map(Map, new double[] { Current_SPLMin, Current_SPLMax }, new double[] { t_hi, t_lo }, c_scale, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, ZeroAtDirect.Checked, false);

                TC();
                Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            }
Exemple #15
0
            public void Create_Map(bool PlotNumbers)
            {
                if (SelectedSources().Count == 0)
                {
                    return;
                }
                Update_Scale();
                Mesh Mesh_Map;

                switch (Parameter_Selection.Text)
                {
                case "Sound Pressure Level":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_SPL_Map(Map, new double[] { Current_SPLMin, Current_SPLMax }, new double[] { (double)End_Time_Control.Value, (double)Start_Time_Control.Value }, c_scale, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, ZeroAtDirect.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Sound Pressure Level (A-weighted)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_SPLA_Map(Map, new double[] { Current_SPLAMin, Current_SPLAMax }, new double[] { (double)End_Time_Control.Value, (double)Start_Time_Control.Value }, c_scale, SelectedSources(), Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Directionality":
                    if (Map != null)
                    {
                        PachMapReceiver.Get_Directional_Map(Map, new double[] { (double)End_Time_Control.Value, (double)Start_Time_Control.Value }, PachTools.OctaveStr2Int(Octave.Text), SelectedSources());
                    }
                    break;

                case "Early Decay Time (EDT)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_EDT_Map(Map, new double[] { Current_EDTMin, Current_EDTMax }, c_scale, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Reverberation Time (T-15)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_RT_Map(Map, new double[] { Current_RTMin, Current_RTMax }, c_scale, 15, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Reverberation Time (T-30)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_RT_Map(Map, new double[] { Current_RTMin, Current_RTMax }, c_scale, 30, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Speech Transmission Index - 2003":
                    if (Map != null)
                    {
                        double[] Noise = new double[8];
                        string   n     = Rhino.RhinoDoc.ActiveDoc.Strings.GetValue("Noise");

                        if (n != "")
                        {
                            string[] ns = n.Split(","[0]);
                            for (int oct = 0; oct < 8; oct++)
                            {
                                Noise[oct] = double.Parse(ns[oct]);
                            }
                        }
                        else
                        {
                            Rhino.RhinoApp.RunScript("Pachyderm_BackgroundNoise", false);
                            n = Rhino.RhinoDoc.ActiveDoc.Strings.GetValue("Noise");
                            string[] ns = n.Split(","[0]);
                            for (int oct = 0; oct < 8; oct++)
                            {
                                Noise[oct] = double.Parse(ns[oct]);
                            }
                        }

                        Mesh_Map = PachMapReceiver.Get_STI_Map(Map, new double[] { Current_STI1Min, Current_STI1Max }, c_scale, Noise, SelectedSources(), 0, Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Speech Transmission Index - Male":
                    if (Map != null)
                    {
                        double[] Noise = new double[8];
                        string   n     = Rhino.RhinoDoc.ActiveDoc.Strings.GetValue("Noise");

                        if (n != "")
                        {
                            string[] ns = n.Split(","[0]);
                            for (int oct = 0; oct < 8; oct++)
                            {
                                Noise[oct] = double.Parse(ns[oct]);
                            }
                        }
                        else
                        {
                            Rhino.RhinoApp.RunScript("Pachyderm_BackgroundNoise", false);
                            n = Rhino.RhinoDoc.ActiveDoc.Strings.GetValue("Noise");
                            string[] ns = n.Split(","[0]);
                            for (int oct = 0; oct < 8; oct++)
                            {
                                Noise[oct] = double.Parse(ns[oct]);
                            }
                        }

                        Mesh_Map = PachMapReceiver.Get_STI_Map(Map, new double[] { Current_STI2Min, Current_STI2Max }, c_scale, Noise, SelectedSources(), 1, Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Speech Transmission Index - Female":
                    if (Map != null)
                    {
                        double[] Noise = new double[8];
                        string   n     = Rhino.RhinoDoc.ActiveDoc.Strings.GetValue("Noise");

                        if (n != "")
                        {
                            string[] ns = n.Split(","[0]);
                            for (int oct = 0; oct < 8; oct++)
                            {
                                Noise[oct] = double.Parse(ns[oct]);
                            }
                        }
                        else
                        {
                            Rhino.RhinoApp.RunScript("Pachyderm_BackgroundNoise", false);
                            n = Rhino.RhinoDoc.ActiveDoc.Strings.GetValue("Noise");
                            string[] ns = n.Split(","[0]);
                            for (int oct = 0; oct < 8; oct++)
                            {
                                Noise[oct] = double.Parse(ns[oct]);
                            }
                        }

                        Mesh_Map = PachMapReceiver.Get_STI_Map(Map, new double[] { Current_STI3Min, Current_STI3Max }, c_scale, Noise, SelectedSources(), 2, Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Clarity (C-80)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_Clarity_Map(Map, new double[] { Current_CMin, Current_CMax }, c_scale, 80, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Definition (D-50)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_Definition_Map(Map, new double[] { Current_DMin, Current_DMax }, c_scale, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), Coherent.Checked, PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Strength/Loudness (G)":
                    if (Map != null)
                    {
                        if (SelectedSources().Count > 1)
                        {
                            MessageBox.Show("G values", "Important: G values are only valid for single sources. Select a single source, and plot the G-values again.");
                            return;
                        }
                        int SrcID = SelectedSources()[0];
                        Mesh_Map = PachMapReceiver.Get_G_Map(Map, new double[] { Current_GMin, Current_GMax }, c_scale, PachTools.OctaveStr2Int(Octave.Text), Source[SrcID].SWL(PachTools.OctaveStr2Int(Octave.Text)), SrcID, Coherent.Checked, PlotNumbers);    //, G_Ref_Energy[PachTools.OctaveStr2Int(Octave.Text)]
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                case "Percent who perceive echoes (EK)":
                    if (Map != null)
                    {
                        Mesh_Map = PachMapReceiver.Get_EchoCritPercent_Map(Map, new double[] { Current_EMin, Current_EMax }, c_scale, PachTools.OctaveStr2Int(Octave.Text), SelectedSources(), PlotNumbers);
                        if (Mesh_Map != null)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(Mesh_Map);
                        }
                    }
                    break;

                default:
                    Rhino.RhinoApp.WriteLine("Whoops... Parameter selection invalid...");
                    break;
                }
            }
Exemple #16
0
            private void CalculateScattering_Click(object sender, EventArgs e)
            {
                Chosenfreq = 0;
                double radius = (double)ScatteringRadius.Value;
                double t      = 4 * (radius + (double)Sample_Depth.Value) / C_Sound() * 1000;

                if (LabCenter == null)
                {
                    return;
                }

                Polygon_Scene Rm      = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                Empty_Scene   Rm_Ctrl = new Empty_Scene((double)Air_Temp.Value, (double)Rel_Humidity.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked, true, Rm.Min(), Rm.Max());

                Rm_Ctrl.PointsInScene(new List <Hare.Geometry.Point> {
                    Rm.Min(), Rm.Max()
                });
                Rm_Ctrl.partition();

                if (!Rm.Complete && Rm_Ctrl.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d ArrayCenter = new Rhino.Geometry.Point3d(LabCenter.X, LabCenter.Y, LabCenter.Z + (double)Sample_Depth.Value);

                Rhino.Geometry.Point3d[] Src = new Rhino.Geometry.Point3d[1] {
                    new Rhino.Geometry.Point3d(LabCenter.X, LabCenter.Y, LabCenter.Z + radius + (double)Sample_Depth.Value)
                };
                List <Rhino.Geometry.Point3d> Rec = new List <Rhino.Geometry.Point3d>();

                for (int phi = 0; phi < 18; phi++)
                {
                    for (int theta = 0; theta < 36; theta++)
                    {
                        double anglePhi   = phi * Math.PI / 18;
                        double angleTheta = theta * Utilities.Numerics.PiX2 / 36;
                        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(angleTheta) * Math.Cos(anglePhi), Math.Sin(angleTheta) * Math.Cos(anglePhi), Math.Sin(anglePhi)));
                    }
                }

                //for (int phi = 0; phi < 18; phi++)
                //    {
                //        double anglePhi = phi * Math.PI / 18;
                //        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(anglePhi), 0, Math.Sin(anglePhi)));
                //    }

                double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Scatter_Extent.SelectedIndex);

                Numeric.TimeDomain.Microphone_Compact    Mic   = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                Numeric.TimeDomain.Signal_Driver_Compact SD    = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDS = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.PachTools.RPttoHPt(LabCenter), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                FDTDS.RuntoCompletion();

                Numeric.TimeDomain.Microphone_Compact    Micf  = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                Numeric.TimeDomain.Signal_Driver_Compact SDf   = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDF = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm_Ctrl, ref SDf, ref Micf, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.PachTools.RPttoHPt(LabCenter) + new Hare.Geometry.Point(0, 0, (double)Sample_Depth.Value), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                FDTDF.RuntoCompletion();

                samplefrequency = FDTDS.SampleFrequency;

                Mic.reset();
                result_signals = Mic.Recordings[0];
                Micf.reset();
                result_signals = Micf.Recordings[0];

                //Calculate Scattering Coefficients
                double[][] TimeS = Mic.Recordings[0];
                double[][] TimeF = Micf.Recordings[0];

                System.Numerics.Complex[][] FS = new System.Numerics.Complex[TimeS.Length][];
                System.Numerics.Complex[][] FF = new System.Numerics.Complex[TimeS.Length][];

                for (int i = 0; i < TimeS.Length; i++)
                {
                    FS[i] = Audio.Pach_SP.FFT_General(TimeS[i], 0);
                    FF[i] = Audio.Pach_SP.FFT_General(TimeF[i], 0);
                }

                Scattering = new double[FS[0].Length];

                for (int i = 0; i < FS[0].Length; i++)
                {
                    System.Numerics.Complex sumFS2  = 0;
                    System.Numerics.Complex sumFF2  = 0;
                    System.Numerics.Complex sumFSFF = 0;

                    for (int j = 0; j < FS.Length; j++)
                    {
                        sumFS2  += System.Numerics.Complex.Pow(FS[j][i].Magnitude, 2);
                        sumFF2  += System.Numerics.Complex.Pow(FF[j][i].Magnitude, 2);
                        sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                        //sumFS2 += System.Numerics.Complex.Pow(FS[j][i], 2);
                        //sumFF2 += System.Numerics.Complex.Pow(FF[j][i], 2);
                        //sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                    }

                    System.Numerics.Complex sumReflected = sumFSFF / sumFF2;
                    System.Numerics.Complex Ratio        = sumFF2 / sumFS2;
                    Scattering[i] = 1 - System.Numerics.Complex.Abs(sumReflected * sumReflected * Ratio);
                }

                Update_Scattering_Graph(null, null);
            }