/// <summary>
 /// Sets the material association for a layer.
 /// </summary>
 /// <param name="LayerIndex"></param>
 /// <param name="Abs">0 to 100</param>
 /// <param name="Scat">0 to 100</param>
 /// <returns></returns>
 public static bool Material_SetLayer(int LayerIndex, int[] Abs, int[] Scat, int[] Trans)
 {
     Rhino.DocObjects.Layer layer = Rhino.RhinoDoc.ActiveDoc.Layers[LayerIndex];
     layer.SetUserString("ABSType", "");
     layer.SetUserString("Acoustics", RC_PachTools.EncodeAcoustics(Abs, Scat, Trans));
     return(Rhino.RhinoDoc.ActiveDoc.Layers.Modify(layer, LayerIndex, false));
 }
            /// <summary>
            /// Sets the material association for a layer.
            /// </summary>
            /// <param name="LayerName"></param>
            /// <param name="Abs">0 to 100</param>
            /// <param name="Scat">0 to 100</param>
            /// <returns></returns>
            public static bool Material_SetLayer(string LayerName, int[] Abs, int[] Scat, int[] Trans = null)
            {
                int layer_index = Rhino.RhinoDoc.ActiveDoc.Layers.Find(LayerName, true);

                Rhino.DocObjects.Layer layer = Rhino.RhinoDoc.ActiveDoc.Layers[layer_index];
                layer.SetUserString("Acoustics", RC_PachTools.EncodeAcoustics(Abs, Scat, Trans));
                return(Rhino.RhinoDoc.ActiveDoc.Layers.Modify(layer, layer_index, false));
            }
            /// <summary>
            /// Sets materials for an object by object.
            /// </summary>
            /// <param name="ID">object GUID (UUID)</param>
            /// <param name="Abs">0 to 100</param>
            /// <param name="Scat">0 to 100</param>
            /// <param name="Trans">0 to 100</param>
            /// <returns></returns>
            public static bool Material_SetByObject(Guid ID, int[] Abs, int[] Scat, int[] Trans)
            {
                Rhino.DocObjects.RhinoObject obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(ID);
                obj.Geometry.SetUserString("Acoustics_User", "yes");
                string MaterialCode = RC_PachTools.EncodeAcoustics(Abs, Scat, Trans);
                bool   result       = obj.Geometry.SetUserString("Acoustics", MaterialCode);

                return(result);
            }
            private void Show_Field()
            {
                List <int> X = new List <int>(), Y = new List <int>(), Z = new List <int>();

                foreach (CutPlane p in Map_Planes.Items)
                {
                    if (p.axis == 0)
                    {
                        X.Add(p.pos);
                    }
                    else if (p.axis == 1)
                    {
                        Y.Add(p.pos);
                    }
                    else if (p.axis == 2)
                    {
                        Z.Add(p.pos);
                    }
                }

                List <List <Hare.Geometry.Point> > hpts = new List <List <Hare.Geometry.Point> >();

                FDTD.Pressure_Points(ref hpts, ref Pressure, X.ToArray(), Y.ToArray(), Z.ToArray(), 0.00002 * Math.Pow(10, (double)Param_Min.Value / 20), false, false, true, Magnitude.Checked);
                List <List <Rhino.Geometry.Point3d> > Pts = new List <List <Rhino.Geometry.Point3d> >();

                for (int i = 0; i < hpts.Count; i++)
                {
                    Pts.Add(new List <Rhino.Geometry.Point3d>());
                    for (int j = 0; j < hpts[i].Count; j++)
                    {
                        Pts[i].Add(RC_PachTools.HPttoRPt(hpts[i][j]));
                    }
                }

                P.Populate(X.ToArray(), Y.ToArray(), Z.ToArray(), FDTD.dx, Pressure, M, Magnitude.Checked);

                Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            }
            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);
            }
            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());
            }
            private void CalculateSim_Click(object sender, EventArgs e)
            {
                EigenFrequencies.Items.Clear();
                Chosenfreq = 0;
                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;
                }

                Hare.Geometry.Point[]      Src = RC_PachTools.GetSource();
                List <Hare.Geometry.Point> Rec = RC_PachTools.GetReceivers();

                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

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

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

                samplefrequency = FDTD.SampleFrequency;

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

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

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

                Receiver_Choice.Items.Clear();
                for (int i = 0; i < result_signals.Length; i++)
                {
                    Receiver_Choice.Items.Add(i);
                }
                Time = new double[result_signals[0].Length];
                for (int i = 0; i < Time.Length; i++)
                {
                    Time[i] = (double)i / samplefrequency;
                }
                Receiver_Choice.SelectedIndex = 0;
                Receiver_Choice.Update();
            }
