Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
vp_transpose.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "vp_global.h"
00032
00033 static int TransposeBlock ANSI_ARGS((void *src, int src_xstride,
00034 int src_ystride, int src_zstride, void *dst, int dst_xstride,
00035 int dst_ystride, int dst_zstride, int xlen, int ylen, int zlen,
00036 int bytes_per_voxel));
00037
00038
00039
00040
00041
00042
00043
00044 vpResult
00045 vpTranspose(vpc, kaxis)
00046 vpContext *vpc;
00047 int kaxis;
00048 {
00049 void *blk;
00050 int xlen, ylen, zlen;
00051 int src_xstride, src_ystride, src_zstride;
00052 int dst_xstride, dst_ystride, dst_zstride;
00053 int bytes_per_voxel;
00054 int retcode;
00055
00056
00057
00058
00059
00060 if ((retcode = VPCheckRawVolume(vpc)) != VP_OK)
00061 return(retcode);
00062
00063
00064 xlen = vpc->xlen;
00065 ylen = vpc->ylen;
00066 zlen = vpc->zlen;
00067 src_xstride = vpc->xstride;
00068 src_ystride = vpc->ystride;
00069 src_zstride = vpc->zstride;
00070 bytes_per_voxel = vpc->raw_bytes_per_voxel;
00071 switch (kaxis) {
00072 case VP_X_AXIS:
00073 dst_xstride = ylen*zlen*bytes_per_voxel;
00074 dst_ystride = bytes_per_voxel;
00075 dst_zstride = ylen*bytes_per_voxel;
00076 break;
00077 case VP_Y_AXIS:
00078 dst_xstride = zlen*bytes_per_voxel;
00079 dst_ystride = zlen*xlen*bytes_per_voxel;
00080 dst_zstride = bytes_per_voxel;
00081 break;
00082 case VP_Z_AXIS:
00083 dst_xstride = bytes_per_voxel;
00084 dst_ystride = xlen*bytes_per_voxel;
00085 dst_zstride = xlen*ylen*bytes_per_voxel;
00086 break;
00087 default:
00088 return(VPSetError(vpc, VPERROR_BAD_OPTION));
00089 }
00090 if (src_xstride == dst_xstride && src_ystride == dst_ystride &&
00091 src_zstride == dst_zstride)
00092 return(VP_OK);
00093
00094
00095 Alloc(vpc, blk, void *, xlen*ylen*zlen*bytes_per_voxel,
00096 "transpose_tmp");
00097 TransposeBlock(vpc->raw_voxels, src_xstride, src_ystride, src_zstride,
00098 blk, dst_xstride, dst_ystride, dst_zstride,
00099 xlen, ylen, zlen, bytes_per_voxel);
00100 bcopy(blk, vpc->raw_voxels, xlen*ylen*zlen*bytes_per_voxel);
00101 Dealloc(vpc, blk);
00102 vpc->xstride = dst_xstride;
00103 vpc->ystride = dst_ystride;
00104 vpc->zstride = dst_zstride;
00105 return(VP_OK);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115 static int
00116 TransposeBlock(src, src_xstride, src_ystride, src_zstride, dst, dst_xstride,
00117 dst_ystride, dst_zstride, xlen, ylen, zlen, bytes_per_voxel)
00118 void *src;
00119 int src_xstride;
00120 int src_ystride;
00121 int src_zstride;
00122 void *dst;
00123 int dst_xstride;
00124 int dst_ystride;
00125 int dst_zstride;
00126 int xlen, ylen, zlen;
00127 int bytes_per_voxel;
00128 {
00129 int x, y, z, b;
00130 unsigned char *src_ptr;
00131 unsigned char *dst_ptr;
00132
00133 src_ptr = src;
00134 dst_ptr = dst;
00135 for (z = 0; z < zlen; z++) {
00136 for (y = 0; y < ylen; y++) {
00137 for (x = 0; x < xlen; x++) {
00138 for (b = 0; b < bytes_per_voxel; b++)
00139 dst_ptr[b] = src_ptr[b];
00140 src_ptr += src_xstride;
00141 dst_ptr += dst_xstride;
00142 }
00143 src_ptr += src_ystride - xlen*src_xstride;
00144 dst_ptr += dst_ystride - xlen*dst_xstride;
00145 }
00146 src_ptr += src_zstride - ylen*src_ystride;
00147 dst_ptr += dst_zstride - ylen*dst_ystride;
00148 }
00149 return 0 ;
00150 }