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 __OPENCV_CORE_TYPES_H__
44 #define __OPENCV_CORE_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 */
57 #if !defined _MSC_VER && !defined __BORLANDC__
69 #elif defined __INTEL_COMPILER
70 #define CV_ICC __INTEL_COMPILER
73 #if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
77 #include <emmintrin.h>
80 #if defined __BORLANDC__
88 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
94 #elif defined __IPL_H__
97 #endif // SKIP_INCLUDES
99 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
100 #define CV_CDECL __cdecl
101 #define CV_STDCALL __stdcall
109 #define CV_EXTERN_C extern "C"
110 #define CV_DEFAULT(val) = val
113 #define CV_DEFAULT(val)
117 #ifndef CV_EXTERN_C_FUNCPTR
119 #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
121 #define CV_EXTERN_C_FUNCPTR(x) typedef x
126 #if defined __cplusplus
127 #define CV_INLINE inline
128 #elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && !defined __GNUC__
129 #define CV_INLINE __inline
131 #define CV_INLINE static
133 #endif /* CV_INLINE */
135 #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && defined CVAPI_EXPORTS
136 #define CV_EXPORTS __declspec(dllexport)
142 #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
145 #if defined _MSC_VER || defined __BORLANDC__
146 typedef __int64 int64;
147 typedef unsigned __int64 uint64;
149 typedef int64_t int64;
150 typedef uint64_t uint64;
154 typedef unsigned char uchar;
155 typedef unsigned short ushort;
158 typedef signed char schar;
160 /* CvArr* is used to pass arbitrary
161 * array-like data structures
162 * into functions where the particular
163 * array type is recognized at runtime:
167 typedef union Cv32suf
175 typedef union Cv64suf
183 /****************************************************************************************\
184 * Common macros and inline functions *
185 \****************************************************************************************/
187 #define CV_PI 3.1415926535897932384626433832795
188 #define CV_LOG2 0.69314718055994530941723212145818
190 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
193 #define MIN(a,b) ((a) > (b) ? (b) : (a))
197 #define MAX(a,b) ((a) < (b) ? (b) : (a))
200 /* min & max without jumps */
201 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
203 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
205 /* absolute value without jumps */
207 #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
209 #define CV_IABS(a) abs(a)
211 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
212 #define CV_SIGN(a) CV_CMP((a),0)
214 CV_INLINE int cvRound( double value )
216 #if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && !defined __APPLE__)
217 __m128d t = _mm_set_sd( value );
218 return _mm_cvtsd_si32(t);
219 #elif defined _MSC_VER && defined _M_X86
227 #elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
228 return (int)lrint(value);
230 // while this is not IEEE754-compliant rounding, it's usually a good enough approximation
231 return (int)(value + 0.5);
236 CV_INLINE int cvFloor( double value )
240 return i - (i > value);
241 #elif defined _MSC_VER && defined _M_X64
242 __m128d t = _mm_set_sd( value );
243 int i = _mm_cvtsd_si32(t);
244 return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
246 int i = cvRound(value);
248 diff.f = (float)(value - i);
249 return i - (diff.i < 0);
254 CV_INLINE int cvCeil( double value )
258 return i + (i < value);
259 #elif defined _MSC_VER && defined _M_X64
260 __m128d t = _mm_set_sd( value );
261 int i = _mm_cvtsd_si32(t);
262 return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
264 int i = cvRound(value);
266 diff.f = (float)(i - value);
267 return i + (diff.i < 0);
271 #define cvInvSqrt(value) ((float)(1./sqrt(value)))
272 #define cvSqrt(value) ((float)sqrt(value))
274 CV_INLINE int cvIsNaN( double value )
276 #if 1/*defined _MSC_VER || defined __BORLANDC__
277 return _isnan(value);
278 #elif defined __GNUC__
283 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
284 ((unsigned)ieee754.u != 0) > 0x7ff00000;
289 CV_INLINE int cvIsInf( double value )
291 #if 1/*defined _MSC_VER || defined __BORLANDC__
292 return !_finite(value);
293 #elif defined __GNUC__
298 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
299 (unsigned)ieee754.u == 0;
304 /*************** Random number generation *******************/
306 typedef uint64 CvRNG;
308 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
310 CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
314 /* Return random 32-bit unsigned integer: */
315 CV_INLINE unsigned cvRandInt( CvRNG* rng )
318 temp = (uint64)(unsigned)temp*4164903690U + (temp >> 32);
320 return (unsigned)temp;
323 /* Returns random floating-point number between 0 and 1: */
324 CV_INLINE double cvRandReal( CvRNG* rng )
326 return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
329 /****************************************************************************************\
330 * Image type (IplImage) *
331 \****************************************************************************************/
336 * The following definitions (until #endif)
337 * is an extract from IPL headers.
338 * Copyright (c) 1995 Intel Corporation.
340 #define IPL_DEPTH_SIGN 0x80000000
342 #define IPL_DEPTH_1U 1
343 #define IPL_DEPTH_8U 8
344 #define IPL_DEPTH_16U 16
345 #define IPL_DEPTH_32F 32
347 #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
348 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
349 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
351 #define IPL_DATA_ORDER_PIXEL 0
352 #define IPL_DATA_ORDER_PLANE 1
354 #define IPL_ORIGIN_TL 0
355 #define IPL_ORIGIN_BL 1
357 #define IPL_ALIGN_4BYTES 4
358 #define IPL_ALIGN_8BYTES 8
359 #define IPL_ALIGN_16BYTES 16
360 #define IPL_ALIGN_32BYTES 32
362 #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
363 #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
365 #define IPL_BORDER_CONSTANT 0
366 #define IPL_BORDER_REPLICATE 1
367 #define IPL_BORDER_REFLECT 2
368 #define IPL_BORDER_WRAP 3
370 typedef struct _IplImage
372 int nSize; /* sizeof(IplImage) */
373 int ID; /* version (=0)*/
374 int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */
375 int alphaChannel; /* Ignored by OpenCV */
376 int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
377 IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */
378 char colorModel[4]; /* Ignored by OpenCV */
379 char channelSeq[4]; /* ditto */
380 int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.
381 cvCreateImage can only create interleaved images */
382 int origin; /* 0 - top-left origin,
383 1 - bottom-left origin (Windows bitmaps style). */
384 int align; /* Alignment of image rows (4 or 8).
385 OpenCV ignores it and uses widthStep instead. */
386 int width; /* Image width in pixels. */
387 int height; /* Image height in pixels. */
388 struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */
389 struct _IplImage *maskROI; /* Must be NULL. */
390 void *imageId; /* " " */
391 struct _IplTileInfo *tileInfo; /* " " */
392 int imageSize; /* Image data size in bytes
393 (==image->height*image->widthStep
394 in case of interleaved data)*/
395 char *imageData; /* Pointer to aligned image data. */
396 int widthStep; /* Size of aligned image row in bytes. */
397 int BorderMode[4]; /* Ignored by OpenCV. */
398 int BorderConst[4]; /* Ditto. */
399 char *imageDataOrigin; /* Pointer to very origin of image data
400 (not necessarily aligned) -
401 needed for correct deallocation */
405 typedef struct _IplTileInfo IplTileInfo;
407 typedef struct _IplROI
409 int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
417 typedef struct _IplConvKernel
428 typedef struct _IplConvKernelFP
438 #define IPL_IMAGE_HEADER 1
439 #define IPL_IMAGE_DATA 2
440 #define IPL_IMAGE_ROI 4
444 /* extra border mode */
445 #define IPL_BORDER_REFLECT_101 4
447 #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
448 #define CV_TYPE_NAME_IMAGE "opencv-image"
450 #define CV_IS_IMAGE_HDR(img) \
451 ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
453 #define CV_IS_IMAGE(img) \
454 (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
456 /* for storing double-precision
457 floating point data in IplImage's */
458 #define IPL_DEPTH_64F 64
460 /* get reference to pixel at (col,row),
461 for multi-channel images (col) should be multiplied by number of channels */
462 #define CV_IMAGE_ELEM( image, elemtype, row, col ) \
463 (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
465 /****************************************************************************************\
466 * Matrix type (CvMat) *
467 \****************************************************************************************/
470 #define CV_CN_SHIFT 3
471 #define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
480 #define CV_USRTYPE1 7
482 #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
483 #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
485 #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
486 #define CV_MAKE_TYPE CV_MAKETYPE
488 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
489 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
490 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
491 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
492 #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
494 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
495 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
496 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
497 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
498 #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
500 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
501 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
502 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
503 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
504 #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
506 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
507 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
508 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
509 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
510 #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
512 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
513 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
514 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
515 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
516 #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
518 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
519 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
520 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
521 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
522 #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
524 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
525 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
526 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
527 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
528 #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
530 #define CV_AUTO_STEP 0x7fffffff
531 #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff )
533 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
534 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
535 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
536 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
537 #define CV_MAT_CONT_FLAG_SHIFT 14
538 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
539 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
540 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
541 #define CV_MAT_TEMP_FLAG_SHIFT 15
542 #define CV_MAT_TEMP_FLAG (1 << CV_MAT_TEMP_FLAG_SHIFT)
543 #define CV_IS_TEMP_MAT(flags) ((flags) & CV_MAT_TEMP_FLAG)
545 #define CV_MAGIC_MASK 0xFFFF0000
546 #define CV_MAT_MAGIC_VAL 0x42420000
547 #define CV_TYPE_NAME_MAT "opencv-matrix"
554 /* for internal use only */
588 #define CV_IS_MAT_HDR(mat) \
590 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
591 ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0)
593 #define CV_IS_MAT(mat) \
594 (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
596 #define CV_IS_MASK_ARR(mat) \
597 (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
599 #define CV_ARE_TYPES_EQ(mat1, mat2) \
600 ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
602 #define CV_ARE_CNS_EQ(mat1, mat2) \
603 ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
605 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \
606 ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
608 #define CV_ARE_SIZES_EQ(mat1, mat2) \
609 ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols)
611 #define CV_IS_MAT_CONST(mat) \
612 (((mat)->rows|(mat)->cols) == 1)
614 /* Size of each channel item,
615 0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
616 #define CV_ELEM_SIZE1(type) \
617 ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
619 /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
620 #define CV_ELEM_SIZE(type) \
621 (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
623 #define IPL2CV_DEPTH(depth) \
624 ((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \
625 (CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \
626 (((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15)
628 /* Inline constructor. No data is allocated internally!!!
629 * (Use together with cvCreateData, or use cvCreateMat instead to
630 * get a matrix with allocated data):
632 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
636 assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
637 type = CV_MAT_TYPE(type);
638 m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
641 m.step = m.cols*CV_ELEM_SIZE(type);
642 m.data.ptr = (uchar*)data;
650 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
651 (assert( (unsigned)(row) < (unsigned)(mat).rows && \
652 (unsigned)(col) < (unsigned)(mat).cols ), \
653 (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
655 #define CV_MAT_ELEM_PTR( mat, row, col ) \
656 CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
658 #define CV_MAT_ELEM( mat, elemtype, row, col ) \
659 (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
662 CV_INLINE double cvmGet( const CvMat* mat, int row, int col )
666 type = CV_MAT_TYPE(mat->type);
667 assert( (unsigned)row < (unsigned)mat->rows &&
668 (unsigned)col < (unsigned)mat->cols );
670 if( type == CV_32FC1 )
671 return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
674 assert( type == CV_64FC1 );
675 return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
680 CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value )
683 type = CV_MAT_TYPE(mat->type);
684 assert( (unsigned)row < (unsigned)mat->rows &&
685 (unsigned)col < (unsigned)mat->cols );
687 if( type == CV_32FC1 )
688 ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
691 assert( type == CV_64FC1 );
692 ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
697 CV_INLINE int cvIplDepth( int type )
699 int depth = CV_MAT_DEPTH(type);
700 return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
701 depth == CV_32S ? IPL_DEPTH_SIGN : 0);
705 /****************************************************************************************\
706 * Multi-dimensional dense array (CvMatND) *
707 \****************************************************************************************/
709 #define CV_MATND_MAGIC_VAL 0x42430000
710 #define CV_TYPE_NAME_MATND "opencv-nd-matrix"
712 #define CV_MAX_DIM 32
713 #define CV_MAX_DIM_HEAP (1 << 16)
715 typedef struct CvMatND
741 #define CV_IS_MATND_HDR(mat) \
742 ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
744 #define CV_IS_MATND(mat) \
745 (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
748 /****************************************************************************************\
749 * Multi-dimensional sparse array (CvSparseMat) *
750 \****************************************************************************************/
752 #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000
753 #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix"
757 typedef struct CvSparseMat
769 int size[CV_MAX_DIM];
773 #define CV_IS_SPARSE_MAT_HDR(mat) \
775 (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
777 #define CV_IS_SPARSE_MAT(mat) \
778 CV_IS_SPARSE_MAT_HDR(mat)
780 /**************** iteration through a sparse array *****************/
782 typedef struct CvSparseNode
785 struct CvSparseNode* next;
789 typedef struct CvSparseMatIterator
797 #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset))
798 #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset))
800 /****************************************************************************************\
802 \****************************************************************************************/
804 typedef int CvHistType;
806 #define CV_HIST_MAGIC_VAL 0x42450000
807 #define CV_HIST_UNIFORM_FLAG (1 << 10)
809 /* indicates whether bin ranges are set already or not */
810 #define CV_HIST_RANGES_FLAG (1 << 11)
812 #define CV_HIST_ARRAY 0
813 #define CV_HIST_SPARSE 1
814 #define CV_HIST_TREE CV_HIST_SPARSE
816 /* should be used as a parameter only,
817 it turns to CV_HIST_UNIFORM_FLAG of hist->type */
818 #define CV_HIST_UNIFORM 1
820 typedef struct CvHistogram
824 float thresh[CV_MAX_DIM][2]; /* For uniform histograms. */
825 float** thresh2; /* For non-uniform histograms. */
826 CvMatND mat; /* Embedded matrix header for array histograms. */
830 #define CV_IS_HIST( hist ) \
832 (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
833 (hist)->bins != NULL)
835 #define CV_IS_UNIFORM_HIST( hist ) \
836 (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
838 #define CV_IS_SPARSE_HIST( hist ) \
839 CV_IS_SPARSE_MAT((hist)->bins)
841 #define CV_HIST_HAS_RANGES( hist ) \
842 (((hist)->type & CV_HIST_RANGES_FLAG) != 0)
844 /****************************************************************************************\
845 * Other supplementary data type definitions *
846 \****************************************************************************************/
848 /*************************************** CvRect *****************************************/
850 typedef struct CvRect
859 CV_INLINE CvRect cvRect( int x, int y, int width, int height )
872 CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
875 roi.xOffset = rect.x;
876 roi.yOffset = rect.y;
877 roi.width = rect.width;
878 roi.height = rect.height;
885 CV_INLINE CvRect cvROIToRect( IplROI roi )
887 return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
890 /*********************************** CvTermCriteria *************************************/
892 #define CV_TERMCRIT_ITER 1
893 #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER
894 #define CV_TERMCRIT_EPS 2
896 typedef struct CvTermCriteria
898 int type; /* may be combination of
906 CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
911 t.max_iter = max_iter;
912 t.epsilon = (float)epsilon;
918 /******************************* CvPoint and variants ***********************************/
920 typedef struct CvPoint
928 CV_INLINE CvPoint cvPoint( int x, int y )
939 typedef struct CvPoint2D32f
947 CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
958 CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
960 return cvPoint2D32f( (float)point.x, (float)point.y );
964 CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
967 ipt.x = cvRound(point.x);
968 ipt.y = cvRound(point.y);
974 typedef struct CvPoint3D32f
983 CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
995 typedef struct CvPoint2D64f
1003 CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
1014 typedef struct CvPoint3D64f
1023 CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
1035 /******************************** CvSize's & CvBox **************************************/
1044 CV_INLINE CvSize cvSize( int width, int height )
1054 typedef struct CvSize2D32f
1062 CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
1066 s.width = (float)width;
1067 s.height = (float)height;
1072 typedef struct CvBox2D
1074 CvPoint2D32f center; /* Center of the box. */
1075 CvSize2D32f size; /* Box width and length. */
1076 float angle; /* Angle between the horizontal axis */
1077 /* and the first side (i.e. length) in degrees */
1082 /* Line iterator state: */
1083 typedef struct CvLineIterator
1085 /* Pointer to the current point: */
1088 /* Bresenham algorithm state: */
1099 /************************************* CvSlice ******************************************/
1101 typedef struct CvSlice
1103 int start_index, end_index;
1107 CV_INLINE CvSlice cvSlice( int start, int end )
1110 slice.start_index = start;
1111 slice.end_index = end;
1116 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
1117 #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
1120 /************************************* CvScalar *****************************************/
1122 typedef struct CvScalar
1128 CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
1129 double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
1132 scalar.val[0] = val0; scalar.val[1] = val1;
1133 scalar.val[2] = val2; scalar.val[3] = val3;
1138 CV_INLINE CvScalar cvRealScalar( double val0 )
1141 scalar.val[0] = val0;
1142 scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
1146 CV_INLINE CvScalar cvScalarAll( double val0123 )
1149 scalar.val[0] = val0123;
1150 scalar.val[1] = val0123;
1151 scalar.val[2] = val0123;
1152 scalar.val[3] = val0123;
1156 /****************************************************************************************\
1157 * Dynamic Data structures *
1158 \****************************************************************************************/
1160 /******************************** Memory storage ****************************************/
1162 typedef struct CvMemBlock
1164 struct CvMemBlock* prev;
1165 struct CvMemBlock* next;
1169 #define CV_STORAGE_MAGIC_VAL 0x42890000
1171 typedef struct CvMemStorage
1174 CvMemBlock* bottom; /* First allocated block. */
1175 CvMemBlock* top; /* Current memory block - top of the stack. */
1176 struct CvMemStorage* parent; /* We get new blocks from parent as needed. */
1177 int block_size; /* Block size. */
1178 int free_space; /* Remaining free space in current block. */
1182 #define CV_IS_STORAGE(storage) \
1183 ((storage) != NULL && \
1184 (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
1187 typedef struct CvMemStoragePos
1195 /*********************************** Sequence *******************************************/
1197 typedef struct CvSeqBlock
1199 struct CvSeqBlock* prev; /* Previous sequence block. */
1200 struct CvSeqBlock* next; /* Next sequence block. */
1201 int start_index; /* Index of the first element in the block + */
1202 /* sequence->first->start_index. */
1203 int count; /* Number of elements in the block. */
1204 schar* data; /* Pointer to the first element of the block. */
1209 #define CV_TREE_NODE_FIELDS(node_type) \
1210 int flags; /* Miscellaneous flags. */ \
1211 int header_size; /* Size of sequence header. */ \
1212 struct node_type* h_prev; /* Previous sequence. */ \
1213 struct node_type* h_next; /* Next sequence. */ \
1214 struct node_type* v_prev; /* 2nd previous sequence. */ \
1215 struct node_type* v_next /* 2nd next sequence. */
1218 Read/Write sequence.
1219 Elements can be dynamically inserted to or deleted from the sequence.
1221 #define CV_SEQUENCE_FIELDS() \
1222 CV_TREE_NODE_FIELDS(CvSeq); \
1223 int total; /* Total number of elements. */ \
1224 int elem_size; /* Size of sequence element in bytes. */ \
1225 schar* block_max; /* Maximal bound of the last block. */ \
1226 schar* ptr; /* Current write pointer. */ \
1227 int delta_elems; /* Grow seq this many at a time. */ \
1228 CvMemStorage* storage; /* Where the seq is stored. */ \
1229 CvSeqBlock* free_blocks; /* Free blocks list. */ \
1230 CvSeqBlock* first; /* Pointer to the first sequence block. */
1232 typedef struct CvSeq
1234 CV_SEQUENCE_FIELDS()
1238 #define CV_TYPE_NAME_SEQ "opencv-sequence"
1239 #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree"
1241 /*************************************** Set ********************************************/
1244 Order is not preserved. There can be gaps between sequence elements.
1245 After the element has been inserted it stays in the same place all the time.
1246 The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists.
1248 #define CV_SET_ELEM_FIELDS(elem_type) \
1250 struct elem_type* next_free;
1252 typedef struct CvSetElem
1254 CV_SET_ELEM_FIELDS(CvSetElem)
1258 #define CV_SET_FIELDS() \
1259 CV_SEQUENCE_FIELDS() \
1260 CvSetElem* free_elems; \
1263 typedef struct CvSet
1270 #define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1)
1271 #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1))
1273 /* Checks whether the element pointed by ptr belongs to a set or not */
1274 #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0)
1276 /************************************* Graph ********************************************/
1279 We represent a graph as a set of vertices.
1280 Vertices contain their adjacency lists (more exactly, pointers to first incoming or
1281 outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.
1282 There is a singly-linked list of incoming/outcoming edges for each vertex.
1284 Each edge consists of
1286 o Two pointers to the starting and ending vertices
1287 (vtx[0] and vtx[1] respectively).
1289 A graph may be oriented or not. In the latter case, edges between
1290 vertex i to vertex j are not distinguished during search operations.
1292 o Two pointers to next edges for the starting and ending vertices, where
1293 next[0] points to the next edge in the vtx[0] adjacency list and
1294 next[1] points to the next edge in the vtx[1] adjacency list.
1296 #define CV_GRAPH_EDGE_FIELDS() \
1299 struct CvGraphEdge* next[2]; \
1300 struct CvGraphVtx* vtx[2];
1303 #define CV_GRAPH_VERTEX_FIELDS() \
1305 struct CvGraphEdge* first;
1308 typedef struct CvGraphEdge
1310 CV_GRAPH_EDGE_FIELDS()
1314 typedef struct CvGraphVtx
1316 CV_GRAPH_VERTEX_FIELDS()
1320 typedef struct CvGraphVtx2D
1322 CV_GRAPH_VERTEX_FIELDS()
1328 Graph is "derived" from the set (this is set a of vertices)
1329 and includes another set (edges)
1331 #define CV_GRAPH_FIELDS() \
1335 typedef struct CvGraph
1341 #define CV_TYPE_NAME_GRAPH "opencv-graph"
1343 /*********************************** Chain/Countour *************************************/
1345 typedef struct CvChain
1347 CV_SEQUENCE_FIELDS()
1352 #define CV_CONTOUR_FIELDS() \
1353 CV_SEQUENCE_FIELDS() \
1358 typedef struct CvContour
1364 typedef CvContour CvPoint2DSeq;
1366 /****************************************************************************************\
1368 \****************************************************************************************/
1370 #define CV_SEQ_MAGIC_VAL 0x42990000
1372 #define CV_IS_SEQ(seq) \
1373 ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
1375 #define CV_SET_MAGIC_VAL 0x42980000
1376 #define CV_IS_SET(set) \
1377 ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
1379 #define CV_SEQ_ELTYPE_BITS 9
1380 #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1)
1382 #define CV_SEQ_ELTYPE_POINT CV_32SC2 /* (x,y) */
1383 #define CV_SEQ_ELTYPE_CODE CV_8UC1 /* freeman code: 0..7 */
1384 #define CV_SEQ_ELTYPE_GENERIC 0
1385 #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1
1386 #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /* &(x,y) */
1387 #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /* #(x,y) */
1388 #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /* &next_o, &next_d, &vtx_o, &vtx_d */
1389 #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /* first_edge, &(x,y) */
1390 #define CV_SEQ_ELTYPE_TRIAN_ATR 0 /* vertex of the binary tree */
1391 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /* connected component */
1392 #define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /* (x,y,z) */
1394 #define CV_SEQ_KIND_BITS 3
1395 #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
1397 /* types of sequences */
1398 #define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS)
1399 #define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS)
1400 #define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS)
1402 /* types of sparse sequences (sets) */
1403 #define CV_SEQ_KIND_GRAPH (3 << CV_SEQ_ELTYPE_BITS)
1404 #define CV_SEQ_KIND_SUBDIV2D (4 << CV_SEQ_ELTYPE_BITS)
1406 #define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
1408 /* flags for curves */
1409 #define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT)
1410 #define CV_SEQ_FLAG_SIMPLE (2 << CV_SEQ_FLAG_SHIFT)
1411 #define CV_SEQ_FLAG_CONVEX (4 << CV_SEQ_FLAG_SHIFT)
1412 #define CV_SEQ_FLAG_HOLE (8 << CV_SEQ_FLAG_SHIFT)
1414 /* flags for graphs */
1415 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
1417 #define CV_GRAPH CV_SEQ_KIND_GRAPH
1418 #define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
1421 #define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
1422 #define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
1423 #define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT)
1424 #define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
1425 #define CV_SEQ_CONTOUR CV_SEQ_POLYGON
1426 #define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON )
1428 /* chain-coded curves */
1429 #define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE)
1430 #define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
1432 /* binary tree for the contour */
1433 #define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR)
1435 /* sequence of the connected components */
1436 #define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP)
1438 /* sequence of the integer numbers */
1439 #define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX)
1441 #define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK)
1442 #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK )
1445 #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
1446 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
1448 #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
1449 #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
1450 #define CV_IS_SEQ_CONVEX( seq ) (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)
1451 #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
1452 #define CV_IS_SEQ_SIMPLE( seq ) ((((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \
1453 CV_IS_SEQ_CONVEX(seq))
1455 /* type checking macros */
1456 #define CV_IS_SEQ_POINT_SET( seq ) \
1457 ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
1459 #define CV_IS_SEQ_POINT_SUBSET( seq ) \
1460 (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
1462 #define CV_IS_SEQ_POLYLINE( seq ) \
1463 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
1465 #define CV_IS_SEQ_POLYGON( seq ) \
1466 (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
1468 #define CV_IS_SEQ_CHAIN( seq ) \
1469 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
1471 #define CV_IS_SEQ_CONTOUR( seq ) \
1472 (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
1474 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
1475 (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
1477 #define CV_IS_SEQ_POLYGON_TREE( seq ) \
1478 (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \
1479 CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE )
1481 #define CV_IS_GRAPH( seq ) \
1482 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
1484 #define CV_IS_GRAPH_ORIENTED( seq ) \
1485 (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
1487 #define CV_IS_SUBDIV2D( seq ) \
1488 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
1490 /****************************************************************************************/
1491 /* Sequence writer & reader */
1492 /****************************************************************************************/
1494 #define CV_SEQ_WRITER_FIELDS() \
1496 CvSeq* seq; /* the sequence written */ \
1497 CvSeqBlock* block; /* current block */ \
1498 schar* ptr; /* pointer to free space */ \
1499 schar* block_min; /* pointer to the beginning of block*/\
1500 schar* block_max; /* pointer to the end of block */
1502 typedef struct CvSeqWriter
1504 CV_SEQ_WRITER_FIELDS()
1509 #define CV_SEQ_READER_FIELDS() \
1511 CvSeq* seq; /* sequence, beign read */ \
1512 CvSeqBlock* block; /* current block */ \
1513 schar* ptr; /* pointer to element be read next */ \
1514 schar* block_min; /* pointer to the beginning of block */\
1515 schar* block_max; /* pointer to the end of block */ \
1516 int delta_index;/* = seq->first->start_index */ \
1517 schar* prev_elem; /* pointer to previous element */
1520 typedef struct CvSeqReader
1522 CV_SEQ_READER_FIELDS()
1526 /****************************************************************************************/
1527 /* Operations on sequences */
1528 /****************************************************************************************/
1530 #define CV_SEQ_ELEM( seq, elem_type, index ) \
1531 /* assert gives some guarantee that <seq> parameter is valid */ \
1532 ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \
1533 (seq)->elem_size == sizeof(elem_type)), \
1534 (elem_type*)((seq)->first && (unsigned)index < \
1535 (unsigned)((seq)->first->count) ? \
1536 (seq)->first->data + (index) * sizeof(elem_type) : \
1537 cvGetSeqElem( (CvSeq*)(seq), (index) )))
1538 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )
1540 /* Add element to sequence: */
1541 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \
1543 if( (writer).ptr >= (writer).block_max ) \
1545 cvCreateSeqBlock( &writer); \
1547 memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
1548 (writer).ptr += (writer).seq->elem_size; \
1551 #define CV_WRITE_SEQ_ELEM( elem, writer ) \
1553 assert( (writer).seq->elem_size == sizeof(elem)); \
1554 if( (writer).ptr >= (writer).block_max ) \
1556 cvCreateSeqBlock( &writer); \
1558 assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
1559 memcpy((writer).ptr, &(elem), sizeof(elem)); \
1560 (writer).ptr += sizeof(elem); \
1564 /* Move reader position forward: */
1565 #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \
1567 if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
1569 cvChangeSeqBlock( &(reader), 1 ); \
1574 /* Move reader position backward: */
1575 #define CV_PREV_SEQ_ELEM( elem_size, reader ) \
1577 if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
1579 cvChangeSeqBlock( &(reader), -1 ); \
1583 /* Read element and move read position forward: */
1584 #define CV_READ_SEQ_ELEM( elem, reader ) \
1586 assert( (reader).seq->elem_size == sizeof(elem)); \
1587 memcpy( &(elem), (reader).ptr, sizeof((elem))); \
1588 CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \
1591 /* Read element and move read position backward: */
1592 #define CV_REV_READ_SEQ_ELEM( elem, reader ) \
1594 assert( (reader).seq->elem_size == sizeof(elem)); \
1595 memcpy(&(elem), (reader).ptr, sizeof((elem))); \
1596 CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \
1600 #define CV_READ_CHAIN_POINT( _pt, reader ) \
1602 (_pt) = (reader).pt; \
1603 if( (reader).ptr ) \
1605 CV_READ_SEQ_ELEM( (reader).code, (reader)); \
1606 assert( ((reader).code & ~7) == 0 ); \
1607 (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \
1608 (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \
1612 #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr)))
1613 #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem)))
1615 #define CV_READ_EDGE( pt1, pt2, reader ) \
1617 assert( sizeof(pt1) == sizeof(CvPoint) && \
1618 sizeof(pt2) == sizeof(CvPoint) && \
1619 reader.seq->elem_size == sizeof(CvPoint)); \
1620 (pt1) = CV_PREV_POINT( reader ); \
1621 (pt2) = CV_CURRENT_POINT( reader ); \
1622 (reader).prev_elem = (reader).ptr; \
1623 CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \
1626 /************ Graph macros ************/
1628 /* Return next graph edge for given vertex: */
1629 #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \
1630 (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \
1631 (edge)->next[(edge)->vtx[1] == (vertex)])
1635 /****************************************************************************************\
1636 * Data structures for persistence (a.k.a serialization) functionality *
1637 \****************************************************************************************/
1639 /* "black box" file storage */
1640 typedef struct CvFileStorage CvFileStorage;
1642 /* Storage flags: */
1643 #define CV_STORAGE_READ 0
1644 #define CV_STORAGE_WRITE 1
1645 #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE
1646 #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE
1647 #define CV_STORAGE_APPEND 2
1649 /* List of attributes: */
1650 typedef struct CvAttrList
1652 const char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs. */
1653 struct CvAttrList* next; /* Pointer to next chunk of the attributes list. */
1657 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL),
1658 CvAttrList* next CV_DEFAULT(NULL) )
1669 #define CV_NODE_NONE 0
1670 #define CV_NODE_INT 1
1671 #define CV_NODE_INTEGER CV_NODE_INT
1672 #define CV_NODE_REAL 2
1673 #define CV_NODE_FLOAT CV_NODE_REAL
1674 #define CV_NODE_STR 3
1675 #define CV_NODE_STRING CV_NODE_STR
1676 #define CV_NODE_REF 4 /* not used */
1677 #define CV_NODE_SEQ 5
1678 #define CV_NODE_MAP 6
1679 #define CV_NODE_TYPE_MASK 7
1681 #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK)
1683 /* file node flags */
1684 #define CV_NODE_FLOW 8 /* Used only for writing structures in YAML format. */
1685 #define CV_NODE_USER 16
1686 #define CV_NODE_EMPTY 32
1687 #define CV_NODE_NAMED 64
1689 #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT)
1690 #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL)
1691 #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING)
1692 #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ)
1693 #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP)
1694 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ)
1695 #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0)
1696 #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0)
1697 #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0)
1698 #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0)
1700 #define CV_NODE_SEQ_SIMPLE 256
1701 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
1703 typedef struct CvString
1710 /* All the keys (names) of elements in the readed file storage
1711 are stored in the hash to speed up the lookup operations: */
1712 typedef struct CvStringHashNode
1716 struct CvStringHashNode* next;
1720 typedef struct CvGenericHash CvFileNodeHash;
1722 /* Basic element of the file storage - scalar or collection: */
1723 typedef struct CvFileNode
1726 struct CvTypeInfo* info; /* type information
1727 (only for user-defined object, for others it is 0) */
1730 double f; /* scalar floating-point number */
1731 int i; /* scalar integer number */
1732 CvString str; /* text string */
1733 CvSeq* seq; /* sequence (ordered collection of file nodes) */
1734 CvFileNodeHash* map; /* map (collection of named file nodes) */
1742 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
1743 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
1744 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
1745 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name,
1746 const void* struct_ptr, CvAttrList attributes );
1747 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
1752 typedef struct CvTypeInfo
1756 struct CvTypeInfo* prev;
1757 struct CvTypeInfo* next;
1758 const char* type_name;
1759 CvIsInstanceFunc is_instance;
1760 CvReleaseFunc release;
1768 /**** System data types ******/
1770 typedef struct CvPluginFuncInfo
1773 void* default_func_addr;
1774 const char* func_names;
1780 typedef struct CvModuleInfo
1782 struct CvModuleInfo* next;
1784 const char* version;
1785 CvPluginFuncInfo* func_tab;
1789 #endif /*_CXCORE_TYPES_H_*/