コード例 #1
0
 public SphereConduit(Sphere_Plot plot_in, Hare.Geometry.Point center_in, Pach_Graphics.colorscale C_in, double[] V_Bounds_in)
 {
     plot     = plot_in;
     center   = center_in;
     C        = C_in;
     Instance = this;
 }
コード例 #2
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();
            }
        }
コード例 #3
0
 public Hare.Geometry.Topology Output(IEnumerable <double> magnitude, double Min, double Max, double Diameter)
 {
     if (magnitude.Count() != Vertices.Length)
     {
         throw new Exception("Invalid data input to spherical plot...");
     }
     Hare.Geometry.Point[] points = new Hare.Geometry.Point[Vertices.Length];
     for (int i = 0; i < magnitude.Count(); i++)
     {
         double mag = (magnitude.ElementAt(i));
         if (double.IsInfinity(mag))
         {
             mag = 0;
         }
         mag       = Math.Max(mag, Min);
         mag       = Math.Min(mag, Max);
         mag      -= Min;
         mag      /= (Max - Min) * Diameter;
         points[i] = mag * Vertices[i];
     }
     Hare.Geometry.Topology T = new Hare.Geometry.Topology();
     T.Set_Topology(points, Faces.ToArray());
     T.Finish_Topology();
     return(T);
 }
            public static Hare.Geometry.Topology Rhino_to_HareMesh(Mesh M)
            {
                Hare.Geometry.Point[][] polys = new Hare.Geometry.Point[M.Faces.Count][];

                for (int i = 0; i < M.Faces.Count; i++)
                {
                    Hare.Geometry.Point[] pts;
                    if (M.Faces[i].IsTriangle)
                    {
                        pts    = new Hare.Geometry.Point[3];
                        pts[0] = RPttoHPt(M.Vertices[M.Faces[i].A]);
                        pts[1] = RPttoHPt(M.Vertices[M.Faces[i].B]);
                        pts[2] = RPttoHPt(M.Vertices[M.Faces[i].C]);
                    }
                    else
                    {
                        pts    = new Hare.Geometry.Point[4];
                        pts[0] = RPttoHPt(M.Vertices[M.Faces[i].A]);
                        pts[1] = RPttoHPt(M.Vertices[M.Faces[i].B]);
                        pts[2] = RPttoHPt(M.Vertices[M.Faces[i].C]);
                        pts[3] = RPttoHPt(M.Vertices[M.Faces[i].D]);
                    }
                    polys[i] = pts;
                }

                Hare.Geometry.Topology HM = new Hare.Geometry.Topology(polys);
                HM.Finish_Topology(new List <Hare.Geometry.Point>());
                return(HM);
            }
コード例 #5
0
            public override double Rho_C(Hare.Geometry.Point pt)
            {
                int X = (int)Math.Floor((pt.x - MinX) / VdimX);
                int Y = (int)Math.Floor((pt.y - MinY) / VdimY);
                int Z = (int)Math.Floor((pt.z - MinZ) / VdimZ);

                return(Zmed[XYTot * Z + Ydom * X + Y]);
            }
コード例 #6
0
            public override double[] Attenuation_Coef(Hare.Geometry.Point pt)
            {
                int X = (int)Math.Floor((pt.x - MinX) / VdimX);
                int Y = (int)Math.Floor((pt.y - MinY) / VdimY);
                int Z = (int)Math.Floor((pt.z - MinZ) / VdimZ);

                return(Atten_Coef[XYTot * Z + Ydom * X + Y]);
            }
コード例 #7
0
            public override double AttenuationPureTone(Hare.Geometry.Point pt, double frequency)
            {
                int X = (int)Math.Floor((pt.x - MinX) / VdimX);
                int Y = (int)Math.Floor((pt.y - MinY) / VdimY);
                int Z = (int)Math.Floor((pt.z - MinZ) / VdimZ);

                return(Spectrum[XYTot * Z + Ydom * X + Y].Interpolate(frequency));
            }
コード例 #8
0
            public bool SourceOrigin(out Hare.Geometry.Point[] Points)
            {
                //Pach_Source_Object c = Pach_Source_Object.Instance;
                Points = new Hare.Geometry.Point[SourceConduit.Instance.UUID.Count];
                for (int i = 0; i < SourceConduit.Instance.UUID.Count; i++)
                {
                    System.Guid S_ID = SourceConduit.Instance.UUID[i];
                    if (S_ID == System.Guid.Empty || S_ID == System.Guid.NewGuid())
                    {
                        break;
                    }
                    Points[i] = Utilities.RC_PachTools.RPttoHPt(Rhino.RhinoDoc.ActiveDoc.Objects.Find(S_ID).Geometry.GetBoundingBox(true).Min);
                }

                if (Points.Length > 0)
                {
                    return(true);
                }
                return(false);
            }
コード例 #9
0
            private bool Read_File()
            {
                if (FileIO.Read_Pac1(ref Direct_Data, ref IS_Data, ref Receiver))
                {
                    SourceList.Items.Clear();
                    LockUserScale.Checked = false;
                    Update_Graph(null, new System.EventArgs());
                    LockUserScale.Checked = true;
                    Receiver_Choice.Text  = "0";
                    OpenAnalysis();
                    cleanup();

                    Source = new Source[Direct_Data.Length];
                    Recs   = new Hare.Geometry.Point[Receiver[0].Count];

                    for (int DDCT = 0; DDCT < Direct_Data.Length; DDCT++)
                    {
                        Source[DDCT] = Direct_Data[DDCT].Src;
                        SourceList.Items.Add(string.Format("S{0}-", DDCT) + Direct_Data[DDCT].type);
                        Source_Aim.Items.Add(string.Format("S{0}-", DDCT) + Direct_Data[DDCT].type);
                        SrcTypeList.Add(Direct_Data[DDCT].type);
                    }

                    CutoffTime = Direct_Data[0].Cutoff_Time;
                    SampleRate = (int)Direct_Data[0].SampleRate;

                    for (int i = 0; i < Recs.Length; i++)
                    {
                        Recs[i] = Receiver[0].Rec_List[i].H_Origin;
                    }
                    return(true);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("File Read Failed...", "Results file was corrupt or incomplete. We apologize for this inconvenience. Please report this to the software author. It will be much appreciated.");
                    return(false);
                }
            }
コード例 #10
0
            public Heterogeneous_Grid_Medium(int Air_Choice, double[, ,] Pa, double[, ,] TC, double[, ,] hr, bool EdgeCorrection, VoxelGrid_PolyRefractive V)
            {
                VdimX = V.Xdim;
                VdimY = V.Ydim;
                VdimZ = V.Zdim;
                Hare.Geometry.Point min = V.MinPt;
                MinX       = min.x;
                MinY       = min.y;
                MinZ       = min.z;
                Xdom       = Pa.GetLength(0);
                Ydom       = Pa.GetLength(1);
                Zdom       = Pa.GetLength(2);
                XYTot      = Xdom * Ydom;
                Atten_Coef = new double[Xdom * Ydom * Zdom][];
                C_Sound    = new double[Xdom * Ydom * Zdom];
                rho        = new double[Xdom * Ydom * Zdom];
                Zmed       = new double[Xdom * Ydom * Zdom];
                Spectrum   = new MathNet.Numerics.Interpolation.CubicSpline[Xdom * Ydom * Zdom];

                for (int x = 0; x < Xdom; x++)
                {
                    for (int y = 0; y < Ydom; y++)
                    {
                        for (int z = 0; z < Zdom; z++)
                        {
                            int code = XYTot * z + Ydom * x + y;
                            Atten_Coef[code] = Calculate_Attenuation(Air_Choice, Pa[x, y, z], TC[x, y, z], hr[x, y, z], EdgeCorrection);
                            rho[code]        = Calculate_Density(TC[x, y, z], Pa[x, y, z], hr[x, y, z]);//TODO - check input
                            C_Sound[code]    = Utilities.AcousticalMath.SoundSpeed(TC[x, y, z] - 273.15);
                            Zmed[code]       = rho[code] * C_Sound[code];

                            //TODO: Is TC termperature in Celsius, or Kelvins?
                            ISO9613_1_Spline(TC[x, y, z], Pa[x, y, z], hr[x, y, z], code);
                        }
                    }
                }
            }
コード例 #11
0
 /// <summary>
 /// Constructor which takes Hare Point input.
 /// </summary>
 /// <param name="Center"></param>
 /// <param name="SrcCenter"></param>
 /// <param name="room"></param>
 /// <param name="RCT"></param>
 /// <param name="C_Sound_in"></param>
 /// <param name="SampleRate_in"></param>
 /// <param name="COTime_in"></param>
 public Spherical_Receiver(Hare.Geometry.Point Center, Hare.Geometry.Point SrcCenter, Scene room, double C_Sound_in, int SampleRate_in, double COTime_in)
 {
     D_Length = Math.Sqrt(Center.x * SrcCenter.x + Center.y * SrcCenter.y * Center.z * SrcCenter.z);
     Radius = 1;
     Radius2 = Radius * Radius;
     CO_Time = COTime_in;
     SampleRate = SampleRate_in;
     H_Origin = Center;
     //Origin = new Point3d(Center.x, Center.y, Center.z);
     Sound_Speed = C_Sound_in;
     Atten = room.Attenuation(Center);
     SizeMod = 1 / Math.PI;
     Recs = new Directional_Histogram(SampleRate, CO_Time);
 }
