opencv: /usr/ports/pobj/OpenCV-2.2.0/OpenCV-2.2.0/modules/core/include/opencv2/core/types_c.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# /usr/ports/pobj/OpenCV-2.2.0/OpenCV-2.2.0/modules/core/include/opencv2/core/types_c.h

Go to the documentation of this file.

    00001 /*M///////////////////////////////////////////////////////////////////////////////////////
    00002 //
    00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
    00004 //
    00005 //  By downloading, copying, installing or using the software you agree to this license.
    00006 //  If you do not agree to this license, do not download, install,
    00007 //  copy or use the software.
    00008 //
    00009 //
    00010 //                          License Agreement
    00011 //                For Open Source Computer Vision Library
    00012 //
    00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
    00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
    00015 // Third party copyrights are property of their respective owners.
    00016 //
    00017 // Redistribution and use in source and binary forms, with or without modification,
    00018 // are permitted provided that the following conditions are met:
    00019 //
    00020 //   * Redistribution's of source code must retain the above copyright notice,
    00021 //     this list of conditions and the following disclaimer.
    00022 //
    00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
    00024 //     this list of conditions and the following disclaimer in the documentation
    00025 //     and/or other materials provided with the distribution.
    00026 //
    00027 //   * The name of the copyright holders may not be used to endorse or promote products
    00028 //     derived from this software without specific prior written permission.
    00029 //
    00030 // This software is provided by the copyright holders and contributors "as is" and
    00031 // any express or implied warranties, including, but not limited to, the implied
    00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
    00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
    00034 // indirect, incidental, special, exemplary, or consequential damages
    00035 // (including, but not limited to, procurement of substitute goods or services;
    00036 // loss of use, data, or profits; or business interruption) however caused
    00037 // and on any theory of liability, whether in contract, strict liability,
    00038 // or tort (including negligence or otherwise) arising in any way out of
    00039 // the use of this software, even if advised of the possibility of such damage.
    00040 //
    00041 //M*/
    00042
    00043 #ifndef __OPENCV_CORE_TYPES_H__
    00044 #define __OPENCV_CORE_TYPES_H__
    00045
    00046 #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
    00047 #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
    00048 #endif
    00049
    00050
    00051 #ifndef SKIP_INCLUDES
    00052   #include <assert.h>
    00053   #include <stdlib.h>
    00054   #include <string.h>
    00055   #include <float.h>
    00056
    00057 #if !defined _MSC_VER && !defined __BORLANDC__
    00058   #include <stdint.h>
    00059 #endif
    00060
    00061   #if defined __ICL
    00062     #define CV_ICC   __ICL
    00063   #elif defined __ICC
    00064     #define CV_ICC   __ICC
    00065   #elif defined __ECL
    00066     #define CV_ICC   __ECL
    00067   #elif defined __ECC
    00068     #define CV_ICC   __ECC
    00069   #elif defined __INTEL_COMPILER
    00070     #define CV_ICC   __INTEL_COMPILER
    00071   #endif
    00072
    00073   #if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
    00074     #if defined WIN32
    00075                 #include <intrin.h>
    00076         #endif
    00077     #include <emmintrin.h>
    00078   #endif
    00079
    00080   #if defined __BORLANDC__
    00081     #include <fastmath.h>
    00082   #else
    00083     #include <math.h>
    00084   #endif
    00085
    00086   #ifdef HAVE_IPL
    00087       #ifndef __IPL_H__
    00088           #if defined WIN32 || defined _WIN32
    00089               #include <ipl.h>
    00090           #else
    00091               #include <ipl/ipl.h>
    00092           #endif
    00093       #endif
    00094   #elif defined __IPL_H__
    00095       #define HAVE_IPL
    00096   #endif
    00097 #endif // SKIP_INCLUDES
    00098
    00099 #if defined WIN32 || defined _WIN32
    00100     #define CV_CDECL __cdecl
    00101     #define CV_STDCALL __stdcall
    00102 #else
    00103     #define CV_CDECL
    00104     #define CV_STDCALL
    00105 #endif
    00106
    00107 #ifndef CV_EXTERN_C
    00108     #ifdef __cplusplus
    00109         #define CV_EXTERN_C extern "C"
    00110         #define CV_DEFAULT(val) = val
    00111     #else
    00112         #define CV_EXTERN_C
    00113         #define CV_DEFAULT(val)
    00114     #endif
    00115 #endif
    00116
    00117 #ifndef CV_EXTERN_C_FUNCPTR
    00118     #ifdef __cplusplus
    00119         #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
    00120     #else
    00121         #define CV_EXTERN_C_FUNCPTR(x) typedef x
    00122     #endif
    00123 #endif
    00124
    00125 #ifndef CV_INLINE
    00126 #if defined __cplusplus
    00127     #define CV_INLINE inline
    00128 #elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__
    00129     #define CV_INLINE __inline
    00130 #else
    00131     #define CV_INLINE static
    00132 #endif
    00133 #endif /* CV_INLINE */
    00134
    00135 #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
    00136     #define CV_EXPORTS __declspec(dllexport)
    00137 #else
    00138     #define CV_EXPORTS
    00139 #endif
    00140
    00141 #ifndef CVAPI
    00142     #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
    00143 #endif
    00144
    00145 #if defined _MSC_VER || defined __BORLANDC__
    00146 typedef __int64 int64;
    00147 typedef unsigned __int64 uint64;
    00148 #else
    00149 typedef int64_t int64;
    00150 typedef uint64_t uint64;
    00151 #endif
    00152
    00153 #ifndef HAVE_IPL
    00154 typedef unsigned char uchar;
    00155 typedef unsigned short ushort;
    00156 #endif
    00157
    00158 typedef signed char schar;
    00159
    00160 /* special informative macros for wrapper generators */
    00161 #define CV_CARRAY(counter)
    00162 #define CV_CUSTOM_CARRAY(args)
    00163 #define CV_EXPORTS_W CV_EXPORTS
    00164 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
    00165 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
    00166 #define CV_EXPORTS_W_MAP CV_EXPORTS
    00167 #define CV_IN_OUT
    00168 #define CV_OUT
    00169 #define CV_PROP
    00170 #define CV_PROP_RW
    00171 #define CV_WRAP
    00172 #define CV_WRAP_AS(synonym)
    00173 #define CV_WRAP_DEFAULT(value)
    00174
    00175 /* CvArr* is used to pass arbitrary
    00176  * array-like data structures
    00177  * into functions where the particular
    00178  * array type is recognized at runtime:
    00179  */
    00180 typedef void CvArr;
    00181
    00182 typedef union Cv32suf
    00183 {
    00184     int i;
    00185     unsigned u;
    00186     float f;
    00187 }
    00188 Cv32suf;
    00189
    00190 typedef union Cv64suf
    00191 {
    00192     int64 i;
    00193     uint64 u;
    00194     double f;
    00195 }
    00196 Cv64suf;
    00197
    00198 typedef int CVStatus;
    00199
    00200 enum {
    00201  CV_StsOk=                       0,  /* everithing is ok                */
    00202  CV_StsBackTrace=               -1,  /* pseudo error for back trace     */
    00203  CV_StsError=                   -2,  /* unknown /unspecified error      */
    00204  CV_StsInternal=                -3,  /* internal error (bad state)      */
    00205  CV_StsNoMem=                   -4,  /* insufficient memory             */
    00206  CV_StsBadArg=                  -5,  /* function arg/param is bad       */
    00207  CV_StsBadFunc=                 -6,  /* unsupported function            */
    00208  CV_StsNoConv=                  -7,  /* iter. didn't converge           */
    00209  CV_StsAutoTrace=               -8,  /* tracing                         */
    00210  CV_HeaderIsNull=               -9,  /* image header is NULL            */
    00211  CV_BadImageSize=              -10, /* image size is invalid           */
    00212  CV_BadOffset=                 -11, /* offset is invalid               */
    00213  CV_BadDataPtr=                -12,
    00214  CV_BadStep=                   -13,
    00215  CV_BadModelOrChSeq=           -14,
    00216  CV_BadNumChannels=            -15,
    00217  CV_BadNumChannel1U=           -16,
    00218  CV_BadDepth=                  -17,
    00219  CV_BadAlphaChannel=           -18,
    00220  CV_BadOrder=                  -19,
    00221  CV_BadOrigin=                 -20,
    00222  CV_BadAlign=                  -21,
    00223  CV_BadCallBack=               -22,
    00224  CV_BadTileSize=               -23,
    00225  CV_BadCOI=                    -24,
    00226  CV_BadROISize=                -25,
    00227  CV_MaskIsTiled=               -26,
    00228  CV_StsNullPtr=                -27, /* null pointer */
    00229  CV_StsVecLengthErr=           -28, /* incorrect vector length */
    00230  CV_StsFilterStructContentErr= -29, /* incorr. filter structure content */
    00231  CV_StsKernelStructContentErr= -30, /* incorr. transform kernel content */
    00232  CV_StsFilterOffsetErr=        -31, /* incorrect filter ofset value */
    00233  CV_StsBadSize=                -201, /* the input/output structure size is incorrect  */
    00234  CV_StsDivByZero=              -202, /* division by zero */
    00235  CV_StsInplaceNotSupported=    -203, /* in-place operation is not supported */
    00236  CV_StsObjectNotFound=         -204, /* request can't be completed */
    00237  CV_StsUnmatchedFormats=       -205, /* formats of input/output arrays differ */
    00238  CV_StsBadFlag=                -206, /* flag is wrong or not supported */
    00239  CV_StsBadPoint=               -207, /* bad CvPoint */
    00240  CV_StsBadMask=                -208, /* bad format of mask (neither 8uC1 nor 8sC1)*/
    00241  CV_StsUnmatchedSizes=         -209, /* sizes of input/output structures do not match */
    00242  CV_StsUnsupportedFormat=      -210, /* the data format/type is not supported by the function*/
    00243  CV_StsOutOfRange=             -211, /* some of parameters are out of range */
    00244  CV_StsParseError=             -212, /* invalid syntax/structure of the parsed file */
    00245  CV_StsNotImplemented=         -213, /* the requested function/feature is not implemented */
    00246  CV_StsBadMemBlock=            -214, /* an allocated block has been corrupted */
    00247  CV_StsAssert=                 -215, /* assertion failed */
    00248  CV_GpuNotSupported=           -216,
    00249  CV_GpuApiCallError=           -217,
    00250  CV_GpuNppCallError=           -218
    00251 };
    00252
    00253 /****************************************************************************************\
    00254 *                             Common macros and inline functions                         *
    00255 \****************************************************************************************/
    00256
    00257 #define CV_PI   3.1415926535897932384626433832795
    00258 #define CV_LOG2 0.69314718055994530941723212145818
    00259
    00260 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
    00261
    00262 #ifndef MIN
    00263 #define MIN(a,b)  ((a) > (b) ? (b) : (a))
    00264 #endif
    00265
    00266 #ifndef MAX
    00267 #define MAX(a,b)  ((a) < (b) ? (b) : (a))
    00268 #endif
    00269
    00270 /* min & max without jumps */
    00271 #define  CV_IMIN(a, b)  ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
    00272
    00273 #define  CV_IMAX(a, b)  ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
    00274
    00275 /* absolute value without jumps */
    00276 #ifndef __cplusplus
    00277 #define  CV_IABS(a)     (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
    00278 #else
    00279 #define  CV_IABS(a)     abs(a)
    00280 #endif
    00281 #define  CV_CMP(a,b)    (((a) > (b)) - ((a) < (b)))
    00282 #define  CV_SIGN(a)     CV_CMP((a),0)
    00283
    00284 CV_INLINE  int  cvRound( double value )
    00285 {
    00286 #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && !defined __APPLE__)
    00287     __m128d t = _mm_set_sd( value );
    00288     return _mm_cvtsd_si32(t);
    00289 #elif defined _MSC_VER && defined _M_IX86
    00290     int t;
    00291     __asm
    00292     {
    00293         fld value;
    00294         fistp t;
    00295     }
    00296     return t;
    00297 #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
    00298     return (int)lrint(value);
    00299 #else
    00300     // while this is not IEEE754-compliant rounding, it's usually a good enough approximation
    00301     return (int)(value + (value >= 0 ? 0.5 : -0.5));
    00302 #endif
    00303 }
    00304
    00305
    00306 CV_INLINE  int  cvFloor( double value )
    00307 {
    00308 #ifdef __GNUC__
    00309     int i = (int)value;
    00310     return i - (i > value);
    00311 #elif defined _MSC_VER && defined _M_X64
    00312     __m128d t = _mm_set_sd( value );
    00313     int i = _mm_cvtsd_si32(t);
    00314     return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
    00315 #else
    00316     int i = cvRound(value);
    00317     Cv32suf diff;
    00318     diff.f = (float)(value - i);
    00319     return i - (diff.i < 0);
    00320 #endif
    00321 }
    00322
    00323
    00324 CV_INLINE  int  cvCeil( double value )
    00325 {
    00326 #ifdef __GNUC__
    00327     int i = (int)value;
    00328     return i + (i < value);
    00329 #elif defined _MSC_VER && defined _M_X64
    00330     __m128d t = _mm_set_sd( value );
    00331     int i = _mm_cvtsd_si32(t);
    00332     return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
    00333 #else
    00334     int i = cvRound(value);
    00335     Cv32suf diff;
    00336     diff.f = (float)(i - value);
    00337     return i + (diff.i < 0);
    00338 #endif
    00339 }
    00340
    00341 #define cvInvSqrt(value) ((float)(1./sqrt(value)))
    00342 #define cvSqrt(value)  ((float)sqrt(value))
    00343
    00344 CV_INLINE int cvIsNaN( double value )
    00345 {
    00346 #if 1/*defined _MSC_VER || defined __BORLANDC__
    00347     return _isnan(value);
    00348 #elif defined __GNUC__
    00349     return isnan(value);
    00350 #else*/
    00351     Cv64suf ieee754;
    00352     ieee754.f = value;
    00353     return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
    00354            ((unsigned)ieee754.u != 0) > 0x7ff00000;
    00355 #endif
    00356 }
    00357
    00358
    00359 CV_INLINE int cvIsInf( double value )
    00360 {
    00361 #if 1/*defined _MSC_VER || defined __BORLANDC__
    00362     return !_finite(value);
    00363 #elif defined __GNUC__
    00364     return isinf(value);
    00365 #else*/
    00366     Cv64suf ieee754;
    00367     ieee754.f = value;
    00368     return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
    00369            (unsigned)ieee754.u == 0;
    00370 #endif
    00371 }
    00372
    00373
    00374 /*************** Random number generation *******************/
    00375
    00376 typedef uint64 CvRNG;
    00377
    00378 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
    00379 {
    00380     CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
    00381     return rng;
    00382 }
    00383
    00384 /* Return random 32-bit unsigned integer: */
    00385 CV_INLINE unsigned cvRandInt( CvRNG* rng )
    00386 {
    00387     uint64 temp = *rng;
    00388     temp = (uint64)(unsigned)temp*4164903690U + (temp >> 32);
    00389     *rng = temp;
    00390     return (unsigned)temp;
    00391 }
    00392
    00393 /* Returns random floating-point number between 0 and 1: */
    00394 CV_INLINE double cvRandReal( CvRNG* rng )
    00395 {
    00396     return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
    00397 }
    00398
    00399 /****************************************************************************************\
    00400 *                                  Image type (IplImage)                                 *
    00401 \****************************************************************************************/
    00402
    00403 #ifndef HAVE_IPL
    00404
    00405 /*
    00406  * The following definitions (until #endif)
    00407  * is an extract from IPL headers.
    00408  * Copyright (c) 1995 Intel Corporation.
    00409  */
    00410 #define IPL_DEPTH_SIGN 0x80000000
    00411
    00412 #define IPL_DEPTH_1U     1
    00413 #define IPL_DEPTH_8U     8
    00414 #define IPL_DEPTH_16U   16
    00415 #define IPL_DEPTH_32F   32
    00416
    00417 #define IPL_DEPTH_8S  (IPL_DEPTH_SIGN| 8)
    00418 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
    00419 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
    00420
    00421 #define IPL_DATA_ORDER_PIXEL  0
    00422 #define IPL_DATA_ORDER_PLANE  1
    00423
    00424 #define IPL_ORIGIN_TL 0
    00425 #define IPL_ORIGIN_BL 1
    00426
    00427 #define IPL_ALIGN_4BYTES   4
    00428 #define IPL_ALIGN_8BYTES   8
    00429 #define IPL_ALIGN_16BYTES 16
    00430 #define IPL_ALIGN_32BYTES 32
    00431
    00432 #define IPL_ALIGN_DWORD   IPL_ALIGN_4BYTES
    00433 #define IPL_ALIGN_QWORD   IPL_ALIGN_8BYTES
    00434
    00435 #define IPL_BORDER_CONSTANT   0
    00436 #define IPL_BORDER_REPLICATE  1
    00437 #define IPL_BORDER_REFLECT    2
    00438 #define IPL_BORDER_WRAP       3
    00439
    00440 typedef struct _IplImage
    00441 {
    00442     int  nSize;             /* sizeof(IplImage) */
    00443     int  ID;                /* version (=0)*/
    00444     int  nChannels;         /* Most of OpenCV functions support 1,2,3 or 4 channels */
    00445     int  alphaChannel;      /* Ignored by OpenCV */
    00446     int  depth;             /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
    00447                                IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported.  */
    00448     char colorModel[4];     /* Ignored by OpenCV */
    00449     char channelSeq[4];     /* ditto */
    00450     int  dataOrder;         /* 0 - interleaved color channels, 1 - separate color channels.
    00451                                cvCreateImage can only create interleaved images */
    00452     int  origin;            /* 0 - top-left origin,
    00453                                1 - bottom-left origin (Windows bitmaps style).  */
    00454     int  align;             /* Alignment of image rows (4 or 8).
    00455                                OpenCV ignores it and uses widthStep instead.    */
    00456     int  width;             /* Image width in pixels.                           */
    00457     int  height;            /* Image height in pixels.                          */
    00458     struct _IplROI *roi;    /* Image ROI. If NULL, the whole image is selected. */
    00459     struct _IplImage *maskROI;      /* Must be NULL. */
    00460     void  *imageId;                 /* "           " */
    00461     struct _IplTileInfo *tileInfo;  /* "           " */
    00462     int  imageSize;         /* Image data size in bytes
    00463                                (==image->height*image->widthStep
    00464                                in case of interleaved data)*/
    00465     char *imageData;        /* Pointer to aligned image data.         */
    00466     int  widthStep;         /* Size of aligned image row in bytes.    */
    00467     int  BorderMode[4];     /* Ignored by OpenCV.                     */
    00468     int  BorderConst[4];    /* Ditto.                                 */
    00469     char *imageDataOrigin;  /* Pointer to very origin of image data
    00470                                (not necessarily aligned) -
    00471                                needed for correct deallocation */
    00472 }
    00473 IplImage;
    00474
    00475 typedef struct _IplTileInfo IplTileInfo;
    00476
    00477 typedef struct _IplROI
    00478 {
    00479     int  coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
    00480     int  xOffset;
    00481     int  yOffset;
    00482     int  width;
    00483     int  height;
    00484 }
    00485 IplROI;
    00486
    00487 typedef struct _IplConvKernel
    00488 {
    00489     int  nCols;
    00490     int  nRows;
    00491     int  anchorX;
    00492     int  anchorY;
    00493     int *values;
    00494     int  nShiftR;
    00495 }
    00496 IplConvKernel;
    00497
    00498 typedef struct _IplConvKernelFP
    00499 {
    00500     int  nCols;
    00501     int  nRows;
    00502     int  anchorX;
    00503     int  anchorY;
    00504     float *values;
    00505 }
    00506 IplConvKernelFP;
    00507
    00508 #define IPL_IMAGE_HEADER 1
    00509 #define IPL_IMAGE_DATA   2
    00510 #define IPL_IMAGE_ROI    4
    00511
    00512 #endif/*HAVE_IPL*/
    00513
    00514 /* extra border mode */
    00515 #define IPL_BORDER_REFLECT_101    4
    00516 #define IPL_BORDER_TRANSPARENT    5
    00517
    00518 #define IPL_IMAGE_MAGIC_VAL  ((int)sizeof(IplImage))
    00519 #define CV_TYPE_NAME_IMAGE "opencv-image"
    00520
    00521 #define CV_IS_IMAGE_HDR(img) \
    00522     ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
    00523
    00524 #define CV_IS_IMAGE(img) \
    00525     (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
    00526
    00527 /* for storing double-precision
    00528    floating point data in IplImage's */
    00529 #define IPL_DEPTH_64F  64
    00530
    00531 /* get reference to pixel at (col,row),
    00532    for multi-channel images (col) should be multiplied by number of channels */
    00533 #define CV_IMAGE_ELEM( image, elemtype, row, col )       \
    00534     (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
    00535
    00536 /****************************************************************************************\
    00537 *                                  Matrix type (CvMat)                                   *
    00538 \****************************************************************************************/
    00539
    00540 #define CV_CN_MAX     512
    00541 #define CV_CN_SHIFT   3
    00542 #define CV_DEPTH_MAX  (1 << CV_CN_SHIFT)
    00543
    00544 #define CV_8U   0
    00545 #define CV_8S   1
    00546 #define CV_16U  2
    00547 #define CV_16S  3
    00548 #define CV_32S  4
    00549 #define CV_32F  5
    00550 #define CV_64F  6
    00551 #define CV_USRTYPE1 7
    00552
    00553 #define CV_MAT_DEPTH_MASK       (CV_DEPTH_MAX - 1)
    00554 #define CV_MAT_DEPTH(flags)     ((flags) & CV_MAT_DEPTH_MASK)
    00555
    00556 #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
    00557 #define CV_MAKE_TYPE CV_MAKETYPE
    00558
    00559 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
    00560 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
    00561 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
    00562 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
    00563 #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
    00564
    00565 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
    00566 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
    00567 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
    00568 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
    00569 #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
    00570
    00571 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
    00572 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
    00573 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
    00574 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
    00575 #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
    00576
    00577 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
    00578 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
    00579 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
    00580 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
    00581 #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
    00582
    00583 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
    00584 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
    00585 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
    00586 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
    00587 #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
    00588
    00589 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
    00590 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
    00591 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
    00592 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
    00593 #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
    00594
    00595 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
    00596 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
    00597 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
    00598 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
    00599 #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
    00600
    00601 #define CV_AUTO_STEP  0x7fffffff
    00602 #define CV_WHOLE_ARR  cvSlice( 0, 0x3fffffff )
    00603
    00604 #define CV_MAT_CN_MASK          ((CV_CN_MAX - 1) << CV_CN_SHIFT)
    00605 #define CV_MAT_CN(flags)        ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
    00606 #define CV_MAT_TYPE_MASK        (CV_DEPTH_MAX*CV_CN_MAX - 1)
    00607 #define CV_MAT_TYPE(flags)      ((flags) & CV_MAT_TYPE_MASK)
    00608 #define CV_MAT_CONT_FLAG_SHIFT  14
    00609 #define CV_MAT_CONT_FLAG        (1 << CV_MAT_CONT_FLAG_SHIFT)
    00610 #define CV_IS_MAT_CONT(flags)   ((flags) & CV_MAT_CONT_FLAG)
    00611 #define CV_IS_CONT_MAT          CV_IS_MAT_CONT
    00612 #define CV_SUBMAT_FLAG_SHIFT    15
    00613 #define CV_SUBMAT_FLAG          (1 << CV_SUBMAT_FLAG_SHIFT)
    00614 #define CV_IS_SUBMAT(flags)     ((flags) & CV_MAT_SUBMAT_FLAG)
    00615
    00616 #define CV_MAGIC_MASK       0xFFFF0000
    00617 #define CV_MAT_MAGIC_VAL    0x42420000
    00618 #define CV_TYPE_NAME_MAT    "opencv-matrix"
    00619
    00620 typedef struct CvMat
    00621 {
    00622     int type;
    00623     int step;
    00624
    00625     /* for internal use only */
    00626     int* refcount;
    00627     int hdr_refcount;
    00628
    00629     union
    00630     {
    00631         uchar* ptr;
    00632         short* s;
    00633         int* i;
    00634         float* fl;
    00635         double* db;
    00636     } data;
    00637
    00638 #ifdef __cplusplus
    00639     union
    00640     {
    00641         int rows;
    00642         int height;
    00643     };
    00644
    00645     union
    00646     {
    00647         int cols;
    00648         int width;
    00649     };
    00650 #else
    00651     int rows;
    00652     int cols;
    00653 #endif
    00654
    00655 }
    00656 CvMat;
    00657
    00658
    00659 #define CV_IS_MAT_HDR(mat) \
    00660     ((mat) != NULL && \
    00661     (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
    00662     ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0)
    00663
    00664 #define CV_IS_MAT_HDR_Z(mat) \
    00665     ((mat) != NULL && \
    00666     (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
    00667     ((const CvMat*)(mat))->cols >= 0 && ((const CvMat*)(mat))->rows >= 0)
    00668
    00669 #define CV_IS_MAT(mat) \
    00670     (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
    00671
    00672 #define CV_IS_MASK_ARR(mat) \
    00673     (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
    00674
    00675 #define CV_ARE_TYPES_EQ(mat1, mat2) \
    00676     ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
    00677
    00678 #define CV_ARE_CNS_EQ(mat1, mat2) \
    00679     ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
    00680
    00681 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \
    00682     ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
    00683
    00684 #define CV_ARE_SIZES_EQ(mat1, mat2) \
    00685     ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols)
    00686
    00687 #define CV_IS_MAT_CONST(mat)  \
    00688     (((mat)->rows|(mat)->cols) == 1)
    00689
    00690 /* Size of each channel item,
    00691    0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
    00692 #define CV_ELEM_SIZE1(type) \
    00693     ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
    00694
    00695 /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
    00696 #define CV_ELEM_SIZE(type) \
    00697     (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
    00698
    00699 #define IPL2CV_DEPTH(depth) \
    00700     ((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \
    00701     (CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \
    00702     (((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15)
    00703
    00704 /* Inline constructor. No data is allocated internally!!!
    00705  * (Use together with cvCreateData, or use cvCreateMat instead to
    00706  * get a matrix with allocated data):
    00707  */
    00708 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
    00709 {
    00710     CvMat m;
    00711
    00712     assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
    00713     type = CV_MAT_TYPE(type);
    00714     m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
    00715     m.cols = cols;
    00716     m.rows = rows;
    00717     m.step = m.cols*CV_ELEM_SIZE(type);
    00718     m.data.ptr = (uchar*)data;
    00719     m.refcount = NULL;
    00720     m.hdr_refcount = 0;
    00721
    00722     return m;
    00723 }
    00724
    00725
    00726 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size )  \
    00727     (assert( (unsigned)(row) < (unsigned)(mat).rows &&   \
    00728              (unsigned)(col) < (unsigned)(mat).cols ),   \
    00729      (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
    00730
    00731 #define CV_MAT_ELEM_PTR( mat, row, col )                 \
    00732     CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
    00733
    00734 #define CV_MAT_ELEM( mat, elemtype, row, col )           \
    00735     (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
    00736
    00737
    00738 CV_INLINE  double  cvmGet( const CvMat* mat, int row, int col )
    00739 {
    00740     int type;
    00741
    00742     type = CV_MAT_TYPE(mat->type);
    00743     assert( (unsigned)row < (unsigned)mat->rows &&
    00744             (unsigned)col < (unsigned)mat->cols );
    00745
    00746     if( type == CV_32FC1 )
    00747         return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
    00748     else
    00749     {
    00750         assert( type == CV_64FC1 );
    00751         return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
    00752     }
    00753 }
    00754
    00755
    00756 CV_INLINE  void  cvmSet( CvMat* mat, int row, int col, double value )
    00757 {
    00758     int type;
    00759     type = CV_MAT_TYPE(mat->type);
    00760     assert( (unsigned)row < (unsigned)mat->rows &&
    00761             (unsigned)col < (unsigned)mat->cols );
    00762
    00763     if( type == CV_32FC1 )
    00764         ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
    00765     else
    00766     {
    00767         assert( type == CV_64FC1 );
    00768         ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
    00769     }
    00770 }
    00771
    00772
    00773 CV_INLINE int cvIplDepth( int type )
    00774 {
    00775     int depth = CV_MAT_DEPTH(type);
    00776     return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
    00777            depth == CV_32S ? IPL_DEPTH_SIGN : 0);
    00778 }
    00779
    00780
    00781 /****************************************************************************************\
    00782 *                       Multi-dimensional dense array (CvMatND)                          *
    00783 \****************************************************************************************/
    00784
    00785 #define CV_MATND_MAGIC_VAL    0x42430000
    00786 #define CV_TYPE_NAME_MATND    "opencv-nd-matrix"
    00787
    00788 #define CV_MAX_DIM            32
    00789 #define CV_MAX_DIM_HEAP       (1 << 16)
    00790
    00791 typedef struct CvMatND
    00792 {
    00793     int type;
    00794     int dims;
    00795
    00796     int* refcount;
    00797     int hdr_refcount;
    00798
    00799     union
    00800     {
    00801         uchar* ptr;
    00802         float* fl;
    00803         double* db;
    00804         int* i;
    00805         short* s;
    00806     } data;
    00807
    00808     struct
    00809     {
    00810         int size;
    00811         int step;
    00812     }
    00813     dim[CV_MAX_DIM];
    00814 }
    00815 CvMatND;
    00816
    00817 #define CV_IS_MATND_HDR(mat) \
    00818     ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
    00819
    00820 #define CV_IS_MATND(mat) \
    00821     (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
    00822
    00823
    00824 /****************************************************************************************\
    00825 *                      Multi-dimensional sparse array (CvSparseMat)                      *
    00826 \****************************************************************************************/
    00827
    00828 #define CV_SPARSE_MAT_MAGIC_VAL    0x42440000
    00829 #define CV_TYPE_NAME_SPARSE_MAT    "opencv-sparse-matrix"
    00830
    00831 struct CvSet;
    00832
    00833 typedef struct CvSparseMat
    00834 {
    00835     int type;
    00836     int dims;
    00837     int* refcount;
    00838     int hdr_refcount;
    00839
    00840     struct CvSet* heap;
    00841     void** hashtable;
    00842     int hashsize;
    00843     int valoffset;
    00844     int idxoffset;
    00845     int size[CV_MAX_DIM];
    00846 }
    00847 CvSparseMat;
    00848
    00849 #define CV_IS_SPARSE_MAT_HDR(mat) \
    00850     ((mat) != NULL && \
    00851     (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
    00852
    00853 #define CV_IS_SPARSE_MAT(mat) \
    00854     CV_IS_SPARSE_MAT_HDR(mat)
    00855
    00856 /**************** iteration through a sparse array *****************/
    00857
    00858 typedef struct CvSparseNode
    00859 {
    00860     unsigned hashval;
    00861     struct CvSparseNode* next;
    00862 }
    00863 CvSparseNode;
    00864
    00865 typedef struct CvSparseMatIterator
    00866 {
    00867     CvSparseMat* mat;
    00868     CvSparseNode* node;
    00869     int curidx;
    00870 }
    00871 CvSparseMatIterator;
    00872
    00873 #define CV_NODE_VAL(mat,node)   ((void*)((uchar*)(node) + (mat)->valoffset))
    00874 #define CV_NODE_IDX(mat,node)   ((int*)((uchar*)(node) + (mat)->idxoffset))
    00875
    00876 /****************************************************************************************\
    00877 *                                         Histogram                                      *
    00878 \****************************************************************************************/
    00879
    00880 typedef int CvHistType;
    00881
    00882 #define CV_HIST_MAGIC_VAL     0x42450000
    00883 #define CV_HIST_UNIFORM_FLAG  (1 << 10)
    00884
    00885 /* indicates whether bin ranges are set already or not */
    00886 #define CV_HIST_RANGES_FLAG   (1 << 11)
    00887
    00888 #define CV_HIST_ARRAY         0
    00889 #define CV_HIST_SPARSE        1
    00890 #define CV_HIST_TREE          CV_HIST_SPARSE
    00891
    00892 /* should be used as a parameter only,
    00893    it turns to CV_HIST_UNIFORM_FLAG of hist->type */
    00894 #define CV_HIST_UNIFORM       1
    00895
    00896 typedef struct CvHistogram
    00897 {
    00898     int     type;
    00899     CvArr*  bins;
    00900     float   thresh[CV_MAX_DIM][2];  /* For uniform histograms.                      */
    00901     float** thresh2;                /* For non-uniform histograms.                  */
    00902     CvMatND mat;                    /* Embedded matrix header for array histograms. */
    00903 }
    00904 CvHistogram;
    00905
    00906 #define CV_IS_HIST( hist ) \
    00907     ((hist) != NULL  && \
    00908      (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
    00909      (hist)->bins != NULL)
    00910
    00911 #define CV_IS_UNIFORM_HIST( hist ) \
    00912     (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
    00913
    00914 #define CV_IS_SPARSE_HIST( hist ) \
    00915     CV_IS_SPARSE_MAT((hist)->bins)
    00916
    00917 #define CV_HIST_HAS_RANGES( hist ) \
    00918     (((hist)->type & CV_HIST_RANGES_FLAG) != 0)
    00919
    00920 /****************************************************************************************\
    00921 *                      Other supplementary data type definitions                         *
    00922 \****************************************************************************************/
    00923
    00924 /*************************************** CvRect *****************************************/
    00925
    00926 typedef struct CvRect
    00927 {
    00928     int x;
    00929     int y;
    00930     int width;
    00931     int height;
    00932 }
    00933 CvRect;
    00934
    00935 CV_INLINE  CvRect  cvRect( int x, int y, int width, int height )
    00936 {
    00937     CvRect r;
    00938
    00939     r.x = x;
    00940     r.y = y;
    00941     r.width = width;
    00942     r.height = height;
    00943
    00944     return r;
    00945 }
    00946
    00947
    00948 CV_INLINE  IplROI  cvRectToROI( CvRect rect, int coi )
    00949 {
    00950     IplROI roi;
    00951     roi.xOffset = rect.x;
    00952     roi.yOffset = rect.y;
    00953     roi.width = rect.width;
    00954     roi.height = rect.height;
    00955     roi.coi = coi;
    00956
    00957     return roi;
    00958 }
    00959
    00960
    00961 CV_INLINE  CvRect  cvROIToRect( IplROI roi )
    00962 {
    00963     return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
    00964 }
    00965
    00966 /*********************************** CvTermCriteria *************************************/
    00967
    00968 #define CV_TERMCRIT_ITER    1
    00969 #define CV_TERMCRIT_NUMBER  CV_TERMCRIT_ITER
    00970 #define CV_TERMCRIT_EPS     2
    00971
    00972 typedef struct CvTermCriteria
    00973 {
    00974     int    type;  /* may be combination of
    00975                      CV_TERMCRIT_ITER
    00976                      CV_TERMCRIT_EPS */
    00977     int    max_iter;
    00978     double epsilon;
    00979 }
    00980 CvTermCriteria;
    00981
    00982 CV_INLINE  CvTermCriteria  cvTermCriteria( int type, int max_iter, double epsilon )
    00983 {
    00984     CvTermCriteria t;
    00985
    00986     t.type = type;
    00987     t.max_iter = max_iter;
    00988     t.epsilon = (float)epsilon;
    00989
    00990     return t;
    00991 }
    00992
    00993
    00994 /******************************* CvPoint and variants ***********************************/
    00995
    00996 typedef struct CvPoint
    00997 {
    00998     int x;
    00999     int y;
    01000 }
    01001 CvPoint;
    01002
    01003
    01004 CV_INLINE  CvPoint  cvPoint( int x, int y )
    01005 {
    01006     CvPoint p;
    01007
    01008     p.x = x;
    01009     p.y = y;
    01010
    01011     return p;
    01012 }
    01013
    01014
    01015 typedef struct CvPoint2D32f
    01016 {
    01017     float x;
    01018     float y;
    01019 }
    01020 CvPoint2D32f;
    01021
    01022
    01023 CV_INLINE  CvPoint2D32f  cvPoint2D32f( double x, double y )
    01024 {
    01025     CvPoint2D32f p;
    01026
    01027     p.x = (float)x;
    01028     p.y = (float)y;
    01029
    01030     return p;
    01031 }
    01032
    01033
    01034 CV_INLINE  CvPoint2D32f  cvPointTo32f( CvPoint point )
    01035 {
    01036     return cvPoint2D32f( (float)point.x, (float)point.y );
    01037 }
    01038
    01039
    01040 CV_INLINE  CvPoint  cvPointFrom32f( CvPoint2D32f point )
    01041 {
    01042     CvPoint ipt;
    01043     ipt.x = cvRound(point.x);
    01044     ipt.y = cvRound(point.y);
    01045
    01046     return ipt;
    01047 }
    01048
    01049
    01050 typedef struct CvPoint3D32f
    01051 {
    01052     float x;
    01053     float y;
    01054     float z;
    01055 }
    01056 CvPoint3D32f;
    01057
    01058
    01059 CV_INLINE  CvPoint3D32f  cvPoint3D32f( double x, double y, double z )
    01060 {
    01061     CvPoint3D32f p;
    01062
    01063     p.x = (float)x;
    01064     p.y = (float)y;
    01065     p.z = (float)z;
    01066
    01067     return p;
    01068 }
    01069
    01070
    01071 typedef struct CvPoint2D64f
    01072 {
    01073     double x;
    01074     double y;
    01075 }
    01076 CvPoint2D64f;
    01077
    01078
    01079 CV_INLINE  CvPoint2D64f  cvPoint2D64f( double x, double y )
    01080 {
    01081     CvPoint2D64f p;
    01082
    01083     p.x = x;
    01084     p.y = y;
    01085
    01086     return p;
    01087 }
    01088
    01089
    01090 typedef struct CvPoint3D64f
    01091 {
    01092     double x;
    01093     double y;
    01094     double z;
    01095 }
    01096 CvPoint3D64f;
    01097
    01098
    01099 CV_INLINE  CvPoint3D64f  cvPoint3D64f( double x, double y, double z )
    01100 {
    01101     CvPoint3D64f p;
    01102
    01103     p.x = x;
    01104     p.y = y;
    01105     p.z = z;
    01106
    01107     return p;
    01108 }
    01109
    01110
    01111 /******************************** CvSize's & CvBox **************************************/
    01112
    01113 typedef struct
    01114 {
    01115     int width;
    01116     int height;
    01117 }
    01118 CvSize;
    01119
    01120 CV_INLINE  CvSize  cvSize( int width, int height )
    01121 {
    01122     CvSize s;
    01123
    01124     s.width = width;
    01125     s.height = height;
    01126
    01127     return s;
    01128 }
    01129
    01130 typedef struct CvSize2D32f
    01131 {
    01132     float width;
    01133     float height;
    01134 }
    01135 CvSize2D32f;
    01136
    01137
    01138 CV_INLINE  CvSize2D32f  cvSize2D32f( double width, double height )
    01139 {
    01140     CvSize2D32f s;
    01141
    01142     s.width = (float)width;
    01143     s.height = (float)height;
    01144
    01145     return s;
    01146 }
    01147
    01148 typedef struct CvBox2D
    01149 {
    01150     CvPoint2D32f center;  /* Center of the box.                          */
    01151     CvSize2D32f  size;    /* Box width and length.                       */
    01152     float angle;          /* Angle between the horizontal axis           */
    01153                           /* and the first side (i.e. length) in degrees */
    01154 }
    01155 CvBox2D;
    01156
    01157
    01158 /* Line iterator state: */
    01159 typedef struct CvLineIterator
    01160 {
    01161     /* Pointer to the current point: */
    01162     uchar* ptr;
    01163
    01164     /* Bresenham algorithm state: */
    01165     int  err;
    01166     int  plus_delta;
    01167     int  minus_delta;
    01168     int  plus_step;
    01169     int  minus_step;
    01170 }
    01171 CvLineIterator;
    01172
    01173
    01174
    01175 /************************************* CvSlice ******************************************/
    01176
    01177 typedef struct CvSlice
    01178 {
    01179     int  start_index, end_index;
    01180 }
    01181 CvSlice;
    01182
    01183 CV_INLINE  CvSlice  cvSlice( int start, int end )
    01184 {
    01185     CvSlice slice;
    01186     slice.start_index = start;
    01187     slice.end_index = end;
    01188
    01189     return slice;
    01190 }
    01191
    01192 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
    01193 #define CV_WHOLE_SEQ  cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
    01194
    01195
    01196 /************************************* CvScalar *****************************************/
    01197
    01198 typedef struct CvScalar
    01199 {
    01200     double val[4];
    01201 }
    01202 CvScalar;
    01203
    01204 CV_INLINE  CvScalar  cvScalar( double val0, double val1 CV_DEFAULT(0),
    01205                                double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
    01206 {
    01207     CvScalar scalar;
    01208     scalar.val[0] = val0; scalar.val[1] = val1;
    01209     scalar.val[2] = val2; scalar.val[3] = val3;
    01210     return scalar;
    01211 }
    01212
    01213
    01214 CV_INLINE  CvScalar  cvRealScalar( double val0 )
    01215 {
    01216     CvScalar scalar;
    01217     scalar.val[0] = val0;
    01218     scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
    01219     return scalar;
    01220 }
    01221
    01222 CV_INLINE  CvScalar  cvScalarAll( double val0123 )
    01223 {
    01224     CvScalar scalar;
    01225     scalar.val[0] = val0123;
    01226     scalar.val[1] = val0123;
    01227     scalar.val[2] = val0123;
    01228     scalar.val[3] = val0123;
    01229     return scalar;
    01230 }
    01231
    01232 /****************************************************************************************\
    01233 *                                   Dynamic Data structures                              *
    01234 \****************************************************************************************/
    01235
    01236 /******************************** Memory storage ****************************************/
    01237
    01238 typedef struct CvMemBlock
    01239 {
    01240     struct CvMemBlock*  prev;
    01241     struct CvMemBlock*  next;
    01242 }
    01243 CvMemBlock;
    01244
    01245 #define CV_STORAGE_MAGIC_VAL    0x42890000
    01246
    01247 typedef struct CvMemStorage
    01248 {
    01249     int signature;
    01250     CvMemBlock* bottom;           /* First allocated block.                   */
    01251     CvMemBlock* top;              /* Current memory block - top of the stack. */
    01252     struct  CvMemStorage* parent; /* We get new blocks from parent as needed. */
    01253     int block_size;               /* Block size.                              */
    01254     int free_space;               /* Remaining free space in current block.   */
    01255 }
    01256 CvMemStorage;
    01257
    01258 #define CV_IS_STORAGE(storage)  \
    01259     ((storage) != NULL &&       \
    01260     (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
    01261
    01262
    01263 typedef struct CvMemStoragePos
    01264 {
    01265     CvMemBlock* top;
    01266     int free_space;
    01267 }
    01268 CvMemStoragePos;
    01269
    01270
    01271 /*********************************** Sequence *******************************************/
    01272
    01273 typedef struct CvSeqBlock
    01274 {
    01275     struct CvSeqBlock*  prev; /* Previous sequence block.                   */
    01276     struct CvSeqBlock*  next; /* Next sequence block.                       */
    01277   int    start_index;         /* Index of the first element in the block +  */
    01278                               /* sequence->first->start_index.              */
    01279     int    count;             /* Number of elements in the block.           */
    01280     schar* data;              /* Pointer to the first element of the block. */
    01281 }
    01282 CvSeqBlock;
    01283
    01284
    01285 #define CV_TREE_NODE_FIELDS(node_type)                               \
    01286     int       flags;             /* Miscellaneous flags.     */      \
    01287     int       header_size;       /* Size of sequence header. */      \
    01288     struct    node_type* h_prev; /* Previous sequence.       */      \
    01289     struct    node_type* h_next; /* Next sequence.           */      \
    01290     struct    node_type* v_prev; /* 2nd previous sequence.   */      \
    01291     struct    node_type* v_next  /* 2nd next sequence.       */
    01292
    01293 /*
    01294    Read/Write sequence.
    01295    Elements can be dynamically inserted to or deleted from the sequence.
    01296 */
    01297 #define CV_SEQUENCE_FIELDS()                                              \
    01298     CV_TREE_NODE_FIELDS(CvSeq);                                           \
    01299     int       total;          /* Total number of elements.            */  \
    01300     int       elem_size;      /* Size of sequence element in bytes.   */  \
    01301     schar*    block_max;      /* Maximal bound of the last block.     */  \
    01302     schar*    ptr;            /* Current write pointer.               */  \
    01303     int       delta_elems;    /* Grow seq this many at a time.        */  \
    01304     CvMemStorage* storage;    /* Where the seq is stored.             */  \
    01305     CvSeqBlock* free_blocks;  /* Free blocks list.                    */  \
    01306     CvSeqBlock* first;        /* Pointer to the first sequence block. */
    01307
    01308 typedef struct CvSeq
    01309 {
    01310     CV_SEQUENCE_FIELDS()
    01311 }
    01312 CvSeq;
    01313
    01314 #define CV_TYPE_NAME_SEQ             "opencv-sequence"
    01315 #define CV_TYPE_NAME_SEQ_TREE        "opencv-sequence-tree"
    01316
    01317 /*************************************** Set ********************************************/
    01318 /*
    01319   Set.
    01320   Order is not preserved. There can be gaps between sequence elements.
    01321   After the element has been inserted it stays in the same place all the time.
    01322   The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists.
    01323 */
    01324 #define CV_SET_ELEM_FIELDS(elem_type)   \
    01325     int  flags;                         \
    01326     struct elem_type* next_free;
    01327
    01328 typedef struct CvSetElem
    01329 {
    01330     CV_SET_ELEM_FIELDS(CvSetElem)
    01331 }
    01332 CvSetElem;
    01333
    01334 #define CV_SET_FIELDS()      \
    01335     CV_SEQUENCE_FIELDS()     \
    01336     CvSetElem* free_elems;   \
    01337     int active_count;
    01338
    01339 typedef struct CvSet
    01340 {
    01341     CV_SET_FIELDS()
    01342 }
    01343 CvSet;
    01344
    01345
    01346 #define CV_SET_ELEM_IDX_MASK   ((1 << 26) - 1)
    01347 #define CV_SET_ELEM_FREE_FLAG  (1 << (sizeof(int)*8-1))
    01348
    01349 /* Checks whether the element pointed by ptr belongs to a set or not */
    01350 #define CV_IS_SET_ELEM( ptr )  (((CvSetElem*)(ptr))->flags >= 0)
    01351
    01352 /************************************* Graph ********************************************/
    01353
    01354 /*
    01355   We represent a graph as a set of vertices.
    01356   Vertices contain their adjacency lists (more exactly, pointers to first incoming or
    01357   outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.
    01358   There is a singly-linked list of incoming/outcoming edges for each vertex.
    01359
    01360   Each edge consists of
    01361
    01362      o   Two pointers to the starting and ending vertices
    01363          (vtx[0] and vtx[1] respectively).
    01364
    01365          A graph may be oriented or not. In the latter case, edges between
    01366          vertex i to vertex j are not distinguished during search operations.
    01367
    01368      o   Two pointers to next edges for the starting and ending vertices, where
    01369          next[0] points to the next edge in the vtx[0] adjacency list and
    01370          next[1] points to the next edge in the vtx[1] adjacency list.
    01371 */
    01372 #define CV_GRAPH_EDGE_FIELDS()      \
    01373     int flags;                      \
    01374     float weight;                   \
    01375     struct CvGraphEdge* next[2];    \
    01376     struct CvGraphVtx* vtx[2];
    01377
    01378
    01379 #define CV_GRAPH_VERTEX_FIELDS()    \
    01380     int flags;                      \
    01381     struct CvGraphEdge* first;
    01382
    01383
    01384 typedef struct CvGraphEdge
    01385 {
    01386     CV_GRAPH_EDGE_FIELDS()
    01387 }
    01388 CvGraphEdge;
    01389
    01390 typedef struct CvGraphVtx
    01391 {
    01392     CV_GRAPH_VERTEX_FIELDS()
    01393 }
    01394 CvGraphVtx;
    01395
    01396 typedef struct CvGraphVtx2D
    01397 {
    01398     CV_GRAPH_VERTEX_FIELDS()
    01399     CvPoint2D32f* ptr;
    01400 }
    01401 CvGraphVtx2D;
    01402
    01403 /*
    01404    Graph is "derived" from the set (this is set a of vertices)
    01405    and includes another set (edges)
    01406 */
    01407 #define  CV_GRAPH_FIELDS()   \
    01408     CV_SET_FIELDS()          \
    01409     CvSet* edges;
    01410
    01411 typedef struct CvGraph
    01412 {
    01413     CV_GRAPH_FIELDS()
    01414 }
    01415 CvGraph;
    01416
    01417 #define CV_TYPE_NAME_GRAPH "opencv-graph"
    01418
    01419 /*********************************** Chain/Countour *************************************/
    01420
    01421 typedef struct CvChain
    01422 {
    01423     CV_SEQUENCE_FIELDS()
    01424     CvPoint  origin;
    01425 }
    01426 CvChain;
    01427
    01428 #define CV_CONTOUR_FIELDS()  \
    01429     CV_SEQUENCE_FIELDS()     \
    01430     CvRect rect;             \
    01431     int color;               \
    01432     int reserved[3];
    01433
    01434 typedef struct CvContour
    01435 {
    01436     CV_CONTOUR_FIELDS()
    01437 }
    01438 CvContour;
    01439
    01440 typedef CvContour CvPoint2DSeq;
    01441
    01442 /****************************************************************************************\
    01443 *                                    Sequence types                                      *
    01444 \****************************************************************************************/
    01445
    01446 #define CV_SEQ_MAGIC_VAL             0x42990000
    01447
    01448 #define CV_IS_SEQ(seq) \
    01449     ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
    01450
    01451 #define CV_SET_MAGIC_VAL             0x42980000
    01452 #define CV_IS_SET(set) \
    01453     ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
    01454
    01455 #define CV_SEQ_ELTYPE_BITS           12
    01456 #define CV_SEQ_ELTYPE_MASK           ((1 << CV_SEQ_ELTYPE_BITS) - 1)
    01457
    01458 #define CV_SEQ_ELTYPE_POINT          CV_32SC2  /* (x,y) */
    01459 #define CV_SEQ_ELTYPE_CODE           CV_8UC1   /* freeman code: 0..7 */
    01460 #define CV_SEQ_ELTYPE_GENERIC        0
    01461 #define CV_SEQ_ELTYPE_PTR            CV_USRTYPE1
    01462 #define CV_SEQ_ELTYPE_PPOINT         CV_SEQ_ELTYPE_PTR  /* &(x,y) */
    01463 #define CV_SEQ_ELTYPE_INDEX          CV_32SC1  /* #(x,y) */
    01464 #define CV_SEQ_ELTYPE_GRAPH_EDGE     0  /* &next_o, &next_d, &vtx_o, &vtx_d */
    01465 #define CV_SEQ_ELTYPE_GRAPH_VERTEX   0  /* first_edge, &(x,y) */
    01466 #define CV_SEQ_ELTYPE_TRIAN_ATR      0  /* vertex of the binary tree   */
    01467 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0  /* connected component  */
    01468 #define CV_SEQ_ELTYPE_POINT3D        CV_32FC3  /* (x,y,z)  */
    01469
    01470 #define CV_SEQ_KIND_BITS        2
    01471 #define CV_SEQ_KIND_MASK        (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
    01472
    01473 /* types of sequences */
    01474 #define CV_SEQ_KIND_GENERIC     (0 << CV_SEQ_ELTYPE_BITS)
    01475 #define CV_SEQ_KIND_CURVE       (1 << CV_SEQ_ELTYPE_BITS)
    01476 #define CV_SEQ_KIND_BIN_TREE    (2 << CV_SEQ_ELTYPE_BITS)
    01477
    01478 /* types of sparse sequences (sets) */
    01479 #define CV_SEQ_KIND_GRAPH       (1 << CV_SEQ_ELTYPE_BITS)
    01480 #define CV_SEQ_KIND_SUBDIV2D    (2 << CV_SEQ_ELTYPE_BITS)
    01481
    01482 #define CV_SEQ_FLAG_SHIFT       (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
    01483
    01484 /* flags for curves */
    01485 #define CV_SEQ_FLAG_CLOSED     (1 << CV_SEQ_FLAG_SHIFT)
    01486 #define CV_SEQ_FLAG_SIMPLE     (0 << CV_SEQ_FLAG_SHIFT)
    01487 #define CV_SEQ_FLAG_CONVEX     (0 << CV_SEQ_FLAG_SHIFT)
    01488 #define CV_SEQ_FLAG_HOLE       (2 << CV_SEQ_FLAG_SHIFT)
    01489
    01490 /* flags for graphs */
    01491 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
    01492
    01493 #define CV_GRAPH               CV_SEQ_KIND_GRAPH
    01494 #define CV_ORIENTED_GRAPH      (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
    01495
    01496 /* point sets */
    01497 #define CV_SEQ_POINT_SET       (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
    01498 #define CV_SEQ_POINT3D_SET     (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
    01499 #define CV_SEQ_POLYLINE        (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_POINT)
    01500 #define CV_SEQ_POLYGON         (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
    01501 #define CV_SEQ_CONTOUR         CV_SEQ_POLYGON
    01502 #define CV_SEQ_SIMPLE_POLYGON  (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON  )
    01503
    01504 /* chain-coded curves */
    01505 #define CV_SEQ_CHAIN           (CV_SEQ_KIND_CURVE  | CV_SEQ_ELTYPE_CODE)
    01506 #define CV_SEQ_CHAIN_CONTOUR   (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
    01507
    01508 /* binary tree for the contour */
    01509 #define CV_SEQ_POLYGON_TREE    (CV_SEQ_KIND_BIN_TREE  | CV_SEQ_ELTYPE_TRIAN_ATR)
    01510
    01511 /* sequence of the connected components */
    01512 #define CV_SEQ_CONNECTED_COMP  (CV_SEQ_KIND_GENERIC  | CV_SEQ_ELTYPE_CONNECTED_COMP)
    01513
    01514 /* sequence of the integer numbers */
    01515 #define CV_SEQ_INDEX           (CV_SEQ_KIND_GENERIC  | CV_SEQ_ELTYPE_INDEX)
    01516
    01517 #define CV_SEQ_ELTYPE( seq )   ((seq)->flags & CV_SEQ_ELTYPE_MASK)
    01518 #define CV_SEQ_KIND( seq )     ((seq)->flags & CV_SEQ_KIND_MASK )
    01519
    01520 /* flag checking */
    01521 #define CV_IS_SEQ_INDEX( seq )      ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
    01522                                      (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
    01523
    01524 #define CV_IS_SEQ_CURVE( seq )      (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
    01525 #define CV_IS_SEQ_CLOSED( seq )     (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
    01526 #define CV_IS_SEQ_CONVEX( seq )     0
    01527 #define CV_IS_SEQ_HOLE( seq )       (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
    01528 #define CV_IS_SEQ_SIMPLE( seq )     1
    01529
    01530 /* type checking macros */
    01531 #define CV_IS_SEQ_POINT_SET( seq ) \
    01532     ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
    01533
    01534 #define CV_IS_SEQ_POINT_SUBSET( seq ) \
    01535     (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
    01536
    01537 #define CV_IS_SEQ_POLYLINE( seq )   \
    01538     (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
    01539
    01540 #define CV_IS_SEQ_POLYGON( seq )   \
    01541     (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
    01542
    01543 #define CV_IS_SEQ_CHAIN( seq )   \
    01544     (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
    01545
    01546 #define CV_IS_SEQ_CONTOUR( seq )   \
    01547     (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
    01548
    01549 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
    01550     (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
    01551
    01552 #define CV_IS_SEQ_POLYGON_TREE( seq ) \
    01553     (CV_SEQ_ELTYPE (seq) ==  CV_SEQ_ELTYPE_TRIAN_ATR &&    \
    01554     CV_SEQ_KIND( seq ) ==  CV_SEQ_KIND_BIN_TREE )
    01555
    01556 #define CV_IS_GRAPH( seq )    \
    01557     (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
    01558
    01559 #define CV_IS_GRAPH_ORIENTED( seq )   \
    01560     (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
    01561
    01562 #define CV_IS_SUBDIV2D( seq )  \
    01563     (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
    01564
    01565 /****************************************************************************************/
    01566 /*                            Sequence writer & reader                                  */
    01567 /****************************************************************************************/
    01568
    01569 #define CV_SEQ_WRITER_FIELDS()                                     \
    01570     int          header_size;                                      \
    01571     CvSeq*       seq;        /* the sequence written */            \
    01572     CvSeqBlock*  block;      /* current block */                   \
    01573     schar*       ptr;        /* pointer to free space */           \
    01574     schar*       block_min;  /* pointer to the beginning of block*/\
    01575     schar*       block_max;  /* pointer to the end of block */
    01576
    01577 typedef struct CvSeqWriter
    01578 {
    01579     CV_SEQ_WRITER_FIELDS()
    01580 }
    01581 CvSeqWriter;
    01582
    01583
    01584 #define CV_SEQ_READER_FIELDS()                                      \
    01585     int          header_size;                                       \
    01586     CvSeq*       seq;        /* sequence, beign read */             \
    01587     CvSeqBlock*  block;      /* current block */                    \
    01588     schar*       ptr;        /* pointer to element be read next */  \
    01589     schar*       block_min;  /* pointer to the beginning of block */\
    01590     schar*       block_max;  /* pointer to the end of block */      \
    01591     int          delta_index;/* = seq->first->start_index   */      \
    01592     schar*       prev_elem;  /* pointer to previous element */
    01593
    01594
    01595 typedef struct CvSeqReader
    01596 {
    01597     CV_SEQ_READER_FIELDS()
    01598 }
    01599 CvSeqReader;
    01600
    01601 /****************************************************************************************/
    01602 /*                                Operations on sequences                               */
    01603 /****************************************************************************************/
    01604
    01605 #define  CV_SEQ_ELEM( seq, elem_type, index )                    \
    01606 /* assert gives some guarantee that <seq> parameter is valid */  \
    01607 (   assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) &&      \
    01608     (seq)->elem_size == sizeof(elem_type)),                      \
    01609     (elem_type*)((seq)->first && (unsigned)index <               \
    01610     (unsigned)((seq)->first->count) ?                            \
    01611     (seq)->first->data + (index) * sizeof(elem_type) :           \
    01612     cvGetSeqElem( (CvSeq*)(seq), (index) )))
    01613 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )
    01614
    01615 /* Add element to sequence: */
    01616 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer )     \
    01617 {                                                     \
    01618     if( (writer).ptr >= (writer).block_max )          \
    01619     {                                                 \
    01620         cvCreateSeqBlock( &writer);                   \
    01621     }                                                 \
    01622     memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
    01623     (writer).ptr += (writer).seq->elem_size;          \
    01624 }
    01625
    01626 #define CV_WRITE_SEQ_ELEM( elem, writer )             \
    01627 {                                                     \
    01628     assert( (writer).seq->elem_size == sizeof(elem)); \
    01629     if( (writer).ptr >= (writer).block_max )          \
    01630     {                                                 \
    01631         cvCreateSeqBlock( &writer);                   \
    01632     }                                                 \
    01633     assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
    01634     memcpy((writer).ptr, &(elem), sizeof(elem));      \
    01635     (writer).ptr += sizeof(elem);                     \
    01636 }
    01637
    01638
    01639 /* Move reader position forward: */
    01640 #define CV_NEXT_SEQ_ELEM( elem_size, reader )                 \
    01641 {                                                             \
    01642     if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
    01643     {                                                         \
    01644         cvChangeSeqBlock( &(reader), 1 );                     \
    01645     }                                                         \
    01646 }
    01647
    01648
    01649 /* Move reader position backward: */
    01650 #define CV_PREV_SEQ_ELEM( elem_size, reader )                \
    01651 {                                                            \
    01652     if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
    01653     {                                                        \
    01654         cvChangeSeqBlock( &(reader), -1 );                   \
    01655     }                                                        \
    01656 }
    01657
    01658 /* Read element and move read position forward: */
    01659 #define CV_READ_SEQ_ELEM( elem, reader )                       \
    01660 {                                                              \
    01661     assert( (reader).seq->elem_size == sizeof(elem));          \
    01662     memcpy( &(elem), (reader).ptr, sizeof((elem)));            \
    01663     CV_NEXT_SEQ_ELEM( sizeof(elem), reader )                   \
    01664 }
    01665
    01666 /* Read element and move read position backward: */
    01667 #define CV_REV_READ_SEQ_ELEM( elem, reader )                     \
    01668 {                                                                \
    01669     assert( (reader).seq->elem_size == sizeof(elem));            \
    01670     memcpy(&(elem), (reader).ptr, sizeof((elem)));               \
    01671     CV_PREV_SEQ_ELEM( sizeof(elem), reader )                     \
    01672 }
    01673
    01674
    01675 #define CV_READ_CHAIN_POINT( _pt, reader )                              \
    01676 {                                                                       \
    01677     (_pt) = (reader).pt;                                                \
    01678     if( (reader).ptr )                                                  \
    01679     {                                                                   \
    01680         CV_READ_SEQ_ELEM( (reader).code, (reader));                     \
    01681         assert( ((reader).code & ~7) == 0 );                            \
    01682         (reader).pt.x += (reader).deltas[(int)(reader).code][0];        \
    01683         (reader).pt.y += (reader).deltas[(int)(reader).code][1];        \
    01684     }                                                                   \
    01685 }
    01686
    01687 #define CV_CURRENT_POINT( reader )  (*((CvPoint*)((reader).ptr)))
    01688 #define CV_PREV_POINT( reader )     (*((CvPoint*)((reader).prev_elem)))
    01689
    01690 #define CV_READ_EDGE( pt1, pt2, reader )               \
    01691 {                                                      \
    01692     assert( sizeof(pt1) == sizeof(CvPoint) &&          \
    01693             sizeof(pt2) == sizeof(CvPoint) &&          \
    01694             reader.seq->elem_size == sizeof(CvPoint)); \
    01695     (pt1) = CV_PREV_POINT( reader );                   \
    01696     (pt2) = CV_CURRENT_POINT( reader );                \
    01697     (reader).prev_elem = (reader).ptr;                 \
    01698     CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader));      \
    01699 }
    01700
    01701 /************ Graph macros ************/
    01702
    01703 /* Return next graph edge for given vertex: */
    01704 #define  CV_NEXT_GRAPH_EDGE( edge, vertex )                              \
    01705      (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)),  \
    01706       (edge)->next[(edge)->vtx[1] == (vertex)])
    01707
    01708
    01709
    01710 /****************************************************************************************\
    01711 *             Data structures for persistence (a.k.a serialization) functionality        *
    01712 \****************************************************************************************/
    01713
    01714 /* "black box" file storage */
    01715 typedef struct CvFileStorage CvFileStorage;
    01716
    01717 /* Storage flags: */
    01718 #define CV_STORAGE_READ          0
    01719 #define CV_STORAGE_WRITE         1
    01720 #define CV_STORAGE_WRITE_TEXT    CV_STORAGE_WRITE
    01721 #define CV_STORAGE_WRITE_BINARY  CV_STORAGE_WRITE
    01722 #define CV_STORAGE_APPEND        2
    01723
    01724 /* List of attributes: */
    01725 typedef struct CvAttrList
    01726 {
    01727     const char** attr;         /* NULL-terminated array of (attribute_name,attribute_value) pairs. */
    01728     struct CvAttrList* next;   /* Pointer to next chunk of the attributes list.                    */
    01729 }
    01730 CvAttrList;
    01731
    01732 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL),
    01733                                  CvAttrList* next CV_DEFAULT(NULL) )
    01734 {
    01735     CvAttrList l;
    01736     l.attr = attr;
    01737     l.next = next;
    01738
    01739     return l;
    01740 }
    01741
    01742 struct CvTypeInfo;
    01743
    01744 #define CV_NODE_NONE        0
    01745 #define CV_NODE_INT         1
    01746 #define CV_NODE_INTEGER     CV_NODE_INT
    01747 #define CV_NODE_REAL        2
    01748 #define CV_NODE_FLOAT       CV_NODE_REAL
    01749 #define CV_NODE_STR         3
    01750 #define CV_NODE_STRING      CV_NODE_STR
    01751 #define CV_NODE_REF         4 /* not used */
    01752 #define CV_NODE_SEQ         5
    01753 #define CV_NODE_MAP         6
    01754 #define CV_NODE_TYPE_MASK   7
    01755
    01756 #define CV_NODE_TYPE(flags)  ((flags) & CV_NODE_TYPE_MASK)
    01757
    01758 /* file node flags */
    01759 #define CV_NODE_FLOW        8 /* Used only for writing structures in YAML format. */
    01760 #define CV_NODE_USER        16
    01761 #define CV_NODE_EMPTY       32
    01762 #define CV_NODE_NAMED       64
    01763
    01764 #define CV_NODE_IS_INT(flags)        (CV_NODE_TYPE(flags) == CV_NODE_INT)
    01765 #define CV_NODE_IS_REAL(flags)       (CV_NODE_TYPE(flags) == CV_NODE_REAL)
    01766 #define CV_NODE_IS_STRING(flags)     (CV_NODE_TYPE(flags) == CV_NODE_STRING)
    01767 #define CV_NODE_IS_SEQ(flags)        (CV_NODE_TYPE(flags) == CV_NODE_SEQ)
    01768 #define CV_NODE_IS_MAP(flags)        (CV_NODE_TYPE(flags) == CV_NODE_MAP)
    01769 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ)
    01770 #define CV_NODE_IS_FLOW(flags)       (((flags) & CV_NODE_FLOW) != 0)
    01771 #define CV_NODE_IS_EMPTY(flags)      (((flags) & CV_NODE_EMPTY) != 0)
    01772 #define CV_NODE_IS_USER(flags)       (((flags) & CV_NODE_USER) != 0)
    01773 #define CV_NODE_HAS_NAME(flags)      (((flags) & CV_NODE_NAMED) != 0)
    01774
    01775 #define CV_NODE_SEQ_SIMPLE 256
    01776 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
    01777
    01778 typedef struct CvString
    01779 {
    01780     int len;
    01781     char* ptr;
    01782 }
    01783 CvString;
    01784
    01785 /* All the keys (names) of elements in the readed file storage
    01786    are stored in the hash to speed up the lookup operations: */
    01787 typedef struct CvStringHashNode
    01788 {
    01789     unsigned hashval;
    01790     CvString str;
    01791     struct CvStringHashNode* next;
    01792 }
    01793 CvStringHashNode;
    01794
    01795 typedef struct CvGenericHash CvFileNodeHash;
    01796
    01797 /* Basic element of the file storage - scalar or collection: */
    01798 typedef struct CvFileNode
    01799 {
    01800     int tag;
    01801     struct CvTypeInfo* info; /* type information
    01802             (only for user-defined object, for others it is 0) */
    01803     union
    01804     {
    01805         double f; /* scalar floating-point number */
    01806         int i;    /* scalar integer number */
    01807         CvString str; /* text string */
    01808         CvSeq* seq; /* sequence (ordered collection of file nodes) */
    01809         CvFileNodeHash* map; /* map (collection of named file nodes) */
    01810     } data;
    01811 }
    01812 CvFileNode;
    01813
    01814 #ifdef __cplusplus
    01815 extern "C" {
    01816 #endif
    01817 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
    01818 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
    01819 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
    01820 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name,
    01821                                       const void* struct_ptr, CvAttrList attributes );
    01822 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
    01823 #ifdef __cplusplus
    01824 }
    01825 #endif
    01826
    01827 typedef struct CvTypeInfo
    01828 {
    01829     int flags;
    01830     int header_size;
    01831     struct CvTypeInfo* prev;
    01832     struct CvTypeInfo* next;
    01833     const char* type_name;
    01834     CvIsInstanceFunc is_instance;
    01835     CvReleaseFunc release;
    01836     CvReadFunc read;
    01837     CvWriteFunc write;
    01838     CvCloneFunc clone;
    01839 }
    01840 CvTypeInfo;
    01841
    01842
    01843 /**** System data types ******/
    01844
    01845 typedef struct CvPluginFuncInfo
    01846 {
    01847     void** func_addr;
    01848     void* default_func_addr;
    01849     const char* func_names;
    01850     int search_modules;
    01851     int loaded_from;
    01852 }
    01853 CvPluginFuncInfo;
    01854
    01855 typedef struct CvModuleInfo
    01856 {
    01857     struct CvModuleInfo* next;
    01858     const char* name;
    01859     const char* version;
    01860     CvPluginFuncInfo* func_tab;
    01861 }
    01862 CvModuleInfo;
    01863
    01864 #endif /*_CXCORE_TYPES_H_*/
    01865
    01866 /* End of file. */

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines