protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { //List<Rhino.DocObjects.RhinoObject> ObjectList = new List<Rhino.DocObjects.RhinoObject>(); Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.DeletedObjects = false; settings.HiddenObjects = false; settings.LockedObjects = true; settings.NormalObjects = true; settings.VisibleFilter = true; settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep & Rhino.DocObjects.ObjectType.Surface & Rhino.DocObjects.ObjectType.Extrusion; List<Rhino.DocObjects.RhinoObject> RC_List = new List<Rhino.DocObjects.RhinoObject>(); foreach (Rhino.DocObjects.RhinoObject RHobj in Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(settings)) { if (RHobj.ObjectType == Rhino.DocObjects.ObjectType.Brep || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Surface || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Extrusion) { RC_List.Add(RHobj); } } if (RC_List.Count != 0) { Ret_NURBS_Scene = new RhCommon_Scene(RC_List, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false); if (!Ret_NURBS_Scene.Valid) return Rhino.Commands.Result.Failure; Ret_Mesh_Scene = new Polygon_Scene(RC_List, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false); if (!Ret_Mesh_Scene.Valid) return Rhino.Commands.Result.Failure; } C_Result = Rhino.Commands.Result.Success; return Rhino.Commands.Result.Success; }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { //List<Rhino.DocObjects.RhinoObject> ObjectList = new List<Rhino.DocObjects.RhinoObject>(); Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.DeletedObjects = false; settings.HiddenObjects = false; settings.LockedObjects = true; settings.NormalObjects = true; settings.VisibleFilter = true; settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep & Rhino.DocObjects.ObjectType.Surface & Rhino.DocObjects.ObjectType.Extrusion; List <Rhino.DocObjects.RhinoObject> RC_List = new List <Rhino.DocObjects.RhinoObject>(); foreach (Rhino.DocObjects.RhinoObject RHobj in Rhino.RhinoDoc.ActiveDoc.Objects.GetObjectList(settings)) { if (RHobj.ObjectType == Rhino.DocObjects.ObjectType.Brep || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Surface || RHobj.ObjectType == Rhino.DocObjects.ObjectType.Extrusion) { RC_List.Add(RHobj); } } if (RC_List.Count != 0) { Ret_NURBS_Scene = new RhCommon_Scene(RC_List, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false); if (!Ret_NURBS_Scene.Valid) { return(Rhino.Commands.Result.Failure); } Ret_Mesh_Scene = new RhCommon_PolygonScene(RC_List, Register_Edges, Air_Temp, Rel_Humidity, Atm_pressure, Atten_Choice, Edge_Freq, false); if (!Ret_Mesh_Scene.Valid) { return(Rhino.Commands.Result.Failure); } } C_Result = Rhino.Commands.Result.Success; return(Rhino.Commands.Result.Success); }
/// <summary> /// Intesects all NURBS Surfaces with Voxels. /// </summary> /// <param name="Model">the scene.</param> /// <param name="Box">the voxel</param> /// <param name="Index">the index of the surface to test.</param> /// <returns></returns> private bool BoxIntersection(RhCommon_Scene Model, BoundingBox Box, int Index) { Point3d CP = Model.Brep(Index).ClosestPoint(Box.Center); Vector3d V = CP - Box.Center; if (V.X * V.X + V.Y * V.Y + V.Z * V.Z < Radius2) { return(true); } return(false); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List <IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List <int> [VoxelCT, VoxelCT, VoxelCT]; Voxel = new List <On3dPoint> [VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT - 1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List <On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List <int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List<IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List<int>[VoxelCT, VoxelCT, VoxelCT]; Voxel = new List<On3dPoint>[VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT-1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List<On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List<int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
/// <summary> /// Intesects all NURBS Surfaces with Voxels. /// </summary> /// <param name="Model">the scene.</param> /// <param name="Box">the voxel</param> /// <param name="Index">the index of the surface to test.</param> /// <returns></returns> private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index) { On3dPoint Center = Box.Center(); double Radius = Center.DistanceTo(Box.Min()); double s = 0; double t = 0; On3dPoint point = new On3dPoint(); if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius)) //if (Center.DistanceTo(point) < Radius) { return(true); } return(false); }
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; }
/// <summary> /// Intesects all NURBS Surfaces with Voxels. /// </summary> /// <param name="Model">the scene.</param> /// <param name="Box">the voxel</param> /// <param name="Index">the index of the surface to test.</param> /// <returns></returns> private bool BoxIntersection(RhCommon_Scene Model, BoundingBox Box, int Index) { Point3d CP = Model.Brep(Index).ClosestPoint(Box.Center); Vector3d V = CP - Box.Center; if (V.X*V.X + V.Y*V.Y + V.Z*V.Z < Radius2) { return true; } return false; }
/// <summary> /// Intesects all NURBS Surfaces with Voxels. /// </summary> /// <param name="Model">the scene.</param> /// <param name="Box">the voxel</param> /// <param name="Index">the index of the surface to test.</param> /// <returns></returns> private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index) { On3dPoint Center = Box.Center(); double Radius = Center.DistanceTo(Box.Min()); double s = 0; double t = 0; On3dPoint point = new On3dPoint(); if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius)) //if (Center.DistanceTo(point) < Radius) { return true; } return false; }