コード例 #12
0
 public override double Rho(Hare.Geometry.Point pt)
 {
     return(rho);
 }
コード例 #13
0
            public override void AttenuationFilter(int no_of_elements, int sample_Frequency, double distance_meters, ref double[] Freq, ref double[] Atten, Hare.Geometry.Point pt)
            {
                double df = sample_Frequency / no_of_elements;

                Freq  = new double[no_of_elements];
                Atten = new double[no_of_elements];

                for (int i = 0; i < no_of_elements; i++)
                {
                    Freq[i]  = df * (i + 1);
                    Atten[i] = Math.Exp(-.1151 * Spectrum.Interpolate(Freq[i]) * distance_meters);
                }
            }
コード例 #14
0
 public override double[] Attenuation_Coef(Hare.Geometry.Point pt)
 {
     return(Atten_Coef);
 }
コード例 #15
0
 public abstract double Sound_Speed(Hare.Geometry.Point pt);
コード例 #16
0
 public abstract void AttenuationFilter(int no_of_elements, int sample_Frequency, double distance_meters, ref double[] Freq, ref double[] Atten, Hare.Geometry.Point pt);
コード例 #17
0
            private void CalculateScattering_Click(object sender, EventArgs e)
            {
                Chosenfreq = 0;
                double radius = (double)ScatteringRadius.Value;
                double t      = 3 * (radius + (double)Sample_Depth.Value) / C_Sound() * 1000;

                if (LabCenter == null)
                {
                    return;
                }

                if (Analysis_Technique.SelectedIndex == 0)
                {
                    Polygon_Scene Rm      = RC_PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, false, (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;
                    }

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

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

                    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 Hare.Geometry.Point(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, comboBox2.SelectedIndex);

                    t += 60 / fs;

                    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.RC_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.RC_PachTools.RPttoHPt(LabCenter), 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];

                    //Zero packing
                    for (int i = 0; i < TimeS.Length; i++)
                    {
                        Array.Resize(ref TimeS[i], (int)(samplefrequency / 2));
                        Array.Resize(ref TimeF[i], (int)(samplefrequency / 2));
                    }
                    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);
                    }
                }
                else if (Analysis_Technique.SelectedIndex == 1)
                {
                    Polygon_Scene Rm      = RC_PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, false, (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;
                    }

                    //if (!Rm.Complete) return;

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

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

                    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 Hare.Geometry.Point(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, Analysis_Technique.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.TransparencyLab, Utilities.RC_PachTools.RPttoHPt(LabCenter), radius * 4, radius * 4, 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.RC_PachTools.RPttoHPt(LabCenter), radius * 4, radius * 4, radius * 1.2 + (double)Sample_Depth.Value);
                    FDTDF.RuntoCompletion();

                    int start = (int)Math.Round((2.25 * radius / Rm.Sound_speed(Src[0])) / FDTDS.dt);

                    samplefrequency = FDTDS.SampleFrequency;

                    Mic.reset();
                    result_signals = Mic.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++)
                    {
                        double[] ts = new double[TimeS[i].Length - start];
                        double[] tf = new double[TimeS[i].Length - start];
                        for (int ti = start; ti < TimeS[i].Length; ti++)
                        {
                            ts[ti - start] = TimeS[i][ti];
                            tf[ti - start] = TimeF[i][ti];
                        }
                        FS[i] = Audio.Pach_SP.FFT_General(ts, 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 sumFF2 = 0;

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

                        Scattering[i] = Utilities.AcousticalMath.SPL_Pressure(System.Numerics.Complex.Abs(sumFF2));
                    }
                }
                Update_Scattering_Graph(null, null);
            }
コード例 #18
0
            public static bool Read_Pac1(string filename, ref Direct_Sound[] Direct_Data, ref ImageSourceData[] IS_Data, ref Environment.Receiver_Bank[] Receiver)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open));
                try
                {
                    //1. Date & Time
                    string Savedate = sr.ReadString();
                    //2. Plugin Version
                    string Pach_version = sr.ReadString();
                    //3. Cut off Time and SampleRate
                    double CO_TIME = sr.ReadDouble();
                    int SampleRate = sr.ReadInt32();
                    //4. Source Count
                    int SrcCt = 1;
                    if (double.Parse(Pach_version.Substring(0, 3)) >= 1.1) SrcCt = sr.ReadInt32();
                    //4.1 Source Location x
                    //4.2 Source Location y
                    //4.3 Source Location z
                    Hare.Geometry.Point[] SrcPt = new Hare.Geometry.Point[SrcCt];
                    for (int s = 0; s < SrcCt; s++) SrcPt[s] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                    //5. No of Receivers
                    int Rec_Ct = sr.ReadInt32();
                    //6. Write the coordinates of each receiver point
                    //6b. Write the environmental characteristics at each receiver point (Rho * C); V2.0 only...
                    Hare.Geometry.Point[] Recs = new Hare.Geometry.Point[Rec_Ct];
                    double[] Rho_C = new double[Rec_Ct];
                    for (int q = 0; q < Rec_Ct; q++)
                    {
                        Recs[q] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                        if (double.Parse(Pach_version.Substring(0, 3)) >= 2.0) Rho_C[q] = sr.ReadDouble();
                        else Rho_C[q] = 400;
                    }

                    Direct_Data = new Direct_Sound[SrcCt];
                    IS_Data = new ImageSourceData[SrcCt];
                    Receiver = new Environment.Receiver_Bank[SrcCt];

                    int DDCT = 0;
                    int ISCT = 0;
                    int RTCT = 0;
                    do
                    {
                        string readin = sr.ReadString();
                        switch (readin)
                        {
                            case "Direct_Sound":
                            case "Direct_Sound w sourcedata":
                                //9. Read Direct Sound Data
                                Direct_Data[DDCT] = Direct_Sound.Read_Data(ref sr, Recs, SrcPt[DDCT], Rho_C, Pach_version);
                                Direct_Data[DDCT].CO_Time = CO_TIME;
                                Direct_Data[DDCT].SampleFreq = (int)SampleRate;
                                DDCT++;
                                break;
                            case "Image-Source_Data":
                                //10. Read Image Source Sound Data
                                IS_Data[ISCT] = ImageSourceData.Read_Data(ref sr, Recs.Length, Direct_Data[DDCT - 1], false, ISCT, Pach_version);
                                ISCT++;
                                break;
                            case "Ray-Traced_Data":
                                //11. Read Ray Traced Sound Data
                                Receiver[RTCT] = Environment.Receiver_Bank.Read_Data(ref sr, Rec_Ct, Recs, Rho_C, Direct_Data[RTCT].Delay_ms, ref SampleRate, Pach_version);
                                RTCT++;
                                break;
                            case "End":
                                sr.Close();
                                return true;
                        }
                    } while (true);
                }
                catch (System.Exception X)
                {
                    sr.Close();
                    System.Windows.Forms.MessageBox.Show("File Read Failed...", String.Format("Results file was corrupt or incomplete. We apologize for this inconvenience. Please report this to the software author. It will be much appreciated. \r\n Exception Message: {0}. \r\n Method: {1}" , X.Message, X.TargetSite));
                    return false;
                }
            }
コード例 #19
0
            private bool Read_File()
            {
                if (FileIO.Read_Pac1(ref Direct_Data, ref IS_Data, ref Receiver))
                {
                    SourceList.Items.Clear();
                    LockUserScale.Checked = false;
                    Update_Graph(null, new System.EventArgs());
                    LockUserScale.Checked = true;
                    Receiver_Choice.Text = "0";
                    OpenAnalysis();
                    cleanup();

                    Source = new Source[Direct_Data.Length];
                    Recs = new Hare.Geometry.Point[Receiver[0].Count];

                    for (int DDCT = 0; DDCT < Direct_Data.Length; DDCT++)
                    {
                        Source[DDCT] = Direct_Data[DDCT].Src;
                        SourceList.Items.Add(string.Format("S{0}-", DDCT) + Direct_Data[DDCT].type);
                        Source_Aim.Items.Add(string.Format("S{0}-", DDCT) + Direct_Data[DDCT].type);
                        SrcTypeList.Add(Direct_Data[DDCT].type);
                    }

                    CutoffTime = Direct_Data[0].Cutoff_Time;
                    SampleRate = (int)Direct_Data[0].SampleRate;

                    for (int i = 0; i < Recs.Length; i++) Recs[i] = Receiver[0].Rec_List[i].H_Origin;
                    return true;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("File Read Failed...", "Results file was corrupt or incomplete. We apologize for this inconvenience. Please report this to the software author. It will be much appreciated.");
                    return false;
                }
            }
