Woolz Image Processing Version 1.4.0
AlgType.h
Go to the documentation of this file.
00001 #ifndef ALGTYPE_H
00002 #define ALGTYPE_H
00003 #if defined(__GNUC__)
00004 #ident "University of Edinburgh $Id: e1fb75b5486a5ec61918f171ee9fcac0c73117d6 $"
00005 #else
00006 static char _AlgType_h[] = "University of Edinburgh $Id: e1fb75b5486a5ec61918f171ee9fcac0c73117d6 $";
00007 #endif
00008 /*!
00009 * \file         libAlg/AlgType.h
00010 * \author       Bill Hill
00011 * \date         March 1999
00012 * \version      $Id: e1fb75b5486a5ec61918f171ee9fcac0c73117d6 $
00013 * \par
00014 * Address:
00015 *               MRC Human Genetics Unit,
00016 *               MRC Institute of Genetics and Molecular Medicine,
00017 *               University of Edinburgh,
00018 *               Western General Hospital,
00019 *               Edinburgh, EH4 2XU, UK.
00020 * \par
00021 * Copyright (C), [2012],
00022 * The University Court of the University of Edinburgh,
00023 * Old College, Edinburgh, UK.
00024 * 
00025 * This program is free software; you can redistribute it and/or
00026 * modify it under the terms of the GNU General Public License
00027 * as published by the Free Software Foundation; either version 2
00028 * of the License, or (at your option) any later version.
00029 *
00030 * This program is distributed in the hope that it will be
00031 * useful but WITHOUT ANY WARRANTY; without even the implied
00032 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00033 * PURPOSE.  See the GNU General Public License for more
00034 * details.
00035 *
00036 * You should have received a copy of the GNU General Public
00037 * License along with this program; if not, write to the Free
00038 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00039 * Boston, MA  02110-1301, USA.
00040 * \brief        Type definitions for the Woolz numerical algorithm
00041 *               library.
00042 * \ingroup      Alg
00043 */
00044 
00045 
00046 #ifndef WLZ_EXT_BIND
00047 #ifdef  __cplusplus
00048 extern "C" {
00049 #endif
00050 #endif /* WLZ_EXT_BIND */
00051 
00052 /* Standard min, max, absolute value and nearest integer macros */
00053 #define ALG_MAX(X,Y)    (((X)>(Y))?(X):(Y))
00054 #define ALG_MIN(X,Y)    (((X)<(Y))?(X):(Y))
00055 #define ALG_MAXIDX(X,Y) (((X)>(Y))?(0):(1))
00056 #define ALG_MINIDX(X,Y) (((X)<(Y))?(0):(1))
00057 #define ALG_ABS(X)      (((X)>0)?(X):(-(X)))
00058 #define ALG_NINT(X)     ((int)(((X)<0)?((X)-(0.5)):((X)+(0.5))))
00059 #define ALG_SQR(X)      ((X)*(X))
00060 #define ALG_MAX3(X,Y,Z) (((X)>(Y))?(((X)>(Z))?(X):(Z)):(((Y)>(Z))?(Y):(Z)))
00061 #define ALG_MIN3(X,Y,Z) (((X)<(Y))?(((X)<(Z))?(X):(Z)):(((Y)<(Z))?(Y):(Z)))
00062 #define ALG_MAXIDX3(X,Y,Z) \
00063                         (((X)>(Y))?(((X)>(Z))?(0):(3)):(((Y)>(Z))?(1):(3)))
00064 #define ALG_MININD3(X,Y,Z) \
00065                         (((X)<(Y))?(((X)<(Z))?(0):(3)):(((Y)<(Z))?(1):(3)))
00066 
00067 /* Standard math constants */
00068 #define ALG_M_E         (2.7182818284590452354)
00069 #define ALG_M_LOG2E     (1.4426950408889634074)
00070 #define ALG_M_LOG10E    (0.43429448190325182765)
00071 #define ALG_M_LN2       (0.69314718055994530942)
00072 #define ALG_M_LN10      (2.30258509299404568402)
00073 #define ALG_M_PI        (3.14159265358979323846)
00074 #define ALG_M_PI_2      (1.57079632679489661923)
00075 #define ALG_M_PI_4      (0.78539816339744830961)
00076 #define ALG_M_1_PI      (0.31830988618379067154)
00077 #define ALG_M_2_PI      (0.63661977236758134308)
00078 #define ALG_M_2_SQRTPI  (1.12837916709551257390)
00079 #define ALG_M_SQRT2     (1.41421356237309504880)
00080 #define ALG_M_SQRT3     (1.73205080756887729353)
00081 #define ALG_M_SQRT1_2   (0.70710678118654752440)
00082 
00083 /* A tollerance value for double precission arithmetic. */
00084 #define ALG_DBL_TOLLERANCE      (1.0E-9)
00085 
00086 /*!
00087 * \enum         _AlgDistribution
00088 * \brief        Statistical distributions.
00089 *               Typedef: ::AlgDistribution.
00090 */
00091 typedef enum _AlgDistribution
00092 {
00093   ALG_DISTRIBUTION_NORMAL,
00094   ALG_DISTRIBUTION_EXP,   
00095   ALG_DISTRIBUTION_POISSON,
00096   ALG_DISTRIBUTION_BINOMIAL 
00097 } AlgDistribution;
00098 
00099 /*!
00100 * \enum         _AlgMatrixType
00101 * \brief        Matrix representations.
00102 *               Typedef: ::AlgMatrixType
00103 */
00104 typedef enum _AlgMatrixType
00105 {
00106   ALG_MATRIX_NULL = 0,          /*!< A NULL matric with no elements. */
00107   ALG_MATRIX_RECT,              /*!< Rectangular matrix, with storage
00108                                      for each element. These matrices should
00109                                      be allocated using the libAlc array
00110                                      allocation functions. */
00111   ALG_MATRIX_SYM,               /*!< Symmetric matrix, with storage
00112                                      for the upper triangle only. These
00113                                      matrices should be allocated using the
00114                                      libAlc symmetric array allocation
00115                                      functions. */
00116   ALG_MATRIX_LLR                /*!< Sparse matrix stored in linked list
00117                                      row format. */
00118 } AlgMatrixType;
00119 
00120 /*!
00121 * \struct       _AlgMatrix
00122 * \brief        A union of all valid matrix types.
00123 *               Typedef: ::AlgMatrix..
00124 */
00125 typedef union _AlgMatrix
00126 {
00127   struct _AlgMatrixCore *core;
00128   struct _AlgMatrixRect *rect;
00129   struct _AlgMatrixSym  *sym;
00130   struct _AlgMatrixLLR  *llr;
00131 } AlgMatrix;
00132 
00133 /*!
00134 * \struct       _AlgMatrixCore
00135 * \brief        A core matrix type with members common to all matrix types.
00136 *               Typedef: ::AlgMatrixCore.
00137 */
00138 typedef struct _AlgMatrixCore
00139 {
00140   AlgMatrixType type;           /*!< Matrix type. */
00141   size_t        nR;             /*!< Number of rows. */
00142   size_t        nC;             /*!< Number of columns. */
00143 } AlgMatrixCore;
00144 
00145 /*!
00146 * \struct       _AlgMatrixRect
00147 * \brief        Rectangular matrix.
00148 *               Typedef: ::AlgMatrixRect.
00149 */
00150 typedef struct _AlgMatrixRect
00151 {
00152   AlgMatrixType type;           /*!< From AlgmatrixCore. */
00153   size_t        nR;             /*!< From AlgmatrixCore. */
00154   size_t        nC;             /*!< From AlgmatrixCore. */
00155   size_t        maxR;           /*!< Rows space allocated for. */
00156   size_t        maxC;           /*!< Columns space allocated for. */
00157   double        **array;        /* Array of elements. */
00158 } AlgMatrixRect;
00159 
00160 /*!
00161 * \struct       _AlgMatrixSym
00162 * \brief        Symmetric matrix.
00163 *               Typedef: ::AlgMatrixRect.
00164 */
00165 typedef struct _AlgMatrixSym
00166 {
00167   AlgMatrixType type;           /*!< From AlgmatrixCore. */
00168   size_t        nR;             /*!< From AlgmatrixCore. */
00169   size_t        nC;             /*!< From AlgmatrixCore. */
00170   size_t        maxN;           /*!< Max rows/columns space allocated for. */
00171   double        **array;
00172 } AlgMatrixSym;
00173 
00174 /*!
00175 * \struct       _AlgMatrixLLRE
00176 * \brief        Entry in the linked list row matrix.
00177 *               Typedef: ::AlgMatrixLLRE.
00178 */
00179 typedef struct _AlgMatrixLLRE
00180 {
00181   size_t        col;            /*!< Column in matrix. */
00182   double        val;            /*!< Value in the row, column. */
00183   struct _AlgMatrixLLRE *nxt;   /*!< Next entry either in the value list or
00184                                      the free list. */
00185 } AlgMatrixLLRE;
00186 
00187 /*!
00188 * \struct       _AlgMatrixLLRE
00189 * \brief        Linked list row matrix, in which the values are stored
00190 *               in linked lists, with a linked list for each row of
00191 *               the matrix. This can be very efficient if the matrix
00192 *               is very sparse, but is very ineffiecient if the matrix
00193 *               is dense. The cross over is around 5 percent values
00194 *               being non-zero. At 1 percent of values being non-zero
00195 *               the linked list matrix is faster than a rectangular matrix
00196 *               (eg for matrix multiplication) by about a factor of ten.
00197 */
00198 typedef struct _AlgMatrixLLR
00199 {
00200   AlgMatrixType type;           /*!< From AlgmatrixCore. */
00201   size_t        nR;             /*!< From AlgmatrixCore. */
00202   size_t        nC;             /*!< From AlgmatrixCore. */
00203   size_t        numEnt;         /*!< Number of (no-zero) entries. */
00204   size_t        maxEnt;         /*!< Maximum number of entries. */
00205   double        tol;            /*!< Lowest absolute non-zero value. */
00206   void          *blk;           /*!< Stack of blocks of triples allocated
00207                                      managed using AlcFreeStack. */
00208   AlgMatrixLLRE *freeStk;       /*!< Stack of free linked list entries. */
00209   AlgMatrixLLRE **tbl;          /*!< Table of matrix linked lists with a list
00210                                      for each row of the matrix. */
00211 } AlgMatrixLLR;
00212 
00213 typedef struct _AlgMatrixTriple
00214 {
00215   size_t        row;            /*!< Row in matrix. */
00216   size_t        col;            /*!< Column in matrix. */
00217   double        val;            /*!< Value in the row, column. */
00218 } AlgMatrixTriple;
00219 
00220 /*!
00221 * \enum         _AlgPadType
00222 * \brief        Types of daat padding.
00223 *               Typedef: ::AlgPadType.
00224 */
00225 typedef enum _AlgPadType
00226 {
00227   ALG_PAD_NONE,                 /*!< No padding, same as padding with zeros. */
00228   ALG_PAD_ZERO,                 /*!< Pad data with zeros. */
00229   ALG_PAD_END                   /*!< Pad data with first/last data values. */
00230 } AlgPadType;
00231 
00232 /*!
00233 * \struct       _ComplexD
00234 * \brief        Complex number data type.
00235 *               Typedef: ::ComplexD.
00236 */
00237 typedef struct _ComplexD
00238 {
00239   double        re;
00240   double        im;
00241 } ComplexD;
00242 
00243 
00244 /*
00245 * \enum         _AlgError
00246 * \brief        Error codes.
00247 *               Typedef: ::AlgError.
00248 */
00249 typedef enum _AlgError
00250 {
00251   ALG_ERR_NONE          = (0),
00252   ALG_ERR_CONVERGENCE,          /*!< Failure to converge. */
00253   ALG_ERR_DIVZERO,              /*!< Divide by zero. */
00254   ALG_ERR_FUNC,                 /*!< Function parameters invalid. */
00255   ALG_ERR_MALLOC,               /*!< Memory allocation failure. */
00256   ALG_ERR_MATRIX_CONDITION,     /*!< Matrix condition number out of range. */
00257   ALG_ERR_MATRIX_HOMOGENEOUS,   /*!< Homogeneous matrix. */
00258   ALG_ERR_MATRIX_SINGULAR,      /*!< Singular matrix. */
00259   ALG_ERR_MATRIX_TYPE,          /*!< Invalid matrix type given. */
00260   ALG_ERR_NONGLOBAL,            /*!< Finds local solution, but fails to global
00261                                      solution. */
00262   ALG_ERR_READ,                 /*!< Read failure. */
00263   ALG_ERR_WRITE,                /*!< Write failure. */
00264   ALG_ERR_MAX
00265 } AlgError;
00266 
00267 /*
00268 * \enum         _AlgDbgMask
00269 * \brief        Debug mask values.
00270 *               Typedef: ::AlgDbgMask.
00271 */
00272 typedef enum _AlgDbgMask
00273 {
00274   ALG_DBG_NONE          = (0),
00275   ALG_DBG_LVL_1         = (1),
00276   ALG_DBG_LVL_2         = (1<<1),
00277   ALG_DBG_LVL_3         = (1<<2),
00278   ALG_DBG_LVL_FN        = (1<<3)
00279 } AlgDbgMask;
00280 
00281 typedef AlgError        (*AlgDbgFn)(char *, ...);
00282  
00283 extern AlgDbgFn         algDbgOutFn;
00284 #define ALG_DBG_FN      (*algDbgOutFn)
00285 #define ALG_DBG(F,M)    ((((F)&(algDbgMask))==(F))?ALG_DBG_FN M:ALG_ERR_NONE)
00286  
00287 #ifndef WLZ_EXT_BIND
00288 #ifdef  __cplusplus 
00289 }
00290 #endif /* __cplusplus */
00291 #endif /* WLZ_EXT_BIND */
00292 
00293 #endif /* ! ALGTYPE_H */