Changeset 218 for trunk/archive/pslib/include/psMath.h
- Timestamp:
- Mar 11, 2004, 11:04:22 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/archive/pslib/include/psMath.h (modified) (3 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
Note:
See TracChangeset
for help on using the changeset viewer.
