-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate TIFF access into vitessce-image-viewer and Improve Metadata…
… Caching (#31)
- Loading branch information
Showing
11 changed files
with
238 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import loadZarr from './zarr-utils'; | ||
import {loadZarr, getZarrConnections} from './zarr-utils'; | ||
import {loadTiff, getTiffConnections} from './tiff-utils'; | ||
|
||
export {loadZarr} | ||
export {loadZarr, loadTiff, getTiffConnections, getZarrConnections} |
46 changes: 46 additions & 0 deletions
46
src/layers/microscopy-viewer-layer/data-utils/tiff-utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {fromUrl, Pool, getDecoder } from 'geotiff/dist/geotiff.bundle.min.js'; | ||
|
||
async function loadTile({image, channel, x, y, pool}) { | ||
var tile = await image.getTileOrStrip(x,y, 0, pool) | ||
var dataObj = {} | ||
const is8Bits = image.fileDirectory.BitsPerSample[0]===8 | ||
const is16Bits = image.fileDirectory.BitsPerSample[0]===16 | ||
const is32Bits = image.fileDirectory.BitsPerSample[0]===32 | ||
dataObj[channel] = (is8Bits && new Uint8Array(tile.data)) || | ||
(is16Bits && new Uint16Array(tile.data)) || | ||
(is32Bits && new Uint32Array(tile.data)) | ||
return dataObj | ||
} | ||
|
||
export function loadTiff({connections, x, y, z, pool}){ | ||
const configListPromises = Object.keys(connections).map((channel) => { | ||
var image = connections[channel][z] | ||
return loadTile({image, channel, x, y, pool}) | ||
}) | ||
return Promise.all(configListPromises).then((dataList) => { | ||
const orderedList = [] | ||
const dataObj = Object.assign({}, ...dataList) | ||
Object.keys(dataObj).sort().forEach((key) => { | ||
orderedList.push(dataObj[key]); | ||
}) | ||
return orderedList; | ||
}); | ||
} | ||
|
||
export function getTiffConnections({sourceChannels, maxZoom}){ | ||
const tiffConnections = Object.keys(sourceChannels).map(async (channel) => { | ||
var tiff = await fromUrl(sourceChannels[channel]) | ||
var imageObj = {} | ||
for(var i = 0; i < -maxZoom; i++) { | ||
var image = await tiff.getImage(i) | ||
if(!imageObj[channel]) { | ||
imageObj[channel] = [image] | ||
} else { | ||
imageObj[channel].push(image) | ||
} | ||
|
||
} | ||
return imageObj | ||
}) | ||
return Promise.all(tiffConnections) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/layers/microscopy-viewer-layer/microscopy-viewer-layer-base.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import {BaseTileLayer} from '@deck.gl/layers'; | ||
import {Texture2D} from '@luma.gl/webgl' | ||
import GL from '@luma.gl/constants'; | ||
import { COORDINATE_SYSTEM } from 'deck.gl'; | ||
import { XRLayer } from '../xr-layer'; | ||
import {tileToBoundingBox} from './tiling-utils'; | ||
import {getTileIndices} from './tiling-utils'; | ||
import { loadZarr, loadTiff } from './data-utils'; | ||
|
||
const defaultProps = Object.assign({}, BaseTileLayer.defaultProps, { | ||
id: `microscopy-tile-layer`, | ||
pickable: false, | ||
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, | ||
maxZoom: 0, | ||
onViewportLoad: false, | ||
renderSubLayers: (props) => { | ||
const { | ||
bbox: { | ||
west, south, east, north, | ||
}, | ||
} = props.tile; | ||
const { sliderValues, data, colorValues } = props; | ||
const xrl = new XRLayer(props, { | ||
id: `XR-Layer-${west}-${south}-${east}-${north}`, | ||
pickable: false, | ||
coordinateSystem: COORDINATE_SYSTEM.CARTESIAN, | ||
rgbData: data, | ||
sliderValues, | ||
colorValues, | ||
bounds: [west, south, east, north], | ||
visible: true, | ||
}); | ||
return xrl; | ||
}, | ||
}); | ||
|
||
export class MicroscopyViewerLayerBase extends BaseTileLayer { | ||
|
||
constructor(props) { | ||
const minZoom = Math.floor(-1 * Math.log2(Math.max(props.imageHeight, props.imageWidth))); | ||
const {sliderValues, colorValues} = props | ||
var orderedSliderValues = [] | ||
var orderedColorValues = [] | ||
Object.keys(sliderValues).sort().forEach(function(key) { | ||
orderedSliderValues.push(sliderValues[key]); | ||
}) | ||
Object.keys(colorValues).sort().forEach(function(key) { | ||
orderedColorValues.push(colorValues[key]); | ||
}) | ||
var diff = 6 - orderedSliderValues.length | ||
for (var i = 0; i < diff; i++) { | ||
orderedSliderValues.push(65535); | ||
} | ||
var diff = 6 - orderedColorValues.length | ||
for (var j = 0; j < diff; j++) { | ||
orderedColorValues.push([0,0,0]); | ||
} | ||
orderedColorValues = orderedColorValues.map(color => color.map(ch => ch / 255)) | ||
const getZarr = ({ x, y, z }) => { | ||
return loadZarr({ | ||
x, y, z: -1 * z, ...props, | ||
}); | ||
} | ||
const getTiff = ({ x, y, z }) => { | ||
return loadTiff({ | ||
x, y, z: -1 * z, ...props, | ||
}); | ||
} | ||
const getTileData = (props.useZarr && getZarr) || | ||
(props.useTiff && getTiff) || | ||
props.getTileData | ||
const overrideValuesProps = Object.assign( | ||
{}, props, { | ||
sliderValues: orderedSliderValues, | ||
colorValues: orderedColorValues, | ||
minZoom, | ||
getTileData, | ||
getTileIndices: (viewport, maxZoom, minZoom) => { | ||
return getTileIndices({ | ||
viewport, maxZoom, minZoom, ...props, | ||
}); | ||
}, | ||
tileToBoundingBox: (x, y, z) => { | ||
return tileToBoundingBox({ | ||
x, y, z, ...props, | ||
}); | ||
}, | ||
} | ||
) | ||
const layerProps = Object.assign({}, defaultProps, overrideValuesProps) | ||
super(layerProps) | ||
} | ||
|
||
} | ||
|
||
MicroscopyViewerLayerBase.layerName = 'MicroscopyViewerLayerBase'; | ||
MicroscopyViewerLayerBase.defaultProps = defaultProps; |
Oops, something went wrong.