コード例 #20
0
            private void Calculate_Click(object sender, System.EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = RC_PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, false, (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
                    });
                }
                Hare.Geometry.Point[] Src = RC_PachTools.GetSource();
                Hare.Geometry.Point[] Rec = new Hare.Geometry.Point[0];//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, RC_PachTools.GetSource());
                Numeric.TimeDomain.Microphone_Compact    Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);

                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD_RC(Rm, ref SD, ref Mic, (double)Freq_Max.Value, (double)CO_TIME.Value, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.Freefield, null, 0, 0, 0);
                //FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, (double)Freq_Max.Value, (double)CO_TIME.Value, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, new Hare.Geometry.Point(0,0,0), 8, 6, 5);
                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());
                }

                Loop_Click(new object(), new EventArgs());
            }
コード例 #21
0
            public void GetSims(ref Hare.Geometry.Point[] Src, ref Hare.Geometry.Point[] Rec, ref Direct_Sound[] D, ref ImageSourceData[] IS, ref Receiver_Bank[] RT)
            {
                Src = new Hare.Geometry.Point[Source.Length];
                for (int i = 0; i < Source.Length; i++) Src[i] = Source[i].H_Origin();
                Rec = Recs;

                if (Direct_Data != null) D = Direct_Data;
                if (IS_Data != null) IS = IS_Data;
                if (Receiver != null) RT = Receiver;
            }
コード例 #22
0
 public override Hare.Geometry.Point ClosestPt(Hare.Geometry.Point P, ref double Dist)
 {
     double Max = double.MaxValue;
     Hare.Geometry.Point RP = new Hare.Geometry.Point();
     Hare.Geometry.Point TP;
     for (int i = 0; i < Topo[0].Polygon_Count; i++)
     {
         TP = Topo[0].Closest_Point(P, i);
         Dist = TP.x * TP.x + TP.y * TP.y + TP.z * TP.z;
         if (Dist < Max)
         {
             RP = TP;
             Max = Dist;
         }
     }
     Dist = Math.Sqrt(Max);
     return RP;
 }
