public Point3d[][] Grid_to_Boxes(Plane BasePlane, Raster3D R3D, ref double[][] BoxMs) { Voxel[, ,] Voxels = R3D.voxels; int XCount = 0; int YCount = 0; int ZCount = 0; XCount = R3D.XCount; YCount = R3D.YCount; ZCount = R3D.ZCount; int BCount = (XCount - 1) * (YCount - 1) * (ZCount - 1); Point3d[][] GBs = new Point3d[BCount][]; double[][] GMs = new double[BCount][]; int i = 0; int j = 0; int k = 0; int Counter = 0; for (k = 0; k <= ZCount - 2; k++) { for (j = 0; j <= YCount - 2; j++) { for (i = 0; i <= XCount - 2; i++) { Point3d[] points = new Point3d[8]; // = New Point3d(7){} double[] values = new double[8]; // = New Double(7){} points[0] = R3D.voxels[i, j, k].vertex; values[0] = R3D.voxels[i, j, k].Value; points[1] = R3D.voxels[i + 1, j, k].vertex; values[1] = R3D.voxels[i + 1, j, k].Value; points[2] = R3D.voxels[i + 1, j + 1, k].vertex; values[2] = R3D.voxels[i + 1, j + 1, k].Value; points[3] = R3D.voxels[i, j + 1, k].vertex; values[3] = R3D.voxels[i, j + 1, k].Value; points[4] = R3D.voxels[i, j, k + 1].vertex; values[4] = R3D.voxels[i, j, k + 1].Value; points[5] = R3D.voxels[i + 1, j, k + 1].vertex; values[5] = R3D.voxels[i + 1, j, k + 1].Value; points[6] = R3D.voxels[i + 1, j + 1, k + 1].vertex; values[6] = R3D.voxels[i + 1, j + 1, k + 1].Value; points[7] = R3D.voxels[i, j + 1, k + 1].vertex; values[7] = R3D.voxels[i, j + 1, k + 1].Value; GBs[Counter] = points; GMs[Counter] = values; Counter += 1; } } } BoxMs = GMs; return(GBs); }
public Mesh Field_to_IsoSurface(double ts) { Raster3D R3D = this; double[][] GMs = null; // can be converted to a 2D array Point3d[][] GBs = Grid_to_Boxes(Plane.WorldXY, R3D, ref GMs); Mesh IsoSurface = new Mesh(); for (int GI = 0; GI <= GBs.Length - 1; GI++) { Mesh facet = local_cube(GBs[GI], GMs[GI], ts); IsoSurface.Append(facet); } IsoSurface.Vertices.CombineIdentical(true, true); // IsoSurface.Normals.ComputeNormals() // IsoSurface.UnifyNormals() return(IsoSurface); }
public Mesh Raster3D_to_Raster2D(List <System.Drawing.Color> Colors, double param, int xyz) { //Dim R3D As OTB_3DGIS.Raster3d = Nothing Raster3D R3D = this; //CType(R3D_O, OTB_3DGIS.Raster3D) Voxel[, ,] Slice = R3D.voxels; int i = 0; int j = 0; int k = 0; int m = 0; int n = 0; int l = 0; m = R3D.XCount - 1; n = R3D.YCount - 1; l = R3D.ZCount - 1; Point3d[,] PR2D_XP = new Point3d[n + 1, l + 1]; Point3d[,] PR2D_YP = new Point3d[l + 1, m + 1]; Point3d[,] PR2D_ZP = new Point3d[m + 1, n + 1]; List <Color> Cols = new List <Color>(); List <Point3d> PixelPoints = new List <Point3d>(); Mesh ZM = new Mesh(); if (xyz == 0) { Interval PDomain = new Interval(0, l); int KP = Convert.ToInt32(Math.Round(PDomain.ParameterAt(param))); int counter = KP * (n + 1) * (l + 1); for (k = 0; k <= l; k++) { for (j = 0; j <= n; j++) { Voxel ThatVoxel = R3D.voxels[KP, j, k]; Point3d PixelPoint = ThatVoxel.vertex; PR2D_XP[j, k] = PixelPoint; PixelPoints.Add(PixelPoint); Cols.Add(Colors[counter]); counter = counter + 1; } } ZM = MeshFromPoints(PixelPoints.ToList(), Cols, n + 1, l + 1); } else if (xyz == 1) { Interval PDomain = new Interval(0, l); int KP = Convert.ToInt32(Math.Round(PDomain.ParameterAt(param))); int counter = KP * (l + 1) * (m + 1); for (k = 0; k <= l; k++) { for (i = 0; i <= m; i++) { Voxel ThatVoxel = R3D.voxels[i, KP, k]; Point3d PixelPoint = ThatVoxel.vertex; PR2D_YP[k, i] = PixelPoint; PixelPoints.Add(PixelPoint); Cols.Add(Colors[counter]); counter = counter + 1; } } ZM = MeshFromPoints(PixelPoints.ToList(), Cols, l + 1, m + 1); } else if (xyz == 2) { Interval PDomain = new Interval(0, l); int KP = Convert.ToInt32(Math.Round(PDomain.ParameterAt(param))); int counter = KP * (m + 1) * (n + 1); for (j = 0; j <= n; j++) { for (i = 0; i <= m; i++) { Voxel ThatVoxel = R3D.voxels[i, j, KP]; Point3d PixelPoint = ThatVoxel.vertex; PR2D_ZP[i, j] = PixelPoint; PixelPoints.Add(PixelPoint); Cols.Add(Colors[counter]); counter = counter + 1; } } ZM = MeshFromPoints(PixelPoints.ToList(), Cols, m + 1, n + 1); } else { return(null); } return(ZM); }