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
00017 ROTATECUBE (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   )
00028 {
00029   register short i, j, k, outi, outj, outk;
00030   char msg[SLEN];
00031 
00032   /* check input */
00033   if (!CHECKIMG (in))
00034     {
00035       MESSAGE ('E', " Can't identify input image.");
00036       goto the_end;
00037     }
00038 
00039   /* validate parameters passed */
00040   if (xaxis == yaxis || yaxis == zaxis || zaxis == xaxis)
00041     {
00042       MESSAGE ('E', " Can't map between same axis.");
00043       goto the_end;
00044     }
00045 
00046   if (TIMES)
00047     TIMING (T_ROTATECUBE);
00048   if (NAMES)
00049     {
00050       MESSAGE ('I', "");
00051       MESSAGE ('I', "ROTATE CUBE");
00052       MESSAGE ('I', "");
00053       sprintf (msg, " Input image:        %s", in->text);
00054       MESSAGE ('I', msg);
00055 
00056       MESSAGE ('I', "");
00057       MESSAGE ('I', " Output format:");
00058       switch (zaxis)
00059         {
00060         case BAND:
00061           switch (yaxis)
00062             {
00063             case LINE:
00064               sprintf (msg, "  X Axis: %c Pixel", (xdir == 0 ? '+' : '-'));
00065               MESSAGE ('I', msg);
00066               sprintf (msg, "  Y Axis: %c Line", (ydir == 0 ? '+' : '-'));
00067               MESSAGE ('I', msg);
00068               sprintf (msg, "  Z Axis: %c Band", (zdir == 0 ? '+' : '-'));
00069               MESSAGE ('I', msg);
00070               break;
00071             case PIXEL:
00072               sprintf (msg, "  X Axis: %c Line", (xdir == 0 ? '+' : '-'));
00073               MESSAGE ('I', msg);
00074               sprintf (msg, "  Y Axis: %c Pixel", (ydir == 0 ? '+' : '-'));
00075               MESSAGE ('I', msg);
00076               sprintf (msg, "  Z Axis: %c Band", (zdir == 0 ? '+' : '-'));
00077               MESSAGE ('I', msg);
00078               break;
00079             }
00080           break;
00081         case LINE:
00082           switch (yaxis)
00083             {
00084             case BAND:
00085               sprintf (msg, "  X Axis: %c Pixel", (xdir == 0 ? '+' : '-'));
00086               MESSAGE ('I', msg);
00087               sprintf (msg, "  Y Axis: %c Band", (ydir == 0 ? '+' : '-'));
00088               MESSAGE ('I', msg);
00089               sprintf (msg, "  Z Axis: %c Line", (zdir == 0 ? '+' : '-'));
00090               MESSAGE ('I', msg);
00091               break;
00092             case PIXEL:
00093               sprintf (msg, "  X Axis: %c Band", (xdir == 0 ? '+' : '-'));
00094               MESSAGE ('I', msg);
00095               sprintf (msg, "  Y Axis: %c Pixel", (ydir == 0 ? '+' : '-'));
00096               MESSAGE ('I', msg);
00097               sprintf (msg, "  Z Axis: %c Line", (zdir == 0 ? '+' : '-'));
00098               MESSAGE ('I', msg);
00099               break;
00100             }
00101           break;
00102         case PIXEL:
00103           switch (yaxis)
00104             {
00105             case BAND:
00106               sprintf (msg, "  X Axis: %c Line", (xdir == 0 ? '+' : '-'));
00107               MESSAGE ('I', msg);
00108               sprintf (msg, "  Y Axis: %c Band", (ydir == 0 ? '+' : '-'));
00109               MESSAGE ('I', msg);
00110               sprintf (msg, "  Z Axis: %c Pixel", (zdir == 0 ? '+' : '-'));
00111               MESSAGE ('I', msg);
00112               break;
00113             case LINE:
00114               sprintf (msg, "  X Axis: %c Band", (xdir == 0 ? '+' : '-'));
00115               MESSAGE ('I', msg);
00116               sprintf (msg, "  Y Axis: %c Line", (ydir == 0 ? '+' : '-'));
00117               MESSAGE ('I', msg);
00118               sprintf (msg, "  Z Axis: %c Pixel", (zdir == 0 ? '+' : '-'));
00119               MESSAGE ('I', msg);
00120               break;
00121             }
00122           break;
00123         }
00124     }
00125 
00126   MESSAGE ('I', " ...............");
00127 
00128   /* switch to decide required cube orientation */
00129   switch (zaxis)
00130     {
00131     case BAND:
00132       switch (yaxis)
00133         {
00134         case LINE:
00135           /* create image of appropriate size */
00136           if (!CHECKIMG (*out))
00137             {
00138               GETMEM (in->nbnd, in->nlin, in->npix, out);
00139             }
00140           if (!*out)
00141             goto the_end;
00142           /* rotate cube */
00143           for (i = 0; i < in->nbnd; i++)
00144             {
00145               for (j = 0; j < in->nlin; j++)
00146                 {
00147                   for (k = 0; k < in->npix; k++)
00148                     {
00149                       outi = abs (zdir * (in->nbnd - 1) - i);
00150                       outj = abs (ydir * (in->nlin - 1) - j);
00151                       outk = abs (xdir * (in->npix - 1) - k);
00152                       (*out)->data[outi][outj][outk] = in->data[i][j][k];
00153                     }
00154                 }
00155             }
00156           break;
00157         case PIXEL:
00158           /* create image of appropriate size */
00159           if (!CHECKIMG (*out))
00160             GETMEM (in->nbnd, in->npix, in->nlin, out);
00161           if (!*out)
00162             goto the_end;
00163           /* rotate cube */
00164           for (i = 0; i < in->nbnd; i++)
00165             {
00166               for (j = 0; j < in->nlin; j++)
00167                 {
00168                   for (k = 0; k < in->npix; k++)
00169                     {
00170                       outi = abs (zdir * (in->nbnd - 1) - i);
00171                       outj = abs (ydir * (in->npix - 1) - k);
00172                       outk = abs (xdir * (in->nlin - 1) - j);
00173                       (*out)->data[outi][outj][outk] = in->data[i][j][k];
00174                     }
00175                 }
00176             }
00177           break;
00178         }
00179       break;
00180     case LINE:
00181       switch (yaxis)
00182         {
00183         case BAND:
00184           /* create image of appropriate size */
00185           if (!CHECKIMG (*out))
00186             GETMEM (in->nlin, in->nbnd, in->npix, out);
00187           if (!*out)
00188             goto the_end;
00189           /* rotate cube */
00190           for (i = 0; i < in->nbnd; i++)
00191             {
00192               for (j = 0; j < in->nlin; j++)
00193                 {
00194                   for (k = 0; k < in->npix; k++)
00195                     {
00196                       outi = abs (zdir * (in->nlin - 1) - j);
00197                       outj = abs (ydir * (in->nbnd - 1) - i);
00198                       outk = abs (xdir * (in->npix - 1) - k);
00199                       (*out)->data[outi][outj][outk] = in->data[i][j][k];
00200                     }
00201                 }
00202             }
00203           break;
00204         case PIXEL:
00205           /* create image of appropriate size */
00206           if (!CHECKIMG (*out))
00207             GETMEM (in->nlin, in->npix, in->nbnd, out);
00208           if (!*out)
00209             goto the_end;
00210           /* rotate cube */
00211           for (i = 0; i < in->nbnd; i++)
00212             {
00213               for (j = 0; j < in->nlin; j++)
00214                 {
00215                   for (k = 0; k < in->npix; k++)
00216                     {
00217                       outi = abs (zdir * (in->nlin - 1) - j);
00218                       outj = abs (ydir * (in->npix - 1) - k);
00219                       outk = abs (xdir * (in->nbnd - 1) - i);
00220                       (*out)->data[outi][outj][outk] = in->data[i][j][k];
00221                     }
00222                 }
00223             }
00224           break;
00225         }
00226       break;
00227     case PIXEL:
00228       switch (yaxis)
00229         {
00230         case BAND:
00231           /* create image of appropriate size */
00232           if (!CHECKIMG (*out))
00233             GETMEM (in->npix, in->nbnd, in->nlin, out);
00234           if (!*out)
00235             goto the_end;
00236           /* rotate cube */
00237           for (i = 0; i < in->nbnd; i++)
00238             {
00239               for (j = 0; j < in->nlin; j++)
00240                 {
00241                   for (k = 0; k < in->npix; k++)
00242                     {
00243                       outi = abs (zdir * (in->npix - 1) - k);
00244                       outj = abs (ydir * (in->nbnd - 1) - i);
00245                       outk = abs (xdir * (in->nlin - 1) - j);
00246                       (*out)->data[outi][outj][outk] = in->data[i][j][k];
00247                     }
00248                 }
00249             }
00250           break;
00251         case LINE:
00252           /* create image of appropriate size */
00253           if (!CHECKIMG (*out))
00254             GETMEM (in->npix, in->nlin, in->nbnd, out);
00255           if (!*out)
00256             goto the_end;
00257           /* rotate cube */
00258           for (i = 0; i < in->nbnd; i++)
00259             {
00260               for (j = 0; j < in->nlin; j++)
00261                 {
00262                   for (k = 0; k < in->npix; k++)
00263                     {
00264                       outi = abs (zdir * (in->npix - 1) - k);
00265                       outj = abs (ydir * (in->nlin - 1) - j);
00266                       outk = abs (xdir * (in->nbnd - 1) - i);
00267                       (*out)->data[outi][outj][outk] = in->data[i][j][k];
00268                     }
00269                 }
00270             }
00271           break;
00272         }
00273       break;
00274     }
00275 
00276 the_end:
00277   if (TIMES)
00278     TIMING (T_EXIT);
00279 }

Generated on Sun May 18 15:36:13 2003 for tclSadie by doxygen1.3