コード例 #23
0
            private void Construct(List<Rhino.DocObjects.RhinoObject> ObjectList)
            {
                BoundingBox Box = ObjectList[0].Geometry.GetBoundingBox(true);
                for (int i = 1; i < ObjectList.Count; i++) Box.Union(ObjectList[i].Geometry.GetBoundingBox(true));

                List<GeometryBase> BList = new List<GeometryBase>();

                Brep_ids = new List<int>();

                List<Material> Mat_Layer = new List<Material>();
                List<Scattering> Scat_Layer = new List<Scattering>();
                List<Material> Mat_Obj = new List<Material>();
                List<Scattering> Scat_Obj = new List<Scattering>();
                List<double[]> Trans_Layer = new List<double[]>();
                List<double[]> Trans_Obj = new List<double[]>();
                List<bool> Finite_Layers = new List<bool>();
                List<bool> Finite_Obj = new List<bool>();
                //Organize the geometry into Breps
                //Get materials for each layer:
                for (int l = 0; l < Rhino.RhinoDoc.ActiveDoc.Layers.Count; l++)
                {
                    Rhino.DocObjects.Layer Layer = Rhino.RhinoDoc.ActiveDoc.Layers[l];
                    string abstype = Layer.GetUserString("ABSType");
                    if (abstype == "Buildup")
                    {
                        Finite_Layers.Add(false);
                        string BU = Layer.GetUserString("BuildUp");
                        string[] BU_split = BU.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        List<AbsorptionModels.ABS_Layer> Buildup = new List<AbsorptionModels.ABS_Layer>();
                        foreach (string swatch in BU_split) Buildup.Add(AbsorptionModels.ABS_Layer.LayerFromCode(swatch));
                        Mat_Layer.Add(new Environment.Smart_Material(Buildup, 44100, Env_Prop.Rho(0), Env_Prop.Sound_Speed(0), 2));

                        double[] Abs = new double[8], Scat = new double[8], Trans = new double[8];
                        Pachyderm_Acoustic.UI.PachydermAc_PlugIn.DecodeAcoustics(Layer.GetUserString("Acoustics"), ref Abs, ref Scat, ref Trans);
                        ///Other properties are still coefficient based...
                        Scat_Layer.Add(new Environment.Lambert_Scattering(Scat, SplitRatio));
                        Trans_Layer.Add(Trans);
                    }
                    else if (abstype == "Buildup_Finite")
                    {
                        Finite_Layers.Add(true);
                        string BU = Layer.GetUserString("BuildUp");
                        string[] BU_split = BU.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        List<AbsorptionModels.ABS_Layer> Buildup = new List<AbsorptionModels.ABS_Layer>();
                        foreach (string swatch in BU_split) Buildup.Add(AbsorptionModels.ABS_Layer.LayerFromCode(swatch));
                        Environment.Smart_Material sm = new Environment.Smart_Material(Buildup, 44100, Env_Prop.Rho(0), Env_Prop.Sound_Speed(0), 2);
                        Mat_Layer.Add(sm);
                        double[] Abs = new double[8], Scat = new double[8], Trans = new double[8];
                        Pachyderm_Acoustic.UI.PachydermAc_PlugIn.DecodeAcoustics(Layer.GetUserString("Acoustics"), ref Abs, ref Scat, ref Trans);
                        ///Other properties are still coefficient based...
                        Scat_Layer.Add(new Environment.Lambert_Scattering(Scat, SplitRatio));
                        Trans_Layer.Add(Trans);
                    }
                    else
                    {
                        Finite_Layers.Add(false);
                        string spec = Layer.GetUserString("Acoustics");

                        if (spec == "")
                        {
                            ///Layer is not used. As long as there is no geometry for pachyderm on this layer without object set properties, this is ok.
                            Mat_Layer.Add(null);
                            Scat_Layer.Add(null);
                            Trans_Layer.Add(null);
                            continue;
                        }

                        double[] Abs = new double[8], Scat = new double[8], Trans = new double[8];
                        Pachyderm_Acoustic.UI.PachydermAc_PlugIn.DecodeAcoustics(spec, ref Abs, ref Scat, ref Trans);
                        Mat_Layer.Add(new Environment.Basic_Material(Abs, new double[8] { 0, 0, 0, 0, 0, 0, 0, 0 }));
                        Scat_Layer.Add(new Environment.Lambert_Scattering(Scat, SplitRatio));
                        Trans_Layer.Add(Trans);
                    }
                }

                for (int q = 0; q <= ObjectList.Count - 1; q++)
                {
                    List<Brep> B = new List<Brep>();
                    if (ObjectList[q].ObjectType == Rhino.DocObjects.ObjectType.Brep)
                    {
                        Rhino.DocObjects.BrepObject BObj = ((Rhino.DocObjects.BrepObject)ObjectList[q]);
                        B.Add(BObj.BrepGeometry.DuplicateBrep());
                        //string m = ObjectList[q].Geometry.GetUserString("Acoustics_User");
                        if (ObjectList[q].Geometry.GetUserString("Acoustics_User") == "yes")
                        {
                            double[] ABS = new double[8], SCAT = new double[8], TRANS = new double[8];
                            Pachyderm_Acoustic.UI.PachydermAc_PlugIn.DecodeAcoustics(ObjectList[q].Geometry.GetUserString("Acoustics"), ref ABS, ref SCAT, ref TRANS);
                            Mat_Obj.Add(new Basic_Material(ABS, new double[] { 0, 0, 0, 0, 0, 0, 0, 0 }));
                            Finite_Obj.Add(false);
                            Scat_Obj.Add(new Lambert_Scattering(SCAT, SplitRatio));
                            Trans_Obj.Add(TRANS);
                        }
                        else
                        {
                            //Rhino.DocObjects.Layer Layer = Rhino.RhinoDoc.ActiveDoc.Layers[ObjectList[q].Attributes.LayerIndex];
                            //AcousticsData.Add(Layer.GetUserString("Acoustics"));
                            Mat_Obj.Add(Mat_Layer[ObjectList[q].Attributes.LayerIndex]);
                            Scat_Obj.Add(Scat_Layer[ObjectList[q].Attributes.LayerIndex]);
                            Trans_Obj.Add(Trans_Layer[ObjectList[q].Attributes.LayerIndex]);
                            Finite_Obj.Add(Finite_Layers[ObjectList[q].Attributes.LayerIndex]);
                        }
                    }
                    else if (ObjectList[q].ObjectType == Rhino.DocObjects.ObjectType.Extrusion)
                    {
                        Rhino.Geometry.Brep BObj = ((Rhino.DocObjects.ExtrusionObject)ObjectList[q]).ExtrusionGeometry.ToBrep();
                        for (int i = 0; i < BObj.Faces.Count; i++)
                        {
                            if (ObjectList[q].Geometry.GetUserString("Acoustics_User") == "yes")
                            {
                                //AcousticsData.Add(ObjectList[q].Geometry.GetUserString("Acoustics"));
                                double[] ABS = new double[8], SCAT = new double[8], TRANS = new double[8];
                                Pachyderm_Acoustic.UI.PachydermAc_PlugIn.DecodeAcoustics(ObjectList[q].Geometry.GetUserString("Acoustics"), ref ABS, ref SCAT, ref TRANS);
                                Mat_Obj.Add(new Basic_Material(ABS, new double[] { 0, 0, 0, 0, 0, 0, 0, 0 }));
                                Scat_Obj.Add(new Lambert_Scattering(SCAT, SplitRatio));
                                Trans_Obj.Add(TRANS);
                                Finite_Obj.Add(false);
                            }
                            else
                            {
                                //Rhino.DocObjects.Layer Layer = Rhino.RhinoDoc.ActiveDoc.Layers[ObjectList[q].Attributes.LayerIndex];
                                //AcousticsData.Add(Layer.GetUserString("Acoustics"));
                                //Rhino.DocObjects.Layer Layer = Rhino.RhinoDoc.ActiveDoc.Layers[ObjectList[q].Attributes.LayerIndex];
                                //AcousticsData.Add(Layer.GetUserString("Acoustics"));
                                Mat_Obj.Add(Mat_Layer[ObjectList[q].Attributes.LayerIndex]);
                                Scat_Obj.Add(Scat_Layer[ObjectList[q].Attributes.LayerIndex]);
                                Trans_Obj.Add(Trans_Layer[ObjectList[q].Attributes.LayerIndex]);
                                Finite_Obj.Add(Finite_Layers[ObjectList[q].Attributes.LayerIndex]);
                            }

                            //B.Add(BObj.Faces[0].ToBrep());
                            //for (int i = 1; i < BObj.Faces.Count; i++)
                            //{
                            //    if (ObjectList[q].Geometry.GetUserString("Acoustics_User") == "yes")
                            //    {
                            //        AcousticsData.Add(ObjectList[q].Geometry.GetUserString("Acoustics"));
                            //    }
                            //    else
                            //    {
                            //        Rhino.DocObjects.Layer Layer = Rhino.RhinoDoc.ActiveDoc.Layers[ObjectList[q].Attributes.LayerIndex];
                            //        AcousticsData.Add(Layer.GetUserString("Acoustics"));
                            //    }
                            B.Add(BObj.Faces[i].ToBrep());
                        }
                    }
                    else
                    {
                        continue;
                    }
                    BList.AddRange(B);
                }

                ////////////////////////////////////////
                Topo = new Hare.Geometry.Topology[1];
                Topo[0] = new Topology(Utilities.PachTools.RPttoHPt(Box.Min), Utilities.PachTools.RPttoHPt(Box.Max));
                ////////////////////////////////////////
                for (int q = 0; q < BList.Count; q++)
                {
                    for (int r = 0; r < ((Brep)BList[q]).Faces.Count; r++)
                    {
                        BrepList.Add(((Brep)BList[q]).Faces[r].DuplicateFace(false));

                        //Material Abs = null ;
                        //Scattering Scat = null;

                        //double[] Transparency = new double[8];
                        double[] Transmission = new double[8];

                        //double[] Scat = new double[8];
                        //if (!string.IsNullOrEmpty(AcousticsData[q]))
                        //if (Mat_Obj[q] != null)
                        //{
                        //    //double[] Absorption = new double[8];
                        //    //double[] phase = new double[8];
                        //    //double[] Scattering = new double[8];
                        //    ////double[,] Scattering = new double[8, 3];
                        //    //double[] Reflection = new double[8];
                        //    //UI.PachydermAc_PlugIn.DecodeAcoustics(AcousticsData[q], ref Absorption, ref Scattering, ref Transparency);
                        //    Abs = Mat_Obj[q];
                        //    Scat = Scat_Obj[q];
                        //    Transmission = Trans_Obj[q];
                        //}
                        //else
                        if ((Mat_Obj[q] == null) || (Scat_Obj[q] == null) || (Trans_Obj[q] == null))
                        {
                            if (!Custom_Method)
                            {
                                Status = System.Windows.Forms.MessageBox.Show("A material is not specified correctly. Please assign absorption and scattering to all layers in the model.", "Materials Error", System.Windows.Forms.MessageBoxButtons.OK);
                                Complete = false;
                                return;
                            }
                            ///Materials do not need to be specified, as it will not be used for an acoustical simulation... (hopefully...)
                        }

                        //for (int i = 0; i < 8; i++)
                        //{
                        //    Reflection[i] = (1 - Absorption[i]);
                        //    Transmission[i] = Transparency[i];
                        //    Scattering[i, 1] = Scat[i];
                        //    double Mod = ((Scattering[i, 1] < (1 - Scattering[i, 1])) ? (Scattering[i, 1] * SplitRatio / 2) : ((1 - Scattering[i, 1]) * SplitRatio / 2));
                        //    Scattering[i, 0] = Scattering[i, 1] - Mod;
                        //    Scattering[i, 2] = Scattering[i, 1] + Mod;
                        //    phase[i] = 0;
                        //}

                        Mesh[] meshes;
                        MeshingParameters mp = new MeshingParameters();
                        if (Finite_Obj[q])
                        {
                            mp.MinimumEdgeLength = 0.1;
                            mp.SimplePlanes = false;
                        }
                        else
                        {
                            mp.MinimumEdgeLength = 0.1;
                            mp.SimplePlanes = true;
                        }

                        meshes = Rhino.Geometry.Mesh.CreateFromBrep((Brep)BrepList[BrepList.Count - 1], mp);
                        if (meshes == null) throw new Exception("Problem with meshes");

                        for (int t = 0; t < meshes.Length; t++)
                        {
                            if (meshes[t].Faces.Count < 1)
                            {
                                Status = System.Windows.Forms.MessageBox.Show("A surface in the model does not generate a rendermesh. This surface will not be represented in the simulation. It is recommended that you cancel this simulation and repair the affected surface. It can be located in shaded view by finding the surface which generates boundary and isoparm lines, but does not generate a fill. It can sometimes be repaired by running the command 'ShrinkTrimmedSurface'. If this does not work, it will have to be replaced by some means which would generate a proper surface.", "Surface without Rendermesh", System.Windows.Forms.MessageBoxButtons.OKCancel);
                                if (Status == System.Windows.Forms.DialogResult.Cancel)
                                {
                                    Complete = false;
                                    return;
                                }
                                continue;
                            }

                            for (int u = 0; u < meshes[t].Faces.Count; u++)
                            {
                                Hare.Geometry.Point[] P;
                                if (meshes[t].Faces[u].IsQuad)
                                {
                                    P = new Hare.Geometry.Point[4];
                                    Point3f FP = meshes[t].Vertices[meshes[t].Faces[u][0]];
                                    P[0] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                    FP = meshes[t].Vertices[meshes[t].Faces[u][1]];
                                    P[1] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                    FP = meshes[t].Vertices[meshes[t].Faces[u][2]];
                                    P[2] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                    FP = meshes[t].Vertices[meshes[t].Faces[u][3]];
                                    P[3] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                }
                                else
                                {
                                    P = new Hare.Geometry.Point[3];
                                    Point3f FP = meshes[t].Vertices[meshes[t].Faces[u][0]];
                                    P[0] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                    FP = meshes[t].Vertices[meshes[t].Faces[u][1]];
                                    P[1] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                    FP = meshes[t].Vertices[meshes[t].Faces[u][2]];
                                    P[2] = new Hare.Geometry.Point(FP.X, FP.Y, FP.Z);
                                }

                                if (Finite_Obj[q])
                                {
                                    if (!(Mat_Obj[q] is Smart_Material)) throw new Exception("Finite Material must have a Smart_Material...");
                                    Smart_Material mat = Mat_Obj[q] as Smart_Material;
                                    AbsorptionData.Add(new Finite_Material(mat, BrepList[q], meshes[t], u, Env_Prop));
                                }
                                else AbsorptionData.Add(Mat_Obj[q]);
                                ScatteringData.Add(Scat_Obj[q]);
                                TransmissionData.Add(Trans_Obj[q]);

                                bool Trans = false;
                                for (int t_oct = 0; t_oct < 8; t_oct++)
                                {
                                    if (Transmission[t_oct] > 0)
                                    {
                                        Trans = true;
                                        break;
                                    }
                                }
                                Transmissive.Add(Trans);
                                if (BrepList[BrepList.Count - 1].Faces[t].IsPlanar())
                                {
                                    Topo[0].Add_Polygon(P);
                                    Brep_ids.Add(BrepList.Count - 1);
                                }
                                else
                                {
                                    Topo[0].Add_Polygon(new Hare.Geometry.Point[3] { P[0], P[1], P[2] });
                                    Brep_ids.Add(BrepList.Count - 1);
                                    if (P.Length > 3)
                                    {
                                        //break this quad into two polygons in order to avoid warping...
                                        if (Finite_Obj[q])
                                        {
                                            if (!(Mat_Obj[q] is Smart_Material)) throw new Exception("Finite Material must have a Smart_Material...");
                                            Smart_Material mat = Mat_Obj[q] as Smart_Material;
                                            AbsorptionData.Add(new Finite_Material(mat, BrepList[q], meshes[t], u, Env_Prop));
                                        }
                                        else AbsorptionData.Add(Mat_Obj[q]);
                                        ScatteringData.Add(Scat_Obj[q]);
                                        TransmissionData.Add(Trans_Obj[q]);
                                        Transmissive.Add(Trans);
                                        Topo[0].Add_Polygon(new Hare.Geometry.Point[3] { P[0], P[2], P[3] });
                                        Brep_ids.Add(BrepList.Count - 1);
                                    }
                                }
                            }
                        }
                    }
                }

                //Set up a system to find random points on planes.//
                Plane_Area = new double[Topo[0].Plane_Members.Length];
                PolyPlaneFract = new double[Topo[0].Plane_Members.Length][];

                for (int q = 0; q < Topo[0].Plane_Members.Length; q++)
                {
                    foreach (int t in Topo[0].Plane_Members[q])
                    {
                        Plane_Area[q] += Topo[0].Polygon_Area(t);
                    }
                }

                //////////////////////////
                for (int i = 0; i < Topo[0].planeList.Count; i++)
                    for (int j = 0; j < Topo[0].Plane_Members[i].Count; j++)
                    {
                        Point3d pt = Utilities.PachTools.HPttoRPt(Topo[0].Polygon_Centroid(Topo[0].Plane_Members[i][j]));
                        string n = Topo[0].Polys[Topo[0].Plane_Members[i][j]].Plane_ID.ToString();
                    }
                //////////////////////////

                for (int q = 0; q < Topo[0].Plane_Members.Length; q++)
                {
                    PolyPlaneFract[q] = new double[Topo[0].Plane_Members[q].Count];
                    PolyPlaneFract[q][0] = Topo[0].Polygon_Area(Topo[0].Plane_Members[q][0]) / Plane_Area[q];
                    for (int t = 1; t < Topo[0].Plane_Members[q].Count; t++)
                    {
                        PolyPlaneFract[q][t] += PolyPlaneFract[q][t - 1] + Topo[0].Polygon_Area(Topo[0].Plane_Members[q][t]) / Plane_Area[q];
                    }
                }
                ////////////////////////////////////////////////////
                //Determine whether or not the room is a closed volume...
                IsContained = Utilities.AcousticalMath.RoomVolume(BrepList, ref Volume, out Area);
                ////////////////////////////////////////////////////
                Valid = true;

                //Utilities.PachTools.Plot_Hare_Topology(Topo[0]);
            }
