public VoxelGrid_RC(Environment.RhCommon_Scene ModelSurfaces, List<Point3d> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List<int>[VoxelCT, VoxelCT, VoxelCT]; Voxel = new List<Point3d>[VoxelCT, VoxelCT, VoxelCT]; //for (int q = 0; q < ModelSurfaces.Objects.Count; q++) //{ // Surfaces[q] = ModelSurfaces.Objects[q].Object(); //} BoundingBox TightOBox = new BoundingBox(); Point3d BoxMin = new Point3d(); Point3d BoxMax = new Point3d(); foreach (Point3d Pt in Pts) { TightOBox.Union(Pt); } foreach (Brep B in ModelSurfaces.Breps()) { TightOBox.Union(B.GetBoundingBox(true)); } OverallBBox = new BoundingBox(new Point3d(TightOBox.Min.X - 1, TightOBox.Min.Y - 1, TightOBox.Min.Z - 1), new Point3d(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; double X_2 = X_Incr/2; double Y_2 = Y_Incr/2; double Z_2 = Z_Incr/2; Radius2 = X_2*X_2 + Y_2*Y_2 + Z_2*Z_2; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { Rhino.RhinoApp.SetCommandPrompt(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 Point3d((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 Point3d((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<Point3d>(); 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++) { BoundingBox TestBox = new BoundingBox(); TestBox = new BoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }