Skip to content

Commit

Permalink
FIX pixel spacing in grid tool, now retrieved from larvitar manager (#…
Browse files Browse the repository at this point in the history
…405)

* FIX pixel spacing in grid tool, now retrieved from larvitar manager

* Update docs

* new version

* Update docs

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 25ac493 commit 0af0164
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 19 deletions.
8 changes: 8 additions & 0 deletions dist/imaging/loaders/commonLoader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ export declare const removeSeriesFromLarvitarManager: (seriesId: string) => void
* @return {Object} larvitar manager data
*/
export declare const getSeriesDataFromLarvitarManager: (seriesId: string) => Series | import("../types").NrrdSeries | null;
/**
* Return the metadata of a specific imageId stored in the Larvitar Manager
* @instance
* @function getImageDataFromLarvitarManager
* @param {String} imageId The Id of the image
* @return {MetaData | null} Image metadata
*/
export declare const getImageDataFromLarvitarManager: (imageId: string) => MetaData | null;
/**
* Compute and return image frame
* @instance
Expand Down
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { addDiameterTool, addContoursTool, addMaskEditingTool, getCurrentMaskDat
import { csToolsCreateStack, csToolsUpdateImageIds, csToolsUpdateImageIndex, initializeCSTools, setToolsStyle, addDefaultTools, addTool, setToolActive, setToolDisabled, setToolEnabled, setToolPassive, exportAnnotations } from "./imaging/tools/main";
import { DEFAULT_TOOLS, dvTools, getDefaultToolsByType, setDefaultToolsProps, registerExternalTool } from "./imaging/tools/default";
import { initSegmentationModule, addSegmentationMask, clearSegmentationState, deleteMask, setActiveLabelmap, setActiveSegment, enableBrushTool, disableBrushTool, undoLastStroke, redoLastStroke, setBrushProps, toggleContourMode, toggleVisibility, hexToRgb, rgbToHex, getActiveLabelmapBuffer } from "./imaging/tools/segmentation";
import { updateLarvitarManager, populateLarvitarManager, populateInstanceGSPSDict, getLarvitarManager, getInstanceGSPSDict, getLarvitarImageTracker, resetLarvitarManager, resetInstanceGSPSDict, removeSeriesFromLarvitarManager, getSeriesDataFromLarvitarManager, getImageFrame, getSopInstanceUIDFromLarvitarManager } from "./imaging/loaders/commonLoader";
import { updateLarvitarManager, populateLarvitarManager, populateInstanceGSPSDict, getLarvitarManager, getInstanceGSPSDict, getLarvitarImageTracker, resetLarvitarManager, resetInstanceGSPSDict, removeSeriesFromLarvitarManager, getSeriesDataFromLarvitarManager, getImageDataFromLarvitarManager, getImageFrame, getSopInstanceUIDFromLarvitarManager } from "./imaging/loaders/commonLoader";
import { buildNrrdImage, getNrrdImageId, loadNrrdImage, getImageIdFromSlice, getSliceNumberFromImageId, getNrrdSerieDimensions } from "./imaging/loaders/nrrdLoader";
import { getDicomImageId, cacheImage, cacheImages, loadAndCacheImageStack, loadAndCacheDsaImageStack } from "./imaging/loaders/dicomLoader";
import { loadReslicedImage } from "./imaging/loaders/resliceLoader";
Expand All @@ -37,4 +37,4 @@ import { getColormapsList, applyColorMap, addColorMap, fillPixelData, HSVToRGB }
import { applyDSAShift } from "./imaging/postProcessing/applyDSA";
import { saveAnnotations, loadAnnotations } from "./imaging/tools/io";
import { addMouseKeyHandlers, removeMouseKeyHandlers, toggleMouseToolsListeners } from "./imaging/tools/interaction";
export { VERSION, cornerstone, cornerstoneTools, parseDicom, cornerstoneFileImageLoader, segModule, cornerstoneDICOMImageLoader, checkAndClearMemory, checkMemoryAllocation, getUsedMemory, getAvailableMemory, getPerformanceMonitor, activatePerformanceMonitor, deactivatePerformanceMonitor, store, parseECG, renderECG, unrenderECG, syncECGFrame, updateECGFrame, getDefaultECGLayout, getImagePresets, setImagePreset, setImageCustomPreset, getNormalOrientation, getMinPixelValue, getMaxPixelValue, getPixelRepresentation, getTypedArrayFromDataType, getSortedStack, randomId, getMeanValue, getReslicedMetadata, getReslicedPixeldata, getDistanceBetweenSlices, getImageMetadata, buildHeader, getCachedPixelData, buildData, buildDataAsync, importNRRDImage, exportImageToBase64, exportImageToBase64OriginalSizes, anonymize, customizeByteArray, buildLayer, updateLayer, getActiveLayer, setActiveLayer, initializeImageLoader, initializeWebImageLoader, initializeFileImageLoader, registerNRRDImageLoader, registerResliceLoader, registerMultiFrameImageLoader, registerDsaImageLoader, updateLoadedStack, readFile, readFiles, parseDataSet, clearImageParsing, clearImageCache, loadAndCacheImages, renderFileImage, renderDICOMPDF, renderWebImage, disableViewport, unloadViewport, resizeViewport, renderImage, updateImage, redrawImage, resetViewports, updateViewportData, toggleMouseToolsListeners, storeViewportData, invertImage, flipImageHorizontal, flipImageVertical, rotateImageLeft, rotateImageRight, resliceSeries, getColormapsList, applyColorMap, addColorMap, fillPixelData, HSVToRGB, parseContours, updateLarvitarManager, populateLarvitarManager, populateInstanceGSPSDict, getLarvitarManager, getInstanceGSPSDict, getLarvitarImageTracker, resetLarvitarManager, resetInstanceGSPSDict, removeSeriesFromLarvitarManager, getSeriesDataFromLarvitarManager, getImageFrame, getSopInstanceUIDFromLarvitarManager, buildNrrdImage, getNrrdImageId, loadNrrdImage, getImageIdFromSlice, getSliceNumberFromImageId, getNrrdSerieDimensions, loadReslicedImage, getDicomImageId, cacheImage, cacheImages, loadAndCacheImageStack, loadAndCacheDsaImageStack, loadMultiFrameImage, buildMultiFrameImage, getMultiFrameImageId, clearMultiFrameCache, populateDsaImageIds, getFileManager, resetFileLoader, resetFileManager, populateFileManager, getFileImageId, applyDSAShift, addDiameterTool, addContoursTool, addMaskEditingTool, getCurrentMaskData, addStackStateToElement, addSeedsTool, clearMeasurements, getToolState, clearToolStateByName, updateDiameterTool, addToolStateSingleSlice, clearCornerstoneElements, syncToolStack, updateStackToolState, setSegmentationConfig, csToolsCreateStack, csToolsUpdateImageIds, csToolsUpdateImageIndex, initializeCSTools, setToolsStyle, addDefaultTools, addTool, setToolActive, setToolDisabled, setToolEnabled, setToolPassive, exportAnnotations, DEFAULT_TOOLS, dvTools, getDefaultToolsByType, setDefaultToolsProps, registerExternalTool, saveAnnotations, loadAnnotations, addMouseKeyHandlers, removeMouseKeyHandlers, initSegmentationModule, addSegmentationMask, setActiveLabelmap, setActiveSegment, undoLastStroke, redoLastStroke, setBrushProps, hexToRgb, rgbToHex, clearSegmentationState, deleteMask, enableBrushTool, disableBrushTool, toggleContourMode, toggleVisibility, getActiveLabelmapBuffer, updateTemporalViewportData };
export { VERSION, cornerstone, cornerstoneTools, parseDicom, cornerstoneFileImageLoader, segModule, cornerstoneDICOMImageLoader, checkAndClearMemory, checkMemoryAllocation, getUsedMemory, getAvailableMemory, getPerformanceMonitor, activatePerformanceMonitor, deactivatePerformanceMonitor, store, parseECG, renderECG, unrenderECG, syncECGFrame, updateECGFrame, getDefaultECGLayout, getImagePresets, setImagePreset, setImageCustomPreset, getNormalOrientation, getMinPixelValue, getMaxPixelValue, getPixelRepresentation, getTypedArrayFromDataType, getSortedStack, randomId, getMeanValue, getReslicedMetadata, getReslicedPixeldata, getDistanceBetweenSlices, getImageMetadata, buildHeader, getCachedPixelData, buildData, buildDataAsync, importNRRDImage, exportImageToBase64, exportImageToBase64OriginalSizes, anonymize, customizeByteArray, buildLayer, updateLayer, getActiveLayer, setActiveLayer, initializeImageLoader, initializeWebImageLoader, initializeFileImageLoader, registerNRRDImageLoader, registerResliceLoader, registerMultiFrameImageLoader, registerDsaImageLoader, updateLoadedStack, readFile, readFiles, parseDataSet, clearImageParsing, clearImageCache, loadAndCacheImages, renderFileImage, renderDICOMPDF, renderWebImage, disableViewport, unloadViewport, resizeViewport, renderImage, updateImage, redrawImage, resetViewports, updateViewportData, toggleMouseToolsListeners, storeViewportData, invertImage, flipImageHorizontal, flipImageVertical, rotateImageLeft, rotateImageRight, resliceSeries, getColormapsList, applyColorMap, addColorMap, fillPixelData, HSVToRGB, parseContours, updateLarvitarManager, populateLarvitarManager, populateInstanceGSPSDict, getLarvitarManager, getInstanceGSPSDict, getLarvitarImageTracker, resetLarvitarManager, resetInstanceGSPSDict, removeSeriesFromLarvitarManager, getSeriesDataFromLarvitarManager, getImageDataFromLarvitarManager, getImageFrame, getSopInstanceUIDFromLarvitarManager, buildNrrdImage, getNrrdImageId, loadNrrdImage, getImageIdFromSlice, getSliceNumberFromImageId, getNrrdSerieDimensions, loadReslicedImage, getDicomImageId, cacheImage, cacheImages, loadAndCacheImageStack, loadAndCacheDsaImageStack, loadMultiFrameImage, buildMultiFrameImage, getMultiFrameImageId, clearMultiFrameCache, populateDsaImageIds, getFileManager, resetFileLoader, resetFileManager, populateFileManager, getFileImageId, applyDSAShift, addDiameterTool, addContoursTool, addMaskEditingTool, getCurrentMaskData, addStackStateToElement, addSeedsTool, clearMeasurements, getToolState, clearToolStateByName, updateDiameterTool, addToolStateSingleSlice, clearCornerstoneElements, syncToolStack, updateStackToolState, setSegmentationConfig, csToolsCreateStack, csToolsUpdateImageIds, csToolsUpdateImageIndex, initializeCSTools, setToolsStyle, addDefaultTools, addTool, setToolActive, setToolDisabled, setToolEnabled, setToolPassive, exportAnnotations, DEFAULT_TOOLS, dvTools, getDefaultToolsByType, setDefaultToolsProps, registerExternalTool, saveAnnotations, loadAnnotations, addMouseKeyHandlers, removeMouseKeyHandlers, initSegmentationModule, addSegmentationMask, setActiveLabelmap, setActiveSegment, undoLastStroke, redoLastStroke, setBrushProps, hexToRgb, rgbToHex, clearSegmentationState, deleteMask, enableBrushTool, disableBrushTool, toggleContourMode, toggleVisibility, getActiveLabelmapBuffer, updateTemporalViewportData };
2 changes: 1 addition & 1 deletion dist/larvitar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/larvitar.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/larvitar.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions imaging/loaders/commonLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,25 @@ export const getSeriesDataFromLarvitarManager = function (seriesId: string) {
return larvitarManager ? larvitarManager[seriesId] : null;
};

/**
* Return the metadata of a specific imageId stored in the Larvitar Manager
* @instance
* @function getImageDataFromLarvitarManager
* @param {String} imageId The Id of the image
* @return {MetaData | null} Image metadata
*/
export const getImageDataFromLarvitarManager = function (imageId: string) {
if (larvitarManager) {
for (const [seriesId, seriesObj] of Object.entries(larvitarManager)) {
if (seriesObj.imageIds && seriesObj.imageIds.includes(imageId)) {
const imageData = seriesObj.instances[imageId].metadata;
return imageData;
}
}
}
return null;
};

