-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
273 lines (219 loc) · 12 KB
/
index.html
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html>
<head>
<title>OpenSeadragon Canvas Overlay Demo</title>
<script src="openseadragon/openseadragon.js"></script>
<script src="openseadragon-threejs-overlay.js"></script>
<script src="js/openseadragon-viewerinputhook.js"></script>
<script src="js/openseadragon-imaginghelper.js"></script>
<script src="js/openseadragon-scalebar.js"></script>
<script src="js/three.js"></script>
<script src="js/wheel.js"></script>
<script src="js/eventify.js"></script>
<script src="js/kinetic.js"></script>
<script src="js/panzoom.js"></script>
<script src="js/stats.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<style type="text/css">
html,
body,
.openseadragon1 {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<script>
// ----------
App = {
// ----------
init: function () {
var self = this;
var tileSource = {
Image: {
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
Url: "http://openseadragon.github.io/example-images/highsmith/highsmith_files/",
Format: "jpg",
Overlap: "2",
TileSize: "256",
Size: {
Height: "9221",
Width: "7026"
}
}
};
this.viewer = OpenSeadragon({
id: "contentDiv",
debugMode: false,
panVertical: false,
panHorizontal: false,
gestureSettingsMouse: { clickToZoom: false, dblClickToZoom: false },
prefixUrl: "openseadragon/images/",
tileSources: /* tileSource */ {
Image: {
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
Url: "/dzi/ccRCC_Slide_files/",
Format: "jpeg",
Overlap: "1",
TileSize: "254",
Size: {
Height: "14305",
Width: "32001"
}
}
},
showReferenceStrip: false,
referenceStripSizeRatio: 0.2,
showNavigator: true
// sequenceMode: false,
// maxZoomPixelRatio: 10
// preserveViewport: true
});
this.viewer.viewport.fitVertically(true);
var overlay = this.viewer.threejsOverlay();
console.log(overlay);
var renderer = overlay.renderer();
var camera = overlay.camera();
var scene = overlay.scene();
var stats = overlay.stats();
// var panZoom = overlay.panZoom();
var geometry, material, index = 0, mesh;
var toggle = true;
setup();
animate();
var imagingHelper = this.viewer.activateImagingHelper({ onImageViewChanged: onImageViewChanged });
function onImageViewChanged(event) {
console.log(event);
let hFar = 2 * Math.tan(camera.fov * Math.PI / 180 / 2) * camera.far; // CHANGED - deg to radians
let wFar = hFar * camera.aspect; // width
camera.position.x = event.eventSource.imgWidth * (event.viewportCenter.x - 0.5);
// camera.position.x = event.viewportCenter.x / Math.abs(event.viewportCenter.x) * event.eventSource.imgWidth * (0.5 - Math.abs(event.viewportCenter.x));
camera.position.y = event.eventSource.imgHeight * (0.5 - event.viewportCenter.y);
// camera.position.y = event.viewportCenter.y / Math.abs(event.viewportCenter.y) * event.eventSource.imgHeight * (0.5 - Math.abs(event.viewportCenter.y));
camera.position.z = (event.viewportHeight / 2) / Math.tan((camera.fov * Math.PI / 180) / 2) * event.eventSource.imgHeight;
// camera.zoom = event.zoomFactor;
// camera.position.x = event.viewportCenter.x * wFar / 2;
// camera.position.y = event.viewportCenter.y * wFar / 2;
// camera.setViewOffset()
camera.updateProjectionMatrix();
console.log(camera.position);
// Far Plane dimensions
// console.log(wFar, hFar);
}
// var viewerInputHook = viewer.addViewerInputHook({ hooks: [...] });
var viewerInputHook = this.viewer.addViewerInputHook({
hooks: [
// { tracker: 'viewer', handler: 'moveHandler', hookHandler: onHookOsdViewerMove },
// { tracker: 'viewer', handler: 'scrollHandler', hookHandler: onHookOsdViewerScroll },
{ tracker: 'viewer', handler: 'keyDownHandler', hookHandler: onHookOsdDownHandler },
{ tracker: 'viewer', handler: 'clickHandler', hookHandler: onHookOsdViewerClick }
]
});
function onHookOsdViewerScroll(event) {
// console.log(event);
let touch = { x: Math.round(event.position.x), y: Math.round(event.position.y) };
// console.log(event.position.x, event.position.y);
let pos = overlay.sceneToWorld(touch.x, touch.y);
camera.position.x += event.scroll * Math.round(pos.x / 100);
camera.position.y += event.scroll * Math.round(pos.y / 100);
camera.updateProjectionMatrix();
console.log(imagingHelper.getZoomFactor());
}
function onHookOsdDownHandler(event) {
console.log(event);
toggle = !toggle;
}
function onHookOsdViewerClick(event) {
console.log(event.position);
if (toggle) {
let touch = { x: Math.round(event.position.x), y: Math.round(event.position.y) };
var pos = overlay.sceneToWorld(touch.x, touch.y);
console.log(pos);
var positions = mesh.geometry.attributes.position.array;
positions[index++] = pos.x;
positions[index++] = pos.y;
positions[index++] = 0;
mesh.geometry.setDrawRange(0, index / 3);
mesh.geometry.computeBoundingSphere();
mesh.geometry.attributes.position.needsUpdate = true; // required after the first render
}
}
$(window).resize(function () {
overlay.resize();
});
function setup() {
let MAX_POINTS = 500000;
// console.log(self.viewer);
let width = self.viewer.container.clientWidth;
let height = self.viewer.container.clientHeight;
console.log(width, height);
/* var geometryPlane = new THREE.PlaneGeometry(5, 20, 32);
var materialPlane = new THREE.MeshBasicMaterial({ color: 0x000000, side: THREE.DoubleSide });
var plane = new THREE.Mesh(geometryPlane, materialPlane);
scene.add(plane); */
geometry = new THREE.BufferGeometry();
var positions = new Float32Array(MAX_POINTS * 3); // 3 vertices per point
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
self.viewer.scalebar({ pixelsPerMeter: 20000000 });
// material
material = new THREE.LineBasicMaterial({ color: 0x000000, linewidth: 2 });
mesh = new THREE.Line(geometry, material);
scene.add(mesh);
/* fetch("ccRCC_Slide_Tumor.json").then((r) => r.json())
.then(function (data) {
// var positions = mesh.geometry.attributes.position.array;
for (var i = 0; i < data.Regions.length; i++) {
// let geometrySub = new THREE.Geometry();
let shape = new THREE.Shape();
var json = data.Regions[i].path[1];
shape.moveTo(json.segments[0][0] - (imagingHelper.imgWidth / 2), (imagingHelper.imgHeight / 2) - json.segments[0][1]);
for (var j = 0; j < json.segments.length; j++) {
shape.lineTo(json.segments[j][0] - (imagingHelper.imgWidth / 2), (imagingHelper.imgHeight / 2) - json.segments[j][1]);
}
shape.lineTo(json.segments[0][0] - (imagingHelper.imgWidth / 2), (imagingHelper.imgHeight / 2) - json.segments[0][1]);
let color = "rgb(" + json.fillColor.map(x => Math.round(x * 100) + "%").join(" ,") + ")";
let materialSub = new THREE.MeshBasicMaterial({ color: new THREE.Color(color), transparent: true, opacity: 0.5 });
let meshSub = new THREE.Mesh(new THREE.ShapeGeometry(shape), materialSub);
meshSub.geometry.computeBoundingSphere();
scene.add(meshSub);
}
mesh.geometry.computeBoundingSphere();
}); */
fetch("ccRCC_Slide_Tumor.json").then((r) => r.json())
.then(function (data) {
// var positions = mesh.geometry.attributes.position.array;
for (var i = 0; i < data.Regions.length; i++) {
// let geometrySub = new THREE.Geometry();
let path = new THREE.Path();
var json = data.Regions[i].path[1].segments;
path.moveTo(json[0][0] - (imagingHelper.imgWidth / 2), (imagingHelper.imgHeight / 2) - json[0][1]);
for (var j = 0; j < json.length; j++) {
path.lineTo(json[j][0] - (imagingHelper.imgWidth / 2), (imagingHelper.imgHeight / 2) - json[j][1]);
}
path.lineTo(json[0][0] - (imagingHelper.imgWidth / 2), (imagingHelper.imgHeight / 2) - json[0][1]);
let points = path.getPoints();
let materialSub = new THREE.LineBasicMaterial({ color: 0x000000, linewidth: 2 });
let meshSub = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(points), materialSub);
meshSub.geometry.computeBoundingSphere();
scene.add(meshSub);
}
mesh.geometry.computeBoundingSphere();
});
}
function animate() {
requestAnimationFrame(animate);
stats.update();
renderer.render(scene, camera);
}
}
};
// ----------
$(document).ready(function () {
App.init();
});
</script>
</head>
<body>
<div id="contentDiv" class="openseadragon1"></div>
</body>
</html>