| 465 | } |
| 466 | |
| 467 | public float[] getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels) { |
| 468 | boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices; |
| 469 | if (voxels==null || voxels.length!=w*h*d) |
| 470 | voxels = new float[w*h*d]; |
| 471 | int i = 0; |
| 472 | int offset; |
| 473 | for (int z=z0; z<z0+d; z++) { |
| 474 | for (int y=y0; y<y0+h; y++) { |
| 475 | if (inBounds) { |
| 476 | switch (bitDepth) { |
| 477 | case 8: |
| 478 | byte[] bytes = (byte[])stack[z]; |
| 479 | for (int x=x0; x<x0+w; x++) |
| 480 | voxels[i++] = bytes[y*width+x]&0xff; |
| 481 | break; |
| 482 | case 16: |
| 483 | short[] shorts = (short[])stack[z]; |
| 484 | for (int x=x0; x<x0+w; x++) |
| 485 | voxels[i++] = shorts[y*width+x]&0xffff; |
| 486 | break; |
| 487 | case 32: |
| 488 | float[] floats = (float[])stack[z]; |
| 489 | for (int x=x0; x<x0+w; x++) |
| 490 | voxels[i++] = floats[y*width+x]; |
| 491 | break; |
| 492 | case 24: |
| 493 | int[] ints = (int[])stack[z]; |
| 494 | for (int x=x0; x<x0+w; x++) |
| 495 | voxels[i++] = ints[y*width+x]&0xffffffff; |
| 496 | break; |
| 497 | default: |
| 498 | for (int x=x0; x<x0+w; x++) |
| 499 | voxels[i++] = 0f; |
| 500 | } |
| 501 | } else { |
| 502 | for (int x=x0; x<x0+w; x++) |
| 503 | voxels[i++] = (float)getVoxel(x, y, z); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | return voxels; |
| 508 | } |
| 509 | |
| 510 | public float[] getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel) { |
| 511 | if (bitDepth!=24) |