/**
* Compute and return image frame
* @instance
Expand Down
24 changes: 11 additions & 13 deletions imaging/tools/custom/gridTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { handleElement } from "./utils/gridToolUtils/gridToolUtils";
import { Coords, GridConfig, MeasurementMouseEvent } from "../types";
import { DEFAULT_TOOLS } from "../default";
import { getImageDataFromLarvitarManager } from "../../loaders/commonLoader";

/**
* @public
Expand Down Expand Up @@ -148,15 +149,12 @@ export class GridTool extends BaseTool {
if (newSetup) this.configuration.setup = newSetup;

const image = enabledElement.image as Image;
const pixelSpacing = {
x: image.columnPixelSpacing,
y: image.rowPixelSpacing
};

const imageMetadata = getImageDataFromLarvitarManager(image.imageId);
const pixelSpacing = imageMetadata!.pixelSpacing!;
try {
validatePixelSpacing(
pixelSpacing.x,
pixelSpacing.y,
pixelSpacing[0],
pixelSpacing[1],
this.configuration.setup.minPixelSpacing
);
} catch (error: any) {
Expand All @@ -178,11 +176,11 @@ export class GridTool extends BaseTool {
);

let patternHeight = this.configuration.setup.gridDimensionMM
? mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing.y)
: mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing.y);
? mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing[1])
: mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing[1]);
let patternWidth = this.configuration.setup.gridDimensionMM
? mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing.x)
: mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing.x);
? mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing[0])
: mmToPixels(this.configuration.setup.gridDimensionMM, pixelSpacing[0]);
const patternCanvasDimensions = convertDimensionsToCanvas(
element,
patternWidth,
Expand All @@ -192,11 +190,11 @@ export class GridTool extends BaseTool {
//dash dimension
let dashHeight = mmToPixels(
this.configuration.setup.dashHeightMM,
pixelSpacing.y
pixelSpacing[1]
);
let dashWidth = mmToPixels(
this.configuration.setup.dashWidthMM,
pixelSpacing.x
pixelSpacing[0]
);
const dashCanvasDimensions = convertDimensionsToCanvas(
element,
Expand Down
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ import {
resetInstanceGSPSDict,
removeSeriesFromLarvitarManager,
getSeriesDataFromLarvitarManager,
getImageDataFromLarvitarManager,
getImageFrame,
getSopInstanceUIDFromLarvitarManager
} from "./imaging/loaders/commonLoader";
Expand Down Expand Up @@ -375,6 +376,7 @@ export {
resetInstanceGSPSDict,
removeSeriesFromLarvitarManager,
getSeriesDataFromLarvitarManager,
getImageDataFromLarvitarManager,
getImageFrame,
getSopInstanceUIDFromLarvitarManager,
// loaders/nrrdLoader
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"medical",
"cornerstone"
],
"version": "2.6.2-beta.0",
"version": "2.6.2-beta.1",
"description": "typescript library for parsing, loading, rendering and interacting with DICOM images",
"repository": {
"url": "https://github.com/dvisionlab/Larvitar.git",
Expand Down

0 comments on commit 0af0164

Please sign in to comment.