Main Page   Data Structures   File List   Data Fields   Globals  

rotatecube.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 #define  BAND   0
00004 #define  LINE   1
00005 #define  PIXEL  2
00006 
00007 /*-Copyright Information------------------------------------------------------*/
00008 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00009 /*----------------------------------------------------------------------------*/
00010 /*-General Information--------------------------------------------------------*/
00011 /*                                                                            */
00012 /*   This function rotates image bands, lines, and pixels.                    */
00013 /*                                                                            */
00014 /*----------------------------------------------------------------------------*/
00015 /*-Interface Information------------------------------------------------------*/
00016 void ROTATECUBE (
00017 IMAGE  *in,     /*  I   Pointer to the input image.                           */
00018 short  xdir,    /*  I   Switches, indicating direction of index of axis:      */
00019 short  ydir,    /*  I   0 - Increasing index.                                 */
00020 short  zdir,    /*  I   1 - Decreasing index.                                 */
00021 short  xaxis,   /*  I   Switches, indicating order of axis:                   */
00022 short  yaxis,   /*  I   0 - Band.                                             */
00023 short  zaxis,   /*  I   1 - Line.                                             */
00024                 /*      2 - Pixel.                                            */
00025 IMAGE  **out    /*  O   Address of a pointer to the output image.             */
00026 /*----------------------------------------------------------------------------*/
00027 ) { register short i, j, k, outi, outj, outk;
00028     char msg[SLEN];
00029     
00030     /* check input */
00031     if (!CHECKIMG(in)) {
00032         MESSAGE('E'," Can't identify input image.");
00033         goto the_end;
00034     }
00035 
00036     /* validate parameters passed */
00037     if (xaxis == yaxis || yaxis == zaxis || zaxis == xaxis) {
00038         MESSAGE('E'," Can't map between same axis.");
00039         goto the_end;
00040     }
00041 
00042     if (TIMES) TIMING(T_ROTATECUBE);
00043     if (NAMES) {
00044         MESSAGE('I',"");
00045         MESSAGE('I',"ROTATE CUBE");
00046         MESSAGE('I',"");
00047         sprintf(msg," Input image:        %s",in->text);
00048         MESSAGE('I',msg);
00049 
00050         MESSAGE('I',"");
00051         MESSAGE('I'," Output format:");
00052         switch (zaxis) {
00053         case BAND:
00054             switch (yaxis) {
00055             case LINE:
00056                 sprintf(msg,"  X Axis: %c Pixel",(xdir==0?'+':'-'));
00057                 MESSAGE('I',msg);
00058                 sprintf(msg,"  Y Axis: %c Line",(ydir==0?'+':'-'));
00059                 MESSAGE('I',msg);
00060                 sprintf(msg,"  Z Axis: %c Band",(zdir==0?'+':'-'));
00061                 MESSAGE('I',msg);
00062                 break;
00063             case PIXEL:
00064                 sprintf(msg,"  X Axis: %c Line",(xdir==0?'+':'-'));
00065                 MESSAGE('I',msg);
00066                 sprintf(msg,"  Y Axis: %c Pixel",(ydir==0?'+':'-'));
00067                 MESSAGE('I',msg);
00068                 sprintf(msg,"  Z Axis: %c Band",(zdir==0?'+':'-'));
00069                 MESSAGE('I',msg);
00070                 break;
00071             }
00072             break;
00073         case LINE:
00074             switch (yaxis) {
00075             case BAND:
00076                 sprintf(msg,"  X Axis: %c Pixel",(xdir==0?'+':'-'));
00077                 MESSAGE('I',msg);
00078                 sprintf(msg,"  Y Axis: %c Band",(ydir==0?'+':'-'));
00079                 MESSAGE('I',msg);
00080                 sprintf(msg,"  Z Axis: %c Line",(zdir==0?'+':'-'));
00081                 MESSAGE('I',msg);
00082                 break;
00083             case PIXEL:
00084                 sprintf(msg,"  X Axis: %c Band",(xdir==0?'+':'-'));
00085                 MESSAGE('I',msg);
00086                 sprintf(msg,"  Y Axis: %c Pixel",(ydir==0?'+':'-'));
00087                 MESSAGE('I',msg);
00088                 sprintf(msg,"  Z Axis: %c Line",(zdir==0?'+':'-'));
00089                 MESSAGE('I',msg);
00090                 break;
00091             }
00092             break;
00093         case PIXEL:
00094             switch (yaxis) {
00095             case BAND:
00096                 sprintf(msg,"  X Axis: %c Line",(xdir==0?'+':'-'));
00097                 MESSAGE('I',msg);
00098                 sprintf(msg,"  Y Axis: %c Band",(ydir==0?'+':'-'));
00099                 MESSAGE('I',msg);
00100                 sprintf(msg,"  Z Axis: %c Pixel",(zdir==0?'+':'-'));
00101                 MESSAGE('I',msg);
00102                 break;
00103             case LINE:
00104                 sprintf(msg,"  X Axis: %c Band",(xdir==0?'+':'-'));
00105                 MESSAGE('I',msg);
00106                 sprintf(msg,"  Y Axis: %c Line",(ydir==0?'+':'-'));
00107                 MESSAGE('I',msg);
00108                 sprintf(msg,"  Z Axis: %c Pixel",(zdir==0?'+':'-'));
00109                 MESSAGE('I',msg);
00110                 break;
00111             }
00112             break;
00113         }
00114     }
00115     
00116     MESSAGE('I'," ...............");
00117 
00118    /* switch to decide required cube orientation */
00119     switch (zaxis) {
00120     case BAND :
00121         switch (yaxis) {
00122         case LINE :
00123             /* create image of appropriate size */
00124             if (!CHECKIMG(*out)) {
00125                 GETMEM(in->nbnd,in->nlin,in->npix,out);
00126             }
00127             if (!*out) goto the_end;
00128             /* rotate cube */
00129             for(i=0; i<in->nbnd; i++) {
00130                 for(j=0; j<in->nlin; j++) {
00131                     for(k=0; k<in->npix; k++) {
00132                         outi = abs(zdir*(in->nbnd-1)-i);
00133                         outj = abs(ydir*(in->nlin-1)-j);
00134                         outk = abs(xdir*(in->npix-1)-k);
00135                         (*out)->data[outi][outj][outk] = in->data[i][j][k]; 
00136                     }
00137                 }
00138             }
00139            break;
00140         case PIXEL :
00141             /* create image of appropriate size */
00142             if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->npix,in->nlin,out);
00143             if (!*out) goto the_end;
00144             /* rotate cube */
00145             for(i=0; i<in->nbnd; i++) {
00146                 for(j=0; j<in->nlin; j++) {
00147                     for(k=0; k<in->npix; k++) {
00148                         outi = abs(zdir*(in->nbnd-1)-i);
00149                         outj = abs(ydir*(in->npix-1)-k);
00150                         outk = abs(xdir*(in->nlin-1)-j);
00151                         (*out)->data[outi][outj][outk] = in->data[i][j][k]; 
00152                     }
00153                 }
00154             }
00155            break;
00156         }
00157         break;
00158     case LINE :
00159         switch (yaxis) {
00160         case BAND :
00161             /* create image of appropriate size */
00162             if (!CHECKIMG(*out)) GETMEM(in->nlin,in->nbnd,in->npix,out);
00163             if (!*out) goto the_end;
00164             /* rotate cube */       
00165             for(i=0; i<in->nbnd; i++) {
00166                 for(j=0; j<in->nlin; j++) {
00167                     for(k=0; k<in->npix; k++) {
00168                         outi = abs(zdir*(in->nlin-1)-j);
00169                         outj = abs(ydir*(in->nbnd-1)-i);
00170                         outk = abs(xdir*(in->npix-1)-k);
00171                         (*out)->data[outi][outj][outk] = in->data[i][j][k]; 
00172                     }
00173                 }
00174             }
00175            break;
00176         case PIXEL :
00177             /* create image of appropriate size */
00178             if (!CHECKIMG(*out)) GETMEM(in->nlin,in->npix,in->nbnd,out);
00179             if (!*out) goto the_end;
00180             /* rotate cube */
00181             for(i=0; i<in->nbnd; i++) {
00182                 for(j=0; j<in->nlin; j++) {
00183                     for(k=0; k<in->npix; k++) {
00184                         outi = abs(zdir*(in->nlin-1)-j);
00185                         outj = abs(ydir*(in->npix-1)-k);
00186                         outk = abs(xdir*(in->nbnd-1)-i);
00187                         (*out)->data[outi][outj][outk] = in->data[i][j][k]; 
00188                     }
00189                 }
00190             }
00191            break;
00192         }
00193         break;
00194     case PIXEL :
00195         switch (yaxis) {
00196         case BAND :
00197             /* create image of appropriate size */
00198             if (!CHECKIMG(*out)) GETMEM(in->npix,in->nbnd,in->nlin,out);
00199             if (!*out) goto the_end;
00200             /* rotate cube */       
00201             for(i=0; i<in->nbnd; i++) {
00202                 for(j=0; j<in->nlin; j++) {
00203                     for(k=0; k<in->npix; k++) {
00204                         outi = abs(zdir*(in->npix-1)-k);
00205                         outj = abs(ydir*(in->nbnd-1)-i);
00206                         outk = abs(xdir*(in->nlin-1)-j);
00207                         (*out)->data[outi][outj][outk] = in->data[i][j][k]; 
00208                     }
00209                 }
00210             }
00211            break;
00212         case LINE :
00213             /* create image of appropriate size */
00214             if (!CHECKIMG(*out)) GETMEM(in->npix,in->nlin,in->nbnd,out);
00215             if (!*out) goto the_end;
00216             /* rotate cube */
00217             for(i=0; i<in->nbnd; i++) {
00218                 for(j=0; j<in->nlin; j++) {
00219                     for(k=0; k<in->npix; k++) {
00220                         outi = abs(zdir*(in->npix-1)-k);
00221                         outj = abs(ydir*(in->nlin-1)-j);
00222                         outk = abs(xdir*(in->nbnd-1)-i);
00223                         (*out)->data[outi][outj][outk] = in->data[i][j][k]; 
00224                     }
00225                 }
00226             }
00227            break;
00228         }
00229         break;
00230     }
00231 
00232     the_end:
00233     if (TIMES) TIMING(T_EXIT);
00234 }
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 

Generated on Wed Apr 9 08:56:11 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002