((function () {
"use strict";
var ARController = (function (width, height, camera) {
var id;
var w = width, h = height;
this.orientation = "landscape";
this.listeners = {};
if (typeof width !== "number") {
var image = width;
camera = height;
w = image.videoWidth || image.width;
h = image.videoHeight || image.height;
this.image = image
}
this.defaultMarkerWidth = 1;
this.patternMarkers = {};
this.barcodeMarkers = {};
this.transform_mat = new Float32Array(16);
this.canvas = document.createElement("canvas");
this.canvas.width = w;
this.canvas.height = h;
this.ctx = this.canvas.getContext("2d");
this.videoWidth = w;
this.videoHeight = h;
if (typeof camera === "string") {
var self = this;
this.cameraParam = new ARCameraParam(camera, (function () {
self._initialize()
}), (function (err) {
console.error("ARController: Failed to load ARCameraParam", err)
}))
} else {
this.cameraParam = camera;
this._initialize()
}
});
ARController.prototype.dispose = (function () {
artoolkit.teardown(this.id);
for (var t in this) {
this[t] = null
}
});
ARController.prototype.process = (function (image) {
this.detectMarker(image);
var markerNum = this.getMarkerNum();
var k, o;
for (k in this.patternMarkers) {
o = this.patternMarkers[k];
o.inPrevious = o.inCurrent;
o.inCurrent = false
}
for (k in this.barcodeMarkers) {
o = this.barcodeMarkers[k];
o.inPrevious = o.inCurrent;
o.inCurrent = false
}
for (var i = 0; i < markerNum; i++) {
var markerInfo = this.getMarker(i);
var markerType = artoolkit.UNKNOWN_MARKER;
var visible = this.trackPatternMarkerId(-1);
if (markerInfo.idPatt > -1 && (markerInfo.id === markerInfo.idPatt || markerInfo.idMatrix === -1)) {
visible = this.trackPatternMarkerId(markerInfo.idPatt);
markerType = artoolkit.PATTERN_MARKER;
if (markerInfo.dir !== markerInfo.dirPatt) {
this.setMarkerInfoDir(i, markerInfo.dirPatt)
}
} else if (markerInfo.idMatrix > -1) {
visible = this.trackBarcodeMarkerId(markerInfo.idMatrix);
markerType = artoolkit.BARCODE_MARKER;
if (markerInfo.dir !== markerInfo.dirMatrix) {
this.setMarkerInfoDir(i, markerInfo.dirMatrix)
}
}
if (markerType !== artoolkit.UNKNOWN_MARKER && visible.inPrevious) {
this.getTransMatSquareCont(i, visible.markerWidth, visible.matrix, visible.matrix)
} else {
this.getTransMatSquare(i, visible.markerWidth, visible.matrix)
}
visible.inCurrent = true;
this.transMatToGLMat(visible.matrix, this.transform_mat);
this.dispatchEvent({
name: "getMarker",
target: this,
data: {index: i, type: markerType, marker: markerInfo, matrix: this.transform_mat}
})
}
var multiMarkerCount = this.getMultiMarkerCount();
for (var i = 0; i < multiMarkerCount; i++) {
var subMarkerCount = this.getMultiMarkerPatternCount(i);
var visible = false;
artoolkit.getTransMatMultiSquareRobust(this.id, i);
this.transMatToGLMat(this.marker_transform_mat, this.transform_mat);
for (var j = 0; j < subMarkerCount; j++) {
var multiEachMarkerInfo = this.getMultiEachMarker(i, j);
if (multiEachMarkerInfo.visible >= 0) {
visible = true;
this.dispatchEvent({
name: "getMultiMarker",
target: this,
data: {multiMarkerId: i, matrix: this.transform_mat}
});
break
}
}
if (visible) {
for (var j = 0; j < subMarkerCount; j++) {
var multiEachMarkerInfo = this.getMultiEachMarker(i, j);
this.transMatToGLMat(this.marker_transform_mat, this.transform_mat);
this.dispatchEvent({
name: "getMultiMarkerSub",
target: this,
data: {
multiMarkerId: i,
markerIndex: j,
marker: multiEachMarkerInfo,
matrix: this.transform_mat
}
})
}
}
}
if (this._bwpointer) {
this.debugDraw()
}
});
ARController.prototype.trackPatternMarkerId = (function (id, markerWidth) {
var obj = this.patternMarkers[id];
if (!obj) {
this.patternMarkers[id] = obj = {
inPrevious: false,
inCurrent: false,
matrix: new Float32Array(12),
markerWidth: markerWidth || this.defaultMarkerWidth
}
}
if (markerWidth) {
obj.markerWidth = markerWidth
}
return obj
});
ARController.prototype.trackBarcodeMarkerId = (function (id, markerWidth) {
var obj = this.barcodeMarkers[id];
if (!obj) {
this.barcodeMarkers[id] = obj = {
inPrevious: false,
inCurrent: false,
matrix: new Float32Array(12),
markerWidth: markerWidth || this.defaultMarkerWidth
}
}
if (markerWidth) {
obj.markerWidth = markerWidth
}
return obj
});
ARController.prototype.getMultiMarkerCount = (function () {
return artoolkit.getMultiMarkerCount(this.id)
});
ARController.prototype.getMultiMarkerPatternCount = (function (multiMarkerId) {
return artoolkit.getMultiMarkerNum(this.id, multiMarkerId)
});
ARController.prototype.addEventListener = (function (name, callback) {
if (!this.listeners[name]) {
this.listeners[name] = []
}
this.listeners[name].push(callback)
});
ARController.prototype.removeEventListener = (function (name, callback) {
if (this.listeners[name]) {
var index = this.listeners[name].indexOf(callback);
if (index > -1) {
this.listeners[name].splice(index, 1)
}
}
});
ARController.prototype.dispatchEvent = (function (event) {
var listeners = this.listeners[event.name];
if (listeners) {
for (var i = 0; i < listeners.length; i++) {
listeners[i].call(this, event)
}
}
});
ARController.prototype.debugSetup = (function () {
document.body.appendChild(this.canvas);
this.setDebugMode(1);
this._bwpointer = this.getProcessingImage()
});
ARController.prototype.loadMarker = (function (markerURL, onSuccess, onError) {
return artoolkit.addMarker(this.id, markerURL, onSuccess, onError)
});
ARController.prototype.loadMultiMarker = (function (markerURL, onSuccess, onError) {
return artoolkit.addMultiMarker(this.id, markerURL, onSuccess, onError)
});
ARController.prototype.getTransMatSquare = (function (markerIndex, markerWidth, dst) {
artoolkit.getTransMatSquare(this.id, markerIndex, markerWidth);
dst.set(this.marker_transform_mat);
return dst
});
ARController.prototype.getTransMatSquareCont = (funct