-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmvexport.js
More file actions
211 lines (202 loc) · 8.82 KB
/
mvexport.js
File metadata and controls
211 lines (202 loc) · 8.82 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
function meshview() {
allpoi[section_id] = poi;
const wnd = window.open("https://meshview.apps.hbp.eu?atlas=" + (args.atlas.startsWith("WHS") ? "WHS_SD_Rat_v4_39um" : "ABA_Mouse_CCFv3_2017_25um"), "MeshView #" + Date.now());
const color = document.getElementById("ancolor").value.substring(1);
const r = parseInt(color.substring(0, 2), 16);
const g = parseInt(color.substring(2, 4), 16);
const b = parseInt(color.substring(4, 6), 16);
const message = [];
for (const section of filmstrip.getmeta()) {
const pois = allpoi[section.id] || [];
if (pois.length) {
const triplets = processSection(section, pois);
message.push({name: section.id, r, g, b, triplets});
}
}
onmessage = () => {
wnd.postMessage(message, "*");
};
}
function meshview_cb() {
allpoi[section_id] = poi;
const alltriplets = [];
for (const section of filmstrip.getmeta()) {
const pois = allpoi[section.id] || [];
if (pois.length) {
const triplets = processSection(section, pois);
alltriplets.push(...triplets);
}
}
if(alltriplets.length===0){
popover("Nothing to copy.");
return;
}
let message = prompt("Name of cloud?");
if(message===null)
return;
const color = document.getElementById("ancolor").value.substring(1);
const r = parseInt(color.substring(0, 2), 16) / 255;
const g = parseInt(color.substring(2, 4), 16) / 255;
const b = parseInt(color.substring(4, 6), 16) / 255;
message = `#${message}\nRGB ${r} ${g} ${b}\n`;
for(let i=0;i<alltriplets.length;i+=3)
message+=`${alltriplets[i]} ${alltriplets[i+1]} ${alltriplets[i+2]}\n`;
navigator.clipboard.writeText(message)
.then(()=>popover("Data copied to clipboard."))
.catch(ex=>alert(ex));
}
function popover(html){
const p=document.getElementById("popover");
p.innerHTML=html;
p.showPopover();
setTimeout(()=>p.hidePopover(),2000);
}
function processSection(section,pois) {
const vertices = [
[-section.w / 10, -section.h / 10, -section.w / 10, -section.h / 10],
[section.w * 1.1, -section.h / 10, section.w * 1.1, -section.h / 10],
[-section.w / 10, section.h * 1.1, -section.w / 10, section.h * 1.1],
[section.w * 1.1, section.h * 1.1, section.w * 1.1, section.h * 1.1]];
const triangles = [[0, 1, 2], [1, 2, 3]];
// i<j j*(j-1)/2+i
const ix = (i, j) => j * (j - 1) / 2 + i;
const edges = [2, 2, 2, 0, 2, 2];
if (!args.linear && allmarkers[section.id])
for (const marker of allmarkers[section.id]) {
const D = [marker.nx, marker.ny];
let found = false;
const remove = [];
for (let i = 0; i < triangles.length; i++) {
const triangle = triangles[i];
const A = vertices[triangle[0]];
const B = vertices[triangle[1]];
const C = vertices[triangle[2]];
if (!found && intri(A, B, C, D))
found = true;
if (incirc(A, B, C, D))
remove.unshift(i);
}
if (found) {
for (const i of remove) {
const triangle = triangles.splice(i, 1)[0];
const A = triangle[0];
const B = triangle[1];
const C = triangle[2];
edges[ix(A, B)]--;
edges[ix(A, C)]--;
edges[ix(B, C)]--;
}
const es = [];
for (let j = 1; j < vertices.length; j++)
for (let i = 0; i < j; i++)
if (edges[ix(i, j)] === 1) {
triangles.push([i, j, vertices.length]);
es.push([i, j], [i, vertices.length], [j, vertices.length]);
}
for (var e of es)
edges[ix(e[0], e[1])] = 2; //..
vertices.push([marker.nx, marker.ny, marker.x, marker.y]);
}
}
for (const triangle of triangles) {
const A = vertices[triangle[0]];
const B = vertices[triangle[1]];
const C = vertices[triangle[2]];
triangle.push(
Math.min(A[0], B[0], C[0]), //3
Math.max(A[0], B[0], C[0]), //4
Math.min(A[1], B[1], C[1]), //5
Math.max(A[1], B[1], C[1]), //6
inv3x3([//7
[B[0] - A[0], B[1] - A[1], 0],
[C[0] - A[0], C[1] - A[1], 0],
[A[0], A[1], 1]
]));
}
const triplets = [];
for (const poi of pois) {
const x = poi.x;
const y = poi.y;
for (const triangle of triangles)
if (x >= triangle[3] && x <= triangle[4] && y >= triangle[5] && y <= triangle[6]) {
const uv1 = mult([[x, y, 1]], triangle[7])[0];
if (uv1[0] >= 0 && uv1[0] < 1 && uv1[1] >= 0 && uv1[1] < 1 && uv1[0] + uv1[1] <= 1) {
const A = vertices[triangle[0]];
const B = vertices[triangle[1]];
const C = vertices[triangle[2]];
const nx = A[2] + (B[2] - A[2]) * uv1[0] + (C[2] - A[2]) * uv1[1];
const ny = A[3] + (B[3] - A[3]) * uv1[0] + (C[3] - A[3]) * uv1[1];
const x = section.ox + section.ux * nx / section.w + section.vx * ny / section.h;
const y = section.oy + section.uy * nx / section.w + section.vy * ny / section.h;
const z = section.oz + section.uz * nx / section.w + section.vz * ny / section.h;
triplets.push(x, y, z);
break;
}
}
}
return triplets;
}
/*
* Linear-only
*/
//allpoi[section_id] = poi;
//let wnd = window.open("https://meshview.apps.hbp.eu?atlas=" + (args.atlas.startsWith("WHS") ? "WHS_SD_Rat_v4_39um" : "ABA_Mouse_CCFv3_2017_25um"), "MeshView #" + Date.now());
//let color = document.getElementById("ancolor").value.substring(1);
//let r = parseInt(color.substring(0, 2), 16);
//let g = parseInt(color.substring(2, 4), 16);
//let b = parseInt(color.substring(4, 6), 16);
//let message = [];
//for (let section of filmstrip.getmeta()) {
// let markers = allpoi[section.id] || [];
// if (markers.length) {
// let triplets = [];
// for (let marker of markers) {
// let nx = marker.x / section.w;
// let ny = marker.y / section.h;
// let x = section.ox + section.ux * nx + section.vx * ny;
// let y = section.oy + section.uy * nx + section.vy * ny;
// let z = section.oz + section.uz * nx + section.vz * ny;
// triplets.push(x, y, z);
// }
// message.push({name: section.id, r, g, b, triplets});
// }
//}
//onmessage = () => {
// wnd.postMessage(message, "*");
//};
/*
* Very old export winth Copy-Paste coordinate transfer
*/
//var wnd=window.open("about:blank","MeshView #"+Date.now());
//var d = wnd.document;
//d.write("<html><head><title>MeshView export</title><style>textarea{width:100%;height:80%}</style></head><body>");
//d.write("Please copy the coordinates below into <a href='http://www.nesys.uio.no/MeshGen/MeshView.html?bitlas="
// + JSON.parse('{"100000":"ABAMouseHier","200000":"WHSRatV2","300000":"ABAv3-Hier"}')[args.atlas]
// + ".bitlas' target='_blank'>MeshView</a>. Viewer needs Adobe Flash.");
//if (args.atlas === "100000")
// d.write("<br>(Hint: \"Basic cell groups and regions\" is the gray wrapper structure to be switched off)");
//if (args.atlas === "300000")
// d.write("<br>(Hint: \"root\" is the gray wrapper structure to be switched off)");
//d.write("<textarea id='ta'>");
//d.write("RGB 0 0 1\n");
//d.write("SCALE 5\n");
//filmstrip.getmeta().forEach(function (section) {
// var markers = allpoi[section.id] || [];
// if (markers.length) {
// d.write("\n# " + section.name + "\n");
// markers.forEach(function (marker) {
// var nx = marker.x / section.w;
// var ny = marker.y / section.h;
// var x = section.ox + section.ux * nx + section.vx * ny;
// var y = section.oy + section.uy * nx + section.vy * ny;
// var z = section.oz + section.uz * nx + section.vz * ny;
// if (args.atlas === "100000") {
// y -= 528;
// z -= 320;
// }
// d.write(x.toFixed(0) + " " + y.toFixed(0) + " " + z.toFixed(0) + "\n");
// });
// }
//});
//d.write("</textarea></body></html>");
//d.close();