private void Calculate_Click(object sender, System.EventArgs e)
            {
                FC = new ForCall(Forw_proc);

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

                if (P == null) P = new WaveConduit(scale, new double[2] { (double)this.Param_Min.Value, (double)this.Param_Max.Value });
                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = new Rhino.Geometry.Point3d[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, PachTools.GetSource());
                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);

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

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

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

                if (Map_Planes.Items.Count == 0)
                {
                    Pos_Select.Value = Pos_Select.Maximum / 2;
                    AddPlane_Click(new object(), new EventArgs());
                }

                Loop_Click(new object(), new EventArgs());
            }
            private void OpenDataToolStripMenuItem_Click(object sender, EventArgs e)
            {
                PachMapReceiver[] RT_IN = new PachMapReceiver[0];
                if (!Utilities.FileIO.Read_pachm(ref RT_IN))
                {
                    return;
                }
                //foreach (PachMapReceiver p in RT_IN) p.Correction(80000);

                Map = RT_IN;
                SourceList.Items.Clear();
                for (int i = 0; i < Map.Length; i++)
                {
                    SourceList.Items.Add(String.Format("S{0}-", i) + Map[i].SrcType);
                }

                WC = new WaveConduit(c_scale, new double[] { Current_SPLMin, Current_SPLMax });
            }
            private void Preview_Click(object sender, EventArgs e)
            {
                Loop.Enabled       = false;
                ForwButton.Enabled = false;
                BackButton.Enabled = false;
                PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance;

                if (PreviewDisplay != null)
                {
                    PreviewDisplay.Enabled = false;
                }

                max = (int)(Frame_Rate.Value * Seconds.Value);

                Point3d[] SPT;

                if (!plugin.SourceOrigin(out SPT))
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                    return;
                }

                if (T != null && T.ThreadState == System.Threading.ThreadState.Running)
                {
                    T.Abort();
                }
                PreviewDisplay = null;

                Pach_GetModel_Command Model = Pach_GetModel_Command.Instance;

                if (object.ReferenceEquals(RoomSelection.SelectedItem, "Use Entire Model"))
                {
                    Model.Rel_Humidity = 50;   //(double)Rel_Humidity.Value;
                    Model.Air_Temp     = (double)Air_Temp.Value;
                    Model.Atm_pressure = 1000; //(double)Air_Pressure.Value;
                    Model.Atten_Choice = 0;    //Atten_Method.SelectedIndex;
                    Rhino.RhinoApp.RunScript("GetModel", false);
                }

                plugin.Source(out Source);

                if (MeshWave)
                {
                    for (int i = 0; i < Source.Length; i++)
                    {
                        Source[i] = new GeodesicMeshSource(plugin.GetSourceSWL(i), Source[i].Origin(), (int)RT_Count.Value, i);
                    }
                }

                ParticleRays[] RTParticles = new ParticleRays[Source.Length];
                List <Point3d> L           = new List <Point3d>();

                for (int i = 0; i < Source.Length; i++)
                {
                    L.Add(Source[i].Origin());
                }
                for (int j = 0; j < Source.Length; j++)
                {
                    if (plugin.Geometry_Spec() == 0)
                    {
                        Model.Ret_NURBS_Scene.partition(L);
                        RTParticles[j] = new ParticleRays(Source[j], Model.Ret_NURBS_Scene, (int)RT_Count.Value, CutOffLength());
                    }
                    else
                    {
                        Model.Ret_Mesh_Scene.partition(L);
                        RTParticles[j] = new ParticleRays(Source[j], Model.Ret_Mesh_Scene, (int)RT_Count.Value, CutOffLength());
                    }

                    RTParticles[j].Begin();
                }

                PreviewDisplay = new WaveConduit(RTParticles, scale, new double[2] {
                    (double)Param_Min.Value, (double)Param_Max.Value
                }, Model.Ret_Mesh_Scene);
                ForwButton.Enabled = true;
                BackButton.Enabled = true;
                Loop.Enabled       = true;
                Loop.Text          = "Stop";
                FC = new ForCall(Forw_proc);
                System.Threading.ParameterizedThreadStart St = new System.Threading.ParameterizedThreadStart(delegate { LoopStart((int)(this.Frame_Rate.Value * Seconds.Value)); });
                T = new System.Threading.Thread(St);
                T.Start();
            }
            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 Calculate_Click(object sender, System.EventArgs e)
            {
                PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance;
                string SavePath = null;

                if (plugin.Save_Results())
                {
                    SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog();
                    sf.DefaultExt = ".pachm";
                    sf.AddExtension = true;
                    sf.Filter = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
                    if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        SavePath = sf.FileName;
                    }
                }

                SourceList.Items.Clear();
                Map = null;
                System.Threading.Thread.Sleep(500);
                PachydermAc_PlugIn p = PachydermAc_PlugIn.Instance;
                Pach_RunSim_Command command = Pach_RunSim_Command.Instance;
                
                if (!p.Source(out Source) || Rec_Srfs == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                    return;
                }

                Point3d[] SPT;
                plugin.SourceOrigin(out SPT);
                Calculate.Enabled = false;
                List<Point3d> P = new List<Point3d>();
                P.AddRange(SPT);

                Polygon_Scene PScene = Utilities.PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                if (!PScene.Complete)
                {
                    Calculate.Enabled = true;
                    return;
                }
                WC = new WaveConduit(c_scale, new double[] { Current_SPLMin, Current_SPLMax });

                PScene.partition(P);
                Scene Flex_Scene;
                if (PachydermAc_PlugIn.Instance.Geometry_Spec() == 0) 
                {
                    RhCommon_Scene NScene = Utilities.PachTools.Get_NURBS_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                    if (!NScene.Complete) return;
                    NScene.partition(P, plugin.VG_Domain());
                    Flex_Scene = NScene;
                } 
                else
                {
                    Flex_Scene = PScene;    
                }

                Map = new PachMapReceiver[Source.Length];
                for (int i = 0; i < Source.Length; i++)
                {
                    Source[i].AppendPts(ref P);
                    Map[i] = new PachMapReceiver(Rec_Srfs, Source[i], 1000, (double)Increment.Value * 0.01, Flex_Scene, (int)RT_Count.Value, (double)CO_TIME.Value, Disp_Audience.Checked, Sum_Time.Checked, DirectionalToggle.Checked, Rec_Vertex.Checked, Offset_Mesh.Checked);
                }

                for (int s_id = 0; s_id < Source.Length; s_id++)
                {
                    command.Sim = new Direct_Sound(Source[s_id], Map[s_id], PScene, new int[8]{0,1,2,3,4,5,6,7});
                    Rhino.RhinoApp.RunScript("Run_Simulation", false);

                    Direct_Sound Direct_Data;
                    if (command.CommandResult != Rhino.Commands.Result.Cancel)
                    {
                        Direct_Data = ((Direct_Sound)command.Sim);
                    }
                    else
                    {
                        Array.Resize(ref Source, s_id);
                        Array.Resize(ref Map, s_id);
                        command.Reset();
                        Calculate.Enabled = true;
                        break;
                    }
                    command.Reset();

                    command.Sim = new SplitRayTracer(Source[s_id], Map[s_id], Flex_Scene, CutOffLength(), (int)RT_Count.Value, 0);

                    Rhino.RhinoApp.RunScript("Run_Simulation", false);

                    if (command.CommandResult == Rhino.Commands.Result.Success)
                    {
                        Map[s_id] = (PachMapReceiver)((SplitRayTracer)command.Sim).GetReceiver;
                    }
                    else
                    {
                        Array.Resize(ref Source, s_id);
                        Array.Resize(ref Map, s_id);
                        command.Reset();
                        Calculate.Enabled = true;
                        break;
                    }
                    command.Reset();
                    Map[s_id].AddDirect(Direct_Data, Source[s_id]);
                }

                if (Source != null)
                {
                    foreach (Source S in Source)
                    {
                        SourceList.Items.Add(String.Format("S{0}-", S.Source_ID()) + S.Type());
                    }

                    if (SavePath != null) Utilities.FileIO.Write_pachm(SavePath, Map);
                }

                if (Map != null)
                {
                    Create_Map(false);
                }

                Rhino.RhinoApp.WriteLine("Calculation has been completed. Have a nice day!");

                ///////
                //for(int i = 0;i < 10000; i++) Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(((Source[0] as LineSource).D as LineSource.ANCON).Pt[i]);
                ///////
                Calculate.Enabled = true;
            }
