-
Notifications
You must be signed in to change notification settings - Fork 117
/
ARMarkerMulti.cpp
171 lines (143 loc) · 5.95 KB
/
ARMarkerMulti.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* ARMarkerMulti.cpp
* ARToolKit5
*
* This file is part of ARToolKit.
*
* ARToolKit is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARToolKit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ARToolKit. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent modules, and to
* copy and distribute the resulting executable under terms of your choice,
* provided that you also meet, for each linked independent module, the terms and
* conditions of the license of that module. An independent module is a module
* which is neither derived from nor based on this library. If you modify this
* library, you may extend this exception to your version of the library, but you
* are not obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Copyright 2015 Daqri, LLC.
* Copyright 2010-2015 ARToolworks, Inc.
*
* Author(s): Philip Lamb.
*
*/
#include <ARWrapper/ARMarkerMulti.h>
#include <ARWrapper/ARController.h>
#ifdef ARDOUBLE_IS_FLOAT
# define _0_0 0.0f
# define _1_0 1.0f
#else
# define _0_0 0.0
# define _1_0 1.0
#endif
ARMarkerMulti::ARMarkerMulti() : ARMarker(MULTI),
m_loaded(false),
config(NULL),
robustFlag(true)
{
}
ARMarkerMulti::~ARMarkerMulti()
{
if (m_loaded) unload();
}
bool ARMarkerMulti::load(const char *multiConfig, ARPattHandle *arPattHandle)
{
if (m_loaded) unload();
config = arMultiReadConfigFile(multiConfig, arPattHandle);
if (!config) {
ARController::logv(AR_LOG_LEVEL_ERROR, "Error loading multimarker config %s", multiConfig);
return false;
}
visible = visiblePrev = false;
// ARPatterns to hold images and positions of the patterns for display to the user.
allocatePatterns(config->marker_num);
for (int i = 0; i < patternCount; i++) {
if (config->marker[i].patt_type == AR_MULTI_PATTERN_TYPE_TEMPLATE) {
patterns[i]->loadTemplate(config->marker[i].patt_id, arPattHandle, (float)config->marker[i].width);
} else {
patterns[i]->loadMatrix(config->marker[i].patt_id, AR_MATRIX_CODE_3x3, (float)config->marker[i].width); // TODO: Determine actual matrix code type in use.
}
patterns[i]->m_matrix[ 0] = config->marker[i].trans[0][0];
patterns[i]->m_matrix[ 1] = config->marker[i].trans[1][0];
patterns[i]->m_matrix[ 2] = config->marker[i].trans[2][0];
patterns[i]->m_matrix[ 3] = _0_0;
patterns[i]->m_matrix[ 4] = config->marker[i].trans[0][1];
patterns[i]->m_matrix[ 5] = config->marker[i].trans[1][1];
patterns[i]->m_matrix[ 6] = config->marker[i].trans[2][1];
patterns[i]->m_matrix[ 7] = _0_0;
patterns[i]->m_matrix[ 8] = config->marker[i].trans[0][2];
patterns[i]->m_matrix[ 9] = config->marker[i].trans[1][2];
patterns[i]->m_matrix[10] = config->marker[i].trans[2][2];
patterns[i]->m_matrix[11] = _0_0;
patterns[i]->m_matrix[12] = config->marker[i].trans[0][3];
patterns[i]->m_matrix[13] = config->marker[i].trans[1][3];
patterns[i]->m_matrix[14] = config->marker[i].trans[2][3];
patterns[i]->m_matrix[15] = _1_0;
}
config->min_submarker = 0;
m_loaded = true;
return true;
}
bool ARMarkerMulti::unload()
{
if (m_loaded) {
freePatterns();
if (config) {
arMultiFreeConfig(config);
config = NULL;
}
m_loaded = false;
}
return true;
}
bool ARMarkerMulti::updateWithDetectedMarkers(ARMarkerInfo* markerInfo, int markerNum, AR3DHandle *ar3DHandle)
{
if (!m_loaded || !config) return false; // Can't update without multimarker config
visiblePrev = visible;
if (markerInfo) {
ARdouble err;
if (robustFlag) {
err = arGetTransMatMultiSquareRobust(ar3DHandle, markerInfo, markerNum, config);
} else {
err = arGetTransMatMultiSquare(ar3DHandle, markerInfo, markerNum, config);
}
// Marker is visible if a match was found.
if (err >= 0) {
visible = true;
for (int j = 0; j < 3; j++) for (int k = 0; k < 4; k++) trans[j][k] = config->trans[j][k];
} else visible = false;
} else visible = false;
return (ARMarker::update()); // Parent class will finish update.
}
bool ARMarkerMulti::updateWithDetectedMarkersStereo(ARMarkerInfo* markerInfoL, int markerNumL, ARMarkerInfo* markerInfoR, int markerNumR, AR3DStereoHandle *handle, ARdouble transL2R[3][4])
{
if (!m_loaded || !config) return false; // Can't update without multimarker config
visiblePrev = visible;
if (markerInfoL && markerInfoR) {
ARdouble err;
if (robustFlag) {
err = arGetTransMatMultiSquareStereoRobust(handle, markerInfoL, markerNumL, markerInfoR, markerNumR, config);
} else {
err = arGetTransMatMultiSquareStereo(handle, markerInfoL, markerNumL, markerInfoR, markerNumR, config);
}
// Marker is visible if a match was found.
if (err >= 0) {
visible = true;
for (int j = 0; j < 3; j++) for (int k = 0; k < 4; k++) trans[j][k] = config->trans[j][k];
} else visible = false;
} else visible = false;
return (ARMarker::update(transL2R)); // Parent class will finish update.
}