File: DMatch.mm

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, 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 (108 lines) | stat: -rw-r--r-- 2,567 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
//
//  DMatch.m
//
//  Created by Giles Payne on 2019/12/25.
//

#import "DMatch.h"

@implementation DMatch {
    cv::DMatch native;
}

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

- (void)setQueryIdx:(int)queryIdx {
    native.queryIdx = queryIdx;
}

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

- (void)setTrainIdx:(int)trainIdx {
    native.trainIdx = trainIdx;
}

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

- (void)setImgIdx:(int)imgIdx {
    native.imgIdx = imgIdx;
}

- (float)distance {
    return native.distance;
}

- (void)setDistance:(float)distance {
    native.distance = distance;
}

- (cv::DMatch&)nativeRef {
    return native;
}

- (instancetype)init {
    return [self initWithQueryIdx:-1 trainIdx:-1 distance:FLT_MAX];
}

- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx distance:(float)distance {
    return [self initWithQueryIdx:queryIdx trainIdx:trainIdx imgIdx:-1 distance:distance];
}

- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx imgIdx:(int)imgIdx distance:(float)distance {
    self = [super init];
    if (self != nil) {
        self.queryIdx = queryIdx;
        self.trainIdx = trainIdx;
        self.imgIdx = imgIdx;
        self.distance = distance;
    }
    return self;
}

+ (instancetype)fromNative:(cv::DMatch&)dMatch {
    return [[DMatch alloc] initWithQueryIdx:dMatch.queryIdx trainIdx:dMatch.trainIdx imgIdx:dMatch.imgIdx distance:dMatch.distance];
}

- (BOOL)lessThan:(DMatch*)it {
    return self.distance < it.distance;
}


- (DMatch*)clone {
    return [[DMatch alloc] initWithQueryIdx:self.queryIdx trainIdx:self.trainIdx imgIdx:self.imgIdx distance:self.distance];
}

- (BOOL)isEqual:(id)other {
    if (other == self) {
        return YES;
    } else if (![other isKindOfClass:[DMatch class]]) {
        return NO;
    } else {
        DMatch* dMatch = (DMatch*)other;
        return self.queryIdx == dMatch.queryIdx && self.trainIdx == dMatch.trainIdx && self.imgIdx == dMatch.imgIdx && self.distance == dMatch.distance;
    }
}

#define FLOAT_TO_BITS(x)  ((Cv32suf){ .f = x }).i

- (NSUInteger)hash {
    int prime = 31;
    uint32_t result = 1;
    result = prime * result + self.queryIdx;
    result = prime * result + self.trainIdx;
    result = prime * result + self.imgIdx;
    result = prime * result + FLOAT_TO_BITS(self.distance);
    return result;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"DMatch { queryIdx: %d, trainIdx: %d, imgIdx: %d, distance: %f}", self.queryIdx, self.trainIdx, self.imgIdx, self.distance];
}

@end