File: TermCriteria.mm

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (120 lines) | stat: -rw-r--r-- 2,608 bytes parent folder | download | duplicates (3)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
//  TermCriteria.m
//
//  Created by Giles Payne on 2019/12/25.
//

#import "TermCriteria.h"

@implementation TermCriteria {
    cv::TermCriteria native;
}

+ (int)COUNT {
    return 1;
}

+ (int)EPS {
    return 2;
}

+ (int)MAX_ITER {
    return 1;
}

- (int)type {
    return native.type;
}

- (void)setType:(int)val {
    native.type = val;
}

- (int)maxCount {
    return native.maxCount;
}

- (void)setMaxCount:(int)val {
    native.maxCount = val;
}

- (double)epsilon {
    return native.epsilon;
}

- (void)setEpsilon:(double)val {
    native.epsilon = val;
}

#ifdef __cplusplus
- (cv::TermCriteria&)nativeRef {
    return native;
}
#endif

- (instancetype)init {
    return [self initWithType:0 maxCount:0 epsilon:0.0];
}

- (instancetype)initWithType:(int)type maxCount:(int)maxCount epsilon:(double)epsilon {
    self = [super init];
    if (self) {
        self.type = type;
        self.maxCount = maxCount;
        self.epsilon = epsilon;
    }
    return self;
}

- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
    self = [super init];
    if (self) {
        [self set:vals];
    }
    return self;
}

#ifdef __cplusplus
+ (instancetype)fromNative:(cv::TermCriteria&)nativeTermCriteria {
    return [[TermCriteria alloc] initWithType:nativeTermCriteria.type maxCount:nativeTermCriteria.maxCount epsilon:nativeTermCriteria.epsilon];
}
#endif

- (void)set:(NSArray<NSNumber*>*)vals {
    self.type = (vals != nil && vals.count > 0) ? vals[0].intValue : 0;
    self.maxCount = (vals != nil && vals.count > 1) ? vals[1].intValue : 0;
    self.epsilon = (vals != nil && vals.count > 2) ? vals[2].doubleValue : 0.0;
}

- (TermCriteria*)clone {
    return [[TermCriteria alloc] initWithType:self.type maxCount:self.maxCount epsilon:self.epsilon];
}

- (BOOL)isEqual:(id)other {
    if (other == self) {
        return YES;
    } else if (![other isKindOfClass:[TermCriteria class]]) {
        return NO;
    } else {
        TermCriteria* it = (TermCriteria*)other;
        return self.type == it.type && self.maxCount == it.maxCount && self.epsilon == it.epsilon;
    }
}

#define DOUBLE_TO_BITS(x)  ((Cv64suf){ .f = x }).i

- (NSUInteger)hash {
    int prime = 31;
    uint32_t result = 1;
    result = prime * result + self.type;
    result = prime * result + self.maxCount;
    int64_t temp = DOUBLE_TO_BITS(self.epsilon);
    result = prime * result + (int32_t) (temp ^ (temp >> 32));
    return result;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"TermCriteria { type: %d, maxCount: %d, epsilon: %lf}", self.type, self.maxCount, self.epsilon];
}

@end