コード例 #24
0
            public override void EdgeFrame_Tangents(Hare.Geometry.Point Origin, Vector Normal, int[] PlaneIDs, ref List<double> dist2, List<Vector> Dir, List<int> EdgeIDs)
            {
                double d = Hare_math.Dot(Normal, Origin);
                //for (int i = 0; i < PlaneCount; i++)
                foreach(int i in EdgeIDs)
                {
                    Hare.Geometry.Point[] Pts = new Hare.Geometry.Point[2];
                    double d_min = double.MaxValue;
                    double d_max = double.MinValue;
                    foreach (int j in Topo[0].Plane_Members[i])
                    {
                        //Do the polygon/plane intersection for each member 'j' of i.
                        Hare.Geometry.Point[] vtx = Topo[0].Polygon_Vertices(j);
                        Hare.Geometry.Point[] temp = new Hare.Geometry.Point[1];
                        uint tmpcount = 0;

                        for (int k = 0, h = 1; k < vtx.Length; k++, h++)
                        {
                            Vector ab = vtx[h % vtx.Length] - vtx[k];
                            double t = (d - Hare_math.Dot(Normal, vtx[k])) / Hare_math.Dot(Normal, ab);

                            // If t in [0..1] compute and return intersection point
                            if (t >= 0.0f && t <= 1.0f)
                            {
                                temp[tmpcount] = vtx[k] + t * ab;
                                tmpcount++;
                            }
                            if (h == 0 && tmpcount == 0) break;
                            if (tmpcount > 1) break;
                        }
                        foreach (Hare.Geometry.Point p in temp)
                        {
                            Hare.Geometry.Point v = Origin - p;
                            double tmp = v.x * v.x + v.y * v.y + v.z * v.z;
                            if (tmp > d_max)
                            {
                                Pts[1] = p;
                                d_max = tmp;
                            }
                            if (tmp < d_min)
                            {
                                Pts[0] = p;
                                d_min = tmp;
                            }
                        }
                    }
                    dist2.Add(d_min);
                    EdgeIDs.Add(i);
                    Vector direction = (Pts[1] - Pts[0]);
                    direction.Normalize();
                    Dir.Add(direction);
                }
            }
コード例 #25
0
 public override bool shoot(Hare.Geometry.Ray R, out double u, out double v, out int Poly_ID, out Hare.Geometry.Point X_PT, out double t)
 {
     Hare.Geometry.X_Event X = new Hare.Geometry.X_Event();
     if (SP.Shoot(R, 0, out X))
     {
         Poly_ID = X.Poly_id;
         X_PT = X.X_Point;
         t = X.t;
         u = 0;
         v = 0;
         return true;
     }
     Poly_ID = 0;
     X_PT = new Hare.Geometry.Point();
     //Rhino.RhinoDoc.ActiveDoc.Objects.Add(new Rhino.Geometry.LineCurve(Utilities.PachTools.HPttoRPt(R.origin), Utilities.PachTools.HPttoRPt(R.origin + R.direction)));
     t = 0;
     u = 0;
     v = 0;
     return false;
 }
コード例 #26
0
 public abstract double[] Attenuation_Coef(Hare.Geometry.Point pt);
コード例 #27
0
            public override bool shoot(Ray R, out double u, out double v, out int Srf_ID, out Hare.Geometry.Point X_PT, out double t)
            {
                S_Origin = Utilities.PachTools.HPttoRPt(R.origin);
                Srf_ID = 0;

                while (true)
                {
                    Point3d[] P = Rhino.Geometry.Intersect.Intersection.RayShoot(new Ray3d(S_Origin, new Vector3d(R.direction.x, R.direction.y, R.direction.z)), BrepList, 1);

                    if (P == null) { X_PT = default(Hare.Geometry.Point); u = 0; v = 0; t = 0; return false; }

                    Voxels.PointIsInVoxel(P[0], ref XVoxel, ref YVoxel, ref ZVoxel);
                    try
                    {
                        SurfaceIndex = Voxels.VoxelList(XVoxel, YVoxel, ZVoxel);
                    }
                    catch (Exception)
                    {
                        //Rare floating point error on some computers... abandon the ray and start the next...
                        //Explanation: This would never happen on my IBM T43P laptop, but happened
                        //consistently millions of function calls into the calculation on my
                        //ASUS K8N-DL based desktop computer. I believe it has something to do with some quirk of that system.
                        //This try...catch statement is here in case this ever manifests on any user's computer.
                        //It is rare enough that this should not affect the accuracy of the calculation.
                        t = 0.0f;
                        X_PT = default(Hare.Geometry.Point);
                        u = 0;
                        v = 0;
                        return false;
                    }

                    Point3d CP;
                    Vector3d N;
                    ComponentIndex CI;
                    double MD = 0.0001;

                    foreach (int index in SurfaceIndex)
                    {
                        if (BrepList[index].ClosestPoint(P[0], out CP, out CI, out u, out v, MD, out N) && (CI.ComponentIndexType == ComponentIndexType.BrepFace))
                        {
                            if ((Math.Abs(P[0].X - CP.X) < 0.0001) && (Math.Abs(P[0].Y - CP.Y) < 0.0001) && (Math.Abs(P[0].Z - CP.Z) < 0.0001))
                            {
                                Srf_ID = index;
                                X_PT = new Hare.Geometry.Point(P[0].X, P[0].Y, P[0].Z);
                                t = (double)(S_Origin.DistanceTo(P[0]));
                                return true;
                            }
                        }
                    }
                    S_Origin = new Point3d(P[0]);
                }
            }
コード例 #28
0
 public abstract double Rho_C(Hare.Geometry.Point pt);
