opencv on mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers types_c.h Source File

types_c.h

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