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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #ifndef _CXCORE_TYPES_H_
43 #define _CXCORE_TYPES_H_
45 #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
46 #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
65 #if defined WIN64 && defined EM64T && (defined _MSC_VER || defined CV_ICC) \
66 || defined __SSE2__ || defined _MM_SHUFFLE2
67 #include <emmintrin.h>
73 #if defined __BORLANDC__
75 #elif defined WIN64 && !defined EM64T && defined CV_ICC
83 #if defined WIN32 || defined WIN64
89 #elif defined __IPL_H__
92 #endif // SKIP_INCLUDES
94 #if defined WIN32 || defined WIN64
95 #define CV_CDECL __cdecl
96 #define CV_STDCALL __stdcall
104 #define CV_EXTERN_C extern "C"
105 #define CV_DEFAULT(val) = val
108 #define CV_DEFAULT(val)
112 #ifndef CV_EXTERN_C_FUNCPTR
114 #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
116 #define CV_EXTERN_C_FUNCPTR(x) typedef x
121 #if defined __cplusplus
122 #define CV_INLINE inline
123 #elif (defined WIN32 || defined WIN64) && !defined __GNUC__
124 #define CV_INLINE __inline
126 #define CV_INLINE static
128 #endif /* CV_INLINE */
130 #if (defined WIN32 || defined WIN64) && defined CVAPI_EXPORTS
131 #define CV_EXPORTS __declspec(dllexport)
137 #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
140 #if defined _MSC_VER || defined __BORLANDC__
141 typedef __int64 int64;
142 typedef unsigned __int64 uint64;
144 typedef long long int64;
145 typedef unsigned long long uint64;
149 typedef unsigned char uchar;
150 typedef unsigned short ushort;
153 typedef signed char schar;
155 /* CvArr* is used to pass arbitrary
156 * array-like data structures
157 * into functions where the particular
158 * array type is recognized at runtime:
162 typedef union Cv32suf
170 typedef union Cv64suf
178 /****************************************************************************************\
179 * Common macros and inline functions *
180 \****************************************************************************************/
182 #define CV_PI 3.1415926535897932384626433832795
183 #define CV_LOG2 0.69314718055994530941723212145818
185 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
188 #define MIN(a,b) ((a) > (b) ? (b) : (a))
192 #define MAX(a,b) ((a) < (b) ? (b) : (a))
195 /* min & max without jumps */
196 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
198 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
200 /* absolute value without jumps */
202 #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
204 #define CV_IABS(a) abs(a)
206 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
207 #define CV_SIGN(a) CV_CMP((a),0)
209 CV_INLINE int cvRound( double value )
212 __m128d t = _mm_load_sd( &value );
213 return _mm_cvtsd_si32(t);
214 #elif defined WIN32 && !defined WIN64 && defined _MSC_VER
222 #elif (defined HAVE_LRINT) || (defined WIN64 && !defined EM64T && defined CV_ICC)
223 return (int)lrint(value);
226 the algorithm was taken from Agner Fog's optimization guide
227 at http://www.agner.org/assem
230 temp.f = value + 6755399441055744.0;
236 CV_INLINE int cvFloor( double value )
239 __m128d t = _mm_load_sd( &value );
240 int i = _mm_cvtsd_si32(t);
241 return i - _mm_movemask_pd(_mm_cmplt_sd(t,_mm_cvtsi32_sd(t,i)));
243 int temp = cvRound(value);
245 diff.f = (float)(value - temp);
246 return temp - (diff.i < 0);
251 CV_INLINE int cvCeil( double value )
254 __m128d t = _mm_load_sd( &value );
255 int i = _mm_cvtsd_si32(t);
256 return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i),t));
258 int temp = cvRound(value);
260 diff.f = (float)(temp - value);
261 return temp + (diff.i < 0);
265 #define cvInvSqrt(value) ((float)(1./sqrt(value)))
266 #define cvSqrt(value) ((float)sqrt(value))
268 CV_INLINE int cvIsNaN( double value )
270 #if 1/*defined _MSC_VER || defined __BORLANDC__
271 return _isnan(value);
272 #elif defined __GNUC__
277 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
278 ((unsigned)ieee754.u != 0) > 0x7ff00000;
283 CV_INLINE int cvIsInf( double value )
285 #if 1/*defined _MSC_VER || defined __BORLANDC__
286 return !_finite(value);
287 #elif defined __GNUC__
292 return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
293 (unsigned)ieee754.u == 0;
298 /*************** Random number generation *******************/
300 typedef uint64 CvRNG;
302 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
304 CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
308 /* Return random 32-bit unsigned integer: */
309 CV_INLINE unsigned cvRandInt( CvRNG* rng )
312 temp = (uint64)(unsigned)temp*1554115554 + (temp >> 32);
314 return (unsigned)temp;
317 /* Returns random floating-point number between 0 and 1: */
318 CV_INLINE double cvRandReal( CvRNG* rng )
320 return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
323 /****************************************************************************************\
324 * Image type (IplImage) *
325 \****************************************************************************************/
330 * The following definitions (until #endif)
331 * is an extract from IPL headers.
332 * Copyright (c) 1995 Intel Corporation.
334 #define IPL_DEPTH_SIGN 0x80000000
336 #define IPL_DEPTH_1U 1
337 #define IPL_DEPTH_8U 8
338 #define IPL_DEPTH_16U 16
339 #define IPL_DEPTH_32F 32
341 #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
342 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
343 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
345 #define IPL_DATA_ORDER_PIXEL 0
346 #define IPL_DATA_ORDER_PLANE 1
348 #define IPL_ORIGIN_TL 0
349 #define IPL_ORIGIN_BL 1
351 #define IPL_ALIGN_4BYTES 4
352 #define IPL_ALIGN_8BYTES 8
353 #define IPL_ALIGN_16BYTES 16
354 #define IPL_ALIGN_32BYTES 32
356 #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
357 #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
359 #define IPL_BORDER_CONSTANT 0
360 #define IPL_BORDER_REPLICATE 1
361 #define IPL_BORDER_REFLECT 2
362 #define IPL_BORDER_WRAP 3
364 typedef struct _IplImage
366 int nSize; /* sizeof(IplImage) */
367 int ID; /* version (=0)*/
368 int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */
369 int alphaChannel; /* Ignored by OpenCV */
370 int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
371 IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */
372 char colorModel[4]; /* Ignored by OpenCV */
373 char channelSeq[4]; /* ditto */
374 int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.
375 cvCreateImage can only create interleaved images */
376 int origin; /* 0 - top-left origin,
377 1 - bottom-left origin (Windows bitmaps style). */
378 int align; /* Alignment of image rows (4 or 8).
379 OpenCV ignores it and uses widthStep instead. */
380 int width; /* Image width in pixels. */
381 int height; /* Image height in pixels. */
382 struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */
383 struct _IplImage *maskROI; /* Must be NULL. */
384 void *imageId; /* " " */
385 struct _IplTileInfo *tileInfo; /* " " */
386 int imageSize; /* Image data size in bytes
387 (==image->height*image->widthStep
388 in case of interleaved data)*/
389 char *imageData; /* Pointer to aligned image data. */
390 int widthStep; /* Size of aligned image row in bytes. */
391 int BorderMode[4]; /* Ignored by OpenCV. */
392 int BorderConst[4]; /* Ditto. */
393 char *imageDataOrigin; /* Pointer to very origin of image data
394 (not necessarily aligned) -
395 needed for correct deallocation */
399 typedef struct _IplTileInfo IplTileInfo;
401 typedef struct _IplROI
403 int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
411 typedef struct _IplConvKernel
422 typedef struct _IplConvKernelFP
432 #define IPL_IMAGE_HEADER 1
433 #define IPL_IMAGE_DATA 2
434 #define IPL_IMAGE_ROI 4
438 /* extra border mode */
439 #define IPL_BORDER_REFLECT_101 4
441 #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
442 #define CV_TYPE_NAME_IMAGE "opencv-image"
444 #define CV_IS_IMAGE_HDR(img) \
445 ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
447 #define CV_IS_IMAGE(img) \
448 (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
450 /* for storing double-precision
451 floating point data in IplImage's */
452 #define IPL_DEPTH_64F 64
454 /* get reference to pixel at (col,row),
455 for multi-channel images (col) should be multiplied by number of channels */
456 #define CV_IMAGE_ELEM( image, elemtype, row, col ) \
457 (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
459 /****************************************************************************************\
460 * Matrix type (CvMat) *
461 \****************************************************************************************/
464 #define CV_CN_SHIFT 3
465 #define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
474 #define CV_USRTYPE1 7
476 #define CV_MAKETYPE(depth,cn) ((depth) + (((cn)-1) << CV_CN_SHIFT))
477 #define CV_MAKE_TYPE CV_MAKETYPE
479 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
480 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
481 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
482 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
483 #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
485 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
486 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
487 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
488 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
489 #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
491 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
492 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
493 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
494 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
495 #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
497 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
498 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
499 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
500 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
501 #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
503 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
504 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
505 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
506 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
507 #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
509 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
510 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
511 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
512 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
513 #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
515 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
516 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
517 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
518 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
519 #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
521 #define CV_AUTO_STEP 0x7fffffff
522 #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff )
524 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
525 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
526 #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
527 #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
528 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
529 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
530 #define CV_MAT_CONT_FLAG_SHIFT 14
531 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
532 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
533 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
534 #define CV_MAT_TEMP_FLAG_SHIFT 15
535 #define CV_MAT_TEMP_FLAG (1 << CV_MAT_TEMP_FLAG_SHIFT)
536 #define CV_IS_TEMP_MAT(flags) ((flags) & CV_MAT_TEMP_FLAG)
538 #define CV_MAGIC_MASK 0xFFFF0000
539 #define CV_MAT_MAGIC_VAL 0x42420000
540 #define CV_TYPE_NAME_MAT "opencv-matrix"
547 /* for internal use only */
581 #define CV_IS_MAT_HDR(mat) \
583 (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
584 ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0)
586 #define CV_IS_MAT(mat) \
587 (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
589 #define CV_IS_MASK_ARR(mat) \
590 (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
592 #define CV_ARE_TYPES_EQ(mat1, mat2) \
593 ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
595 #define CV_ARE_CNS_EQ(mat1, mat2) \
596 ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
598 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \
599 ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
601 #define CV_ARE_SIZES_EQ(mat1, mat2) \
602 ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols)
604 #define CV_IS_MAT_CONST(mat) \
605 (((mat)->rows|(mat)->cols) == 1)
607 /* Size of each channel item,
608 0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
609 #define CV_ELEM_SIZE1(type) \
610 ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
612 /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
613 #define CV_ELEM_SIZE(type) \
614 (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
616 /* Inline constructor. No data is allocated internally!!!
617 * (Use together with cvCreateData, or use cvCreateMat instead to
618 * get a matrix with allocated data):
620 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
624 assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
625 type = CV_MAT_TYPE(type);
626 m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
629 m.step = rows > 1 ? m.cols*CV_ELEM_SIZE(type) : 0;
630 m.data.ptr = (uchar*)data;
638 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
639 (assert( (unsigned)(row) < (unsigned)(mat).rows && \
640 (unsigned)(col) < (unsigned)(mat).cols ), \
641 (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
643 #define CV_MAT_ELEM_PTR( mat, row, col ) \
644 CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
646 #define CV_MAT_ELEM( mat, elemtype, row, col ) \
647 (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
650 CV_INLINE double cvmGet( const CvMat* mat, int row, int col )
654 type = CV_MAT_TYPE(mat->type);
655 assert( (unsigned)row < (unsigned)mat->rows &&
656 (unsigned)col < (unsigned)mat->cols );
658 if( type == CV_32FC1 )
659 return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
662 assert( type == CV_64FC1 );
663 return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
668 CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value )
671 type = CV_MAT_TYPE(mat->type);
672 assert( (unsigned)row < (unsigned)mat->rows &&
673 (unsigned)col < (unsigned)mat->cols );
675 if( type == CV_32FC1 )
676 ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
679 assert( type == CV_64FC1 );
680 ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
685 CV_INLINE int cvCvToIplDepth( int type )
687 int depth = CV_MAT_DEPTH(type);
688 return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
689 depth == CV_32S ? IPL_DEPTH_SIGN : 0);
693 /****************************************************************************************\
694 * Multi-dimensional dense array (CvMatND) *
695 \****************************************************************************************/
697 #define CV_MATND_MAGIC_VAL 0x42430000
698 #define CV_TYPE_NAME_MATND "opencv-nd-matrix"
700 #define CV_MAX_DIM 32
701 #define CV_MAX_DIM_HEAP (1 << 16)
703 typedef struct CvMatND
729 #define CV_IS_MATND_HDR(mat) \
730 ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
732 #define CV_IS_MATND(mat) \
733 (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
736 /****************************************************************************************\
737 * Multi-dimensional sparse array (CvSparseMat) *
738 \****************************************************************************************/
740 #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000
741 #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix"
745 typedef struct CvSparseMat
757 int size[CV_MAX_DIM];
761 #define CV_IS_SPARSE_MAT_HDR(mat) \
763 (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
765 #define CV_IS_SPARSE_MAT(mat) \
766 CV_IS_SPARSE_MAT_HDR(mat)
768 /**************** iteration through a sparse array *****************/
770 typedef struct CvSparseNode
773 struct CvSparseNode* next;
777 typedef struct CvSparseMatIterator
785 #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset))
786 #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset))
788 /****************************************************************************************\
790 \****************************************************************************************/
792 typedef int CvHistType;
794 #define CV_HIST_MAGIC_VAL 0x42450000
795 #define CV_HIST_UNIFORM_FLAG (1 << 10)
797 /* indicates whether bin ranges are set already or not */
798 #define CV_HIST_RANGES_FLAG (1 << 11)
800 #define CV_HIST_ARRAY 0
801 #define CV_HIST_SPARSE 1
802 #define CV_HIST_TREE CV_HIST_SPARSE
804 /* should be used as a parameter only,
805 it turns to CV_HIST_UNIFORM_FLAG of hist->type */
806 #define CV_HIST_UNIFORM 1
808 typedef struct CvHistogram
812 float thresh[CV_MAX_DIM][2]; /* For uniform histograms. */
813 float** thresh2; /* For non-uniform histograms. */
814 CvMatND mat; /* Embedded matrix header for array histograms. */
818 #define CV_IS_HIST( hist ) \
820 (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
821 (hist)->bins != NULL)
823 #define CV_IS_UNIFORM_HIST( hist ) \
824 (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
826 #define CV_IS_SPARSE_HIST( hist ) \
827 CV_IS_SPARSE_MAT((hist)->bins)
829 #define CV_HIST_HAS_RANGES( hist ) \
830 (((hist)->type & CV_HIST_RANGES_FLAG) != 0)
832 /****************************************************************************************\
833 * Other supplementary data type definitions *
834 \****************************************************************************************/
836 /*************************************** CvRect *****************************************/
838 typedef struct CvRect
847 CV_INLINE CvRect cvRect( int x, int y, int width, int height )
860 CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
863 roi.xOffset = rect.x;
864 roi.yOffset = rect.y;
865 roi.width = rect.width;
866 roi.height = rect.height;
873 CV_INLINE CvRect cvROIToRect( IplROI roi )
875 return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
878 /*********************************** CvTermCriteria *************************************/
880 #define CV_TERMCRIT_ITER 1
881 #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER
882 #define CV_TERMCRIT_EPS 2
884 typedef struct CvTermCriteria
886 int type; /* may be combination of
894 CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
899 t.max_iter = max_iter;
900 t.epsilon = (float)epsilon;
906 /******************************* CvPoint and variants ***********************************/
908 typedef struct CvPoint
916 CV_INLINE CvPoint cvPoint( int x, int y )
927 typedef struct CvPoint2D32f
935 CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
946 CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
948 return cvPoint2D32f( (float)point.x, (float)point.y );
952 CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
955 ipt.x = cvRound(point.x);
956 ipt.y = cvRound(point.y);
962 typedef struct CvPoint3D32f
971 CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
983 typedef struct CvPoint2D64f
991 CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
1002 typedef struct CvPoint3D64f
1011 CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
1023 /******************************** CvSize's & CvBox **************************************/
1032 CV_INLINE CvSize cvSize( int width, int height )
1042 typedef struct CvSize2D32f
1050 CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
1054 s.width = (float)width;
1055 s.height = (float)height;
1060 typedef struct CvBox2D
1062 CvPoint2D32f center; /* Center of the box. */
1063 CvSize2D32f size; /* Box width and length. */
1064 float angle; /* Angle between the horizontal axis */
1065 /* and the first side (i.e. length) in degrees */
1070 /* Line iterator state: */
1071 typedef struct CvLineIterator
1073 /* Pointer to the current point: */
1076 /* Bresenham algorithm state: */
1087 /************************************* CvSlice ******************************************/
1089 typedef struct CvSlice
1091 int start_index, end_index;
1095 CV_INLINE CvSlice cvSlice( int start, int end )
1098 slice.start_index = start;
1099 slice.end_index = end;
1104 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
1105 #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
1108 /************************************* CvScalar *****************************************/
1110 typedef struct CvScalar
1116 CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
1117 double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
1120 scalar.val[0] = val0; scalar.val[1] = val1;
1121 scalar.val[2] = val2; scalar.val[3] = val3;
1126 CV_INLINE CvScalar cvRealScalar( double val0 )
1129 scalar.val[0] = val0;
1130 scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
1134 CV_INLINE CvScalar cvScalarAll( double val0123 )
1137 scalar.val[0] = val0123;
1138 scalar.val[1] = val0123;
1139 scalar.val[2] = val0123;
1140 scalar.val[3] = val0123;
1144 /****************************************************************************************\
1145 * Dynamic Data structures *
1146 \****************************************************************************************/
1148 /******************************** Memory storage ****************************************/
1150 typedef struct CvMemBlock
1152 struct CvMemBlock* prev;
1153 struct CvMemBlock* next;
1157 #define CV_STORAGE_MAGIC_VAL 0x42890000
1159 typedef struct CvMemStorage
1162 CvMemBlock* bottom; /* First allocated block. */
1163 CvMemBlock* top; /* Current memory block - top of the stack. */
1164 struct CvMemStorage* parent; /* We get new blocks from parent as needed. */
1165 int block_size; /* Block size. */
1166 int free_space; /* Remaining free space in current block. */
1170 #define CV_IS_STORAGE(storage) \
1171 ((storage) != NULL && \
1172 (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
1175 typedef struct CvMemStoragePos
1183 /*********************************** Sequence *******************************************/
1185 typedef struct CvSeqBlock
1187 struct CvSeqBlock* prev; /* Previous sequence block. */
1188 struct CvSeqBlock* next; /* Next sequence block. */
1189 int start_index; /* Index of the first element in the block + */
1190 /* sequence->first->start_index. */
1191 int count; /* Number of elements in the block. */
1192 schar* data; /* Pointer to the first element of the block. */
1197 #define CV_TREE_NODE_FIELDS(node_type) \
1198 int flags; /* Miscellaneous flags. */ \
1199 int header_size; /* Size of sequence header. */ \
1200 struct node_type* h_prev; /* Previous sequence. */ \
1201 struct node_type* h_next; /* Next sequence. */ \
1202 struct node_type* v_prev; /* 2nd previous sequence. */ \
1203 struct node_type* v_next /* 2nd next sequence. */
1206 Read/Write sequence.
1207 Elements can be dynamically inserted to or deleted from the sequence.
1209 #define CV_SEQUENCE_FIELDS() \
1210 CV_TREE_NODE_FIELDS(CvSeq); \
1211 int total; /* Total number of elements. */ \
1212 int elem_size; /* Size of sequence element in bytes. */ \
1213 schar* block_max; /* Maximal bound of the last block. */ \
1214 schar* ptr; /* Current write pointer. */ \
1215 int delta_elems; /* Grow seq this many at a time. */ \
1216 CvMemStorage* storage; /* Where the seq is stored. */ \
1217 CvSeqBlock* free_blocks; /* Free blocks list. */ \
1218 CvSeqBlock* first; /* Pointer to the first sequence block. */
1220 typedef struct CvSeq
1222 CV_SEQUENCE_FIELDS()
1226 #define CV_TYPE_NAME_SEQ "opencv-sequence"
1227 #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree"
1229 /*************************************** Set ********************************************/
1232 Order is not preserved. There can be gaps between sequence elements.
1233 After the element has been inserted it stays in the same place all the time.
1234 The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists.
1236 #define CV_SET_ELEM_FIELDS(elem_type) \
1238 struct elem_type* next_free;
1240 typedef struct CvSetElem
1242 CV_SET_ELEM_FIELDS(CvSetElem)
1246 #define CV_SET_FIELDS() \
1247 CV_SEQUENCE_FIELDS() \
1248 CvSetElem* free_elems; \
1251 typedef struct CvSet
1258 #define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1)
1259 #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1))
1261 /* Checks whether the element pointed by ptr belongs to a set or not */
1262 #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0)
1264 /************************************* Graph ********************************************/
1267 We represent a graph as a set of vertices.
1268 Vertices contain their adjacency lists (more exactly, pointers to first incoming or
1269 outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.
1270 There is a singly-linked list of incoming/outcoming edges for each vertex.
1272 Each edge consists of
1274 o Two pointers to the starting and ending vertices
1275 (vtx[0] and vtx[1] respectively).
1277 A graph may be oriented or not. In the latter case, edges between
1278 vertex i to vertex j are not distinguished during search operations.
1280 o Two pointers to next edges for the starting and ending vertices, where
1281 next[0] points to the next edge in the vtx[0] adjacency list and
1282 next[1] points to the next edge in the vtx[1] adjacency list.
1284 #define CV_GRAPH_EDGE_FIELDS() \
1287 struct CvGraphEdge* next[2]; \
1288 struct CvGraphVtx* vtx[2];
1291 #define CV_GRAPH_VERTEX_FIELDS() \
1293 struct CvGraphEdge* first;
1296 typedef struct CvGraphEdge
1298 CV_GRAPH_EDGE_FIELDS()
1302 typedef struct CvGraphVtx
1304 CV_GRAPH_VERTEX_FIELDS()
1308 typedef struct CvGraphVtx2D
1310 CV_GRAPH_VERTEX_FIELDS()
1316 Graph is "derived" from the set (this is set a of vertices)
1317 and includes another set (edges)
1319 #define CV_GRAPH_FIELDS() \
1323 typedef struct CvGraph
1329 #define CV_TYPE_NAME_GRAPH "opencv-graph"
1331 /*********************************** Chain/Countour *************************************/
1333 typedef struct CvChain
1335 CV_SEQUENCE_FIELDS()
1340 #define CV_CONTOUR_FIELDS() \
1341 CV_SEQUENCE_FIELDS() \
1346 typedef struct CvContour
1352 typedef CvContour CvPoint2DSeq;
1354 /****************************************************************************************\
1356 \****************************************************************************************/
1358 #define CV_SEQ_MAGIC_VAL 0x42990000
1360 #define CV_IS_SEQ(seq) \
1361 ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
1363 #define CV_SET_MAGIC_VAL 0x42980000
1364 #define CV_IS_SET(set) \
1365 ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
1367 #define CV_SEQ_ELTYPE_BITS 9
1368 #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1)
1370 #define CV_SEQ_ELTYPE_POINT CV_32SC2 /* (x,y) */
1371 #define CV_SEQ_ELTYPE_CODE CV_8UC1 /* freeman code: 0..7 */
1372 #define CV_SEQ_ELTYPE_GENERIC 0
1373 #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1
1374 #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /* &(x,y) */
1375 #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /* #(x,y) */
1376 #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /* &next_o, &next_d, &vtx_o, &vtx_d */
1377 #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /* first_edge, &(x,y) */
1378 #define CV_SEQ_ELTYPE_TRIAN_ATR 0 /* vertex of the binary tree */
1379 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /* connected component */
1380 #define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /* (x,y,z) */
1382 #define CV_SEQ_KIND_BITS 3
1383 #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
1385 /* types of sequences */
1386 #define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS)
1387 #define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS)
1388 #define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS)
1390 /* types of sparse sequences (sets) */
1391 #define CV_SEQ_KIND_GRAPH (3 << CV_SEQ_ELTYPE_BITS)
1392 #define CV_SEQ_KIND_SUBDIV2D (4 << CV_SEQ_ELTYPE_BITS)
1394 #define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
1396 /* flags for curves */
1397 #define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT)
1398 #define CV_SEQ_FLAG_SIMPLE (2 << CV_SEQ_FLAG_SHIFT)
1399 #define CV_SEQ_FLAG_CONVEX (4 << CV_SEQ_FLAG_SHIFT)
1400 #define CV_SEQ_FLAG_HOLE (8 << CV_SEQ_FLAG_SHIFT)
1402 /* flags for graphs */
1403 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
1405 #define CV_GRAPH CV_SEQ_KIND_GRAPH
1406 #define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
1409 #define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
1410 #define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
1411 #define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT)
1412 #define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
1413 #define CV_SEQ_CONTOUR CV_SEQ_POLYGON
1414 #define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON )
1416 /* chain-coded curves */
1417 #define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE)
1418 #define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
1420 /* binary tree for the contour */
1421 #define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR)
1423 /* sequence of the connected components */
1424 #define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP)
1426 /* sequence of the integer numbers */
1427 #define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX)
1429 #define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK)
1430 #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK )
1433 #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
1434 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
1436 #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
1437 #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
1438 #define CV_IS_SEQ_CONVEX( seq ) (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)
1439 #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
1440 #define CV_IS_SEQ_SIMPLE( seq ) ((((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \
1441 CV_IS_SEQ_CONVEX(seq))
1443 /* type checking macros */
1444 #define CV_IS_SEQ_POINT_SET( seq ) \
1445 ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
1447 #define CV_IS_SEQ_POINT_SUBSET( seq ) \
1448 (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
1450 #define CV_IS_SEQ_POLYLINE( seq ) \
1451 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
1453 #define CV_IS_SEQ_POLYGON( seq ) \
1454 (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
1456 #define CV_IS_SEQ_CHAIN( seq ) \
1457 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
1459 #define CV_IS_SEQ_CONTOUR( seq ) \
1460 (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
1462 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
1463 (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
1465 #define CV_IS_SEQ_POLYGON_TREE( seq ) \
1466 (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \
1467 CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE )
1469 #define CV_IS_GRAPH( seq ) \
1470 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
1472 #define CV_IS_GRAPH_ORIENTED( seq ) \
1473 (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
1475 #define CV_IS_SUBDIV2D( seq ) \
1476 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
1478 /****************************************************************************************/
1479 /* Sequence writer & reader */
1480 /****************************************************************************************/
1482 #define CV_SEQ_WRITER_FIELDS() \
1484 CvSeq* seq; /* the sequence written */ \
1485 CvSeqBlock* block; /* current block */ \
1486 schar* ptr; /* pointer to free space */ \
1487 schar* block_min; /* pointer to the beginning of block*/\
1488 schar* block_max; /* pointer to the end of block */
1490 typedef struct CvSeqWriter
1492 CV_SEQ_WRITER_FIELDS()
1497 #define CV_SEQ_READER_FIELDS() \
1499 CvSeq* seq; /* sequence, beign read */ \
1500 CvSeqBlock* block; /* current block */ \
1501 schar* ptr; /* pointer to element be read next */ \
1502 schar* block_min; /* pointer to the beginning of block */\
1503 schar* block_max; /* pointer to the end of block */ \
1504 int delta_index;/* = seq->first->start_index */ \
1505 schar* prev_elem; /* pointer to previous element */
1508 typedef struct CvSeqReader
1510 CV_SEQ_READER_FIELDS()
1514 /****************************************************************************************/
1515 /* Operations on sequences */
1516 /****************************************************************************************/
1518 #define CV_SEQ_ELEM( seq, elem_type, index ) \
1519 /* assert gives some guarantee that <seq> parameter is valid */ \
1520 ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \
1521 (seq)->elem_size == sizeof(elem_type)), \
1522 (elem_type*)((seq)->first && (unsigned)index < \
1523 (unsigned)((seq)->first->count) ? \
1524 (seq)->first->data + (index) * sizeof(elem_type) : \
1525 cvGetSeqElem( (CvSeq*)(seq), (index) )))
1526 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )
1528 /* Add element to sequence: */
1529 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \
1531 if( (writer).ptr >= (writer).block_max ) \
1533 cvCreateSeqBlock( &writer); \
1535 memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
1536 (writer).ptr += (writer).seq->elem_size; \
1539 #define CV_WRITE_SEQ_ELEM( elem, writer ) \
1541 assert( (writer).seq->elem_size == sizeof(elem)); \
1542 if( (writer).ptr >= (writer).block_max ) \
1544 cvCreateSeqBlock( &writer); \
1546 assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
1547 memcpy((writer).ptr, &(elem), sizeof(elem)); \
1548 (writer).ptr += sizeof(elem); \
1552 /* Move reader position forward: */
1553 #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \
1555 if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
1557 cvChangeSeqBlock( &(reader), 1 ); \
1562 /* Move reader position backward: */
1563 #define CV_PREV_SEQ_ELEM( elem_size, reader ) \
1565 if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
1567 cvChangeSeqBlock( &(reader), -1 ); \
1571 /* Read element and move read position forward: */
1572 #define CV_READ_SEQ_ELEM( elem, reader ) \
1574 assert( (reader).seq->elem_size == sizeof(elem)); \
1575 memcpy( &(elem), (reader).ptr, sizeof((elem))); \
1576 CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \
1579 /* Read element and move read position backward: */
1580 #define CV_REV_READ_SEQ_ELEM( elem, reader ) \
1582 assert( (reader).seq->elem_size == sizeof(elem)); \
1583 memcpy(&(elem), (reader).ptr, sizeof((elem))); \
1584 CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \
1588 #define CV_READ_CHAIN_POINT( _pt, reader ) \
1590 (_pt) = (reader).pt; \
1591 if( (reader).ptr ) \
1593 CV_READ_SEQ_ELEM( (reader).code, (reader)); \
1594 assert( ((reader).code & ~7) == 0 ); \
1595 (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \
1596 (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \
1600 #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr)))
1601 #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem)))
1603 #define CV_READ_EDGE( pt1, pt2, reader ) \
1605 assert( sizeof(pt1) == sizeof(CvPoint) && \
1606 sizeof(pt2) == sizeof(CvPoint) && \
1607 reader.seq->elem_size == sizeof(CvPoint)); \
1608 (pt1) = CV_PREV_POINT( reader ); \
1609 (pt2) = CV_CURRENT_POINT( reader ); \
1610 (reader).prev_elem = (reader).ptr; \
1611 CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \
1614 /************ Graph macros ************/
1616 /* Return next graph edge for given vertex: */
1617 #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \
1618 (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \
1619 (edge)->next[(edge)->vtx[1] == (vertex)])
1623 /****************************************************************************************\
1624 * Data structures for persistence (a.k.a serialization) functionality *
1625 \****************************************************************************************/
1627 /* "black box" file storage */
1628 typedef struct CvFileStorage CvFileStorage;
1630 /* Storage flags: */
1631 #define CV_STORAGE_READ 0
1632 #define CV_STORAGE_WRITE 1
1633 #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE
1634 #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE
1635 #define CV_STORAGE_APPEND 2
1637 /* List of attributes: */
1638 typedef struct CvAttrList
1640 const char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs. */
1641 struct CvAttrList* next; /* Pointer to next chunk of the attributes list. */
1645 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL),
1646 CvAttrList* next CV_DEFAULT(NULL) )
1657 #define CV_NODE_NONE 0
1658 #define CV_NODE_INT 1
1659 #define CV_NODE_INTEGER CV_NODE_INT
1660 #define CV_NODE_REAL 2
1661 #define CV_NODE_FLOAT CV_NODE_REAL
1662 #define CV_NODE_STR 3
1663 #define CV_NODE_STRING CV_NODE_STR
1664 #define CV_NODE_REF 4 /* not used */
1665 #define CV_NODE_SEQ 5
1666 #define CV_NODE_MAP 6
1667 #define CV_NODE_TYPE_MASK 7
1669 #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK)
1671 /* file node flags */
1672 #define CV_NODE_FLOW 8 /* Used only for writing structures in YAML format. */
1673 #define CV_NODE_USER 16
1674 #define CV_NODE_EMPTY 32
1675 #define CV_NODE_NAMED 64
1677 #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT)
1678 #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL)
1679 #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING)
1680 #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ)
1681 #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP)
1682 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ)
1683 #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0)
1684 #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0)
1685 #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0)
1686 #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0)
1688 #define CV_NODE_SEQ_SIMPLE 256
1689 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
1691 typedef struct CvString
1698 /* All the keys (names) of elements in the readed file storage
1699 are stored in the hash to speed up the lookup operations: */
1700 typedef struct CvStringHashNode
1704 struct CvStringHashNode* next;
1708 typedef struct CvGenericHash CvFileNodeHash;
1710 /* Basic element of the file storage - scalar or collection: */
1711 typedef struct CvFileNode
1714 struct CvTypeInfo* info; /* type information
1715 (only for user-defined object, for others it is 0) */
1718 double f; /* scalar floating-point number */
1719 int i; /* scalar integer number */
1720 CvString str; /* text string */
1721 CvSeq* seq; /* sequence (ordered collection of file nodes) */
1722 CvFileNodeHash* map; /* map (collection of named file nodes) */
1730 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
1731 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
1732 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
1733 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name,
1734 const void* struct_ptr, CvAttrList attributes );
1735 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
1740 typedef struct CvTypeInfo
1744 struct CvTypeInfo* prev;
1745 struct CvTypeInfo* next;
1746 const char* type_name;
1747 CvIsInstanceFunc is_instance;
1748 CvReleaseFunc release;
1756 /**** System data types ******/
1758 typedef struct CvPluginFuncInfo
1761 void* default_func_addr;
1762 const char* func_names;
1768 typedef struct CvModuleInfo
1770 struct CvModuleInfo* next;
1772 const char* version;
1773 CvPluginFuncInfo* func_tab;
1777 #endif /*_CXCORE_TYPES_H_*/