aboutsummaryrefslogtreecommitdiff
path: root/src/conversion/czi/pyramidWorker.ts
diff options
context:
space:
mode:
authorTom Harley2018-04-23 01:53:39 +0100
committerTom Harley2018-04-23 01:53:39 +0100
commitde38a80b0b69a2655e5a2f30cf207aab63379d69 (patch)
tree9b907384e015ad6751ecc74ab77ceb8d271ff7cf /src/conversion/czi/pyramidWorker.ts
parentFix tests and add handy server scripts (diff)
parentfixing stuff in the csv conversion and adding supported views capability (diff)
downloadmedicine-de38a80b0b69a2655e5a2f30cf207aab63379d69.tar.gz
medicine-de38a80b0b69a2655e5a2f30cf207aab63379d69.zip

Merge branch ‘cjd24/conversion’ into trh/gets

Diffstat (limited to 'src/conversion/czi/pyramidWorker.ts')
-rw-r--r--src/conversion/czi/pyramidWorker.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/conversion/czi/pyramidWorker.ts b/src/conversion/czi/pyramidWorker.ts
new file mode 100644
index 0000000..5e6911c
--- /dev/null
+++ b/src/conversion/czi/pyramidWorker.ts
@@ -0,0 +1,76 @@
+import { CZIHeightMap, CZITile, CZITileRequest } from '../types/customPyramidIndex';
+import { TileBounds, execpaths } from '../types/helpers';
+import * as sharp from 'sharp';
+import { isTileRelated } from './tileExtraction';
+import { uuid } from '../../uuid'
+
+const findRelatedTiles: Function = function(plane: CZIHeightMap, desired: TileBounds): CZITile[][] {
+
+ const relatedTiles: CZITile[][] = [];
+ for (const planeTileRow of plane.plane) {
+ let tileRow: CZITile[] = [];
+ let foundTiles: boolean = false;
+
+ for (const tile of planeTileRow) {
+
+ if (isTileRelated(
+ new TileBounds(
+ tile.x_offset,
+ tile.x_offset + tile.width,
+ tile.y_offset,
+ tile.y_offset + tile.height
+ ), desired)
+ ) {
+ tileRow.push(tile);
+ foundTiles = true;
+ }
+ }
+ if (foundTiles) {
+ relatedTiles.push(tileRow);
+ }
+ }
+ return relatedTiles;
+};
+
+const getFinalTile: Function = async function(imageDir: string, imageTier: CZIHeightMap, cVal: string, desiredRegion: TileBounds): Promise<CZITileRequest> {
+
+ console.error("Has the calling function checked that the image has completed processing in WholeCZIHierarchy??");
+
+ let involvedTiles: string = '';
+ for (const row of imageTier.plane) {
+ for (const tile of row) {
+ involvedTiles += `${imageDir}/data/${tile.file} `
+ }
+ }
+
+ let outputFileName: string =`${imageDir}/tmp/${uuid.generate()}.png`
+ require('shelljs').exec(`${execpaths} vips arrayjoin "${involvedTiles}" ${outputFileName} --across ${imageTier.plane[0].length}`)
+
+ let extractionRegion = new TileBounds(
+ desiredRegion.left - imageTier.plane[0][0].width,
+ desiredRegion.right - imageTier.plane[0][0].width,
+ desiredRegion.top - imageTier.plane[0][0].height,
+ desiredRegion.bottom - imageTier.plane[0][0].height
+ );
+ extractionRegion.scaleDown(imageTier.zoom_level);
+
+ await sharp(outputFileName)
+ .extract({
+ top: extractionRegion.top,
+ left: extractionRegion.left,
+ width: extractionRegion.width(),
+ height: extractionRegion.height()
+ })
+ .toFile(outputFileName);
+
+ return {
+ dimensions: new TileBounds(
+ 0, extractionRegion.width(),
+ 0, extractionRegion.height()
+ ),
+ original_bounds: desiredRegion,
+ zoom_level: imageTier.zoom_level,
+ c_value: cVal,
+ file_path: outputFileName
+ };
+}