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_
56 #if defined WIN64 && defined EM64T && defined _MSC_VER
57 #include <emmintrin.h>
62 #if defined WIN32 || defined WIN64
68 #elif defined __IPL_H__
71 #endif // SKIP_INCLUDES
73 #if defined WIN32 || defined WIN64
74 #define CV_CDECL __cdecl
75 #define CV_STDCALL __stdcall
83 #define CV_EXTERN_C extern "C"
84 #define CV_DEFAULT(val) = val
87 #define CV_DEFAULT(val)
91 #ifndef CV_EXTERN_C_FUNCPTR
93 #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
95 #define CV_EXTERN_C_FUNCPTR(x) typedef x
100 #if defined __cplusplus
101 #define CV_INLINE inline
102 #elif (defined WIN32 || defined WIN64) && !defined __GNUC__
103 #define CV_INLINE __inline
105 #define CV_INLINE static
107 #endif /* CV_INLINE */
109 #if (defined WIN32 || defined WIN64) && defined CVAPI_EXPORTS
110 #define CV_EXPORTS __declspec(dllexport)
116 #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
119 #if defined _MSC_VER || defined __BORLANDC__
120 typedef __int64 int64;
121 typedef unsigned __int64 uint64;
123 typedef long long int64;
124 typedef unsigned long long uint64;
128 typedef unsigned char uchar;
129 typedef unsigned short ushort;
133 #if defined __SSE2__ || defined _MM_SHUFFLE2 || (defined WIN64 && defined EM64T && defined _MSC_VER)
140 /* CvArr* is used to pass arbitrary array-like data structures
141 into the functions where the particular
142 array type is recognized at runtime */
145 /****************************************************************************************\
146 * Common macros and inline functions *
147 \****************************************************************************************/
149 #define CV_PI 3.1415926535897932384626433832795
150 #define CV_LOG2 0.69314718055994530941723212145818
152 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
155 #define MIN(a,b) ((a) > (b) ? (b) : (a))
159 #define MAX(a,b) ((a) < (b) ? (b) : (a))
162 /* min & max without jumps */
163 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
165 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
167 /* absolute value without jumps */
169 #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
171 #define CV_IABS(a) abs(a)
173 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
174 #define CV_SIGN(a) CV_CMP((a),0)
176 CV_INLINE int cvRound( double value )
179 __m128d t = _mm_load_sd( &value );
180 return _mm_cvtsd_si32(t);
181 #elif defined WIN32 && !defined WIN64 && defined _MSC_VER
190 return (int)lrint( value );
193 the algorithm was taken from Agner Fog's optimization guide
194 at http://www.agner.org/assem
196 double temp = value + 6755399441055744.0;
197 return (int)*((uint64*)&temp);
202 CV_INLINE int cvFloor( double value )
205 __m128d t = _mm_load_sd( &value );
206 int i = _mm_cvtsd_si32(t);
207 return i - _mm_movemask_pd(_mm_cmplt_sd(t,_mm_cvtsi32_sd(t,i)));
209 int temp = cvRound(value);
210 float diff = (float)(value - temp);
211 return temp - (*(int*)&diff < 0);
216 CV_INLINE int cvCeil( double value )
219 __m128d t = _mm_load_sd( &value );
220 int i = _mm_cvtsd_si32(t);
221 return i + _mm_movemask_pd(_mm_cmpgt_sd(t,_mm_cvtsi32_sd(t,i)));
223 int temp = cvRound(value);
224 float diff = (float)(temp - value);
225 return temp + (*(int*)&diff < 0);
229 #define cvInvSqrt(value) ((float)(1./sqrt(value)))
230 #define cvSqrt(value) ((float)sqrt(value))
232 CV_INLINE int cvIsNaN( double value )
234 #if 1/*defined _MSC_VER || defined __BORLANDC__
235 return _isnan(value);
236 #elif defined __GNUC__
239 unsigned lo = (unsigned)*(uint64*)&value;
240 unsigned hi = (unsigned)(*(uint64*)&value >> 32);
241 return (hi & 0x7fffffff) + (lo != 0) > 0x7ff00000;
246 CV_INLINE int cvIsInf( double value )
248 #if 1/*defined _MSC_VER || defined __BORLANDC__
249 return !_finite(value);
250 #elif defined __GNUC__
253 unsigned lo = (unsigned)*(uint64*)&value;
254 unsigned hi = (unsigned)(*(uint64*)&value >> 32);
255 return (hi & 0x7fffffff) == 0x7ff00000 && lo == 0;
260 /*************** Random number generation *******************/
262 typedef uint64 CvRNG;
264 CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
266 CvRNG rng = (uint64)(seed ? seed : (int64)-1);
270 /* returns random 32-bit unsigned integer */
271 CV_INLINE unsigned cvRandInt( CvRNG* rng )
274 temp = (uint64)(unsigned)temp*1554115554 + (temp >> 32);
276 return (unsigned)temp;
279 /* returns random floating-point number between 0 and 1 */
280 CV_INLINE double cvRandReal( CvRNG* rng )
282 return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
285 /****************************************************************************************\
286 * Image type (IplImage) *
287 \****************************************************************************************/
292 * The following definitions (until #endif)
293 * is an extract from IPL headers.
294 * Copyright (c) 1995 Intel Corporation.
296 #define IPL_DEPTH_SIGN 0x80000000
298 #define IPL_DEPTH_1U 1
299 #define IPL_DEPTH_8U 8
300 #define IPL_DEPTH_16U 16
301 #define IPL_DEPTH_32F 32
303 #define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
304 #define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
305 #define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
307 #define IPL_DATA_ORDER_PIXEL 0
308 #define IPL_DATA_ORDER_PLANE 1
310 #define IPL_ORIGIN_TL 0
311 #define IPL_ORIGIN_BL 1
313 #define IPL_ALIGN_4BYTES 4
314 #define IPL_ALIGN_8BYTES 8
315 #define IPL_ALIGN_16BYTES 16
316 #define IPL_ALIGN_32BYTES 32
318 #define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
319 #define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
321 #define IPL_BORDER_CONSTANT 0
322 #define IPL_BORDER_REPLICATE 1
323 #define IPL_BORDER_REFLECT 2
324 #define IPL_BORDER_WRAP 3
326 typedef struct _IplImage
328 int nSize; /* sizeof(IplImage) */
329 int ID; /* version (=0)*/
330 int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */
331 int alphaChannel; /* ignored by OpenCV */
332 int depth; /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
333 IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */
334 char colorModel[4]; /* ignored by OpenCV */
335 char channelSeq[4]; /* ditto */
336 int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.
337 cvCreateImage can only create interleaved images */
338 int origin; /* 0 - top-left origin,
339 1 - bottom-left origin (Windows bitmaps style) */
340 int align; /* Alignment of image rows (4 or 8).
341 OpenCV ignores it and uses widthStep instead */
342 int width; /* image width in pixels */
343 int height; /* image height in pixels */
344 struct _IplROI *roi;/* image ROI. if NULL, the whole image is selected */
345 struct _IplImage *maskROI; /* must be NULL */
346 void *imageId; /* ditto */
347 struct _IplTileInfo *tileInfo; /* ditto */
348 int imageSize; /* image data size in bytes
349 (==image->height*image->widthStep
350 in case of interleaved data)*/
351 char *imageData; /* pointer to aligned image data */
352 int widthStep; /* size of aligned image row in bytes */
353 int BorderMode[4]; /* ignored by OpenCV */
354 int BorderConst[4]; /* ditto */
355 char *imageDataOrigin; /* pointer to very origin of image data
356 (not necessarily aligned) -
357 needed for correct deallocation */
361 typedef struct _IplTileInfo IplTileInfo;
363 typedef struct _IplROI
365 int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
373 typedef struct _IplConvKernel
384 typedef struct _IplConvKernelFP
394 #define IPL_IMAGE_HEADER 1
395 #define IPL_IMAGE_DATA 2
396 #define IPL_IMAGE_ROI 4
400 #define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
401 #define CV_TYPE_NAME_IMAGE "opencv-image"
403 #define CV_IS_IMAGE_HDR(img) \
404 ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
406 #define CV_IS_IMAGE(img) \
407 (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
409 /* for storing double-precision
410 floating point data in IplImage's */
411 #define IPL_DEPTH_64F 64
413 /* get reference to pixel at (col,row),
414 for multi-channel images (col) should be multiplied by number of channels */
415 #define CV_IMAGE_ELEM( image, elemtype, row, col ) \
416 (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
418 /****************************************************************************************\
419 * Matrix type (CvMat) *
420 \****************************************************************************************/
423 #define CV_CN_SHIFT 3
424 #define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
433 #define CV_USRTYPE1 7
435 #define CV_MAKETYPE(depth,cn) ((depth) + (((cn)-1) << CV_CN_SHIFT))
436 #define CV_MAKE_TYPE CV_MAKETYPE
438 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
439 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
440 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
441 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
443 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
444 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
445 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
446 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
448 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
449 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
450 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
451 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
453 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
454 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
455 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
456 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
458 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
459 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
460 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
461 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
463 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
464 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
465 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
466 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
468 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
469 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
470 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
471 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
473 #define CV_AUTO_STEP 0x7fffffff
474 #define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff )
476 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
477 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
478 #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
479 #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
480 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
481 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
482 #define CV_MAT_CONT_FLAG_SHIFT 9
483 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
484 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
485 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
486 #define CV_MAT_TEMP_FLAG_SHIFT 10
487 #define CV_MAT_TEMP_FLAG (1 << CV_MAT_TEMP_FLAG_SHIFT)
488 #define CV_IS_TEMP_MAT(flags) ((flags) & CV_MAT_TEMP_FLAG)
490 #define CV_MAGIC_MASK 0xFFFF0000
491 #define CV_MAT_MAGIC_VAL 0x42420000
492 #define CV_TYPE_NAME_MAT "opencv-matrix"
499 /* for internal use only */
532 #define CV_IS_MAT_HDR(mat) \
533 ((mat) != NULL && (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL)
535 #define CV_IS_MAT(mat) \
536 (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
538 #define CV_IS_MASK_ARR(mat) \
539 (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
541 #define CV_ARE_TYPES_EQ(mat1, mat2) \
542 ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
544 #define CV_ARE_CNS_EQ(mat1, mat2) \
545 ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
547 #define CV_ARE_DEPTHS_EQ(mat1, mat2) \
548 ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
550 #define CV_ARE_SIZES_EQ(mat1, mat2) \
551 ((mat1)->height == (mat2)->height && (mat1)->width == (mat2)->width)
553 #define CV_IS_MAT_CONST(mat) \
554 (((mat)->height|(mat)->width) == 1)
556 /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
557 #define CV_ELEM_SIZE(type) \
558 (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
560 /* inline constructor. No data is allocated internally!!!
561 (use together with cvCreateData, or use cvCreateMat instead to
562 get a matrix with allocated data) */
563 CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
567 assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
568 type = CV_MAT_TYPE(type);
569 m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
572 m.step = rows > 1 ? m.cols*CV_ELEM_SIZE(type) : 0;
573 m.data.ptr = (uchar*)data;
580 #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
581 (assert( (unsigned)(row) < (unsigned)(mat).rows && \
582 (unsigned)(col) < (unsigned)(mat).cols ), \
583 (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
585 #define CV_MAT_ELEM_PTR( mat, row, col ) \
586 CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
588 #define CV_MAT_ELEM( mat, elemtype, row, col ) \
589 (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
592 CV_INLINE double cvmGet( const CvMat* mat, int row, int col )
596 type = CV_MAT_TYPE(mat->type);
597 assert( (unsigned)row < (unsigned)mat->rows &&
598 (unsigned)col < (unsigned)mat->cols );
600 if( type == CV_32FC1 )
601 return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
604 assert( type == CV_64FC1 );
605 return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
610 CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value )
613 type = CV_MAT_TYPE(mat->type);
614 assert( (unsigned)row < (unsigned)mat->rows &&
615 (unsigned)col < (unsigned)mat->cols );
617 if( type == CV_32FC1 )
618 ((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
621 assert( type == CV_64FC1 );
622 ((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
627 CV_INLINE int cvCvToIplDepth( int type )
629 int depth = CV_MAT_DEPTH(type);
630 return CV_ELEM_SIZE(depth)*8 | (depth == CV_8S || depth == CV_16S ||
631 depth == CV_32S ? IPL_DEPTH_SIGN : 0);
635 /****************************************************************************************\
636 * Multi-dimensional dense array (CvMatND) *
637 \****************************************************************************************/
639 #define CV_MATND_MAGIC_VAL 0x42430000
640 #define CV_TYPE_NAME_MATND "opencv-nd-matrix"
642 #define CV_MAX_DIM 32
643 #define CV_MAX_DIM_HEAP (1 << 16)
645 typedef struct CvMatND
669 #define CV_IS_MATND_HDR(mat) \
670 ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
672 #define CV_IS_MATND(mat) \
673 (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
676 /****************************************************************************************\
677 * Multi-dimensional sparse array (CvSparseMat) *
678 \****************************************************************************************/
680 #define CV_SPARSE_MAT_MAGIC_VAL 0x42440000
681 #define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix"
685 typedef struct CvSparseMat
695 int size[CV_MAX_DIM];
699 #define CV_IS_SPARSE_MAT_HDR(mat) \
701 (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
703 #define CV_IS_SPARSE_MAT(mat) \
704 CV_IS_SPARSE_MAT_HDR(mat)
706 /**************** iteration through a sparse array *****************/
708 typedef struct CvSparseNode
711 struct CvSparseNode* next;
715 typedef struct CvSparseMatIterator
723 #define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset))
724 #define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset))
726 /****************************************************************************************\
728 \****************************************************************************************/
730 typedef int CvHistType;
732 #define CV_HIST_MAGIC_VAL 0x42450000
733 #define CV_HIST_UNIFORM_FLAG (1 << 10)
735 /* indicates whether bin ranges are set already or not */
736 #define CV_HIST_RANGES_FLAG (1 << 11)
738 #define CV_HIST_ARRAY 0
739 #define CV_HIST_SPARSE 1
740 #define CV_HIST_TREE CV_HIST_SPARSE
742 /* should be used as a parameter only,
743 it turns to CV_HIST_UNIFORM_FLAG of hist->type */
744 #define CV_HIST_UNIFORM 1
746 typedef struct CvHistogram
750 float thresh[CV_MAX_DIM][2]; /* for uniform histograms */
751 float** thresh2; /* for non-uniform histograms */
752 CvMatND mat; /* embedded matrix header for array histograms */
756 #define CV_IS_HIST( hist ) \
758 (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
759 (hist)->bins != NULL)
761 #define CV_IS_UNIFORM_HIST( hist ) \
762 (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
764 #define CV_IS_SPARSE_HIST( hist ) \
765 CV_IS_SPARSE_MAT((hist)->bins)
767 #define CV_HIST_HAS_RANGES( hist ) \
768 (((hist)->type & CV_HIST_RANGES_FLAG) != 0)
770 /****************************************************************************************\
771 * Other supplementary data type definitions *
772 \****************************************************************************************/
774 /*************************************** CvRect *****************************************/
776 typedef struct CvRect
785 CV_INLINE CvRect cvRect( int x, int y, int width, int height )
798 CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
801 roi.xOffset = rect.x;
802 roi.yOffset = rect.y;
803 roi.width = rect.width;
804 roi.height = rect.height;
811 CV_INLINE CvRect cvROIToRect( IplROI roi )
813 return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
816 /*********************************** CvTermCriteria *************************************/
818 #define CV_TERMCRIT_ITER 1
819 #define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER
820 #define CV_TERMCRIT_EPS 2
822 typedef struct CvTermCriteria
824 int type; /* may be combination of
832 CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
837 t.max_iter = max_iter;
838 t.epsilon = (float)epsilon;
844 /******************************* CvPoint and variants ***********************************/
846 typedef struct CvPoint
854 CV_INLINE CvPoint cvPoint( int x, int y )
865 typedef struct CvPoint2D32f
873 CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
884 CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
886 return cvPoint2D32f( (float)point.x, (float)point.y );
890 CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
893 ipt.x = cvRound(point.x);
894 ipt.y = cvRound(point.y);
900 typedef struct CvPoint3D32f
909 CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
921 typedef struct CvPoint2D64f
929 CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
940 typedef struct CvPoint3D64f
949 CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
961 /******************************** CvSize's & CvBox **************************************/
970 CV_INLINE CvSize cvSize( int width, int height )
980 typedef struct CvSize2D32f
988 CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
992 s.width = (float)width;
993 s.height = (float)height;
998 typedef struct CvBox2D
1000 CvPoint2D32f center; /* center of the box */
1001 CvSize2D32f size; /* box width and length */
1002 float angle; /* angle between the horizontal axis
1003 and the first side (i.e. length) in radians */
1007 /************************************* CvSlice ******************************************/
1009 typedef struct CvSlice
1011 int start_index, end_index;
1015 CV_INLINE CvSlice cvSlice( int start, int end )
1018 slice.start_index = start;
1019 slice.end_index = end;
1024 #define CV_WHOLE_SEQ_END_INDEX 0x3fffffff
1025 #define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX)
1028 /************************************* CvScalar *****************************************/
1030 typedef struct CvScalar
1036 CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
1037 double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
1040 scalar.val[0] = val0; scalar.val[1] = val1;
1041 scalar.val[2] = val2; scalar.val[3] = val3;
1046 CV_INLINE CvScalar cvRealScalar( double val0 )
1049 scalar.val[0] = val0;
1050 scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
1054 CV_INLINE CvScalar cvScalarAll( double val0123 )
1057 scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = val0123;
1061 /****************************************************************************************\
1062 * Dynamic Data structures *
1063 \****************************************************************************************/
1065 /******************************** Memory storage ****************************************/
1067 typedef struct CvMemBlock
1069 struct CvMemBlock* prev;
1070 struct CvMemBlock* next;
1074 #define CV_STORAGE_MAGIC_VAL 0x42890000
1076 typedef struct CvMemStorage
1079 CvMemBlock* bottom;/* first allocated block */
1080 CvMemBlock* top; /* current memory block - top of the stack */
1081 struct CvMemStorage* parent; /* borrows new blocks from */
1082 int block_size; /* block size */
1083 int free_space; /* free space in the current block */
1087 #define CV_IS_STORAGE(storage) \
1088 ((storage) != NULL && \
1089 (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL)
1092 typedef struct CvMemStoragePos
1100 /*********************************** Sequence *******************************************/
1102 typedef struct CvSeqBlock
1104 struct CvSeqBlock* prev; /* previous sequence block */
1105 struct CvSeqBlock* next; /* next sequence block */
1106 int start_index; /* index of the first element in the block +
1107 sequence->first->start_index */
1108 int count; /* number of elements in the block */
1109 char* data; /* pointer to the first element of the block */
1114 #define CV_TREE_NODE_FIELDS(node_type) \
1115 int flags; /* micsellaneous flags */ \
1116 int header_size; /* size of sequence header */ \
1117 struct node_type* h_prev; /* previous sequence */ \
1118 struct node_type* h_next; /* next sequence */ \
1119 struct node_type* v_prev; /* 2nd previous sequence */ \
1120 struct node_type* v_next /* 2nd next sequence */
1123 Read/Write sequence.
1124 Elements can be dynamically inserted to or deleted from the sequence.
1126 #define CV_SEQUENCE_FIELDS() \
1127 CV_TREE_NODE_FIELDS(CvSeq); \
1128 int total; /* total number of elements */ \
1129 int elem_size; /* size of sequence element in bytes */ \
1130 char* block_max; /* maximal bound of the last block */ \
1131 char* ptr; /* current write pointer */ \
1132 int delta_elems; /* how many elements allocated when the seq grows */ \
1133 CvMemStorage* storage; /* where the seq is stored */ \
1134 CvSeqBlock* free_blocks; /* free blocks list */ \
1135 CvSeqBlock* first; /* pointer to the first sequence block */
1137 typedef struct CvSeq
1139 CV_SEQUENCE_FIELDS()
1143 #define CV_TYPE_NAME_SEQ "opencv-sequence"
1144 #define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree"
1146 /*************************************** Set ********************************************/
1149 Order is not preserved. There can be gaps between sequence elements.
1150 After the element has been inserted it stays in the same place all the time.
1151 The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists.
1153 #define CV_SET_ELEM_FIELDS(elem_type) \
1155 struct elem_type* next_free;
1157 typedef struct CvSetElem
1159 CV_SET_ELEM_FIELDS(CvSetElem)
1163 #define CV_SET_FIELDS() \
1164 CV_SEQUENCE_FIELDS() \
1165 CvSetElem* free_elems; \
1168 typedef struct CvSet
1175 #define CV_SET_ELEM_IDX_MASK ((1 << 24) - 1)
1176 #define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1))
1178 /* Checks whether the element pointed by ptr belongs to a set or not */
1179 #define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0)
1181 /************************************* Graph ********************************************/
1184 Graph is represented as a set of vertices.
1185 Vertices contain their adjacency lists (more exactly, pointers to first incoming or
1186 outcoming edge (or 0 if isolated vertex)). Edges are stored in another set.
1187 There is a single-linked list of incoming/outcoming edges for each vertex.
1189 Each edge consists of:
1190 two pointers to the starting and the ending vertices (vtx[0] and vtx[1],
1191 respectively). Graph may be oriented or not. In the second case, edges between
1192 vertex i to vertex j are not distingueshed (during the search operations).
1194 two pointers to next edges for the starting and the ending vertices.
1195 next[0] points to the next edge in the vtx[0] adjacency list and
1196 next[1] points to the next edge in the vtx[1] adjacency list.
1198 #define CV_GRAPH_EDGE_FIELDS() \
1201 struct CvGraphEdge* next[2]; \
1202 struct CvGraphVtx* vtx[2];
1205 #define CV_GRAPH_VERTEX_FIELDS() \
1207 struct CvGraphEdge* first;
1210 typedef struct CvGraphEdge
1212 CV_GRAPH_EDGE_FIELDS()
1216 typedef struct CvGraphVtx
1218 CV_GRAPH_VERTEX_FIELDS()
1222 typedef struct CvGraphVtx2D
1224 CV_GRAPH_VERTEX_FIELDS()
1230 Graph is "derived" from the set (this is set a of vertices)
1231 and includes another set (edges)
1233 #define CV_GRAPH_FIELDS() \
1237 typedef struct CvGraph
1243 #define CV_TYPE_NAME_GRAPH "opencv-graph"
1245 /*********************************** Chain/Countour *************************************/
1247 typedef struct CvChain
1249 CV_SEQUENCE_FIELDS()
1254 #define CV_CONTOUR_FIELDS() \
1255 CV_SEQUENCE_FIELDS() \
1260 typedef struct CvContour
1266 typedef CvContour CvPoint2DSeq;
1268 /****************************************************************************************\
1270 \****************************************************************************************/
1272 #define CV_SEQ_MAGIC_VAL 0x42990000
1274 #define CV_IS_SEQ(seq) \
1275 ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL)
1277 #define CV_SET_MAGIC_VAL 0x42980000
1278 #define CV_IS_SET(set) \
1279 ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL)
1281 #define CV_SEQ_ELTYPE_BITS 5
1282 #define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1)
1284 #define CV_SEQ_ELTYPE_POINT CV_32SC2 /* (x,y) */
1285 #define CV_SEQ_ELTYPE_CODE CV_8UC1 /* freeman code: 0..7 */
1286 #define CV_SEQ_ELTYPE_GENERIC 0
1287 #define CV_SEQ_ELTYPE_PTR CV_USRTYPE1
1288 #define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /* &(x,y) */
1289 #define CV_SEQ_ELTYPE_INDEX CV_32SC1 /* #(x,y) */
1290 #define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /* &next_o, &next_d, &vtx_o, &vtx_d */
1291 #define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /* first_edge, &(x,y) */
1292 #define CV_SEQ_ELTYPE_TRIAN_ATR 0 /* vertex of the binary tree */
1293 #define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /* connected component */
1294 #define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /* (x,y,z) */
1296 #define CV_SEQ_KIND_BITS 5
1297 #define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS)
1299 /* types of sequences */
1300 #define CV_SEQ_KIND_GENERIC (0 << CV_SEQ_ELTYPE_BITS)
1301 #define CV_SEQ_KIND_CURVE (1 << CV_SEQ_ELTYPE_BITS)
1302 #define CV_SEQ_KIND_BIN_TREE (2 << CV_SEQ_ELTYPE_BITS)
1304 /* types of sparse sequences (sets) */
1305 #define CV_SEQ_KIND_GRAPH (3 << CV_SEQ_ELTYPE_BITS)
1306 #define CV_SEQ_KIND_SUBDIV2D (4 << CV_SEQ_ELTYPE_BITS)
1308 #define CV_SEQ_FLAG_SHIFT (CV_SEQ_KIND_BITS + CV_SEQ_ELTYPE_BITS)
1310 /* flags for curves */
1311 #define CV_SEQ_FLAG_CLOSED (1 << CV_SEQ_FLAG_SHIFT)
1312 #define CV_SEQ_FLAG_SIMPLE (2 << CV_SEQ_FLAG_SHIFT)
1313 #define CV_SEQ_FLAG_CONVEX (4 << CV_SEQ_FLAG_SHIFT)
1314 #define CV_SEQ_FLAG_HOLE (8 << CV_SEQ_FLAG_SHIFT)
1316 /* flags for graphs */
1317 #define CV_GRAPH_FLAG_ORIENTED (1 << CV_SEQ_FLAG_SHIFT)
1319 #define CV_GRAPH CV_SEQ_KIND_GRAPH
1320 #define CV_ORIENTED_GRAPH (CV_SEQ_KIND_GRAPH|CV_GRAPH_FLAG_ORIENTED)
1323 #define CV_SEQ_POINT_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT)
1324 #define CV_SEQ_POINT3D_SET (CV_SEQ_KIND_GENERIC| CV_SEQ_ELTYPE_POINT3D)
1325 #define CV_SEQ_POLYLINE (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_POINT)
1326 #define CV_SEQ_POLYGON (CV_SEQ_FLAG_CLOSED | CV_SEQ_POLYLINE )
1327 #define CV_SEQ_CONTOUR CV_SEQ_POLYGON
1328 #define CV_SEQ_SIMPLE_POLYGON (CV_SEQ_FLAG_SIMPLE | CV_SEQ_POLYGON )
1330 /* chain-coded curves */
1331 #define CV_SEQ_CHAIN (CV_SEQ_KIND_CURVE | CV_SEQ_ELTYPE_CODE)
1332 #define CV_SEQ_CHAIN_CONTOUR (CV_SEQ_FLAG_CLOSED | CV_SEQ_CHAIN)
1334 /* binary tree for the contour */
1335 #define CV_SEQ_POLYGON_TREE (CV_SEQ_KIND_BIN_TREE | CV_SEQ_ELTYPE_TRIAN_ATR)
1337 /* sequence of the connected components */
1338 #define CV_SEQ_CONNECTED_COMP (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_CONNECTED_COMP)
1340 /* sequence of the integer numbers */
1341 #define CV_SEQ_INDEX (CV_SEQ_KIND_GENERIC | CV_SEQ_ELTYPE_INDEX)
1343 #define CV_SEQ_ELTYPE( seq ) ((seq)->flags & CV_SEQ_ELTYPE_MASK)
1344 #define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK )
1347 #define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \
1348 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC))
1350 #define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE)
1351 #define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0)
1352 #define CV_IS_SEQ_CONVEX( seq ) (((seq)->flags & CV_SEQ_FLAG_CONVEX) != 0)
1353 #define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0)
1354 #define CV_IS_SEQ_SIMPLE( seq ) ((((seq)->flags & CV_SEQ_FLAG_SIMPLE) != 0) || \
1355 CV_IS_SEQ_CONVEX(seq))
1357 /* type checking macros */
1358 #define CV_IS_SEQ_POINT_SET( seq ) \
1359 ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2))
1361 #define CV_IS_SEQ_POINT_SUBSET( seq ) \
1362 (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT)
1364 #define CV_IS_SEQ_POLYLINE( seq ) \
1365 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq))
1367 #define CV_IS_SEQ_POLYGON( seq ) \
1368 (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq))
1370 #define CV_IS_SEQ_CHAIN( seq ) \
1371 (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1)
1373 #define CV_IS_SEQ_CONTOUR( seq ) \
1374 (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq)))
1376 #define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \
1377 (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq ))
1379 #define CV_IS_SEQ_POLYGON_TREE( seq ) \
1380 (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \
1381 CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE )
1383 #define CV_IS_GRAPH( seq ) \
1384 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH)
1386 #define CV_IS_GRAPH_ORIENTED( seq ) \
1387 (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0)
1389 #define CV_IS_SUBDIV2D( seq ) \
1390 (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D)
1392 /****************************************************************************************/
1393 /* Sequence writer & reader */
1394 /****************************************************************************************/
1396 #define CV_SEQ_WRITER_FIELDS() \
1398 CvSeq* seq; /* the sequence written */ \
1399 CvSeqBlock* block; /* current block */ \
1400 char* ptr; /* pointer to free space */ \
1401 char* block_min; /* pointer to the beginning of block*/\
1402 char* block_max; /* pointer to the end of block */
1404 typedef struct CvSeqWriter
1406 CV_SEQ_WRITER_FIELDS()
1407 int reserved[4]; /* some reserved fields */
1412 #define CV_SEQ_READER_FIELDS() \
1414 CvSeq* seq; /* sequence, beign read */ \
1415 CvSeqBlock* block; /* current block */ \
1416 char* ptr; /* pointer to element be read next */ \
1417 char* block_min; /* pointer to the beginning of block */\
1418 char* block_max; /* pointer to the end of block */ \
1419 int delta_index;/* = seq->first->start_index */ \
1420 char* prev_elem; /* pointer to previous element */
1423 typedef struct CvSeqReader
1425 CV_SEQ_READER_FIELDS()
1430 /****************************************************************************************/
1431 /* Operations on sequences */
1432 /****************************************************************************************/
1434 #define CV_SEQ_ELEM( seq, elem_type, index ) \
1435 /* assert gives some guarantee that <seq> parameter is valid */ \
1436 ( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \
1437 (seq)->elem_size == sizeof(elem_type)), \
1438 (elem_type*)((seq)->first && (unsigned)index < \
1439 (unsigned)((seq)->first->count) ? \
1440 (seq)->first->data + (index) * sizeof(elem_type) : \
1441 cvGetSeqElem( (CvSeq*)(seq), (index) )))
1442 #define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )
1444 /* macro that adds element to sequence */
1445 #define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \
1447 if( (writer).ptr >= (writer).block_max ) \
1449 cvCreateSeqBlock( &writer); \
1451 memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\
1452 (writer).ptr += (writer).seq->elem_size; \
1455 #define CV_WRITE_SEQ_ELEM( elem, writer ) \
1457 assert( (writer).seq->elem_size == sizeof(elem)); \
1458 if( (writer).ptr >= (writer).block_max ) \
1460 cvCreateSeqBlock( &writer); \
1462 assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
1463 memcpy((writer).ptr, &(elem), sizeof(elem)); \
1464 (writer).ptr += sizeof(elem); \
1468 /* move reader position forward */
1469 #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \
1471 if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \
1473 cvChangeSeqBlock( &(reader), 1 ); \
1478 /* move reader position backward */
1479 #define CV_PREV_SEQ_ELEM( elem_size, reader ) \
1481 if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \
1483 cvChangeSeqBlock( &(reader), -1 ); \
1487 /* read element and move read position forward */
1488 #define CV_READ_SEQ_ELEM( elem, reader ) \
1490 assert( (reader).seq->elem_size == sizeof(elem)); \
1491 memcpy( &(elem), (reader).ptr, sizeof((elem))); \
1492 CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \
1495 /* read element and move read position backward */
1496 #define CV_REV_READ_SEQ_ELEM( elem, reader ) \
1498 assert( (reader).seq->elem_size == sizeof(elem)); \
1499 memcpy(&(elem), (reader).ptr, sizeof((elem))); \
1500 CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \
1504 #define CV_READ_CHAIN_POINT( _pt, reader ) \
1506 (_pt) = (reader).pt; \
1507 if( (reader).ptr ) \
1509 CV_READ_SEQ_ELEM( (reader).code, (*((CvSeqReader*)&(reader)))); \
1510 assert( ((reader).code & ~7) == 0 ); \
1511 (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \
1512 (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \
1516 #define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr)))
1517 #define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem)))
1519 #define CV_READ_EDGE( pt1, pt2, reader ) \
1521 assert( sizeof(pt1) == sizeof(CvPoint) && \
1522 sizeof(pt2) == sizeof(CvPoint) && \
1523 reader.seq->elem_size == sizeof(CvPoint)); \
1524 (pt1) = CV_PREV_POINT( reader ); \
1525 (pt2) = CV_CURRENT_POINT( reader ); \
1526 (reader).prev_elem = (reader).ptr; \
1527 CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \
1530 /************ Graph macros ************/
1532 /* returns next graph edge for given vertex */
1533 #define CV_NEXT_GRAPH_EDGE( edge, vertex ) \
1534 (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \
1535 (edge)->next[(edge)->vtx[1] == (vertex)])
1539 /****************************************************************************************\
1540 * Data structures for persistence (a.k.a serialization) functionality *
1541 \****************************************************************************************/
1543 /* "black box" file storage */
1544 typedef struct CvFileStorage CvFileStorage;
1547 #define CV_STORAGE_READ 0
1548 #define CV_STORAGE_WRITE 1
1549 #define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE
1550 #define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE
1551 #define CV_STORAGE_APPEND 2
1553 /* list of attributes */
1554 typedef struct CvAttrList
1556 const char** attr; /* NULL-terminated array of (attribute_name,attribute_value) pairs */
1557 struct CvAttrList* next; /* pointer to next chunk of the attributes list */
1561 CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL),
1562 CvAttrList* next CV_DEFAULT(NULL) )
1573 #define CV_NODE_NONE 0
1574 #define CV_NODE_INT 1
1575 #define CV_NODE_INTEGER CV_NODE_INT
1576 #define CV_NODE_REAL 2
1577 #define CV_NODE_FLOAT CV_NODE_REAL
1578 #define CV_NODE_STR 3
1579 #define CV_NODE_STRING CV_NODE_STR
1580 #define CV_NODE_REF 4 /* not used */
1581 #define CV_NODE_SEQ 5
1582 #define CV_NODE_MAP 6
1583 #define CV_NODE_TYPE_MASK 7
1585 #define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK)
1587 /* file node flags */
1588 #define CV_NODE_FLOW 8 /* used only for writing structures to YAML format */
1589 #define CV_NODE_USER 16
1590 #define CV_NODE_EMPTY 32
1591 #define CV_NODE_NAMED 64
1593 #define CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT)
1594 #define CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL)
1595 #define CV_NODE_IS_STRING(flags) (CV_NODE_TYPE(flags) == CV_NODE_STRING)
1596 #define CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) == CV_NODE_SEQ)
1597 #define CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) == CV_NODE_MAP)
1598 #define CV_NODE_IS_COLLECTION(flags) (CV_NODE_TYPE(flags) >= CV_NODE_SEQ)
1599 #define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0)
1600 #define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0)
1601 #define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0)
1602 #define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0)
1604 #define CV_NODE_SEQ_SIMPLE 256
1605 #define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0)
1607 typedef struct CvString
1614 /* all the keys (names) of elements in the readed file storage
1615 are stored in the hash to speed up the lookup operations */
1616 typedef struct CvStringHashNode
1620 struct CvStringHashNode* next;
1624 typedef struct CvGenericHash CvFileNodeHash;
1626 /* basic element of the file storage - scalar or collection */
1627 typedef struct CvFileNode
1630 struct CvTypeInfo* info; /* type information
1631 (only for user-defined object, for others it is 0) */
1634 double f; /* scalar floating-point number */
1635 int i; /* scalar integer number */
1636 CvString str; /* text string */
1637 CvSeq* seq; /* sequence (ordered collection of file nodes) */
1638 CvFileNodeHash* map; /* map (collection of named file nodes) */
1646 typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr );
1647 typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr );
1648 typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node );
1649 typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name,
1650 const void* struct_ptr, CvAttrList attributes );
1651 typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr );
1656 typedef struct CvTypeInfo
1660 struct CvTypeInfo* prev;
1661 struct CvTypeInfo* next;
1662 const char* type_name;
1663 CvIsInstanceFunc is_instance;
1664 CvReleaseFunc release;
1672 /**** System data types ******/
1674 typedef struct CvPluginFuncInfo
1677 void* default_func_addr;
1678 const char* func_names;
1684 typedef struct CvModuleInfo
1686 struct CvModuleInfo* next;
1688 const char* version;
1689 CvPluginFuncInfo* func_tab;
1693 #endif /*_CXCORE_TYPES_H_*/