IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 11, 2004, 11:04:22 AM (22 years ago)
Author:
eugene
Message:

cleaned psMath.h : we have settled on a scheme for binary & unary operators
fixed up the psType entries in psStdArrays.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/pslib/include/psMath.h

    r208 r218  
    11#if !defined (PS_MATH_H)
    22#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 last
    10 } 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 value
    27                     char *operator,     ///< operator
    28                     psDataItem *in2     ///< second input value
    29 );
    30 
    31 psDataItem *
    32 psDataItemUnaryOp (psDataItem *out,     ///< destination value (may be NULL)
    33                    psDataItem *in1,     ///< input value
    34                    char *operator       ///< operator
    35 );
    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 image
    70                 char *operator,         ///< operator
    71                 psImage *in2            ///< second input image
    72 );
    73 
    74 /// Perform a binary operation on two images.
    75 psImage *
    76 psImageOpScalar (psImage *out,          ///< destination image (may be NULL)
    77                  psImage *in1,          ///< input image
    78                  char *operator,        ///< operator
    79                  float in2              ///< input float
    80 );
    81 
    82 /// Perform a binary operation on two images.
    83 psImage *
    84 psScalarOpImage (psImage *out,          ///< destination image (may be NULL)
    85                  float in1,             ///< input float
    86                  char *operator,        ///< operator
    87                  psImage *in2           ///< input image
    88 );
    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 */
    1003
    1014/** in this method, the data types (psImage, psVector) include embedded information about their data type in
     
    1069 */
    10710
     11/** Perform a binary operation on two data items (psImage, psVector, psScalar). */
     12psType *
     13psBinaryOp (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). */
     20psType *
     21psUnaryOp (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. */
     27p_ps_Scalar *
     28psScalar (double value);
     29
     30/** create a psType-ed structure from a specified type  */
     31p_ps_Scalar *
     32psScalarType (char *mode,               ///< type description
     33              ...                       ///< value (or values) of specified types
     34);
     35
    10836typedef struct {
    10937    psType type;
     
    11240        float f;
    11341        double d;
     42        complex float c;
    11443    }
    11544} p_psScalar;
    11645
     46/* examples of usage:
     47
     48psImage A, B, C;
     49psVector X, Y;
     50
     51calculate C = sin(A^2)
     52
     53B = psBinaryOp (NULL, A, "^", psScalar(2));
     54C = psUnaryOp (NULL, B, "sin");
     55psFree (B);
     56
     57calculate Y = X^2
     58
     59Y = psBinaryOp (NULL, Y, "^", psScalar(2));
     60
     61Y = psBinaryOp (NULL, A, "^", X);
     62
     63Y = psBinaryOp (NULL, A, "^", psVectorTranspose(X));
     64
     65psFree (B);
     66
     67*/
     68
     69
    11770#endif
Note: See TracChangeset for help on using the changeset viewer.