コード例 #29
0
            /// <summary>
            /// Receiver bank constructor.
            /// </summary>
            /// <param name="Pt">array of receiver origin points</param>
            /// <param name="SrcPT">sound source point</param>
            /// <param name="Room">the acoustical scene</param>
            /// <param name="RCT">the number or rays emanating from the source</param>
            /// <param name="CSound">the speed of sound in m/s</param>
            /// <param name="SampleRate_in">the simulation histogram sampling frequency</param>
            /// <param name="COTime_in">the Cut Off Time in ms.</param>
            /// <param name="Type">the type of receivers contained in this receiver bank</param>
            public Receiver_Bank(IEnumerable<Point3d> Pt, Point3d SrcPT, Scene Sc, int SampleRate_in, double COTime_in, double delayinms, Type Type)
            {
                delay_ms = delayinms;
                SampleRate = SampleRate_in;
                SampleCT = (int)Math.Floor(COTime_in * SampleRate_in / 1000);
                this.CutOffTime = COTime_in;
                Rec_Type = Type;
                Point3d[] arrPts = Pt.ToArray<Point3d>();
                Rec_List = new Spherical_Receiver[arrPts.Length];
                Min = new Hare.Geometry.Point(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity);
                Max = new Hare.Geometry.Point(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity);

                for (int i = 0; i < arrPts.Length; i++)
                {
                    if (Type == Type.Stationary) Rec_List[i] = new Spherical_Receiver(new Point3d(arrPts[i]), new Point3d(SrcPT), Sc.Attenuation(Utilities.PachTools.RPttoHPt(arrPts[i])), Sc.Sound_speed(Utilities.PachTools.RPttoHPt(arrPts[i])), Sc.Rho(Utilities.PachTools.RPttoHPt(arrPts[i])), SampleRate_in, COTime_in);
                    if (Type == Type.Variable) Rec_List[i] = new Expanding_Receiver(new Point3d(arrPts[i]), new Point3d(SrcPT), RayCount, Sc.Attenuation(Utilities.PachTools.RPttoHPt(arrPts[i])), Sc.Sound_speed(Utilities.PachTools.RPttoHPt(arrPts[i])), Sc.Rho(Utilities.PachTools.RPttoHPt(arrPts[i])), SampleRate_in, COTime_in);

                    if (arrPts[i].X > Max.x) Max.x = arrPts[i].X;
                    if (arrPts[i].Y > Max.y) Max.y = arrPts[i].Y;
                    if (arrPts[i].Z > Max.z) Max.z = arrPts[i].Z;
                    if (arrPts[i].X < Min.x) Min.x = arrPts[i].X;
                    if (arrPts[i].Y < Min.y) Min.y = arrPts[i].Y;
                    if (arrPts[i].Z < Min.z) Min.z = arrPts[i].Z;
                }
            }
コード例 #30
0
 public abstract double AttenuationPureTone(Hare.Geometry.Point pt, double frequency);
コード例 #31
0
 /// <summary>
 /// Constructor which takes Rhino point input.
 /// </summary>
 /// <param name="Center"></param>
 /// <param name="SrcCenter"></param>
 /// <param name="room"></param>
 /// <param name="RCT"></param>
 /// <param name="C_Sound_in"></param>
 /// <param name="SampleRate_in"></param>
 /// <param name="COTime_in"></param>
 public Spherical_Receiver(Point3d Center, Point3d SrcCenter, double[] Attenuation, double C_Sound_in, double rho, int SampleRate_in, double COTime_in)
 {
     D_Length = Center.DistanceTo(SrcCenter);
     Radius = 1;
     Radius2 = Radius * Radius;
     SampleRate = SampleRate_in;
     CO_Time = COTime_in;
     H_Origin = new Hare.Geometry.Point(Center.X, Center.Y, Center.Z);
     Sound_Speed = C_Sound_in;
     Rho_C = C_Sound_in * rho;
     Atten = new double[8];
     for (int o = 0; o < 8; o++) Atten[o] = Attenuation[o] * 2;
     SizeMod = 1 / Math.PI;
     Recs = new Directional_Histogram(SampleRate, CO_Time);
 }
コード例 #32
0
 public override double AttenuationPureTone(Hare.Geometry.Point pt, double frequency)
 {
     return(Spectrum.Interpolate(frequency));
 }
コード例 #33
0
                private void Build_Mesh_Sections()
                {
                    int ct = -1;

                    m_templateX    = new Rhino.Geometry.Mesh[2];
                    m_templateX[0] = new Rhino.Geometry.Mesh();
                    m_templateX[1] = new Rhino.Geometry.Mesh();
                    m_templateY    = new Rhino.Geometry.Mesh[2];
                    m_templateY[0] = new Rhino.Geometry.Mesh();
                    m_templateY[1] = new Rhino.Geometry.Mesh();
                    m_templateZ    = new Rhino.Geometry.Mesh[2];
                    m_templateZ[0] = new Rhino.Geometry.Mesh();
                    m_templateZ[1] = new Rhino.Geometry.Mesh();

                    double rt2 = Math.Sqrt(2);

                    Hare.Geometry.Point min = RDD_Location(Bounds.Min_PT, 0, 0, 0, dx, dy, dz);

                    for (int i = 0; i < 2; i++)
                    {
                        ct = -1;
                        for (int y = 0; y < PFrame[i].Length; y++)
                        {
                            for (int z = 0; z < PFrame[i][y].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = Utilities.RC_PachTools.HPttoRPt(RDD_Location(Bounds.Min_PT, i, y, z, dx, dy, dz)); //new Rhino.Geometry.Point3d(PFrame[0][0][0].Pt.x, PFrame[i][y][z].Pt.y, PFrame[i][y][z].Pt.z);
                                pt.X = min.x;
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, dz)));
                                int ct4 = ct * 4;
                                m_templateX[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int z = 0; z < PFrame[x][i].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = Utilities.RC_PachTools.HPttoRPt(RDD_Location(Bounds.Min_PT, x, i, z, dx, dy, dz)); //new Rhino.Geometry.Point3d(PFrame[x][i][z].Pt.x, PFrame[0][0][0].Pt.y, PFrame[x][i][z].Pt.z);
                                pt.Y = min.y;
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(dx, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, -dz)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(-dx, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, dz)));
                                int ct4 = ct * 4;
                                m_templateY[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int y = 0; y < PFrame[x].Length; y++)
                            {
                                ct++;

                                Rhino.Geometry.Point3d pt = Utilities.RC_PachTools.HPttoRPt(RDD_Location(Bounds.Min_PT, x, y, i, dx, dy, dz)); //new Rhino.Geometry.Point3d(PFrame[x][y][i].Pt.x, PFrame[x][y][i].Pt.y, PFrame[0][0][0].Pt.z);
                                pt.Z = min.z;
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(dx, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, -dy, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(-dx, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, dy, 0)));
                                int ct4 = ct * 4;
                                m_templateZ[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        m_templateX[i].Normals.ComputeNormals();
                        m_templateX[i].FaceNormals.ComputeFaceNormals();
                        m_templateY[i].Normals.ComputeNormals();
                        m_templateY[i].FaceNormals.ComputeFaceNormals();
                        m_templateZ[i].Normals.ComputeNormals();
                        m_templateZ[i].FaceNormals.ComputeFaceNormals();
                    }
                }
コード例 #34
0
 public override double Sound_Speed(Hare.Geometry.Point pt)
 {
     return(C_Sound);
 }