예제 #6
0
            private void Calculate_Click(object sender, System.EventArgs e)
            {
                PachydermAc_PlugIn plugin   = PachydermAc_PlugIn.Instance;
                string             SavePath = null;

                if (plugin.Save_Results())
                {
                    SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog();
                    sf.DefaultExt   = ".pachm";
                    sf.AddExtension = true;
                    sf.Filter       = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
                    if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        SavePath = sf.FileName;
                    }
                }

                SourceList.Items.Clear();
                Map = null;
                System.Threading.Thread.Sleep(500);
                PachydermAc_PlugIn  p       = PachydermAc_PlugIn.Instance;
                Pach_RunSim_Command command = Pach_RunSim_Command.Instance;

                if (!p.Source(out Source) || Rec_Srfs == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                    return;
                }

                Point3d[] SPT;
                plugin.SourceOrigin(out SPT);
                Calculate.Enabled = false;
                List <Point3d> P = new List <Point3d>();

                P.AddRange(SPT);

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

                if (!PScene.Complete)
                {
                    Calculate.Enabled = true;
                    return;
                }
                WC = new WaveConduit(c_scale, new double[] { Current_SPLMin, Current_SPLMax });

                PScene.partition(P);
                Scene Flex_Scene;

                if (PachydermAc_PlugIn.Instance.Geometry_Spec() == 0)
                {
                    RhCommon_Scene NScene = Utilities.PachTools.Get_NURBS_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                    if (!NScene.Complete)
                    {
                        return;
                    }
                    NScene.partition(P, plugin.VG_Domain());
                    Flex_Scene = NScene;
                }
                else
                {
                    Flex_Scene = PScene;
                }

                Map = new PachMapReceiver[Source.Length];
                for (int i = 0; i < Source.Length; i++)
                {
                    Source[i].AppendPts(ref P);
                    Map[i] = new PachMapReceiver(Rec_Srfs, Source[i], 1000, (double)Increment.Value * 0.01, Flex_Scene, (int)RT_Count.Value, (double)CO_TIME.Value, Disp_Audience.Checked, Sum_Time.Checked, DirectionalToggle.Checked, Rec_Vertex.Checked, Offset_Mesh.Checked);
                }

                for (int s_id = 0; s_id < Source.Length; s_id++)
                {
                    command.Sim = new Direct_Sound(Source[s_id], Map[s_id], PScene, new int[8] {
                        0, 1, 2, 3, 4, 5, 6, 7
                    });
                    Rhino.RhinoApp.RunScript("Run_Simulation", false);

                    Direct_Sound Direct_Data;
                    if (command.CommandResult != Rhino.Commands.Result.Cancel)
                    {
                        Direct_Data = ((Direct_Sound)command.Sim);
                    }
                    else
                    {
                        Array.Resize(ref Source, s_id);
                        Array.Resize(ref Map, s_id);
                        command.Reset();
                        Calculate.Enabled = true;
                        break;
                    }
                    command.Reset();

                    command.Sim = new SplitRayTracer(Source[s_id], Map[s_id], Flex_Scene, CutOffLength(), (int)RT_Count.Value, 0);

                    Rhino.RhinoApp.RunScript("Run_Simulation", false);

                    if (command.CommandResult == Rhino.Commands.Result.Success)
                    {
                        Map[s_id] = (PachMapReceiver)((SplitRayTracer)command.Sim).GetReceiver;
                    }
                    else
                    {
                        Array.Resize(ref Source, s_id);
                        Array.Resize(ref Map, s_id);
                        command.Reset();
                        Calculate.Enabled = true;
                        break;
                    }
                    command.Reset();
                    Map[s_id].AddDirect(Direct_Data, Source[s_id]);
                }

                if (Source != null)
                {
                    foreach (Source S in Source)
                    {
                        SourceList.Items.Add(String.Format("S{0}-", S.Source_ID()) + S.Type());
                    }

                    if (SavePath != null)
                    {
                        Utilities.FileIO.Write_pachm(SavePath, ref Map);
                    }
                }

                if (Map != null)
                {
                    Create_Map(false);
                }

                Rhino.RhinoApp.WriteLine("Calculation has been completed. Have a nice day!");

                ///////
                //for(int i = 0;i < 10000; i++) Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(((Source[0] as LineSource).D as LineSource.ANCON).Pt[i]);
                ///////
                Calculate.Enabled = true;
            }
            private void Preview_Click(object sender, EventArgs e)
            {
                Loop.Enabled = false;
                ForwButton.Enabled = false;
                BackButton.Enabled = false;
                PachydermAc_PlugIn plugin = PachydermAc_PlugIn.Instance;

                if (PreviewDisplay != null) PreviewDisplay.Enabled = false;

                max = (int)(Frame_Rate.Value * Seconds.Value);

                Point3d[] SPT;

                if (!plugin.SourceOrigin(out SPT))
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                    return;
                }

                if (T != null && T.ThreadState == System.Threading.ThreadState.Running) T.Abort();
                PreviewDisplay = null;

                Pach_GetModel_Command Model = Pach_GetModel_Command.Instance;
                if (object.ReferenceEquals(RoomSelection.SelectedItem, "Use Entire Model"))
                {
                    Model.Rel_Humidity = 50;//(double)Rel_Humidity.Value;
                    Model.Air_Temp = (double)Air_Temp.Value;
                    Model.Atm_pressure = 1000;//(double)Air_Pressure.Value;
                    Model.Atten_Choice = 0;//Atten_Method.SelectedIndex;
                    Rhino.RhinoApp.RunScript("GetModel", false);
                }

                plugin.Source(out Source);

                if (MeshWave)
                {
                    for (int i = 0; i < Source.Length; i++) Source[i] = new GeodesicMeshSource(plugin.GetSourceSWL(i), Source[i].Origin(), (int)RT_Count.Value, i);
                }

                ParticleRays[] RTParticles = new ParticleRays[Source.Length];
                List<Point3d> L = new List<Point3d>();
                for (int i = 0; i < Source.Length; i++)
                {
                    L.Add(Source[i].Origin());
                }
                for (int j = 0; j < Source.Length; j++)
                {
                    if (plugin.Geometry_Spec() == 0)
                    {
                        Model.Ret_NURBS_Scene.partition(L);
                        RTParticles[j] = new ParticleRays(Source[j], Model.Ret_NURBS_Scene, (int)RT_Count.Value, CutOffLength());
                    }
                    else
                    {
                        Model.Ret_Mesh_Scene.partition(L);
                        RTParticles[j] = new ParticleRays(Source[j], Model.Ret_Mesh_Scene, (int)RT_Count.Value, CutOffLength());
                    }

                    RTParticles[j].Begin();
                }

                PreviewDisplay = new WaveConduit(RTParticles, scale, new double[2] { (double)Param_Min.Value, (double)Param_Max.Value }, Model.Ret_Mesh_Scene);
                ForwButton.Enabled = true;
                BackButton.Enabled = true;
                Loop.Enabled = true;
                Loop.Text = "Stop";
                FC = new ForCall(Forw_proc);
                System.Threading.ParameterizedThreadStart St = new System.Threading.ParameterizedThreadStart(delegate { LoopStart((int)(this.Frame_Rate.Value * Seconds.Value)); });
                T = new System.Threading.Thread(St);
                T.Start();
            }