-
Notifications
You must be signed in to change notification settings - Fork 15
/
GraphCut.h
81 lines (74 loc) · 2.03 KB
/
GraphCut.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* GraphCut.h
*
* Wrapper for Weksler Olga's GraphCut to Matlab
*
* wrapper by Shai Bagon 2006, contact [email protected]
*
*/
#ifndef _GRAPH_CUT_H_
#define _GRAPH_CUT_H_
#include "mex.h"
#include <tmwtypes.h>
/* handle type for graph class */
typedef void* GraphHandle;
/* we want to verify that the class is valid */
#define VALID_CLASS_SIGNITURE 0xabcd0123
/* pointer types in 64 bits machines */
#ifdef A64BITS
#define MATLAB_POINTER_TYPE mxUINT64_CLASS
#else
#define MATLAB_POINTER_TYPE mxUINT32_CLASS
#endif
template<class T>
void GetScalar(const mxArray* x, T& scalar)
{
if ( mxGetNumberOfElements(x) != 1 )
mexErrMsgIdAndTxt("GraphCut:GetScalar","input is not a scalar!");
void *p = mxGetData(x);
switch (mxGetClassID(x)) {
case mxCHAR_CLASS:
scalar = *(char*)p;
break;
case mxDOUBLE_CLASS:
scalar = *(double*)p;
break;
case mxSINGLE_CLASS:
scalar = *(float*)p;
break;
case mxINT8_CLASS:
scalar = *(char*)p;
break;
case mxUINT8_CLASS:
scalar = *(unsigned char*)p;
break;
case mxINT16_CLASS:
scalar = *(short*)p;
break;
case mxUINT16_CLASS:
scalar = *(unsigned short*)p;
break;
case mxINT32_CLASS:
scalar = *(int*)p;
break;
case mxUINT32_CLASS:
scalar = *(unsigned int*)p;
break;
#ifdef A64BITS
case mxINT64_CLASS:
scalar = *(int64_T*)p;
break;
case mxUINT64_CLASS:
scalar = *(uint64_T*)p;
break;
#endif /* 64 bits machines */
default:
mexErrMsgIdAndTxt("GraphCut:GetScalar","unsupported data type");
}
}
/* memory allocations - redirect to MATLAB memory menager */
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void* ptr);
void operator delete[](void* ptr);
#endif /* _GRAPH_CUT_H_ */