Skip to content

Commit b354c56

Browse files
author
Pavol Klacansky
committed
Allow only one preview in flight
1 parent e590f9d commit b354c56

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ New dataset is added by following these steps:
3535
- Value range (or show example how to use Python to compute them)
3636
- Histogram (Python sample to compute them?)
3737
- Volume rendering (https://arxiv.org/abs/2406.15634)
38-
- If one preview is being downloaded and the user selects another preview, it may show the old preview (it will also jump the % progress display between the two)
3938
- render multiple surfaces (+ opacity)?
4039
- improve quality of previews (rendering)
4140
- render continuously instead of firing on events. Should make it smoother. (what about battery life?)

data/header.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@
222222
let viewer
223223
let extent
224224

225+
// Monotonically increasing counter that uniquely identifies the currently opened preview.
226+
// Previews being loaded with counter that is not equal to previewCounter are cancelled.
227+
let previewCounter = 0;
228+
225229

226230
function
227231
loadDataset(elem, name, width, height, depth, previewFileSize, previewWidth, previewHeight, previewDepth, boxWidth, boxHeight, boxDepth)
@@ -274,7 +278,9 @@
274278
viewer = new Viewer(viewerElement.querySelector('canvas'))
275279
}
276280

277-
const previewPrecision = 8
281+
previewCounter++;
282+
const thisPreviewCounter = previewCounter;
283+
278284
const previewUrl = `${name}/preview_${name}_${previewWidth}x${previewHeight}x${previewDepth}_float32.raw`
279285
fetch(previewUrl)
280286
.then(response => {
@@ -290,8 +296,13 @@
290296

291297
// stream the data into an array in chunks to allow for progress bar
292298
return reader.read().then(function processChunk(result) {
299+
if (thisPreviewCounter !== previewCounter) {
300+
reader.cancel()
301+
return null;
302+
}
303+
293304
if (result.done) {
294-
progress.textContent = `Downloading preview (100%)`
305+
progressElement.textContent = `Downloading preview (100%)`
295306
return array.buffer
296307
}
297308

@@ -304,6 +315,10 @@
304315
return reader.read().then(processChunk)
305316
})
306317
}).then(data => {
318+
if (data === null) {
319+
return;
320+
}
321+
307322
const array = new Float32Array(data);
308323
viewer.uploadData(array, previewWidth, previewHeight, previewDepth, boxWidth, boxHeight, boxDepth)
309324
viewer.isovalue(iso_select.value)

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ func wrapHandler(h http.Handler) http.HandlerFunc {
3434

3535
func main() {
3636
http.ListenAndServeTLS(":443", "fullchain.pem", "privkey.pem", wrapHandler(http.FileServer(http.Dir("./static"))))
37-
//log.Fatal(http.ListenAndServe(":8000", wrapHandler(http.FileServer(http.Dir("./static")))))
37+
//http.ListenAndServe(":8000", wrapHandler(http.FileServer(http.Dir("./static"))))
3838
}

0 commit comments

Comments
 (0)