IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 218


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

Location:
trunk/archive/pslib/include
Files:
2 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
  • trunk/archive/pslib/include/psStdArrays.h

    r210 r218  
    88/** Types of the elements of vectors, matrices, etc. */
    99enum {
    10     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
     10    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
    2222} psElemType;
    2323
    2424/** Dimensions of a data type */
    2525enum {
    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
    3031} psDimen;
    3132
    3233/** The type of a data type */
    3334typedef struct {
    34     enum psElemType type;               //!< The type
    35     enum psDimen dimen;                 //!< The dimensionality
     35    enum psElemType type;               ///< The type
     36    enum psDimen dimen;                 ///< The dimensionality
    3637} psType;
    3738
     
    7172/** An array of real numbers */
    7273typedef struct {
    73     enum psType type;                   //!< Type of data.  THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!
    74     int size;                           //!< Total number of elements available
    75     int n;                              //!< Number of elements in use
    76     float *arr;                         //!< The array data
     74    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
    7778} psFloatArray;
    7879
    7980/** Constructor */
    80 psFloatArray *psFloatArrayAlloc(int s,  //!< Total number of elements to make available
    81                                 int n   //!< Number of elements that will be used
     81psFloatArray *psFloatArrayAlloc(int s,  ///< Total number of elements to make available
     82                                int n   ///< Number of elements that will be used
    8283    );
    8384/** Reallocator */
    84 psFloatArray *psFloatArrayRealloc(psFloatArray *myArray, //!< Array to reallocate
    85                                   int s //!< Total number of elements to make available
     85psFloatArray *psFloatArrayRealloc(psFloatArray *myArray, ///< Array to reallocate
     86                                  int s ///< Total number of elements to make available
    8687    );
    8788/** Destructor */
    88 void psFloatArrayFree(psFloatArray *restrict myArray //!< Array to free
     89void psFloatArrayFree(psFloatArray *restrict myArray ///< Array to free
    8990    );
    9091
     
    9394/** Define a vector as an array of real numbers */
    9495typedef psFloatArray psVector;
    95 #define psVectorAlloc(S,N) psFloatArrayAlloc(S,N) //!< Constructor
    96 #define psVectorRealloc(A,S) psFloatArrayRealloc(A,S) //!< Reallocator
    97 #define psVectorFree(A) psFloatArrayFree(A) //!< Destructor
     96#define psVectorAlloc(S,N) psFloatArrayAlloc(S,N) ///< Constructor
     97#define psVectorRealloc(A,S) psFloatArrayRealloc(A,S) ///< Reallocator
     98#define psVectorFree(A) psFloatArrayFree(A) ///< Destructor
    9899
    99100/************************************************************************************************************/
     
    101102/** An array of complex numbers */
    102103typedef struct {
    103     enum psType type;                   //!< Type of data.  THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!
    104     int size;                           //!< Total number of elements available
    105     int n;                              //!< Number of elements in use
    106     complex float *arr;                 //!< The array data
     104    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
    107108} psComplexArray;
    108109
    109110/** Constructor */
    110 psComplexArray *psComplexArrayAlloc(int s, //!< Total number of elements to make available
    111                                     int n       //!< Number of elements that will be used
     111psComplexArray *psComplexArrayAlloc(int s, ///< Total number of elements to make available
     112                                    int n       ///< Number of elements that will be used
    112113    );
    113114/** Reallocator */
    114 psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, //!< Array to reallocate
    115                                       int s     //!< Total number of elements to make available
     115psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, ///< Array to reallocate
     116                                      int s     ///< Total number of elements to make available
    116117    );
    117118/** Destructor */
    118 void psComplexArrayFree(psComplexArray *restrict myArray //!< Array to free
     119void psComplexArrayFree(psComplexArray *restrict myArray ///< Array to free
    119120    );
    120121
     
    123124/** An array of integers */
    124125typedef struct {
    125     enum psType type;                   //!< Type of data.  THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!
    126     int size;                           //!< Total number of elements available
    127     int n;                              //!< Number of elements in use
    128     int *arr;                           //!< The array data
     126    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
    129130} psIntArray;
    130131
    131132/** Constructor */
    132 psIntArray *psIntArrayAlloc(int s,      //!< Total number of elements to make available
    133                             int n       //!< Number of elements that will be used
     133psIntArray *psIntArrayAlloc(int s,      ///< Total number of elements to make available
     134                            int n       ///< Number of elements that will be used
    134135    );
    135136/** Reallocator */
    136 psIntArray *psIntArrayRealloc(psIntArray *myArray, //!< Array to reallocate
    137                               int s     //!< Total number of elements to make available
     137psIntArray *psIntArrayRealloc(psIntArray *myArray, ///< Array to reallocate
     138                              int s     ///< Total number of elements to make available
    138139    );
    139140/** Destructor */
    140 void psIntArrayFree(psIntArray *restrict myArray //!< Array to free
     141void psIntArrayFree(psIntArray *restrict myArray ///< Array to free
    141142    );
    142143
     
    145146/** An array of double-precision real numbers */
    146147typedef struct {
    147     enum psType type;                   //!< Type of data.  THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!
    148     int size;                           //!< Total number of elements available
    149     int n;                              //!< Number of elements in use
    150     double *arr;                        //!< The array data
     148    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
    151152} psDoubleArray;
    152153
    153154/** Constructor */
    154 psDoubleArray *psDoubleArrayAlloc(int s, //!< Total number of elements to make available
    155                                   int n //!< Number of elements that will be used
     155psDoubleArray *psDoubleArrayAlloc(int s, ///< Total number of elements to make available
     156                                  int n ///< Number of elements that will be used
    156157    );
    157158/** Reallocator */
    158 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, //!< Array to reallocate
    159                                     int s       //!< Total number of elements to make available
     159psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, ///< Array to reallocate
     160                                    int s       ///< Total number of elements to make available
    160161    );
    161162/** Destructor */
    162 void psDoubleArrayFree(psDoubleArray *restrict myArray //!< Array to free
     163void psDoubleArrayFree(psDoubleArray *restrict myArray ///< Array to free
    163164    );
    164165
     
    167168/** An array of real vectors */
    168169typedef struct {
    169     enum psType type;                   //!< Type of data.  THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!
    170     int size;                           //!< Total number of elements available
    171     int n;                              //!< Number of elements in use
    172     psFloatArray *arr;                  //!< The array data
     170    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
    173174} psVectorArray;
    174175
    175176/** Constructor */
    176 psVectorArray *psVectorArrayAlloc(int s, //!< Total number of elements to make available
    177                                   int n //!< Number of elements that will be used
     177psVectorArray *psVectorArrayAlloc(int s, ///< Total number of elements to make available
     178                                  int n ///< Number of elements that will be used
    178179    );
    179180/** Reallocator */
    180 psVectorArray *psVectorArrayRealloc(psVectorArray *myArray, //!< Array to reallocate
    181                                     int s       //!< Total number of elements to make available
     181psVectorArray *psVectorArrayRealloc(psVectorArray *myArray, ///< Array to reallocate
     182                                    int s       ///< Total number of elements to make available
    182183    );
    183184/** Destructor */
    184 void psVectorArrayFree(psVectorArray *restrict myArray //!< Array to free
     185void psVectorArrayFree(psVectorArray *restrict myArray ///< Array to free
    185186    );
    186187
Note: See TracChangeset for help on using the changeset viewer.