1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #ifndef _CXCORE_TYPES_H_
44 #define _CXCORE_TYPES_H_
46 #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
47 #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
56 #if !defined _MSC_VER && !defined __BORLANDC__
70 #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && \
71 (_MSC_VER >= 1400 || defined CV_ICC)) \
72 || (defined __SSE2__ && defined __GNUC__ && __GNUC__ >= 4)
73 #include <emmintrin.h>
79 #if ((defined __SSE__ || defined __MMX__) && defined __GNUC__ && __GNUC__ >= 3)
83 #if defined __BORLANDC__
91 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
97 #elif defined __IPL_H__
100 #endif // SKIP_INCLUDES
102 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
103 #define CV_CDECL __cdecl
104 #define CV_STDCALL __stdcall
112 #define CV_EXTERN_C extern "C"
113 #define CV_DEFAULT(val) = val
116 #define CV_DEFAULT(val)
120 #ifndef CV_EXTERN_C_FUNCPTR
122 #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
124 #define CV_EXTERN_C_FUNCPTR(x) typedef x
129 #if defined __cplusplus
130 #define CV_INLINE inline
131 #elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && !defined __GNUC__
132 #define CV_INLINE __inline
134 #define CV_INLINE static
136 #endif /* CV_INLINE */
138 #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && defined CVAPI_EXPORTS
139 #define CV_EXPORTS __declspec(dllexport)
145 #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
148 #if defined _MSC_VER || defined __BORLANDC__
149 typedef __int64 int64;
150 typedef unsigned __int64 uint64;
152 typedef int64_t int64;
153 typedef uint64_t uint64;
157 typedef unsigned char uchar;
158 typedef unsigned short ushort;
161 typedef signed char schar;
163 /* CvArr* is used to pass arbitrary
164 * array-like data structures
165 * into functions where the particular
166 * array type is recognized at runtime:
170 typedef union Cv32suf
178 typedef union Cv64suf
186 /****************************************************************************************\
187 * Common macros and inline functions *
188 \****************************************************************************************/
190 #define CV_PI 3.1415926535897932384626433832795
191 #define CV_LOG2 0.69314718055994530941723212145818
193 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
196 #define MIN(a,b) ((a) > (b) ? (b) : (a))
200 #define MAX(a,b) ((a) < (b) ? (b) : (a))
203 /* min & max without jumps */
204 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
206 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
208 /* absolute value without jumps */
210 #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
212 #define CV_IABS(a) abs(a)
214 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
215 #define CV_SIGN(a) CV_CMP((a),0)
217 CV_INLINE int cvRound( double value )
220 __m128d t = _mm_set_sd( value );
221 return _mm_cvtsd_si32(t);
222 #elif (defined WIN32 || defined _WIN32) && !defined WIN64 && !defined _WIN64 && defined _MSC_VER
230 #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
231 return (int)lrint(value);
233 // while this is not IEEE754-compliant rounding, it's usually a good enough approximation
234 return (int)(value + 0.5);
239 CV_INLINE int cvFloor( double value )
243 return i - (i > value);
245 __m128d t = _mm_set_sd( value );
246 int i = _mm_cvtsd_si32(t);
247 return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
249 int i = cvRound(value);
251 diff.f = (float)(value - i);
252 return i - (diff.i < 0);
257 CV_INLINE int cvCeil( double value )
261 return i + (i < value);
263 __m128d t = _mm_set_sd( value );
264 int i = _mm_cvtsd_si32(t);
265 return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
267 int i = cvRound(value);
269 diff.f = (float)(i - value);
270 return i + (diff.i < 0);
274 #define cvInvSqrt(value) ((float)(1./sqrt(value)))
275 #define cvSqrt(value) ((float)sqrt(value))
277 CV_INLINE int cvIsNaN( double value )
279 #if 1/*defined _MSC_VER || defined __BORLANDC__
280 return _isnan(value);
281 #elif defined __GNUC__
286 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
287 ((unsigned)ieee754.u != 0) > 0x7ff00000;
292 CV_INLINE int cvIsInf( double value )
294 #if 1/*defined _MSC_VER || defined __BORLANDC__
295 return !_finite(value);
296 #elif defined __GNUC__
301 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
302 (unsigned)ieee754.u == 0;
307 /*************** Random number generation *******************/
309 typedef uint64 CvRNG;
311 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
313 CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
317 /* Return random 32-bit unsigned integer: */
318 CV_INLINE unsigned cvRandInt( CvRNG* rng )
321 temp = (uint64)(unsigned)temp*4164903690U + (temp >> 32);
323 return (unsigned)temp;
326 /* Returns random floating-point number between 0 and 1: */
327 CV_INLINE double cvRandReal( CvRNG* rng )
329 return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
332 /****************************************************************************************\
333 * Image type (IplImage) *
334 \****************************************************************************************/
339 * The following definitions (until #endif)
340 * is an extract from IPL headers.
341 * Copyright (c) 1995 Intel Corporation.
343 #define IPL_DEPTH_SIGN 0x80000000
345 #define IPL_DEPTH_1U 1
346 #define IPL_DEPTH_8U 8
347 #define IPL_DEPTH_16U 16
348 #define IPL_DEPTH_32F 32
350 #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
351 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
352 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
354 #define IPL_DATA_ORDER_PIXEL 0
355 #define IPL_DATA_ORDER_PLANE 1
357 #define IPL_ORIGIN_TL 0
358 #define IPL_ORIGIN_BL 1
360 #define IPL_ALIGN_4BYTES 4
361 #define IPL_ALIGN_8BYTES 8
362 #define IPL_ALIGN_16BYTES 16
363 #define IPL_ALIGN_32BYTES 32
365 #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
366 #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
368 #define IPL_BORDER_CONSTANT 0
369 #define IPL_BORDER_REPLICATE 1
370 #define IPL_BORDER_REFLECT 2
371 #define IPL_BORDER_WRAP 3
373 typedef struct _IplImage
375 int nSize; /* sizeof(IplImage) */
376 int ID; /* version (=0)*/
377 int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */
378 int alphaChannel; /* Ignored by OpenCV */
379 int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
380 IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */
381 char colorModel[4]; /* Ignored by OpenCV */
382 char channelSeq[4]; /* ditto */
383 int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.
384 cvCreateImage can only create interleaved images */
385 int origin; /* 0 - top-left origin,
386 1 - bottom-left origin (Windows bitmaps style). */
387 int align; /* Alignment of image rows (4 or 8).
388 OpenCV ignores it and uses widthStep instead. */
389 int width; /* Image width in pixels. */
390 int height; /* Image height in pixels. */
391 struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */
392 struct _IplImage *maskROI; /* Must be NULL. */
393 void *imageId; /* " " */
394 struct _IplTileInfo *tileInfo; /* " " */
395 int imageSize; /* Image data size in bytes
396 (==image->height*image->widthStep
397 in case of interleaved data)*/
398 char *imageData; /* Pointer to aligned image data. */
399 int widthStep; /* Size of aligned image row in bytes. */
400 int BorderMode[4]; /* Ignored by OpenCV. */
401 int BorderConst[4]; /* Ditto. */
402 char *imageDataOrigin; /* Pointer to very origin of image data
403 (not necessarily aligned) -
404 needed for correct deallocation */
408 typedef struct _IplTileInfo IplTileInfo;
410 typedef struct _IplROI
412 int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
420 typedef struct _IplConvKernel
431 typedef struct _IplConvKernelFP
441 #define IPL_IMAGE_HEADER 1
442 #define IPL_IMAGE_DATA 2
443 #define IPL_IMAGE_ROI 4
447 /* extra border mode */
448 #define IPL_BORDER_REFLECT_101 4
450 #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
451 #define CV_TYPE_NAME_IMAGE "opencv-image"
453 #define CV_IS_IMAGE_HDR(img) \
454 ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
456 #define CV_IS_IMAGE(img) \
457 (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
459 /* for storing double-precision
460 floating point data in IplImage's */
461 #define IPL_DEPTH_64F 64
463 /* get reference to pixel at (col,row),
464 for multi-channel images (col) should be multiplied by number of channels */
465 #define CV_IMAGE_ELEM( image, elemtype, row, col ) \
466 (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
468 /****************************************************************************************\
469 * Matrix type (CvMat) *
470 \****************************************************************************************/
473 #define CV_CN_SHIFT 3
474 #define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
483 #define CV_USRTYPE1 7
485 #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
486 #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
488 #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
489 #define CV_MAKE_TYPE CV_MAKETYPE
491 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
492 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
493 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
494 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
495 #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
497 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
498 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
499 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
500 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
501 #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
503 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
504 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
505 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
506 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
507 #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
509 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
510 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
511 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
512 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
513 #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
515 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
516 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
517 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
518 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
519 #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
521 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
522 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
523 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
524 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
525 #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
527 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
528 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
529 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
530 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
531 #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
533 #define CV_AUTO_STEP 0x7fffffff
534 #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff )
536 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
537 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
538 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
539 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
540 #define CV_MAT_CONT_FLAG_SHIFT 14
541 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
542 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
543 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
544 #define CV_MAT_TEMP_FLAG_SHIFT 15
545 #define CV_MAT_TEMP_FLAG (1 << CV_MAT_TEMP_FLAG_SHIFT)
546 #define CV_IS_TEMP_MAT(flags) ((flags) & CV_MAT_TEMP_FLAG)
548 #define CV_MAGIC_MASK 0xFFFF0000
549 #define CV_MAT_MAGIC_VAL 0x42420000
550 #define CV_TYPE_NAME_MAT "opencv-matrix"
557 /* for internal use only */
591 #define CV_IS_MAT_HDR(mat) \
593 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
594 ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0)
596 #define CV_IS_MAT(mat) \
597 (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
599 #define CV_IS_MASK_ARR(mat) \
600 (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
602 #define CV_ARE_TYPES_EQ(mat1, mat2) \
603 ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
605 #define CV_ARE_CNS_EQ(mat1, mat2) \
606 ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
608 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \
609 ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
611 #define CV_ARE_SIZES_EQ(mat1, mat2) \
612 ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols)
614 #define CV_IS_MAT_CONST(mat) \
615 (((mat)->rows|(mat)->cols) == 1)
617 /* Size of each channel item,
618 0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
619 #define CV_ELEM_SIZE1(type) \
620 ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
622 /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
623 #define CV_ELEM_SIZE(type) \
624 (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
626 /* Inline constructor. No data is allocated internally!!!
627 * (Use together with cvCreateData, or use cvCreateMat instead to
628 * get a matrix with allocated data):
630 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
634 assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
635 type = CV_MAT_TYPE(type);
636 m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
639 m.step = m.cols*CV_ELEM_SIZE(type);
640 m.data.ptr = (uchar*)data;
648 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
649 (assert( (unsigned)(row) < (unsigned)(mat).rows && \
650 (unsigned)(col) < (unsigned)(mat).cols ), \
651 (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
653 #define CV_MAT_ELEM_PTR( mat, row, col ) \
654 CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
656 #define CV_MAT_ELEM( mat, elemtype, row, col ) \
657 (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
660 CV_INLINE double cvmGet( const CvMat* mat, int row, int col )
664 type = CV_MAT_TYPE(mat->type);
665 assert( (unsigned)row < (unsigned)mat->rows &&
666 (unsigned)col < (unsigned)mat->cols );
668 if( type == CV_32FC1 )
669 return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
672 assert( type == CV_64FC1 );
673 return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
678 CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value )
681 type = CV_MAT_TYPE(mat->type);
682 assert( (unsigned)row < (unsigned)mat->rows &&
683 (unsigned)col < (unsigned)mat->cols );
685 if( type == CV_32FC1 )
686 ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
689 assert( type == CV_64FC1 );
690 ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
695 CV_INLINE int cvIplDepth( int type )
697 int depth = CV_MAT_DEPTH(type);
698 return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
699 depth == CV_32S ? IPL_DEPTH_SIGN : 0);
703 /****************************************************************************************\
704 * Multi-dimensional dense array (CvMatND) *
705 \****************************************************************************************/
707 #define CV_MATND_MAGIC_VAL 0x42430000
708 #define CV_TYPE_NAME_MATND "opencv-nd-matrix"
710 #define CV_MAX_DIM 32
711 #define CV_MAX_DIM_HEAP (1 << 16)
713 typedef struct CvMatND
739 #define CV_IS_MATND_HDR(mat) \
740 ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
742 #define CV_IS_MATND(mat) \
743 (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
746 /****************************************************************************************\
747 * Multi-dimensional sparse array (CvSparseMat) *
748 \****************************************************************************************/
750 #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000
751 #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix"
755 typedef struct CvSparseMat
767 int size[CV_MAX_DIM];
771 #define CV_IS_SPARSE_MAT_HDR(mat) \
773 (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
775 #define CV_IS_SPARSE_MAT(mat) \
776 CV_IS_SPARSE_MAT_HDR(mat)
778 /**************** iteration through a sparse array *****************/
780 typedef struct CvSparseNode
783 struct CvSparseNode* next;
787 typedef struct CvSparseMatIterator
795 #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset))
796 #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset))
798 /****************************************************************************************\
800 \****************************************************************************************/
802 typedef int CvHistType;
804 #define CV_HIST_MAGIC_VAL 0x42450000
805 #define CV_HIST_UNIFORM_FLAG (1 << 10)
807 /* indicates whether bin ranges are set already or not */
808 #define CV_HIST_RANGES_FLAG (1 << 11)
810 #define CV_HIST_ARRAY 0
811 #define CV_HIST_SPARSE 1
812 #define CV_HIST_TREE CV_HIST_SPARSE
814 /* should be used as a parameter only,
815 it turns to CV_HIST_UNIFORM_FLAG of hist->type */
816 #define CV_HIST_UNIFORM 1
818 typedef struct CvHistogram
822 float thresh[CV_MAX_DIM][2]; /* For uniform histograms. */
823 float** thresh2; /* For non-uniform histograms. */
824 CvMatND mat; /* Embedded matrix header for array histograms. */
828 #define CV_IS_HIST( hist ) \
830 (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
831 (hist)->bins != NULL)
833 #define CV_IS_UNIFORM_HIST( hist ) \
834 (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
836 #define CV_IS_SPARSE_HIST( hist ) \
837 CV_IS_SPARSE_MAT((hist)->bins)
839 #define CV_HIST_HAS_RANGES( hist ) \
840 (((hist)->type & CV_HIST_RANGES_FLAG) != 0)
842 /****************************************************************************************\
843 * Other supplementary data type definitions *
844 \****************************************************************************************/
846 /*************************************** CvRect *****************************************/
848 typedef struct CvRect
857 CV_INLINE CvRect cvRect( int x, int y, int width, int height )
870 CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
873 roi.xOffset = rect.x;
874 roi.yOffset = rect.y;
875 roi.width = rect.width;
876 roi.height = rect.height;
883 CV_INLINE CvRect cvROIToRect( IplROI roi )
885 return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
888 /*********************************** CvTermCriteria *************************************/
890 #define CV_TERMCRIT_ITER 1
891 #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER
892 #define CV_TERMCRIT_EPS 2
894 typedef struct CvTermCriteria
896 int type; /* may be combination of
904 CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
909 t.max_iter = max_iter;
910 t.epsilon = (float)epsilon;
916 /******************************* CvPoint and variants ***********************************/
918 typedef struct CvPoint
926 CV_INLINE CvPoint cvPoint( int x, int y )
937 typedef struct CvPoint2D32f
945 CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
956 CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
958 return cvPoint2D32f( (float)point.x, (float)point.y );
962 CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
965 ipt.x = cvRound(point.x);
966 ipt.y = cvRound(point.y);
972 typedef struct CvPoint3D32f
981 CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
993 typedef struct CvPoint2D64f
1001 CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
1012 typedef struct CvPoint3D64f
1021 CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
1033 /******************************** CvSize's & CvBox **************************************/
1042 CV_INLINE CvSize cvSize( int width, int height )
1052 typedef struct CvSize2D32f
1060 CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
1064 s.width = (float)width;
1065 s.height = (float)height;
1070 typedef struct CvBox2D
1072 CvPoint2D32f center; /* Center of the box. */
1073 CvSize2D32f size; /* Box width and length. */
1074 float angle; /* Angle between the horizontal axis */
1075 /* and the first side (i.e. length) in degrees */
1080 /* Line iterator state: */
1081 typedef struct CvLineIterator
1083 /* Pointer to the current point: */
1086 /* Bresenham algorithm state: */
1097 /************************************* CvSlice ******************************************/
1099 typedef struct CvSlice
1101 int start_index, end_index;
1105 CV_INLINE CvSlice cvSlice( int start, int end )
1108 slice.start_index = start;
1109 slice.end_index = end;
1114 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
1115 #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
1118 /************************************* CvScalar *****************************************/
1120 typedef struct CvScalar
1126 CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
1127 double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
1130 scalar.val[0] = val0; scalar.val[1] = val1;
1131 scalar.val[2] = val2; scalar.val[3] = val3;
1136 CV_INLINE CvScalar cvRealScalar( double val0 )
1139 scalar.val[0] = val0;
1140 scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
1144 CV_INLINE CvScalar cvScalarAll( double val0123 )
1147 scalar.val[0] = val0123;
1148 scalar.val[1] = val0123;
1149 scalar.val[2] = val0123;
1150 scalar.val[3] = val0123;
1154 /****************************************************************************************\
1155 * Dynamic Data structures *
1156 \****************************************************************************************/
1158 /******************************** Memory storage ****************************************/
1160 typedef struct CvMemBlock
1162 struct CvMemBlock* prev;
1163 struct CvMemBlock* next;
1167 #define CV_STORAGE_MAGIC_VAL 0x42890000
1169 typedef struct CvMemStorage
1172 CvMemBlock* bottom; /* First allocated block. */
1173 CvMemBlock* top; /* Current memory block - top of the stack. */
1174 struct CvMemStorage* parent; /* We get new blocks from parent as needed. */
1175 int block_size; /* Block size. */
1176 int free_space; /* Remaining free space in current block. */
1180 #define CV_IS_STORAGE(storage) \
1181 ((storage) != NULL && \
1182 (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
1185 typedef struct CvMemStoragePos
1193 /*********************************** Sequence *******************************************/
1195 typedef struct CvSeqBlock
1197 struct CvSeqBlock* prev; /* Previous sequence block. */
1198 struct CvSeqBlock* next; /* Next sequence block. */
1199 int start_index; /* Index of the first element in the block + */
1200 /* sequence->first->start_index. */
1201 int count; /* Number of elements in the block. */
1202 schar* data; /* Pointer to the first element of the block. */
1207 #define CV_TREE_NODE_FIELDS(node_type) \
1208 int flags; /* Miscellaneous flags. */ \
1209 int header_size; /* Size of sequence header. */ \
1210 struct node_type* h_prev; /* Previous sequence. */ \
1211 struct node_type* h_next; /* Next sequence. */ \
1212 struct node_type* v_prev; /* 2nd previous sequence. */ \
1213 struct node_type* v_next /* 2nd next sequence. */
1216 Read/Write sequence.
1217 Elements can be dynamically inserted to or deleted from the sequence.
1219 #define CV_SEQUENCE_FIELDS() \
1220 CV_TREE_NODE_FIELDS(CvSeq); \
1221 int total; /* Total number of elements. */ \
1222 int elem_size; /* Size of sequence element in bytes. */ \
1223 schar* block_max; /* Maximal bound of the last block. */ \
1224 schar* ptr; /* Current write pointer. */ \
1225 int delta_elems; /* Grow seq this many at a time. */ \
1226 CvMemStorage* storage; /* Where the seq is stored. */ \
1227 CvSeqBlock* free_blocks; /* Free blocks list. */ \
1228 CvSeqBlock* first; /* Pointer to the first sequence block. */
1230 typedef struct CvSeq
1232 CV_SEQUENCE_FIELDS()
1236 #define CV_TYPE_NAME_SEQ "opencv-sequence"
1237 #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree"
1239 /*************************************** Set ********************************************/
1242 Order is not preserved. There can be gaps between sequence elements.
1243 After the element has been inserted it stays in the same place all the time.
1244 The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists.
1246 #define CV_SET_ELEM_FIELDS(elem_type) \
1248 struct elem_type* next_free;
1250 typedef struct CvSetElem
1252 CV_SET_ELEM_FIELDS(CvSetElem)
1256 #define CV_SET_FIELDS() \
1257 CV_SEQUENCE_FIELDS() \
1258 CvSetElem* free_elems; \
1261 typedef struct CvSet
1268 #define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1)
1269 #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1))
1271 /* Checks whether the element pointed by ptr belongs to a set or not */
1272 #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0)
1274 /************************************* Graph ********************************************/
1277 We represent a graph as a set of vertices.
1278 Vertices contain their adjacency lists (more exactly, pointers to first incoming or
1279 outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.
1280 There is a singly-linked list of incoming/outcoming edges for each vertex.
1282 Each edge consists of
1284 o Two pointers to the starting and ending vertices
1285 (vtx[0] and vtx[1] respectively).
1287 A graph may be oriented or not. In the latter case, edges between
1288 vertex i to vertex j are not distinguished during search operations.
1290 o Two pointers to next edges for the starting and ending vertices, where
1291 next[0] points to the next edge in the vtx[0] adjacency list and
1292 next[1] points to the next edge in the vtx[1] adjacency list.
1294 #define CV_GRAPH_EDGE_FIELDS() \
1297 struct CvGraphEdge* next[2]; \
1298 struct CvGraphVtx* vtx[2];
1301 #define CV_GRAPH_VERTEX_FIELDS() \
1303 struct CvGraphEdge* first;
1306 typedef struct CvGraphEdge
1308 CV_GRAPH_EDGE_FIELDS()
1312 typedef struct CvGraphVtx
1314 CV_GRAPH_VERTEX_FIELDS()
1318 typedef struct CvGraphVtx2D
1320 CV_GRAPH_VERTEX_FIELDS()
1326 Graph is "derived" from the set (this is set a of vertices)
1327 and includes another set (edges)
1329 #define CV_GRAPH_FIELDS() \
1333 typedef struct CvGraph
1339 #define CV_TYPE_NAME_GRAPH "opencv-graph"
1341 /*********************************** Chain/Countour *************************************/
1343 typedef struct CvChain
1345 CV_SEQUENCE_FIELDS()
1350 #define CV_CONTOUR_FIELDS() \
1351 CV_SEQUENCE_FIELDS() \
1356 typedef struct CvContour
1362 typedef CvContour CvPoint2DSeq;
1364 /****************************************************************************************\
1366 \****************************************************************************************/
1368 #define CV_SEQ_MAGIC_VAL 0x42990000
1370 #define CV_IS_SEQ(seq) \
1371 ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
1373 #define CV_SET_MAGIC_VAL 0x42980000
1374 #define CV_IS_SET(set) \
1375 ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
1377 #define CV_SEQ_ELTYPE_BITS 9
1378 #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1)
1380 #define CV_SEQ_ELTYPE_POINT CV_32SC2 /* (x,y) */
1381 #define CV_SEQ_ELTYPE_CODE CV_8UC1 /* freeman code: 0..7 */
1382 #define CV_SEQ_ELTYPE_GENERIC 0
1383 #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1
1384 #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /* &(x,y) */
1385 #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /* #(x,y) */
1386 #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /* &next_o, &next_d, &vtx_o, &vtx_d */
1387 #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /* first_edge, &(x,y) */
1388 #define CV_SEQ_ELTYPE_TRIAN_ATR 0 /* vertex of the binary tree */
1389 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /* connected component */
1390 #define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /* (x,y,z) */
1392 #define CV_SEQ_KIND_BITS 3
1393 #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
1395 /* types of sequences */
1396 #define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS)
1397 #define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS)
1398 #define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS)
1400 /* types of sparse sequences (sets) */
1401 #define CV_SEQ_KIND_GRAPH (3 << CV_SEQ_ELTYPE_BITS)
1402 #define CV_SEQ_KIND_SUBDIV2D (4 << CV_SEQ_ELTYPE_BITS)
1404 #define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
1406 /* flags for curves */
1407 #define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT)
1408 #define CV_SEQ_FLAG_SIMPLE (2 << CV_SEQ_FLAG_SHIFT)
1409 #define CV_SEQ_FLAG_CONVEX (4 << CV_SEQ_FLAG_SHIFT)
1410 #define CV_SEQ_FLAG_HOLE (8 << CV_SEQ_FLAG_SHIFT)
1412 /* flags for graphs */
1413 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
1415 #define CV_GRAPH CV_SEQ_KIND_GRAPH
1416 #define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
1419 #define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
1420 #define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
1421 #define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT)
1422 #define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
1423 #define CV_SEQ_CONTOUR CV_SEQ_POLYGON
1424 #define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON )
1426 /* chain-coded curves */
1427 #define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE)
1428 #define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
1430 /* binary tree for the contour */
1431 #define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR)
1433 /* sequence of the connected components */
1434 #define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP)
1436 /* sequence of the integer numbers */
1437 #define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX)
1439 #define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK)
1440 #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK )
1443 #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
1444 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
1446 #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
1447 #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
1448 #define CV_IS_SEQ_CONVEX( seq ) (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)
1449 #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
1450 #define CV_IS_SEQ_SIMPLE( seq ) ((((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \
1451 CV_IS_SEQ_CONVEX(seq))
1453 /* type checking macros */
1454 #define CV_IS_SEQ_POINT_SET( seq ) \
1455 ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
1457 #define CV_IS_SEQ_POINT_SUBSET( seq ) \
1458 (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
1460 #define CV_IS_SEQ_POLYLINE( seq ) \
1461 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
1463 #define CV_IS_SEQ_POLYGON( seq ) \
1464 (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
1466 #define CV_IS_SEQ_CHAIN( seq ) \
1467 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
1469 #define CV_IS_SEQ_CONTOUR( seq ) \
1470 (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
1472 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
1473 (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
1475 #define CV_IS_SEQ_POLYGON_TREE( seq ) \
1476 (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \
1477 CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE )
1479 #define CV_IS_GRAPH( seq ) \
1480 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
1482 #define CV_IS_GRAPH_ORIENTED( seq ) \
1483 (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
1485 #define CV_IS_SUBDIV2D( seq ) \
1486 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
1488 /****************************************************************************************/
1489 /* Sequence writer & reader */
1490 /****************************************************************************************/
1492 #define CV_SEQ_WRITER_FIELDS() \
1494 CvSeq* seq; /* the sequence written */ \
1495 CvSeqBlock* block; /* current block */ \
1496 schar* ptr; /* pointer to free space */ \
1497 schar* block_min; /* pointer to the beginning of block*/\
1498 schar* block_max; /* pointer to the end of block */
1500 typedef struct CvSeqWriter
1502 CV_SEQ_WRITER_FIELDS()
1507 #define CV_SEQ_READER_FIELDS() \
1509 CvSeq* seq; /* sequence, beign read */ \
1510 CvSeqBlock* block; /* current block */ \
1511 schar* ptr; /* pointer to element be read next */ \
1512 schar* block_min; /* pointer to the beginning of block */\
1513 schar* block_max; /* pointer to the end of block */ \
1514 int delta_index;/* = seq->first->start_index */ \
1515 schar* prev_elem; /* pointer to previous element */
1518 typedef struct CvSeqReader
1520 CV_SEQ_READER_FIELDS()
1524 /****************************************************************************************/
1525 /* Operations on sequences */
1526 /****************************************************************************************/
1528 #define CV_SEQ_ELEM( seq, elem_type, index ) \
1529 /* assert gives some guarantee that <seq> parameter is valid */ \
1530 ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \
1531 (seq)->elem_size == sizeof(elem_type)), \
1532 (elem_type*)((seq)->first && (unsigned)index < \
1533 (unsigned)((seq)->first->count) ? \
1534 (seq)->first->data + (index) * sizeof(elem_type) : \
1535 cvGetSeqElem( (CvSeq*)(seq), (index) )))
1536 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )
1538 /* Add element to sequence: */
1539 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \
1541 if( (writer).ptr >= (writer).block_max ) \
1543 cvCreateSeqBlock( &writer); \
1545 memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
1546 (writer).ptr += (writer).seq->elem_size; \
1549 #define CV_WRITE_SEQ_ELEM( elem, writer ) \
1551 assert( (writer).seq->elem_size == sizeof(elem)); \
1552 if( (writer).ptr >= (writer).block_max ) \
1554 cvCreateSeqBlock( &writer); \
1556 assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
1557 memcpy((writer).ptr, &(elem), sizeof(elem)); \
1558 (writer).ptr += sizeof(elem); \
1562 /* Move reader position forward: */
1563 #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \
1565 if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
1567 cvChangeSeqBlock( &(reader), 1 ); \
1572 /* Move reader position backward: */
1573 #define CV_PREV_SEQ_ELEM( elem_size, reader ) \
1575 if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
1577 cvChangeSeqBlock( &(reader), -1 ); \
1581 /* Read element and move read position forward: */
1582 #define CV_READ_SEQ_ELEM( elem, reader ) \
1584 assert( (reader).seq->elem_size == sizeof(elem)); \
1585 memcpy( &(elem), (reader).ptr, sizeof((elem))); \
1586 CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \
1589 /* Read element and move read position backward: */
1590 #define CV_REV_READ_SEQ_ELEM( elem, reader ) \
1592 assert( (reader).seq->elem_size == sizeof(elem)); \
1593 memcpy(&(elem), (reader).ptr, sizeof((elem))); \
1594 CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \
1598 #define CV_READ_CHAIN_POINT( _pt, reader ) \
1600 (_pt) = (reader).pt; \
1601 if( (reader).ptr ) \
1603 CV_READ_SEQ_ELEM( (reader).code, (reader)); \
1604 assert( ((reader).code & ~7) == 0 ); \
1605 (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \
1606 (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \
1610 #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr)))
1611 #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem)))
1613 #define CV_READ_EDGE( pt1, pt2, reader ) \
1615 assert( sizeof(pt1) == sizeof(CvPoint) && \
1616 sizeof(pt2) == sizeof(CvPoint) && \
1617 reader.seq->elem_size == sizeof(CvPoint)); \
1618 (pt1) = CV_PREV_POINT( reader ); \
1619 (pt2) = CV_CURRENT_POINT( reader ); \
1620 (reader).prev_elem = (reader).ptr; \
1621 CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \
1624 /************ Graph macros ************/
1626 /* Return next graph edge for given vertex: */
1627 #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \
1628 (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \
1629 (edge)->next[(edge)->vtx[1] == (vertex)])
1633 /****************************************************************************************\
1634 * Data structures for persistence (a.k.a serialization) functionality *
1635 \****************************************************************************************/
1637 /* "black box" file storage */
1638 typedef struct CvFileStorage CvFileStorage;
1640 /* Storage flags: */
1641 #define CV_STORAGE_READ 0
1642 #define CV_STORAGE_WRITE 1
1643 #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE
1644 #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE
1645 #define CV_STORAGE_APPEND 2
1647 /* List of attributes: */
1648 typedef struct CvAttrList
1650 const char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs. */
1651 struct CvAttrList* next; /* Pointer to next chunk of the attributes list. */
1655 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL),
1656 CvAttrList* next CV_DEFAULT(NULL) )
1667 #define CV_NODE_NONE 0
1668 #define CV_NODE_INT 1
1669 #define CV_NODE_INTEGER CV_NODE_INT
1670 #define CV_NODE_REAL 2
1671 #define CV_NODE_FLOAT CV_NODE_REAL
1672 #define CV_NODE_STR 3
1673 #define CV_NODE_STRING CV_NODE_STR
1674 #define CV_NODE_REF 4 /* not used */
1675 #define CV_NODE_SEQ 5
1676 #define CV_NODE_MAP 6
1677 #define CV_NODE_TYPE_MASK 7
1679 #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK)
1681 /* file node flags */
1682 #define CV_NODE_FLOW 8 /* Used only for writing structures in YAML format. */
1683 #define CV_NODE_USER 16
1684 #define CV_NODE_EMPTY 32
1685 #define CV_NODE_NAMED 64
1687 #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT)
1688 #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL)
1689 #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING)
1690 #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ)
1691 #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP)
1692 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ)
1693 #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0)
1694 #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0)
1695 #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0)
1696 #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0)
1698 #define CV_NODE_SEQ_SIMPLE 256
1699 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
1701 typedef struct CvString
1708 /* All the keys (names) of elements in the readed file storage
1709 are stored in the hash to speed up the lookup operations: */
1710 typedef struct CvStringHashNode
1714 struct CvStringHashNode* next;
1718 typedef struct CvGenericHash CvFileNodeHash;
1720 /* Basic element of the file storage - scalar or collection: */
1721 typedef struct CvFileNode
1724 struct CvTypeInfo* info; /* type information
1725 (only for user-defined object, for others it is 0) */
1728 double f; /* scalar floating-point number */
1729 int i; /* scalar integer number */
1730 CvString str; /* text string */
1731 CvSeq* seq; /* sequence (ordered collection of file nodes) */
1732 CvFileNodeHash* map; /* map (collection of named file nodes) */
1740 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
1741 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
1742 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
1743 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name,
1744 const void* struct_ptr, CvAttrList attributes );
1745 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
1750 typedef struct CvTypeInfo
1754 struct CvTypeInfo* prev;
1755 struct CvTypeInfo* next;
1756 const char* type_name;
1757 CvIsInstanceFunc is_instance;
1758 CvReleaseFunc release;
1766 /**** System data types ******/
1768 typedef struct CvPluginFuncInfo
1771 void* default_func_addr;
1772 const char* func_names;
1778 typedef struct CvModuleInfo
1780 struct CvModuleInfo* next;
1782 const char* version;
1783 CvPluginFuncInfo* func_tab;
1787 #endif /*_CXCORE_TYPES_H_*/