Changeset 7785
 Timestamp:
 10/13/11 15:53:55 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/projects/visbioplugins/src/main/java/loci/visbio/OrthoStack.java
r7784 r7785 123 123 final int sizeX = imp.getWidth(); 124 124 final int sizeY = imp.getHeight(); 125 final int sizeC = imp.getNChannels(); 125 126 final int sizeZ = imp.getNSlices(); 127 final int sizeT = imp.getNFrames(); 128 final int[] lengths = { sizeC, sizeZ, sizeT }; 129 130 final int posC = imp.getChannel()  1; 131 final int posZ = imp.getSlice()  1; 132 final int posT = imp.getFrame()  1; 133 final int[] pos = { posC, posZ, posT }; 126 134 127 135 // create VisAD display … … 146 154 final ImageStack stack = imp.getStack(); 147 155 for (int z = 0; z < sizeZ; z++) { 148 // TODO  support for multiC and/or multiT data as well 149 // need to convert (Z, C, T) triple into processor index 156 pos[1] = z; 150 157 151 158 // convert plane to BufferedImage 152 final ImageProcessor ip = stack.getProcessor(z + 1); 159 final int n = positionToRaster(pos, lengths) + 1; 160 final ImageProcessor ip = stack.getProcessor(n); 153 161 final Image image = ip.createImage(); 154 162 final BufferedImage bufImage = makeBuffered(image); … … 369 377 } 370 378 379 /** 380 * Computes a unique 1D index corresponding to the given multidimensional 381 * position. 382 * 383 * @param pos position along each dimensional axis 384 * @param lengths the maximum value for each positional dimension 385 * @return rasterized index value 386 */ 387 public static int positionToRaster(final int[] pos, final int... lengths) { 388 int offset = 1; 389 int raster = 0; 390 for (int i = 0; i < pos.length; i++) { 391 raster += offset * pos[i]; 392 offset *= lengths[i]; 393 } 394 return raster; 395 } 396 397 /** 398 * Computes a unique ND position corresponding to the given rasterized index 399 * value. 400 * 401 * @param raster rasterized index value 402 * @param lengths the maximum value at each positional dimension 403 * @return position along each dimensional axis 404 */ 405 public static int[] rasterToPosition(final int raster, final int... lengths) { 406 return rasterToPosition(new int[lengths.length], raster, lengths); 407 } 408 409 /** 410 * Computes a unique ND position corresponding to the given rasterized index 411 * value. 412 * 413 * @param pos preallocated position array to populate with the result 414 * @param raster rasterized index value 415 * @param lengths the maximum value at each positional dimension 416 * @return position along each dimensional axis 417 */ 418 public static int[] rasterToPosition(final int[] pos, final int raster, 419 final int... lengths) 420 { 421 int offset = 1; 422 int r = raster; 423 for (int i = 0; i < pos.length; i++) { 424 final int nextOffset = offset * lengths[i]; 425 final int q = i < pos.length  1 ? r % nextOffset : r; 426 pos[i] = q / offset; 427 r = q; 428 offset = nextOffset; 429 } 430 return pos; 431 } 432 371 433 }
Note: See TracChangeset
for help on using the changeset viewer.