-
Notifications
You must be signed in to change notification settings - Fork 386
fix CircleROI tool for wsi #1940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
b9c9f50
ca3fdb8
3c6e74a
0356835
c6db595
f8b94a0
64a7b95
7f07ac4
bebdbd6
9f286a5
57c88c5
63336f6
5ded038
99f2d2b
048f9dd
00bf564
65d8149
b8fb6b2
73a6d4b
6d21c80
88b5bfd
613279f
5fb2331
1fb803a
474fb89
cd18632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import type { | |
ViewportInput, | ||
BoundsIJK, | ||
CPUImageData, | ||
PixelDataTypedArray, | ||
} from '../types'; | ||
import uuidv4 from '../utilities/uuidv4'; | ||
import * as metaData from '../metaData'; | ||
|
@@ -228,8 +229,11 @@ class WSIViewport extends Viewport { | |
this.setProperties({}); | ||
} | ||
|
||
protected getScalarData() { | ||
return null; | ||
public getScalarData() { | ||
const scalarData = null as PixelDataTypedArray; | ||
//scalarData.length = 0; | ||
//scarlarData = []; | ||
return scalarData; | ||
} | ||
|
||
public getImageData(): CPUIImageData { | ||
|
@@ -272,7 +276,7 @@ class WSIViewport extends Viewport { | |
preScale: { | ||
scaled: false, | ||
}, | ||
scalarData: this.getScalarData(), | ||
scalarData: null, | ||
imageData, | ||
// It is for the annotations to work, since all of them work on voxelManager and not on scalarData now | ||
voxelManager: { | ||
|
@@ -615,12 +619,18 @@ class WSIViewport extends Viewport { | |
protected canvasToIndex = (canvasPos: Point2): Point2 => { | ||
const transform = this.getTransform(); | ||
transform.invert(); | ||
return transform.transformPoint(canvasPos); | ||
return transform.transformPoint( | ||
canvasPos.map((it) => it * devicePixelRatio) as Point2 | ||
); | ||
// return transform.transformPoint(canvasPos); | ||
}; | ||
|
||
protected indexToCanvas = (indexPos: Point2): Point2 => { | ||
const transform = this.getTransform(); | ||
return transform.transformPoint(indexPos); | ||
return transform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will need to convert back to negative values, so if you on initial setup store an index of which values are negative and multiple by that vector you should get the right sign. |
||
.transformPoint(indexPos) | ||
.map((it) => it / devicePixelRatio) as Point2; | ||
// return transform.transformPoint(indexPos); | ||
}; | ||
|
||
/** This can be implemented later when multi-slice WSI is supported */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -982,19 +982,20 @@ class CircleROITool extends AnnotationTool { | |
pixelUnitsOptions | ||
); | ||
|
||
const pointsInShape = voxelManager.forEach( | ||
this.configuration.statsCalculator.statsCallback, | ||
{ | ||
isInObject: (pointLPS) => | ||
pointInEllipse(ellipseObj, pointLPS, { fast: true }), | ||
boundsIJK, | ||
imageData, | ||
returnPoints: this.configuration.storePointData, | ||
} | ||
); | ||
|
||
let pointsInShape; | ||
if (imageData.getScalarData() !== null) { | ||
pointsInShape = voxelManager.forEach( | ||
this.configuration.statsCalculator.statsCallback, | ||
{ | ||
isInObject: (pointLPS) => | ||
pointInEllipse(ellipseObj, pointLPS, { fast: true }), | ||
boundsIJK, | ||
imageData, | ||
returnPoints: this.configuration.storePointData, | ||
} | ||
); | ||
} | ||
const stats = this.configuration.statsCalculator.getStatistics(); | ||
|
||
cachedStats[targetId] = { | ||
Modality: metadata.Modality, | ||
area, | ||
|
@@ -1028,6 +1029,14 @@ class CircleROITool extends AnnotationTool { | |
}; | ||
|
||
_isInsideVolume = (index1, index2, dimensions) => { | ||
// for wsiViewport | ||
if (index1[1] < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you put this fix into the WSIViewport itself? |
||
index1[1] = -index1[1]; | ||
} | ||
if (index2[1] < 0) { | ||
index2[1] = -index2[1]; | ||
Comment on lines
+1033
to
+1038
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look good. Could you please check if the viewport type is WSI before proceeding? I imagine this might disrupt other types of viewports. |
||
} | ||
|
||
return ( | ||
csUtils.indexWithinDimensions(index1, dimensions) && | ||
csUtils.indexWithinDimensions(index2, dimensions) | ||
|
@@ -1135,7 +1144,7 @@ function defaultGetTextLines(data, targetId): string[] { | |
textLines.push(`Mean: ${csUtils.roundNumber(mean)} ${modalityUnit}`); | ||
} | ||
|
||
if (max) { | ||
if (max && isFinite(max)) { | ||
textLines.push(`Max: ${csUtils.roundNumber(max)} ${modalityUnit}`); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -930,16 +930,18 @@ class RectangleROITool extends AnnotationTool { | |
pixelUnitsOptions | ||
); | ||
|
||
const pointsInShape = voxelManager.forEach( | ||
this.configuration.statsCalculator.statsCallback, | ||
{ | ||
boundsIJK, | ||
imageData, | ||
returnPoints: this.configuration.storePointData, | ||
} | ||
); | ||
let pointsInShape; | ||
if (imageData.getScalarData() !== null) { | ||
pointsInShape = voxelManager.forEach( | ||
this.configuration.statsCalculator.statsCallback, | ||
{ | ||
boundsIJK, | ||
imageData, | ||
returnPoints: this.configuration.storePointData, | ||
} | ||
); | ||
} | ||
const stats = this.configuration.statsCalculator.getStatistics(); | ||
|
||
cachedStats[targetId] = { | ||
Modality: metadata.Modality, | ||
area, | ||
|
@@ -968,6 +970,14 @@ class RectangleROITool extends AnnotationTool { | |
}; | ||
|
||
_isInsideVolume = (index1, index2, dimensions) => { | ||
// for wsiViewport | ||
if (index1[1] < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look good. Could you please check if the viewport type is WSI before proceeding? I imagine this might disrupt other types of viewports. |
||
index1[1] = -index1[1]; | ||
} | ||
if (index2[1] < 0) { | ||
index2[1] = -index2[1]; | ||
} | ||
|
||
return ( | ||
csUtils.indexWithinDimensions(index1, dimensions) && | ||
csUtils.indexWithinDimensions(index2, dimensions) | ||
|
@@ -1048,12 +1058,16 @@ function defaultGetTextLines(data, targetId: string): string[] { | |
} | ||
|
||
const textLines: string[] = []; | ||
|
||
textLines.push(`Area: ${csUtils.roundNumber(area)} ${areaUnit}`); | ||
textLines.push(`Mean: ${csUtils.roundNumber(mean)} ${modalityUnit}`); | ||
textLines.push(`Max: ${csUtils.roundNumber(max)} ${modalityUnit}`); | ||
textLines.push(`Std Dev: ${csUtils.roundNumber(stdDev)} ${modalityUnit}`); | ||
|
||
if (isFinite(mean) && !isNaN(mean)) { | ||
textLines.push(`Mean: ${csUtils.roundNumber(mean)} ${modalityUnit}`); | ||
} | ||
if (isFinite(max) && !isNaN(max)) { | ||
textLines.push(`Max: ${csUtils.roundNumber(max)} ${modalityUnit}`); | ||
} | ||
if (isFinite(stdDev) && !isNaN(stdDev)) { | ||
textLines.push(`Std Dev: ${csUtils.roundNumber(stdDev)} ${modalityUnit}`); | ||
} | ||
return textLines; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use Math.abs on the result here - I think that will get us close to the right value, or on initial setup, figure out which attribute is negative and store a negative multiplier for it.