///<summary> This gets called when when the user runs this command.</summary> protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { SourceConduit m_source_conduit = SourceConduit.Instance; Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject(); GO.SetCommandPrompt("Select source curve..."); GO.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; GO.AddOption("TrafficWelsh"); GO.AddOption("TrafficFHWA"); GO.AddOption("AircraftANCON"); GO.AddOption("Custom"); //GO.AddOptionList("SourceType", new List<string>() { "TrafficWelshStandard", "TrafficFHWA Standard", "Custom" }, 2); GO.GroupSelect = false; GO.SubObjectSelect = false; GO.EnableClearObjectsOnEntry(false); GO.EnableUnselectObjectsOnExit(false); GO.DeselectAllBeforePostSelect = false; int pavement = 0; double SPLW = 0; double[] SWL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 }; double velocity = 83; double delta = 45; double choice = 0; for (; ; ) { Rhino.Input.GetResult GR = GO.GetMultiple(1, 1); int type = GO.OptionIndex(); if (GR == Rhino.Input.GetResult.Option) { choice = (int)type; //type = GO.Option().EnglishName; if (type == 1)//"Traffic (Welsh Standard)") { Rhino.Input.RhinoGet.GetNumber("Input basis road sound pressure level at 1 m from street...", false, ref SPLW); SPLW += 8; } else if (type == 2)//"Traffic (FHWA Standard)") { ///Described at: ///http://www.fhwa.dot.gov/environment/noise/traffic_noise_model/old_versions/tnm_version_10/tech_manual/tnm03.cfm#tnma2 double s = 0; //int i = 0; Rhino.Input.RhinoGet.GetNumber("Enter the speed of traffic on this road (in kph)...", false, ref s); ///Pavement Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption(); GOpt.SetCommandPrompt("Pavement type..."); GOpt.AddOption("Average_DGAC_PCC)"); GOpt.AddOption("DGAC_Asphalt"); GOpt.AddOption("PCC_Concrete"); GOpt.AddOption("OGAC_OpenGradedAsphalt"); GOpt.AcceptNothing(false); GOpt.Get(); pavement = GOpt.OptionIndex(); ///Vehicle tallies double[] Veh = new double[5] { 0, 0, 0, 0, 0 }; Rhino.Input.RhinoGet.GetNumber("Enter the number of automobiles per hour...", false, ref Veh[0]); Rhino.Input.RhinoGet.GetNumber("Enter the number of medium trucks per hour...", false, ref Veh[1]); Rhino.Input.RhinoGet.GetNumber("Enter the number of heavy trucks per hour...", false, ref Veh[2]); Rhino.Input.RhinoGet.GetNumber("Enter the number of buses per hour...", false, ref Veh[3]); Rhino.Input.RhinoGet.GetNumber("Enter the number of motorcycles per hour...", false, ref Veh[4]); bool throttle = false; int t = 0; Rhino.Input.RhinoGet.GetBool("Full throttle?", false, "Yes", "No", ref throttle); t = (throttle) ? 1 : 0; double root2 = Math.Sqrt(2); double vtot = 0; double[] Es = new double[8] { 0, 0, 0, 0, 0, 0, 0, 0 }; for (int v = 0; v < 5; v++) { double A = FHWATraffic[v][pavement][t][0]; double B = FHWATraffic[v][pavement][t][1]; double C = FHWATraffic[v][pavement][t][2]; double D1 = FHWATraffic[v][pavement][t][3]; double D2 = FHWATraffic[v][pavement][t][4]; double E1 = FHWATraffic[v][pavement][t][5]; double E2 = FHWATraffic[v][pavement][t][6]; double F1 = FHWATraffic[v][pavement][t][7]; double F2 = FHWATraffic[v][pavement][t][8]; double G1 = FHWATraffic[v][pavement][t][9]; double G2 = FHWATraffic[v][pavement][t][10]; double H1 = FHWATraffic[v][pavement][t][11]; double H2 = FHWATraffic[v][pavement][t][12]; double I1 = FHWATraffic[v][pavement][t][13]; double I2 = FHWATraffic[v][pavement][t][14]; double J1 = FHWATraffic[v][pavement][t][15]; double J2 = FHWATraffic[v][pavement][t][16]; vtot += Veh[v]; for (int oct = 0; oct < 8; oct++) { double f = 62.5 * Math.Pow(2, oct); double[] freq = new double[3] { f / root2, f, f * root2 }; for (int oct3 = 0; oct3 < 3; oct3++) { double Ea = Math.Pow(0.6214 * s, A / 10) * Math.Pow(10, B / 10) + Math.Pow(10, C / 10); double logf = Math.Log10(freq[oct3]); double Ls = 10 * Math.Log10(Ea) + (D1 + 0.6214 * D2 * s) + (E1 + 0.6214 * E2 * s) * logf + (F1 + 0.6214 * F2 * s) * logf * logf + (G1 + 0.6214 * G2 * s) * logf * logf * logf + (H1 + 0.6214 * H2 * s) * logf * logf * logf * logf + (I1 + 0.6214 * I2 * s) * logf * logf * logf * logf * logf + (J1 + 0.6214 * J2 * s) * logf * logf * logf * logf * logf * logf; Es[oct] += 0.0476 * Math.Pow(10, Ls / 10) * Veh[v] / s; } } } double[] Awt = new double[8] { -26, -16, -9, -3, 0, 1.2, 1, -1 }; double dmod = 10 * Math.Log10(1 / (Utilities.Numerics.PiX2 * 15)); for (int oct = 0; oct < 8; oct++) { SWL[oct] = 10 * Math.Log10(Es[oct]) - Awt[oct] - dmod;// } } else if (type == 3)//"Aircraft (ANCON-derived)") { Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption(); GOpt.SetCommandPrompt("Takeoff or Landing?"); GOpt.AddOption("Takeoff"); GOpt.AddOption("Landing"); GOpt.AddOption("Both"); GOpt.AcceptNothing(false); GOpt.Get(); int TL_Choice = GOpt.OptionIndex(); double SWLA = 150; Rhino.Input.RhinoGet.GetNumber("What is the broadband sound power of the aircraft (in dBA)?", false, ref SWLA); Rhino.Input.RhinoGet.GetNumber("What is the maximum velocity of the aircraft in m/s?", false, ref velocity); Rhino.Input.RhinoGet.GetNumber("What is the slant angle for this aircraft?", false, ref delta); double[][] Aircraft_Normalization = new double[3][] { //new double[8]{ -12, -10.5, -12, -15, -20, -27, -40, -44}, //new double[8]{-11, -13, -12, -13.5, -18, -21, -25, -35}, //new double[8]{-11, -10.5, -12, -13.5, -18, -21, -25, -35} new double[8] { 6.191472203, 7.691472203, 6.191472203, 3.191472203, -1.808527797, -8.808527797,-21.8085278, -25.8085278}, new double[8] { 5.6783811710, 3.6783811710, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883}, new double[8] { 5.678381171, 6.178381171, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883} }; for (int oct = 0; oct < 8; oct++) { SWL[oct] = SWLA + Aircraft_Normalization[TL_Choice-1][oct];// } } // continue; // //return Result.Success; //} } else if (GR == Rhino.Input.GetResult.Object) { for (int i = 0; i < GO.ObjectCount; i++) { Rhino.DocObjects.ObjRef obj = GO.Object(i); Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId); rhObj.Attributes.Name = "Acoustical Source"; if (choice == 1)//"Traffic (Welsh Standard)") { rhObj.Geometry.SetUserString("SourceType", "Traffic (Welsh)"); for (int oct = 0; oct < 8; oct++) SWL[oct] = SPLW + WelshTraffic[oct]; } else if (choice == 2)//"Traffic (FWHA Standard)") { rhObj.Geometry.SetUserString("SourceType", "Traffic (FHWA)"); } else if (choice == 3)//"Aircraft (ANCON-derived)") { rhObj.Geometry.SetUserString("SourceType", "Aircraft (ANCON derived)"); rhObj.Geometry.SetUserString("Velocity", velocity.ToString()); rhObj.Geometry.SetUserString("delta", delta.ToString()); } else { Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SWL[0]); Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SWL[1]); Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SWL[2]); Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SWL[3]); Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SWL[4]); Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SWL[5]); Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SWL[6]); Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SWL[7]); } rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SWL)); rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0"); doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true); m_source_conduit.SetSource(rhObj); } doc.Views.Redraw(); return Result.Success; } else return Result.Cancel; } }
///<summary> This gets called when when the user runs this command.</summary> protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { SourceConduit m_source_conduit = SourceConduit.Instance; //Rhino.DocObjects.ObjRef location; string type = "custom"; Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject(); GO.SetCommandPrompt("Select source surface..."); GO.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; GO.AddOption("Crowd"); GO.GroupSelect = false; GO.SubObjectSelect = false; GO.EnableClearObjectsOnEntry(false); GO.EnableUnselectObjectsOnExit(false); GO.DeselectAllBeforePostSelect = false; int Men = 100, Women = 100, Kids = 100, effort = 0; do { Rhino.Input.GetResult GR = GO.Get(); if (GR == Rhino.Input.GetResult.Option) { type = GO.Option().EnglishName; if (type == "Crowd") { Rhino.Input.RhinoGet.GetInteger("Number of Men in Crowd...", true, ref Men); Rhino.Input.RhinoGet.GetInteger("Number of Women in Crowd...", true, ref Women); Rhino.Input.RhinoGet.GetInteger("Number of Children in Crowd...", true, ref Kids); Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption(); GOpt.SetCommandPrompt("Speech Activity"); GOpt.AddOption("SoftOrWhispered"); GOpt.AddOption("Conversation"); GOpt.AddOption("CompetingConversation"); GOpt.AddOption("Singing"); GOpt.AddOption("AllShouting"); GOpt.AcceptNothing(false); GOpt.Get(); effort = GOpt.OptionIndex() - 1; } continue; } else if (GR == Rhino.Input.GetResult.Object) { for (int i = 0; i < GO.ObjectCount; i++) { Rhino.DocObjects.ObjRef obj = GO.Object(i); Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId); double Area = (rhObj.Geometry as Rhino.Geometry.Brep).GetArea(); rhObj.Attributes.Name = "Acoustical Source"; rhObj.Geometry.SetUserString("SourceType", ""); double[] SPL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 }; if (type == "Crowd") { //double mod = (effort < 3) ? .5 : 1; //Correct for tightly packed spaces, and competing speech. //if (Area / (Men + Women + Kids) < 3.0f) //{ // //In overcrowded scenarios, vocal effort escalates as such: // //whispering becomes conversation. // //conversation becomes competing conversation. // //competing conversation becomes shouting. // //Singing stays singing... I'm pretty sure experienced singers wouldn't start shouting... // if (effort < 2) effort++; // else effort = 4; //} for (int oct = 0; oct < 8; oct++) { double Power = Men * Math.Pow(10, Males[effort][oct] / 10) + Women * Math.Pow(10, Females[effort][oct] / 10) + Kids * Math.Pow(10, Children[effort][oct] / 10); //Power /= (Area); SPL[oct] = 10 * Math.Log10(Power) + 11; } } else { Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SPL[0]); Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SPL[1]); Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SPL[2]); Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SPL[3]); Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SPL[4]); Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SPL[5]); Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SPL[6]); Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SPL[7]); } rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SPL)); rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0"); doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true); m_source_conduit.SetSource(rhObj); } doc.Views.Redraw(); return Result.Success; } else return Result.Cancel; } while (true); }