Changeset 12381
- Timestamp:
- Mar 9, 2007, 10:16:40 AM (19 years ago)
- Location:
- trunk/psLib/src/mathtypes
- Files:
-
- 4 edited
-
psImage.c (modified) (6 diffs)
-
psImage.h (modified) (3 diffs)
-
psVector.c (modified) (2 diffs)
-
psVector.h (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/mathtypes/psImage.c
r11699 r12381 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.12 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 2-08 03:10:33$11 * @version $Revision: 1.124 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-03-09 20:16:40 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 121 121 } 122 122 123 bool psImageInit (psImage *image,...) 124 { 125 PS_ASSERT_PTR(image, false); 126 PS_ASSERT_IMAGE_NON_NULL(image, false); 127 128 va_list argp; 129 va_start (argp, image); 130 131 switch (image->type.type) { 132 #define IMAGEINIT_INTCASE(TYPE,NATIVETYPE) \ 123 124 125 // Image initialisation for integer types 126 #define IMAGEINIT_INTCASE(TYPE) \ 133 127 case PS_TYPE_##TYPE: { \ 134 NATIVETYPE temp = va_arg(argp, NATIVETYPE); \ 135 if ( temp < PS_MIN_##TYPE || temp > PS_MAX_##TYPE ) { \ 136 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %d out of Range.\n", temp); \ 137 return false; \ 138 } \ 139 ps##TYPE value = temp; \ 140 if (value == 0) { \ 128 if (value == 0.0) { \ 141 129 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 142 130 for (int y = 0; y < image->numRows; y++) { \ … … 144 132 } \ 145 133 } else { \ 134 if (value < (double)PS_MIN_##TYPE || value > (double)PS_MAX_##TYPE) { \ 135 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %f out of range for type %s.\n", \ 136 value, #TYPE); \ 137 return false; \ 138 } \ 139 ps##TYPE castValue = (ps##TYPE)value; \ 146 140 for (int iy = 0; iy < image->numRows; iy++) { \ 147 141 ps##TYPE *row = image->data.TYPE[iy]; \ 148 142 for (int ix = 0; ix < image->numCols; ix++) { \ 149 row[ix] = value; \143 row[ix] = castValue; \ 150 144 } \ 151 145 } \ … … 154 148 } 155 149 156 IMAGEINIT_INTCASE(U8,unsigned int) 157 IMAGEINIT_INTCASE(U16,unsigned int) 158 IMAGEINIT_INTCASE(U32,unsigned int) 159 IMAGEINIT_INTCASE(S8,int) 160 IMAGEINIT_INTCASE(S16,int) 161 IMAGEINIT_INTCASE(S32,int) 162 163 #define IMAGEINIT_LONGCASE(TYPE,NATIVETYPE) \ 150 // Image initialisation for char-size integer types 151 #define IMAGEINIT_CHARCASE(TYPE) \ 164 152 case PS_TYPE_##TYPE: { \ 165 ps##TYPE value = va_arg(argp, NATIVETYPE); \ 166 if (value == 0) { \ 153 if (value < (double)PS_MIN_##TYPE || value > (double)PS_MAX_##TYPE) { \ 154 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %f out of range for type %s.\n", \ 155 value, #TYPE); \ 156 return false; \ 157 } \ 158 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 159 ps##TYPE castValue = (ps##TYPE)value; \ 160 for (int y = 0; y < image->numRows; y++) { \ 161 memset(image->data.TYPE[y], castValue, numBytes); \ 162 } \ 163 return true; \ 164 } 165 // Image initialisation for floating point types 166 #define IMAGEINIT_FLOATCASE(TYPE) \ 167 case PS_TYPE_##TYPE: { \ 168 if (value == 0.0) { \ 167 169 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 168 170 for (int y = 0; y < image->numRows; y++) { \ … … 170 172 } \ 171 173 } else { \ 174 ps##TYPE castValue = (ps##TYPE)value; \ 172 175 for (int iy = 0; iy < image->numRows; iy++) { \ 173 176 ps##TYPE *row = image->data.TYPE[iy]; \ 174 177 for (int ix = 0; ix < image->numCols; ix++) { \ 175 row[ix] = value; \178 row[ix] = castValue; \ 176 179 } \ 177 180 } \ … … 180 183 } 181 184 182 IMAGEINIT_LONGCASE(U64,unsigned long) 183 IMAGEINIT_LONGCASE(S64,long) 184 185 #define IMAGEINIT_FLOATCASE(TYPE) \ 186 case PS_TYPE_##TYPE: { \ 187 ps##TYPE value = va_arg(argp, psF64); \ 188 if (value == 0) { \ 189 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 190 for (int y = 0; y < image->numRows; y++) { \ 191 memset(image->data.TYPE[y], 0, numBytes); \ 192 } \ 193 } else { \ 194 for (int iy = 0; iy < image->numRows; iy++) { \ 195 ps##TYPE *row = image->data.TYPE[iy]; \ 196 for (int ix = 0; ix < image->numCols; ix++) { \ 197 row[ix] = value; \ 198 } \ 199 } \ 200 } \ 201 return true; \ 202 } 203 185 186 bool psImageInit (psImage *image, double value) 187 { 188 PS_ASSERT_PTR(image, false); 189 PS_ASSERT_IMAGE_NON_NULL(image, false); 190 191 switch (image->type.type) { 192 IMAGEINIT_CHARCASE(U8) 193 IMAGEINIT_INTCASE(U16) 194 IMAGEINIT_INTCASE(U32) 195 IMAGEINIT_CHARCASE(S8) 196 IMAGEINIT_INTCASE(S16) 197 IMAGEINIT_INTCASE(S32) 198 IMAGEINIT_INTCASE(U64) 199 IMAGEINIT_INTCASE(S64) 204 200 IMAGEINIT_FLOATCASE(F32) 205 201 IMAGEINIT_FLOATCASE(F64) 206 207 202 default: 208 psError(PS_ERR_BAD_PARAMETER_TYPE, true, " datatype not defined in psImageInit\n");203 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Type %x not supported", image->type.type); 209 204 } 210 205 return (false); -
trunk/psLib/src/mathtypes/psImage.h
r11700 r12381 9 9 * @author Joshua Hoblitt, University of Hawaii 10 10 * 11 * @version $Revision: 1.8 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-0 2-08 03:26:15$11 * @version $Revision: 1.89 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-03-09 20:16:40 $ 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 14 14 */ … … 116 116 /** Checks the type of a particular pointer. 117 117 * 118 * Uses the appropriate deallocation function in psMemBlock to check the ptr * datatype. 118 * Uses the appropriate deallocation function in psMemBlock to check the ptr * datatype. 119 119 * @return bool: True if the pointer matches a psImage structure, false otherwise. 120 120 */ … … 131 131 bool psImageInit( 132 132 psImage *image, ///< the image to be initialized 133 ... ///< Variable argument list for initialization133 double value ///< Value to which to initialise 134 134 ); 135 135 -
trunk/psLib/src/mathtypes/psVector.c
r11698 r12381 10 10 * @author Joshua Hoblitt, University of Hawaii 11 11 * 12 * @version $Revision: 1.9 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 2-08 02:59:36$12 * @version $Revision: 1.95 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-03-09 20:16:40 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 678 678 } 679 679 680 681 bool psVectorInit(psVector *vector, 682 ...) 683 { 684 va_list argp; 685 psU8 vU8; 686 psU16 vU16; 687 psU32 vU32; 688 psU64 vU64; 689 psS8 vS8; 690 psS16 vS16; 691 psS32 vS32; 692 psS64 vS64; 693 psF32 vF32; 694 psF64 vF64; 695 psC32 vC32; 696 psC64 vC64; 697 698 unsigned int temp; 699 int temp2; 700 701 if (vector == NULL) 702 return (false); 703 704 va_start (argp, vector); 680 // Image initialisation for integer types 681 #define VECTORINIT_INTCASE(TYPE) \ 682 case PS_TYPE_##TYPE: { \ 683 if (value == 0.0) { \ 684 memset(vector->data.TYPE, 0, vector->n * sizeof(ps##TYPE)); \ 685 } else { \ 686 if (value < (double)PS_MIN_##TYPE || value > (double)PS_MAX_##TYPE) { \ 687 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %f out of range for type %s.\n", \ 688 value, #TYPE); \ 689 return false; \ 690 } \ 691 ps##TYPE castValue = (ps##TYPE)value; \ 692 ps##TYPE *vectorData = vector->data.TYPE; \ 693 for (int i = 0; i < vector->n; i++) { \ 694 vectorData[i] = castValue; \ 695 } \ 696 } \ 697 return true; \ 698 } 699 700 // Image initialisation for char-size integer types 701 #define VECTORINIT_CHARCASE(TYPE) \ 702 case PS_TYPE_##TYPE: { \ 703 if (value < (double)PS_MIN_##TYPE || value > (double)PS_MAX_##TYPE) { \ 704 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %f out of range for type %s.\n", \ 705 value, #TYPE); \ 706 return false; \ 707 } \ 708 memset(vector->data.TYPE, (ps##TYPE)value, vector->n * sizeof(ps##TYPE)); \ 709 return true; \ 710 } 711 712 // Image initialisation for floating point types 713 #define VECTORINIT_FLOATCASE(TYPE) \ 714 case PS_TYPE_##TYPE: { \ 715 if (value == 0.0) { \ 716 memset(vector->data.TYPE, 0, vector->n * sizeof(ps##TYPE)); \ 717 } else { \ 718 ps##TYPE castValue = (ps##TYPE)value; \ 719 ps##TYPE *vectorData = vector->data.TYPE; \ 720 for (int i = 0; i < vector->n; i++) { \ 721 vectorData[i] = castValue; \ 722 } \ 723 } \ 724 return true; \ 725 } 726 727 728 729 bool psVectorInit(psVector *vector, double value) 730 { 731 PS_ASSERT_VECTOR_NON_NULL(vector, false); 705 732 706 733 switch (vector->type.type) { 707 case PS_TYPE_BOOL: { 708 // This is a little ugly, because psVector doesn't have a boolean type yet. 709 int temp = va_arg(argp, int); 710 bool value = temp; 711 if (!value) { 712 memset(vector->data.U8, 0, vector->n * sizeof(bool)); 713 } else { 714 for (long i = 0; i < vector->n; i++) { 715 vector->data.U8[i] = value; 716 } 717 } 718 return true; 719 } 720 case PS_TYPE_U8: 721 temp = va_arg (argp, psU32); 722 if ( temp >= PS_MIN_U8 && temp <= PS_MAX_U8 ) { 723 vU8 = temp; 724 } else { 725 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: U8 Value out of Range.\n"); 726 return false; 727 } 728 // Can use memset for char-size values 729 memset(vector->data.U8, vU8, vector->n * sizeof(psU8)); 730 return (true); 731 case PS_TYPE_F32: 732 vF32 = (psF32)va_arg (argp, psF64); 733 if (vF32 == 0.0) { 734 memset(vector->data.F32, 0, vector->n * sizeof(psF32)); 735 } else { 736 for (long iy = 0; iy < vector->n; iy++) { 737 vector->data.F32[iy] = vF32; 738 } 739 } 740 return (true); 741 case PS_TYPE_F64: 742 vF64 = va_arg (argp, psF64); 743 if (vF64 == 0.0) { 744 memset(vector->data.F64, 0, vector->n * sizeof(psF64)); 745 } else { 746 for (long iy = 0; iy < vector->n; iy++) { 747 vector->data.F64[iy] = vF64; 748 } 749 } 750 return (true); 751 case PS_TYPE_U16: 752 temp = va_arg (argp, psU32); 753 if ( temp >= PS_MIN_U16 && temp <= PS_MAX_U16 ) 754 vU16 = temp; 755 else { 756 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: U16 Value out of Range.\n"); 757 return false; 758 } 759 if (vU16 == 0) { 760 memset(vector->data.U16, 0, vector->n * sizeof(psU16)); 761 } else { 762 for (long iy = 0; iy < vector->n; iy++) { 763 vector->data.U16[iy] = vU16; 764 } 765 } 766 return (true); 767 case PS_TYPE_U32: 768 vU32 = va_arg (argp, psU32); 769 if (vU32 == 0) { 770 memset(vector->data.U32, 0, vector->n * sizeof(psU32)); 771 } else { 772 for (long iy = 0; iy < vector->n; iy++) { 773 vector->data.U32[iy] = vU32; 774 } 775 } 776 return (true); 777 case PS_TYPE_U64: 778 vU64 = va_arg (argp, psU64); 779 if (vU64 == 0) { 780 memset(vector->data.U64, 0, vector->n * sizeof(psU64)); 781 } else { 782 for (long iy = 0; iy < vector->n; iy++) { 783 vector->data.U64[iy] = vU64; 784 } 785 } 786 return (true); 787 case PS_TYPE_S8: 788 temp2 = va_arg (argp, psS32); 789 if ( temp2 >= PS_MIN_S8 && temp2 <= PS_MAX_S8 ) 790 vS8 = temp2; 791 else { 792 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: S8 Value out of Range.\n"); 793 return false; 794 } 795 // Can use memset for char-size values 796 memset(vector->data.S8, vS8, vector->n * sizeof(psS8)); 797 return (true); 798 case PS_TYPE_S16: 799 temp2 = va_arg (argp, psS32); 800 if ( temp2 >= PS_MIN_S16 && temp2 <= PS_MAX_S16 ) 801 vS16 = temp2; 802 else { 803 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: S16 Value out of Range.\n"); 804 return false; 805 } 806 if (vS16 == 0) { 807 memset(vector->data.S16, 0, vector->n * sizeof(psS16)); 808 } else { 809 for (long iy = 0; iy < vector->n; iy++) { 810 vector->data.S16[iy] = vS16; 811 } 812 } 813 return (true); 814 case PS_TYPE_S32: 815 vS32 = va_arg (argp, psS32); 816 if (vS32 == 0) { 817 memset(vector->data.S32, 0, vector->n * sizeof(psS32)); 818 } else { 819 for (long iy = 0; iy < vector->n; iy++) { 820 vector->data.S32[iy] = vS32; 821 } 822 } 823 return (true); 824 case PS_TYPE_S64: 825 vS64 = va_arg (argp, psS64); 826 if (vS64 == 0) { 827 memset(vector->data.S64, 0, vector->n * sizeof(psS64)); 828 } else { 829 for (long iy = 0; iy < vector->n; iy++) { 830 vector->data.S64[iy] = vS64; 831 } 832 } 833 return (true); 834 case PS_TYPE_C32: 835 vC32 = va_arg (argp, psC32); 836 if (vC32 == 0) { 837 memset(vector->data.C32, 0, vector->n * sizeof(psC32)); 838 } else { 839 for (long iy = 0; iy < vector->n; iy++) { 840 vector->data.C32[iy] = vC32; 841 } 842 } 843 return (true); 844 case PS_TYPE_C64: 845 vC64 = va_arg (argp, psC64); 846 if (vC64 == 0) { 847 memset(vector->data.C64, 0, vector->n * sizeof(psC64)); 848 } else { 849 for (long iy = 0; iy < vector->n; iy++) { 850 vector->data.C64[iy] = vC64; 851 } 852 } 853 return (true); 734 VECTORINIT_CHARCASE(U8) 735 VECTORINIT_INTCASE(U16) 736 VECTORINIT_INTCASE(U32) 737 VECTORINIT_CHARCASE(S8) 738 VECTORINIT_INTCASE(S16) 739 VECTORINIT_INTCASE(S32) 740 VECTORINIT_INTCASE(U64) 741 VECTORINIT_INTCASE(S64) 742 VECTORINIT_FLOATCASE(F32) 743 VECTORINIT_FLOATCASE(F64) 854 744 default: 855 psError (PS_ERR_BAD_PARAMETER_TYPE, true, "datatype not defined in psImageInit\n"); 856 return (false); 745 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Type %x not supported", vector->type.type); 857 746 } 858 747 return (false); -
trunk/psLib/src/mathtypes/psVector.h
r11698 r12381 10 10 * @author Joshua Hoblitt, University of Hawaii 11 11 * 12 * @version $Revision: 1.6 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 2-08 02:59:36$12 * @version $Revision: 1.66 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-03-09 20:16:40 $ 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 15 15 */ … … 89 89 const char *file, ///< File of caller 90 90 unsigned int lineno, ///< Line number of caller 91 const char *func, ///< Function name of caller 91 const char *func, ///< Function name of caller 92 92 long nalloc, ///< Total number of elements to make available. 93 93 psElemType type ///< Type of data to be held by vector. … … 98 98 //#endif // ifdef __GNUC__ 99 99 #define psVectorAlloc(nalloc, type) \ 100 p_psVectorAlloc(__FILE__, __LINE__, __func__, nalloc, type) 100 p_psVectorAlloc(__FILE__, __LINE__, __func__, nalloc, type) 101 101 #endif // ifdef DOXYGEN 102 102 … … 118 118 const char *file, ///< File of caller 119 119 unsigned int lineno, ///< Line number of caller 120 const char *func, ///< Function name of caller 120 const char *func, ///< Function name of caller 121 121 long nalloc, ///< Total number of elements to make available. 122 122 psElemType type ///< Type of data to be held by vector. … … 127 127 //#endif // ifdef __GNUC__ 128 128 #define psVectorAllocEmpty(nalloc, type) \ 129 p_psVectorAllocEmpty(__FILE__, __LINE__, __func__, nalloc, type) 129 p_psVectorAllocEmpty(__FILE__, __LINE__, __func__, nalloc, type) 130 130 #endif // ifdef DOXYGEN 131 131 … … 184 184 const char *file, ///< File of caller 185 185 unsigned int lineno, ///< Line number of caller 186 const char *func, ///< Function name of caller 186 const char *func, ///< Function name of caller 187 187 psVector* vector, 188 188 ///< Vector to recycle. If NULL, a new vector is created. No effort … … 215 215 const char *file, ///< File of caller 216 216 unsigned int lineno, ///< Line number of caller 217 const char *func, ///< Function name of caller 217 const char *func, ///< Function name of caller 218 218 psVector* output, ///< if non-NULL, a psVector to recycle 219 219 const psVector* input, ///< the vector to copy. … … 221 221 ); 222 222 #define psVectorCopy(output, input, type) \ 223 p_psVectorCopy(__FILE__, __LINE__, __func__, output, input, type) 223 p_psVectorCopy(__FILE__, __LINE__, __func__, output, input, type) 224 224 #endif // ifdef DOXYGEN 225 225 … … 291 291 bool psVectorInit( 292 292 psVector *vector, ///< the vector to be initialized 293 ... ///< Variable argument list for initialization293 double value ///< Value to which to initialise 294 294 ); 295 295 … … 315 315 const char *file, ///< File of caller 316 316 unsigned int lineno, ///< Line number of caller 317 const char *func, ///< Function name of caller 317 const char *func, ///< Function name of caller 318 318 psVector *input, ///< Input vector 319 319 double lower, ///< lower bound
Note:
See TracChangeset
for help on using the changeset viewer.
