Esempio n. 1
0
 void PointToVoxel(List<Point> basedata)
 {
     double maxX = Math.Ceiling(basedata.Max(p => p.GetVector3().x));
     double minX = Math.Floor(basedata.Min(p => p.GetVector3().x));
     double maxY = Math.Ceiling(basedata.Max(p => p.GetVector3().y));
     double minY = Math.Floor(basedata.Min(p => p.GetVector3().y));
     double maxZ = Math.Ceiling(basedata.Max(p => p.GetVector3().z));
     double minZ = Math.Floor(basedata.Min(p => p.GetVector3().z));
     //1 = 1メートル
     double delta = 0.05;
     int inverse = (int)(1 / delta);
     int width = (int)((maxX - minX) * inverse);
     int height = (int)((maxY - minY) * inverse);
     int depth = (int)((maxZ - minZ) * inverse);
     Voxel = new Voxel<List<Point>>(width, height, depth, minX, minY, minZ, delta);
     AnotherVoxel = new Voxel<List<Point>>(width, height, depth, minX - delta * 0.5, minY - delta * 0.5, minZ - delta * 0.5, delta);
     for (int i = 0; i < width; i++) {
         for (int j = 0; j < height; j++) {
             for (int k = 0; k < depth; k++) {
                 Voxel[i, j, k] = new List<Point>();
                 AnotherVoxel[i, j, k] = new List<Point>();
             }
         }
     }
     foreach (var d in basedata) {
         var indexVec = Voxel.GetIndexFromPosition(d.GetVector3());
         if (indexVec.x == Voxel.Width) indexVec.x -= 1;
         if (indexVec.y == Voxel.Height) indexVec.y -= 1;
         if (indexVec.z == Voxel.Depth) indexVec.z -= 1;
         Voxel[(int)indexVec.x, (int)indexVec.y, (int)indexVec.z].Add(d);
         var aindex = AnotherVoxel.GetIndexFromPosition(d.GetVector3());
         if (aindex.x == AnotherVoxel.Width) aindex.x -= 1;
         if (aindex.y == AnotherVoxel.Height) aindex.y -= 1;
         if (aindex.z == AnotherVoxel.Depth) aindex.z -= 1;
         AnotherVoxel[(int)indexVec.x, (int)indexVec.y, (int)indexVec.z].Add(d);
     }
 }