From 267788d7fa51baf7770151ca4730f6e7ca2b5ac7 Mon Sep 17 00:00:00 2001 From: Gergely Csucs Date: Wed, 20 Mar 2024 14:42:13 +0100 Subject: [PATCH] Loaders --- configuration.js | 128 ++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 78 deletions(-) diff --git a/configuration.js b/configuration.js index 46fa0cd..65c2fe8 100644 --- a/configuration.js +++ b/configuration.js @@ -1,84 +1,56 @@ -/** - * Demo configuration running from GitHub pages, using remote data - * - * URL parameters are stored in args:
- * * atlas=WHS_SD_Rat_v4_39um
- * * series=https://data-proxy.ebrains.eu/api/v1/public/buckets/localizoom/!Series/visualign.json
- * * pyramids=https://data-proxy.ebrains.eu/api/v1/public/buckets/localizoom - * @type Object - */ +const loaders = { + SeriesLoader: async series_id => fetch(series_id).then(response => response.json()), + DZILoader: () => {}, + TileLoader: () => {}, + AtlasLoader: async atlas_id => fetch(atlas_id + ".json").then(response => response.json()), + AtlasVolumeLoader: async atlas_id => fetch(atlas_id + ".pack").then(response => response.arrayBuffer()) +}; -/** - * Do whatever transformation on the series descriptor to make the work of various locators easier.
- * This demo strips filenames from their extension, this makes DZILocator and - * TileLocator very simple to implement - * @param {type} series - */ async function transformSeries(series) { - for (const slice of series.slices) { - slice.filename = slice.filename.substring(0, slice.filename.lastIndexOf(".")); + /* + * convert extensions to .tif except when directed otherwise: + */ + if (args.pyramids !== "buckets/img-eff39c41-6eaa-4d3f-a91f-ef936e793606" + && args.pyramids !== "buckets/d-d12e41db-78ec-46ac-b3e7-8f22b219f6fb" + && !args.nontiff) { + for (const slice of series.slices) { + const filename = slice.filename; + const pos = filename.lastIndexOf("."); + if (pos >= 0) { + slice.filename = filename.substring(0, pos) + ".tif"; + } + } } /* - * Small hack: the demo series consists of dark images, overlay colors are set to light here. - * This could be an URL parameter too, maybe it becomes one in the future. + * argument-specific loaders */ - document.getElementById("outline").value="#FFFFFF"; - document.getElementById("ancolor").value="#00FFFF"; - document.getElementById("nlcolor").value="#00FFFF"; + if (args.pyramids.startsWith("buckets/")) { + /* + * pyramids in collab bucket + */ + loaders.DZILoader = section_id => + fetch(`https://data-proxy.ebrains.eu/api/v1/${args.pyramids}/${section_id}/${section_id.substring(0, section_id.lastIndexOf("."))}.dzi`).then(response => response.text()); + loaders.TileLoader = async (section_id, level, x, y, format) => { + const img = document.createElement("img"); + await new Promise(resolve => { + img.onload = resolve; + img.src = `https://data-proxy.ebrains.eu/api/v1/${args.pyramids}/${section_id}/${section_id.substring(0, section_id.lastIndexOf("."))}_files/${level}/${x}_${y}.${format}`; + }); + return img; + }; + } else { + /* + * pyramids in legacy image service container + */ + loaders.DZILoader = section_id => + fetch(`https://object.cscs.ch/v1/AUTH_08c08f9f119744cbbf77e216988da3eb/${args.pyramids}/${section_id}/${section_id.substring(0, section_id.lastIndexOf("."))}.dzi`).then(response => response.text()); + loaders.TileLoader = async (section_id, level, x, y, format) => { + const img = document.createElement("img"); + await new Promise(resolve => { + img.onload = resolve; + img.src = `https://object.cscs.ch/v1/AUTH_08c08f9f119744cbbf77e216988da3eb/${args.pyramids}/${section_id}/${section_id.substring(0, section_id.lastIndexOf("."))}_files/${level}/${x}_${y}.${format}`; + }); + return img; + }; + } } - -const loaders = { - /** - * Provide the link of an actual QuickNII/VisuAlign JSON. - *
- * This demo simply passes the complete URL, no transformation is done - * @param {string} series_id series URL parameter - * @returns {string} - */ - SeriesLoader: async series_id => fetch(series_id).then(response => response.json()), - /** - * Provide the link of an actual DZI descriptor. - *
- * This demo uses the pyramids parameter and also makes a shortcut via - * assuming that pyramids reside in a section_id.tif folder. Original - * extension is removed by transformSeries below. - * @param {string} section_id filename field of a section - * @returns {string} - */ - DZILoader: async section_id => fetch(`${args.pyramids}/${section_id}.tif/${section_id}.dzi`).then(response => response.text()), - /** - * Provide the link of an actual image tile. - *
- * This demo uses the pyramids parameter and also makes a shortcut via - * assuming that pyramids reside in a section_id.tif folder. Original - * extension is removed by transformSeries below. - * @param {string} section_id filename field of a section - * @param {type} level pyramid level - * @param {type} x tile coordinates - * @param {type} y tile coordinates - * @param {type} format Format field (from the DZI descriptor, usually "png" or "jpg") - * @returns {string} - */ - TileLoader: async (section_id, level, x, y, format) => { - const img = document.createElement("img"); - await new Promise(resolve => { - img.onload = resolve; - img.src = `${args.pyramids}/${section_id}.tif/${section_id}_files/${level}/${x}_${y}.${format}`; - }); - return img; - }, - /** - * Provide the link of the atlas descriptor, atlas data is often just next to LocaliZoom, - * and appending a .json extension is enough - * @param {type} atlas_id atlas URL parameter - * @returns {string} - */ - AtlasLoader: async atlas_id => fetch(atlas_id + ".json").then(response => response.json()), - /** - * Provide the link of the atlas descriptor, atlas data is often just next to LocaliZoom, - * and appending a .pack extension is enough - * @param {type} atlas_id atlas URL parameter - * @returns {string} - */ - AtlasVolumeLoader: async atlas_id => fetch(atlas_id + ".pack").then(response => response.arrayBuffer()) -};