home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / fitssubs / matxpos.c < prev    next >
C/C++ Source or Header  |  1998-04-02  |  3KB  |  96 lines

  1. /*  MatrixPos class implementation  */ 
  2. /* a MatrixPos contains information relating to a pixel position in a Matrix
  3.    and functions for manipulating them. Pixel numbers are 0 relative.*/
  4. /*-----------------------------------------------------------------------
  5. *  Copyright (C) 1996,1998
  6. *  Associated Universities, Inc. Washington DC, USA.
  7. *  This program is free software; you can redistribute it and/or
  8. *  modify it under the terms of the GNU General Public License as
  9. *  published by the Free Software Foundation; either version 2 of
  10. *  the License, or (at your option) any later version.
  11. *
  12. *  This program is distributed in the hope that it will be useful,
  13. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. *  GNU General Public License for more details.
  16. *-----------------------------------------------------------------------*/
  17.   
  18. #include "matxpos.h" 
  19.  
  20. /* MatrixPos class implementation.  */ 
  21.   
  22. /* Constructor  */
  23. MatrixPos* MakeMatrixPos(Integer n, Integer *p) 
  24.   Integer i; 
  25.   MatrixPos *temp = (MatrixPos *) malloc (sizeof(MatrixPos)); 
  26.   temp->ndims = n; 
  27.   for (i=0; i<7; i++) temp->pos[i] = 0; 
  28.   for (i=0; i<n; i++) temp->pos[i] = p[i]; 
  29.   return temp;} /* end MakeMatrixPos */ 
  30.   
  31. /* destructor  */ 
  32. void KillMatrixPos(MatrixPos* me)
  33.   if (me) free (me);
  34. }  /* end KillMatrixPos */ 
  35.   
  36.   
  37. /* copy pos2 to pos1 */ 
  38. void MatrixPosCopy (MatrixPos *pos1, MatrixPos *pos2) 
  39.   Integer i; 
  40.   if (!pos1) return;
  41.   if (!pos2) return;
  42.   pos1->ndims = pos2->ndims; 
  43.   for (i=0; i<7; i++) pos1->pos[i]=pos2->pos[i]; 
  44. } /* end MatrixPosCopy */ 
  45.   
  46. /* increment a MatrixPos, returns false when done  */ 
  47. /* Honors the window.  */ 
  48. Logical inc_pixel(MatrixPos *me, MatrixDescriptor *d)
  49. {Integer i=0; 
  50.  if (!me) return 0;
  51.  if (!d) return 0;
  52.  me->pos[i]++;
  53.  while (me->pos[i]>=d->window_hi[i])
  54.      {me->pos[i] = d->window_lo[i]; i++;
  55.       me->pos[i]++;
  56.       if (i>=me->ndims-1) break;}
  57. /* Done?  */ 
  58.  if ((me->pos[i])>=d->dims[i])
  59.      return 0;   /* Yes  */ 
  60.  else 
  61.      return 1;   /*  No  */ 
  62. }  /*  End inc_pixel  */ 
  63.   
  64. Logical inc_patch(MatrixPos *me, MatrixDescriptor *d)
  65. {Integer i=1; 
  66.  if (!me) return 0;
  67.  if (!d) return 0;
  68.  me->pos[i] += d->num_row;
  69.  while (me->pos[i]>=d->window_hi[i])
  70.      {me->pos[i] = d->window_lo[i]; i++;
  71.       me->pos[i]++;
  72.       if (i>=me->ndims-1) break;}
  73. /* Done?  */ 
  74.  if ((me->pos[i])>=d->dims[i])
  75.      {me->pos[me->ndims-1] =
  76.     d->dims[me->ndims-1] + 100; /* Force invalid pixel */
  77.       return 0;}   /* Yes  */ 
  78.  else 
  79.      return 1;   /*  No  */ 
  80. }  /*  End increment patch  */ 
  81.   
  82. /* Zero a MatrixPos  */ 
  83. void ZeroMatrixPos(MatrixPos *me)
  84.   Integer i; 
  85.  if (!me) return;
  86.   for (i=0; i<7; i++) me->pos[i] = 0; 
  87. }  /* end ZeroMatrixPos  */ 
  88.   
  89. /*  End of MatrixPos class  */
  90.   
  91.   
  92.