Пример #8
0
            public bool RayPt(int Index, double u, int oct, out double energy, out Point3d Next, out Point3d Result)
            {
                ///TODO: Use new protocol here.

                //double energy = 1.0;
                double S_Length = 0;

                for (int q = 0; q < RayList[Index].Count - 1; q++)
                {
                    double Modifier = RayList[Index][q].DistanceTo(RayList[Index][q + 1]);
                    S_Length += Modifier;
                    //Locate which segment it is on...)
                    if (S_Length > u)
                    {
                        //energy *= Math.Pow(10,-.1 * Room.Attenuation[oct] * u) / (4 * Math.PI * u * u);
                        Point3d Point = RayList[Index].PointAt(q + ((u - (S_Length - Modifier)) / Modifier));
                        energy = Power[Index][q] * Math.Pow(10, -.1 * Room.Attenuation(RC_PachTools.RPttoHPt(Point))[oct] * (u - S_Length - Modifier) / Modifier) / (4 * Math.PI * u * u);
                        Next   = RayList[Index][q + 1];
                        Result = Point;
                        return(true);
                    }
                    if (q >= RayList[Index].SegmentCount)
                    {
                        break;
                    }
                    //energy *= Room.ReflectionValue[Poly_ID[Index][q]][oct];
                }
                energy = 0;
                Next   = default(Point3d);
                Result = default(Point3d);
                return(false);
            }
Пример #9
0
            public void Begin()
            {
                Random Rnd = new Random();

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


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

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

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

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

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

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

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

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

                Source[] Source;


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

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

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

                for (int i = 0; i < Source.Length; i++)
                {
                    if (Source != null)
                    {
                        List <Hare.Geometry.Point> L = new List <Hare.Geometry.Point>();
                        for (int j = 0; j < Source.Length; j++)
                        {
                            L.Add(Source[j].Origin());
                        }

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

                    Pachyderm_Acoustic.Visualization.Phonon P;
                    if (ParticleChoice.SelectedIndex == 0)
                    {
                        P = new Tetrahedron();
                    }
                    else if (ParticleChoice.SelectedIndex == 1)
                    {
                        P = new Icosahedron();
                    }
                    else
                    {
                        P = new Geodesic_sphere();
                    }
                    RenderParticles(RTParticles, (double)(Frame_Rate.Value * Seconds.Value), P);
                    Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                }
                Calculate.Enabled = true;
            }
Пример #11
0
            private void Forw_proc()
            {
                j++;
                if (j >= max)
                {
                    j = 0;
                    return;
                }
                if (MeshWave)
                {
                    PreviewDisplay.Populate(j * (double)CO_TIME.Value * C_Sound() / (max * 1000), RC_PachTools.Hare_to_RhinoMesh(((GeodesicMeshSource)Source[0]).T, true));
                }
                else
                {
                    PreviewDisplay.Populate(j * (double)CO_TIME.Value * C_Sound() / (max * 1000), SmartParticles);
                }
                ////////////////////////
                if (Folder_Status.Text != "")
                {
                    string number;
                    if (j < 100)
                    {
                        if (j < 10)
                        {
                            number = "00" + j.ToString();
                        }
                        else
                        {
                            number = "0" + j.ToString();
                        }
                    }
                    else
                    {
                        number = j.ToString();
                    }

                    this.Invoke((MethodInvoker) delegate { Rhino.RhinoApp.RunScript("-ViewCaptureToFile " + Folder_Status.Text + "\\"[0] + "frame" + number + ".jpg Width=1280 Height=720 DrawGrid=No Enter", true); });
                }
                /////////////////////////
                this.Invoke((MethodInvoker) delegate { Time_Preview.Text = (CO_TIME.Value * j / max).ToString(); });
                Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            }