コード例 #35
0
            public static bool Read_Pac1(string filename, ref Direct_Sound[] Direct_Data, ref ImageSourceData[] IS_Data, ref Environment.Receiver_Bank[] Receiver)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open));
                try
                {
                    //1. Date & Time
                    string Savedate = sr.ReadString();
                    //2. Plugin Version
                    string Pach_version = sr.ReadString();
                    //3. Cut off Time and SampleRate
                    double CO_TIME    = sr.ReadDouble();
                    int    SampleRate = sr.ReadInt32();
                    //4. Source Count
                    int SrcCt = 1;
                    if (double.Parse(Pach_version.Substring(0, 3)) >= 1.1)
                    {
                        SrcCt = sr.ReadInt32();
                    }
                    //4.1 Source Location x
                    //4.2 Source Location y
                    //4.3 Source Location z
                    Hare.Geometry.Point[] SrcPt = new Hare.Geometry.Point[SrcCt];
                    for (int s = 0; s < SrcCt; s++)
                    {
                        SrcPt[s] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                    }
                    //5. No of Receivers
                    int Rec_Ct = sr.ReadInt32();
                    //6. Write the coordinates of each receiver point
                    //6b. Write the environmental characteristics at each receiver point (Rho * C); V2.0 only...
                    Hare.Geometry.Point[] Recs = new Hare.Geometry.Point[Rec_Ct];
                    double[] Rho_C             = new double[Rec_Ct];
                    for (int q = 0; q < Rec_Ct; q++)
                    {
                        Recs[q] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                        if (double.Parse(Pach_version.Substring(0, 3)) >= 2.0)
                        {
                            Rho_C[q] = sr.ReadDouble();
                        }
                        else
                        {
                            Rho_C[q] = 400;
                        }
                    }

                    Direct_Data = new Direct_Sound[SrcCt];
                    IS_Data     = new ImageSourceData[SrcCt];
                    Receiver    = new Environment.Receiver_Bank[SrcCt];

                    int DDCT = 0;
                    int ISCT = 0;
                    int RTCT = 0;
                    do
                    {
                        string readin = sr.ReadString();
                        switch (readin)
                        {
                        case "Direct_Sound":
                        case "Direct_Sound w sourcedata":
                            //9. Read Direct Sound Data
                            Direct_Data[DDCT]            = Direct_Sound.Read_Data(ref sr, Recs, SrcPt[DDCT], Rho_C, Pach_version);
                            Direct_Data[DDCT].CO_Time    = CO_TIME;
                            Direct_Data[DDCT].SampleFreq = (int)SampleRate;
                            DDCT++;
                            break;

                        case "Image-Source_Data":
                            //10. Read Image Source Sound Data
                            IS_Data[ISCT] = ImageSourceData.Read_Data(ref sr, Recs.Length, Direct_Data[DDCT - 1], false, ISCT, Pach_version);
                            ISCT++;
                            break;

                        case "Ray-Traced_Data":
                            //11. Read Ray Traced Sound Data
                            Receiver[RTCT] = Environment.Receiver_Bank.Read_Data(ref sr, Direct_Data[RTCT].SWL, Rec_Ct, Recs, Rho_C, Direct_Data[RTCT].Delay_ms, ref SampleRate, Pach_version);
                            RTCT++;
                            break;

                        case "End":
                            sr.Close();
                            return(true);
                        }
                    } while (true);
                }
                catch (System.Exception X)
                {
                    sr.Close();
                    System.Windows.Forms.MessageBox.Show("File Read Failed...", String.Format("Results file was corrupt or incomplete. We apologize for this inconvenience. Please report this to the software author. It will be much appreciated. \r\n Exception Message: {0}. \r\n Method: {1}", X.Message, X.TargetSite));
                    return(false);
                }
            }
コード例 #36
0
 public override double Rho_C(Hare.Geometry.Point pt)
 {
     return(Zmed);
 }
コード例 #37
0
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(string path, ref PachMapReceiver[] Map)
            {
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(path, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();

                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir")
                {
                    throw new Exception("Map Data File Expected");
                }
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev     = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct = 1;

                Hare.Geometry.Topology Map_Mesh = new Hare.Geometry.Topology();
                Map    = new PachMapReceiver[1];
                Map[0] = new PachMapReceiver();
                //double[] Rho_C = null;

                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                    case "Version":
                        //Pach1.7 = Versioning functionality added.
                        string v = sr.ReadString();
                        version = double.Parse(v.Substring(0, 3));
                        rev     = int.Parse(v.Split(new char[1] {
                            '.'
                        })[3]);
                        break;

                    case "Mesh Information":
                        //6. Announce Mesh Vertices (string)
                        //Write the number of vertices & faces (int) (int)
                        if (sr.ReadString() != "Mesh Vertices")
                        {
                            throw new Exception("Mesh Vertices Expected");
                        }

                        int VC = (int)sr.ReadUInt32();
                        int FC = (int)sr.ReadUInt32();

                        Hare.Geometry.Point[] Vertices = new Hare.Geometry.Point[VC];

                        for (int i = 0; i < VC; i++)
                        {
                            //Write Vertex: (double) (double) (double)
                            //Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                            Vertices[i] = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                        }

                        //7. Announce Mesh Faces (string)
                        if (sr.ReadString() != "Mesh Faces")
                        {
                            throw new Exception("Mesh Faces Expected");
                        }

                        Hare.Geometry.Point[][] Polys = new Hare.Geometry.Point[FC][];
                        for (int i = 0; i < FC; i++)
                        {
                            // Write mesh vertex indices: (int) (int) (int) (int)
                            int F0 = (int)sr.ReadUInt32(), F1 = (int)sr.ReadUInt32(), F2 = (int)sr.ReadUInt32(), F3 = (int)sr.ReadUInt32();

                            if (F2 == F3)
                            {
                                Polys[i] = new Hare.Geometry.Point[3] {
                                    Vertices[F0], Vertices[F1], Vertices[F2]
                                }
                            }
                            ;                                                                                                  // Map_Mesh.Faces.AddFace(F0, F1, f2);
                            else
                            {
                                Polys[i] = new Hare.Geometry.Point[4] {
                                    Vertices[F0], Vertices[F1], Vertices[F2], Vertices[F3]
                                }
                            };                                                                                                        //Map_Mesh.Faces.AddFace(F0, F1, f2, F3);
                        }

                        Map_Mesh = new Hare.Geometry.Topology(Polys);
                        break;

                    case "Sources":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                        }
                        break;

                    case "SourceswLoc":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].Src        = new Hare.Geometry.Point(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                        }
                        break;

                    case "Receiver Hit Data":
                        if (Map[0] == null)
                        {
                            Map               = new PachMapReceiver[1];
                            Map[0]            = new PachMapReceiver();
                            Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[0].SampleRate = SampleRate;
                            Map[0].SampleCT   = SampleCT;
                            Map[0].Map_Mesh   = Map_Mesh;
                            Map[0].Rec_List   = new PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[0].SrcType    = "Geodesic";
                        }

                        //8. Announce that the following data pertains to the receiver histograms (string)
                        //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                        bool vert_Receiver = sr.ReadBoolean();
                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s].Rec_Vertex = vert_Receiver;
                            for (int i = 0; i < Map[s].Rec_List.Length; i++)
                            {
                                //for version 1.7 and up, write direct sound arrival time.
                                //Write Receiver Index (int)
                                int j = (int)sr.ReadUInt32();
                                //Write Direct Sound Arrival Time.
                                double Direct_Time;
                                if (version >= 1.7)
                                {
                                    Direct_Time = sr.ReadDouble();
                                }
                                else
                                {
                                    Direct_Time = (Map[s].Src - Map[s].Rec_List[i].Origin).Length() / 343f;
                                }
                                //Write Impedance of Air
                                double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                if (vert_Receiver)
                                {
                                    Map[s].Rec_List[i] = new PachMapReceiver.Map_Receiver(Map_Mesh[i], Map[s].Src, Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }
                                else
                                {
                                    Hare.Geometry.Point RecLoc = Map_Mesh.Polys[i].Points[0] + Map_Mesh.Polys[i].Points[1] + Map_Mesh.Polys[i].Points[2];
                                    if (Map_Mesh.Polys[i].VertextCT > 3)
                                    {
                                        RecLoc += Map_Mesh.Polys[i].Points[3];
                                        RecLoc /= 4;
                                    }
                                    else
                                    {
                                        RecLoc /= 3;
                                    }
                                    Map[s].Rec_List[i] = new PachMapReceiver.Map_Receiver(RecLoc, Map[s].Src, Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }

                                for (int Octave = 0; Octave < 8; Octave++)
                                {
                                    //Write Octave (int)
                                    int Oct_out = (int)sr.ReadUInt32();
                                    if (Oct_out != Octave)
                                    {
                                        throw new Exception(string.Format("Octave {0} Expected", Octave));
                                    }
                                    double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                    if (Directional)
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                    }
                                }
                                if (sr.ReadString() != "End_Receiver_Hits")
                                {
                                    throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                        }
                        break;

                    case "End_of_File":
                        sr.Close();
                        return(true);
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }
コード例 #38
0
            public override void AttenuationFilter(int no_of_elements, int sample_Frequency, double distance_meters, ref double[] Freq, ref double[] Atten, Hare.Geometry.Point pt)
            {
                double df = sample_Frequency / no_of_elements;
                int    X  = (int)Math.Floor((pt.x - MinX) / VdimX);
                int    Y  = (int)Math.Floor((pt.y - MinY) / VdimY);
                int    Z  = (int)Math.Floor((pt.z - MinZ) / VdimZ);

                for (int i = 0; i < no_of_elements; i++)
                {
                    Freq[i]  = df * (i + 1);
                    Atten[i] = Math.Exp(-.1151 * this.Spectrum[XYTot * Z + Ydom * X + Y].Interpolate(Freq[i]) * distance_meters);
                }
            }
コード例 #39
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();
            }
