-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelmerttrans.js
120 lines (114 loc) · 3.78 KB
/
helmerttrans.js
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
"use strict";
/*
* 2024/04/13- (c) [email protected]
*/
document.addEventListener("DOMContentLoaded", function(event) {
main();
});
function main() {
// console.debug("main");
var srcCanvas = document.getElementById("srcCanvas");
var dstCanvas = document.getElementById("dstCanvas");
var srcImage = new Image(srcCanvas.width, srcCanvas.height);
//
var helmertMatrixTable = document.getElementById("helmertMatrixTable");
var helmert = document.getElementById("helmertSelect").value;
var helmertMatrix = helmert2Matrix(helmert, srcCanvas);
var helmertWindow = 3;
var params = {};
//
dropFunction(document, function(dataURL) {
srcImage = new Image();
srcImage.onload = function() {
let maxWidthHeight = params["maxWidthHeightRange"];
drawSrcImage(srcImage, srcCanvas, maxWidthHeight);
drawHelmertTransform(srcCanvas, dstCanvas, helmertMatrix, params, true);
}
srcImage.src = dataURL;
}, "DataURL");
//
bindFunction({"maxWidthHeightRange":"maxWidthHeightText"},
function(target, rel) {
let maxWidthHeight = params["maxWidthHeightRange"];
drawSrcImage(srcImage, srcCanvas, maxWidthHeight);
drawHelmertTransform(srcCanvas, dstCanvas, helmertMatrix, params, rel);
}, params);
bindFunction({"helmertSelect":null, "outfillSelect":null},
function(target, rel) {
let helmert = params["helmertSelect"];
helmertMatrix = helmert2Matrix(helmert, srcCanvas);
drawHelmertTransform(srcCanvas, dstCanvas, helmertMatrix, params, rel);
setTableValues("helmertMatrixTable", helmertMatrix);
}, params);
//
bindTableFunction("helmertMatrixTable", function(table, values, width) {
for (const idx in helmertMatrix) {
if (helmertMatrix[idx] != values[idx]) {
// mapping: { 0:4, 1:3, 3:1, 4:0 }
// | 0 1 2 |
// | 3 4 5 |
if (idx == 0 || idx == 4) {
values[4 - idx] = values[idx];
} else if (idx == 1 || idx == 3) {
values[4 - idx] = - values[idx];
}
}
}
helmertMatrix = values;
setTableValues("helmertMatrixTable", helmertMatrix);
drawHelmertTransform(srcCanvas, dstCanvas, helmertMatrix, params, true);
}, helmertMatrix, helmertWindow);
//
helmert = params["helmertSelect"];
helmertMatrix = helmert2Matrix(helmert, srcCanvas);
}
function helmert2Matrix(helmert, canvas) {
var mat = null;
switch (helmert) {
case "ident":
mat = [1, 0, 0,
0, 1, 0];
break;
case "scale2":
mat = [2, 0, 0,
0, 2, 0];
break;
case "scale0.5":
mat = [0.5, 0, 0,
0, 0.5, 0];
break;
case "rotate45":
var theta = Math.PI / 4;
mat = [Math.cos(theta), -Math.sin(theta), 0,
Math.sin(theta), Math.cos(theta), 0];
mat[2] = - mat[1] * canvas.height; // minX
break;
case "rotate90":
var theta = Math.PI / 2;
mat = [Math.cos(theta), -Math.sin(theta), canvas.height,
Math.sin(theta), Math.cos(theta), 0];
break;
case "rotate180":
var theta = Math.PI / 2 * 2;
mat = [Math.cos(theta), -Math.sin(theta), canvas.width,
Math.sin(theta), Math.cos(theta), canvas.height];
break;
case "rotate270":
var theta = Math.PI / 2 * 3;
mat = [Math.cos(theta), -Math.sin(theta), 0,
Math.sin(theta), Math.cos(theta), canvas.width];
break;
default:
console.error("Invalid helmert:"+helmert);
break;
}
return mat;
};
var worker = new workerProcess("worker/helmerttrans.js");
function drawHelmertTransform(srcCanvas, dstCanvas, helmertMatrix, params, sync) {
var params_w = {
helmertMatrix: helmertMatrix,
outfill : outfillStyleNumber(params["outfillSelect"]),
};
worker.process(srcCanvas, dstCanvas, params_w, sync);
}