Changeset 218
- Timestamp:
- Mar 11, 2004, 11:04:22 AM (22 years ago)
- Location:
- trunk/archive/pslib/include
- Files:
-
- 2 edited
-
psMath.h (modified) (3 diffs)
-
psStdArrays.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/include/psMath.h
r208 r218 1 1 #if !defined (PS_MATH_H) 2 2 #define PS_MATH_H 3 4 typedef enum { // type of val is:5 PS_DATA_FLOAT, // float (.f)6 PS_DATA_INT, // int (.i)7 PS_DATA_ARRAY, // array (.v)8 PS_DATA_IMAGE, // image (.v)9 PS_DATA_NTYPE // Number of types; must be last10 } psDataItemType;11 12 /// basic data structure.13 typedef struct {14 int id;15 char *name;16 psDataItemType type;17 union {18 float f;19 int i;20 void *v;21 }22 } psDataItem;23 24 psDataItem *25 psDataItemBinaryOp (psDataItem *out, ///< destination value (may be NULL)26 psDataItem *in1, ///< first input value27 char *operator, ///< operator28 psDataItem *in2 ///< second input value29 );30 31 psDataItem *32 psDataItemUnaryOp (psDataItem *out, ///< destination value (may be NULL)33 psDataItem *in1, ///< input value34 char *operator ///< operator35 );36 37 /*** test: given an image "A", calculate log (a^2) ***/38 39 /*** example 1: data type abstraction */40 41 /*42 psImage A, Y;43 psDI a, b, x, y;44 45 a.v = A;46 a.type = PS_DATA_IMAGE;47 x.f = 2.0;48 x.type = PS_DATA_FLOAT;49 50 b = psDataItemBinaryOp (NULL, a, "^", x);51 y = psDataItemUnaryOp (NULL, b, "log");52 Y = y.v;53 */54 55 /*** example 2: explicit functions ***/56 57 /*58 psImage A, B, Y;59 60 B = psImageOpScalar (NULL, A, "^", 2.0);61 Y = psImageOp (NULL, B, "log");62 */63 64 /* in the later example, we would have the following functions */65 66 /// Perform a binary operation on two images.67 psImage *68 psImageOpImage (psImage *out, ///< destination image (may be NULL)69 psImage *in1, ///< first input image70 char *operator, ///< operator71 psImage *in2 ///< second input image72 );73 74 /// Perform a binary operation on two images.75 psImage *76 psImageOpScalar (psImage *out, ///< destination image (may be NULL)77 psImage *in1, ///< input image78 char *operator, ///< operator79 float in2 ///< input float80 );81 82 /// Perform a binary operation on two images.83 psImage *84 psScalarOpImage (psImage *out, ///< destination image (may be NULL)85 float in1, ///< input float86 char *operator, ///< operator87 psImage *in2 ///< input image88 );89 90 /** for a set of N data types, you need a collection of N^2 - 1 functions **/91 92 /*** example 3: embedded data type */93 94 /*95 psImage A, B, Y;96 97 B = psBinaryOp (NULL, A, "^", psScalar(2));98 Y = psUnaryOp (NULL, B, "log");99 */100 3 101 4 /** in this method, the data types (psImage, psVector) include embedded information about their data type in … … 106 9 */ 107 10 11 /** Perform a binary operation on two data items (psImage, psVector, psScalar). */ 12 psType * 13 psBinaryOp (void *out, ///< destination (may be NULL) 14 void *in1, ///< first input 15 char *operator, ///< operator 16 void *in2 ///< second input 17 ); 18 19 /** Perform a binary operation on two data items (psImage, psVector, psScalar). */ 20 psType * 21 psUnaryOp (void *out, ///< destination (may be NULL) 22 void *in, ///< input 23 char *operator, ///< operator 24 ); 25 26 /** create a psType-ed structure from a constant value. */ 27 p_ps_Scalar * 28 psScalar (double value); 29 30 /** create a psType-ed structure from a specified type */ 31 p_ps_Scalar * 32 psScalarType (char *mode, ///< type description 33 ... ///< value (or values) of specified types 34 ); 35 108 36 typedef struct { 109 37 psType type; … … 112 40 float f; 113 41 double d; 42 complex float c; 114 43 } 115 44 } p_psScalar; 116 45 46 /* examples of usage: 47 48 psImage A, B, C; 49 psVector X, Y; 50 51 calculate C = sin(A^2) 52 53 B = psBinaryOp (NULL, A, "^", psScalar(2)); 54 C = psUnaryOp (NULL, B, "sin"); 55 psFree (B); 56 57 calculate Y = X^2 58 59 Y = psBinaryOp (NULL, Y, "^", psScalar(2)); 60 61 Y = psBinaryOp (NULL, A, "^", X); 62 63 Y = psBinaryOp (NULL, A, "^", psVectorTranspose(X)); 64 65 psFree (B); 66 67 */ 68 69 117 70 #endif -
trunk/archive/pslib/include/psStdArrays.h
r210 r218 8 8 /** Types of the elements of vectors, matrices, etc. */ 9 9 enum { 10 PS_TYPE_CHAR, // !< Character11 PS_TYPE_SHORT, // !< Short integer12 PS_TYPE_INT, // !< Integer13 PS_TYPE_LONG, // !< Long integer14 PS_TYPE_UCHAR, // !< Unsigned character15 PS_TYPE_USHORT, // !< Unsigned short integer16 PS_TYPE_UINT, // !< Unsigned integer17 PS_TYPE_ULONG, // !< Unsigned long integer18 PS_TYPE_FLOAT, // !< Floating point19 PS_TYPE_DOUBLE, // !< Double-precision floating point20 PS_TYPE_COMPLEX // !< Complex numbers consisting of floating point21 PS_TYPE_OTHER // !< Something else that's not supported for arithmetic10 PS_TYPE_CHAR, ///< Character 11 PS_TYPE_SHORT, ///< Short integer 12 PS_TYPE_INT, ///< Integer 13 PS_TYPE_LONG, ///< Long integer 14 PS_TYPE_UCHAR, ///< Unsigned character 15 PS_TYPE_USHORT, ///< Unsigned short integer 16 PS_TYPE_UINT, ///< Unsigned integer 17 PS_TYPE_ULONG, ///< Unsigned long integer 18 PS_TYPE_FLOAT, ///< Floating point 19 PS_TYPE_DOUBLE, ///< Double-precision floating point 20 PS_TYPE_COMPLEX ///< Complex numbers consisting of floating point 21 PS_TYPE_OTHER ///< Something else that's not supported for arithmetic 22 22 } psElemType; 23 23 24 24 /** Dimensions of a data type */ 25 25 enum { 26 PS_DIMEN_SCALAR, //!< Scalar 27 PS_DIMEN_VECTOR, //!< A vector 28 PS_DIMEN_MATRIX, //!< A matrix 29 PS_DIMEN_OTHER //!< Something else that's not supported for arithmetic 26 PS_DIMEN_SCALAR, ///< Scalar 27 PS_DIMEN_VECTOR, ///< A vector 28 PS_DIMEN_TRANSV, ///< A transposed vector 29 PS_DIMEN_MATRIX, ///< A matrix 30 PS_DIMEN_OTHER ///< Something else that's not supported for arithmetic 30 31 } psDimen; 31 32 32 33 /** The type of a data type */ 33 34 typedef struct { 34 enum psElemType type; // !< The type35 enum psDimen dimen; // !< The dimensionality35 enum psElemType type; ///< The type 36 enum psDimen dimen; ///< The dimensionality 36 37 } psType; 37 38 … … 71 72 /** An array of real numbers */ 72 73 typedef struct { 73 enum psType type; // !< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!74 int size; // !< Total number of elements available75 int n; // !< Number of elements in use76 float *arr; // !< The array data74 enum psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 75 int size; ///< Total number of elements available 76 int n; ///< Number of elements in use 77 float *arr; ///< The array data 77 78 } psFloatArray; 78 79 79 80 /** Constructor */ 80 psFloatArray *psFloatArrayAlloc(int s, // !< Total number of elements to make available81 int n // !< Number of elements that will be used81 psFloatArray *psFloatArrayAlloc(int s, ///< Total number of elements to make available 82 int n ///< Number of elements that will be used 82 83 ); 83 84 /** Reallocator */ 84 psFloatArray *psFloatArrayRealloc(psFloatArray *myArray, // !< Array to reallocate85 int s // !< Total number of elements to make available85 psFloatArray *psFloatArrayRealloc(psFloatArray *myArray, ///< Array to reallocate 86 int s ///< Total number of elements to make available 86 87 ); 87 88 /** Destructor */ 88 void psFloatArrayFree(psFloatArray *restrict myArray // !< Array to free89 void psFloatArrayFree(psFloatArray *restrict myArray ///< Array to free 89 90 ); 90 91 … … 93 94 /** Define a vector as an array of real numbers */ 94 95 typedef psFloatArray psVector; 95 #define psVectorAlloc(S,N) psFloatArrayAlloc(S,N) // !< Constructor96 #define psVectorRealloc(A,S) psFloatArrayRealloc(A,S) // !< Reallocator97 #define psVectorFree(A) psFloatArrayFree(A) // !< Destructor96 #define psVectorAlloc(S,N) psFloatArrayAlloc(S,N) ///< Constructor 97 #define psVectorRealloc(A,S) psFloatArrayRealloc(A,S) ///< Reallocator 98 #define psVectorFree(A) psFloatArrayFree(A) ///< Destructor 98 99 99 100 /************************************************************************************************************/ … … 101 102 /** An array of complex numbers */ 102 103 typedef struct { 103 enum psType type; // !< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!104 int size; // !< Total number of elements available105 int n; // !< Number of elements in use106 complex float *arr; // !< The array data104 enum psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 105 int size; ///< Total number of elements available 106 int n; ///< Number of elements in use 107 complex float *arr; ///< The array data 107 108 } psComplexArray; 108 109 109 110 /** Constructor */ 110 psComplexArray *psComplexArrayAlloc(int s, // !< Total number of elements to make available111 int n // !< Number of elements that will be used111 psComplexArray *psComplexArrayAlloc(int s, ///< Total number of elements to make available 112 int n ///< Number of elements that will be used 112 113 ); 113 114 /** Reallocator */ 114 psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, // !< Array to reallocate115 int s // !< Total number of elements to make available115 psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, ///< Array to reallocate 116 int s ///< Total number of elements to make available 116 117 ); 117 118 /** Destructor */ 118 void psComplexArrayFree(psComplexArray *restrict myArray // !< Array to free119 void psComplexArrayFree(psComplexArray *restrict myArray ///< Array to free 119 120 ); 120 121 … … 123 124 /** An array of integers */ 124 125 typedef struct { 125 enum psType type; // !< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!126 int size; // !< Total number of elements available127 int n; // !< Number of elements in use128 int *arr; // !< The array data126 enum psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 127 int size; ///< Total number of elements available 128 int n; ///< Number of elements in use 129 int *arr; ///< The array data 129 130 } psIntArray; 130 131 131 132 /** Constructor */ 132 psIntArray *psIntArrayAlloc(int s, // !< Total number of elements to make available133 int n // !< Number of elements that will be used133 psIntArray *psIntArrayAlloc(int s, ///< Total number of elements to make available 134 int n ///< Number of elements that will be used 134 135 ); 135 136 /** Reallocator */ 136 psIntArray *psIntArrayRealloc(psIntArray *myArray, // !< Array to reallocate137 int s // !< Total number of elements to make available137 psIntArray *psIntArrayRealloc(psIntArray *myArray, ///< Array to reallocate 138 int s ///< Total number of elements to make available 138 139 ); 139 140 /** Destructor */ 140 void psIntArrayFree(psIntArray *restrict myArray // !< Array to free141 void psIntArrayFree(psIntArray *restrict myArray ///< Array to free 141 142 ); 142 143 … … 145 146 /** An array of double-precision real numbers */ 146 147 typedef struct { 147 enum psType type; // !< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!148 int size; // !< Total number of elements available149 int n; // !< Number of elements in use150 double *arr; // !< The array data148 enum psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 149 int size; ///< Total number of elements available 150 int n; ///< Number of elements in use 151 double *arr; ///< The array data 151 152 } psDoubleArray; 152 153 153 154 /** Constructor */ 154 psDoubleArray *psDoubleArrayAlloc(int s, // !< Total number of elements to make available155 int n // !< Number of elements that will be used155 psDoubleArray *psDoubleArrayAlloc(int s, ///< Total number of elements to make available 156 int n ///< Number of elements that will be used 156 157 ); 157 158 /** Reallocator */ 158 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, // !< Array to reallocate159 int s // !< Total number of elements to make available159 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, ///< Array to reallocate 160 int s ///< Total number of elements to make available 160 161 ); 161 162 /** Destructor */ 162 void psDoubleArrayFree(psDoubleArray *restrict myArray // !< Array to free163 void psDoubleArrayFree(psDoubleArray *restrict myArray ///< Array to free 163 164 ); 164 165 … … 167 168 /** An array of real vectors */ 168 169 typedef struct { 169 enum psType type; // !< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!170 int size; // !< Total number of elements available171 int n; // !< Number of elements in use172 psFloatArray *arr; // !< The array data170 enum psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 171 int size; ///< Total number of elements available 172 int n; ///< Number of elements in use 173 psFloatArray *arr; ///< The array data 173 174 } psVectorArray; 174 175 175 176 /** Constructor */ 176 psVectorArray *psVectorArrayAlloc(int s, // !< Total number of elements to make available177 int n // !< Number of elements that will be used177 psVectorArray *psVectorArrayAlloc(int s, ///< Total number of elements to make available 178 int n ///< Number of elements that will be used 178 179 ); 179 180 /** Reallocator */ 180 psVectorArray *psVectorArrayRealloc(psVectorArray *myArray, // !< Array to reallocate181 int s // !< Total number of elements to make available181 psVectorArray *psVectorArrayRealloc(psVectorArray *myArray, ///< Array to reallocate 182 int s ///< Total number of elements to make available 182 183 ); 183 184 /** Destructor */ 184 void psVectorArrayFree(psVectorArray *restrict myArray // !< Array to free185 void psVectorArrayFree(psVectorArray *restrict myArray ///< Array to free 185 186 ); 186 187
Note:
See TracChangeset
for help on using the changeset viewer.