コード例 #40
0
            public bool Source(out Environment.Source[] S)
            {
                S = new Environment.Source[0];
                System.Guid[] S_ID = SourceConduit.Instance.UUID.ToArray();
                S = new Environment.Source[S_ID.Length];
                for (int id = 0; id < S_ID.Length; id++)
                {
                    if (S_ID[id] == System.Guid.Empty || S_ID[id] == System.Guid.NewGuid())
                    {
                        break;
                    }
                    Rhino.DocObjects.RhinoObject Origin = Rhino.RhinoDoc.ActiveDoc.Objects.Find(S_ID[id]);

                    if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Point)
                    {
                        string S_Type = Origin.Geometry.GetUserString("SourceType");
                        string SWL    = Origin.Geometry.GetUserString("SWL");
                        string D      = Origin.Geometry.GetUserString("Delay");
                        double delay; if (D != "" && D != null)
                        {
                            delay = double.Parse(D) / 1000;
                        }
                        else
                        {
                            delay = 0;
                        }

                        string Ph = Origin.Geometry.GetUserString("Phase");
                        //double[] phase = new double[8];
                        //if (Ph != "")
                        //{
                        //    string[] phstr = Ph.Split(";"[0]);
                        //    for (int o = 0; o < 8; o++) phase[o] = double.Parse(phstr[o]);
                        //}

                        double[] SWL_Values = Utilities.PachTools.DecodeSourcePower(SWL);
                        switch (S_Type)
                        {
                        case "":
                        case "0":
                            S[id] = new Environment.GeodesicSource(SWL_Values, Utilities.RC_PachTools.RPttoHPt(Origin.Geometry.GetBoundingBox(true).Min), id);
                            break;

                        case "1":
                            S[id] = new Environment.RandomSource(SWL_Values, Utilities.RC_PachTools.RPttoHPt(Origin.Geometry.GetBoundingBox(true).Min), id);
                            break;

                        case "2":
                        case "3":
                            string   Bands = Origin.Geometry.GetUserString("Bands");
                            string[] B;
                            if (Bands != "")
                            {
                                B = Bands.Split(';');
                            }
                            else
                            {
                                B = new string[2] {
                                    "0", "7"
                                }
                            };
                            SourceConduit SC = SourceConduit.Instance;
                            S[id] = new Environment.DirectionalSource(SC.m_Balloons[id], SWL_Values, Utilities.RC_PachTools.RPttoHPt(Origin.Geometry.GetBoundingBox(true).Min), new int[] { int.Parse(B[0]), int.Parse(B[1]) }, id);
                            break;
                        }
                    }
                    else if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Brep)
                    {
                        //string SWL = Origin.Geometry.GetUserString("SWL");

                        //string Ph = Origin.Geometry.GetUserString("Phase");
                        //double[] phase = new double[8];
                        //if (Ph != "")
                        //{
                        //    string[] phstr = Ph.Split(";"[0]);
                        //    for (int o = 0; o < 8; o++) phase[o] = double.Parse(phstr[o]);
                        //}
                        //double el_m;
                        //double area = Brep.GetArea();
                        //Hare.Geometry.Topology t = new Hare.Geometry.Topology();
                        //Hare.Geometry.Point Samples;
                        ////TODO: develope discretization of surface
                        ////new Brep[] { (Origin.Geometry as Brep) };

                        //S[id] = new Environment.SurfaceSource(Samples, t, SWL, area, el_m, id, Environment.Source.Phase_Regime.Random);
                    }
                    else if (Origin.ObjectType == Rhino.DocObjects.ObjectType.Curve)
                    {
                        string SWL = Origin.Geometry.GetUserString("SWL");

                        //string Ph = Origin.Geometry.GetUserString("Phase");
                        //double[] phase = new double[8];
                        //if (Ph != "")
                        //{
                        //    string[] phstr = Ph.Split(";"[0]);
                        //    for (int o = 0; o < 8; o++) phase[o] = double.Parse(phstr[o]);
                        //}

                        Rhino.Geometry.Point3d[] pts = (Origin.Geometry as Curve).DivideEquidistant(1d / 4d);
                        if (pts == null || pts.Length == 0)
                        {
                            pts = new Point3d[1] {
                                (Origin.Geometry as Curve).PointAtNormalizedLength(0.5)
                            }
                        }
                        ;
                        Hare.Geometry.Point[] Samples = new Hare.Geometry.Point[pts.Length];

                        for (int i = 0; i < pts.Length; i++)
                        {
                            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(pts[i]);
                            Samples[i] = Utilities.RC_PachTools.RPttoHPt(pts[i]);
                        }
                        S[id] = new Environment.LineSource(Samples, (Origin.Geometry as Curve).GetLength(), SWL, 4, id);
                    }
                }
                if (S.Length > 0)
                {
                    return(true);
                }
                return(false);
            }
コード例 #41
0
 public override Point3d ClosestPt(Point3d P, ref double Dist)
 {
     Hare.Geometry.Point PH = new Hare.Geometry.Point(P.X, P.Y, P.Z);
     PH = ClosestPt(PH, ref Dist);
     return new Point3d(PH.x, PH.y, PH.z);
 }
コード例 #42
0
 public Acoustic_Compact_FDTD_RC(Environment.Polygon_Scene Rm_in, ref Signal_Driver_Compact S_in, ref Microphone_Compact M_in, double fmax_in, double tmax_in, GridType GT, Hare.Geometry.Point SampleOrigin, double MindimX, double MindimY, double MindimZ)
     : base(Rm_in, ref S_in, ref M_in, fmax_in, tmax_in, GridType.Freefield, SampleOrigin, MindimX, MindimY, MindimZ)
 {
     Build_Mesh_Sections();
 }
            public static Complex[][] Finite_Radiation_Impedance_Rect_Longhand(double x, double y, Rhino.Geometry.Brep S, double freq, double[] altitude, double[] azimuth, double C_Sound)
            {
                Complex[][] Zr = new Complex[altitude.Length][];
                double lambda = C_Sound / freq;
                double step = lambda / 30;
                double A = Rhino.Geometry.AreaMassProperties.Compute(S).Area;
                Rhino.Geometry.MeshingParameters MP = new Rhino.Geometry.MeshingParameters();
                MP.MaximumEdgeLength = step;
                Rhino.Geometry.Mesh M = Rhino.Geometry.Mesh.CreateFromBrep(S, MP)[0];

                Complex integral_Mod = Complex.ImaginaryOne * Utilities.Numerics.PiX2 * freq * 1.2 / A;
                List<double> Areas = new List<double>();
                List<Rhino.Geometry.Point3d> pts = new List<Rhino.Geometry.Point3d>();
                for (int f = 0; f < M.Faces.Count; f++)
                {
                    if (M.Faces[f].IsQuad)
                    {
                        Hare.Geometry.Point[][] verts = new Hare.Geometry.Point[1][];
                        verts[0] = new Hare.Geometry.Point[]{
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].A].X, M.Vertices[M.Faces[f].A].Y, M.Vertices[M.Faces[f].A].Z),
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].B].X, M.Vertices[M.Faces[f].B].Y, M.Vertices[M.Faces[f].B].Z),
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].C].X, M.Vertices[M.Faces[f].C].Y, M.Vertices[M.Faces[f].C].Z),
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].D].X, M.Vertices[M.Faces[f].D].Y, M.Vertices[M.Faces[f].D].Z)};
                        Areas.Add(new Hare.Geometry.Topology(verts).Polygon_Area(0));
                    }
                    else
                    {
                        Hare.Geometry.Point[][] verts = new Hare.Geometry.Point[1][];
                        verts[0] = new Hare.Geometry.Point[]{
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].A].X, M.Vertices[M.Faces[f].A].Y, M.Vertices[M.Faces[f].A].Z),
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].B].X, M.Vertices[M.Faces[f].B].Y, M.Vertices[M.Faces[f].B].Z),
                            new Hare.Geometry.Point(M.Vertices[M.Faces[f].C].X, M.Vertices[M.Faces[f].C].Y, M.Vertices[M.Faces[f].C].Z)};
                        Areas.Add(new Hare.Geometry.Topology(verts).Polygon_Area(0));
                    }

                    pts.Add(M.Faces.GetFaceCenter(f));
                }

                Parallel.For(0, altitude.Length, j =>
                {
                    double k = Utilities.Numerics.PiX2 / C_Sound;
                    double kt = k * Math.Sin(Math.Abs(altitude[j]) * Math.PI / 180);
                    Zr[j] = new Complex[azimuth.Length];
                    for (int phi = 0; phi < azimuth.Length; phi++) //Parallel.For(0, 16, phi =>
                        {
                        double cosphi = Math.Cos(azimuth[phi] * Math.PI / 180), sinphi = Math.Sin(azimuth[phi] * Math.PI / 180);
                        for (int i = 0; i < pts.Count; i++)
                        {
                            double xd = pts[i].X - x, yd = pts[i].Y - y;
                            double R = Math.Sqrt(xd * xd + yd * yd);
                            Complex GMM = Complex.Exp(-Complex.ImaginaryOne * k * freq * R) / (Utilities.Numerics.PiX2 * R);
                            Complex PiMPiM0 = Complex.Exp(Complex.ImaginaryOne * kt * freq * (cosphi * xd + sinphi * yd));
                            Zr[j][phi] += GMM * PiMPiM0 * Areas[i];
                        }
                            ///By distributive property, all multipliers moved to outer loop.
                            Zr[j][phi] *= integral_Mod;
                            //Zr[j][35 - phi] = Zr[j][phi];
                            ///this is now Zr for a given angle theta.
                        }
                });

                return Zr;
            }