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