-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #882 from cornerstonejs/fix-bidirectional-sync
feat(BidirectionalTool): Update tool data on every modified event of …
- Loading branch information
Showing
26 changed files
with
200 additions
and
59 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
47 changes: 47 additions & 0 deletions
47
src/tools/annotation/bidirectionalTool/utils/calculateLongestAndShortestDiameters.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,47 @@ | ||
/** | ||
* Calculates longest and shortest diameters using measurement handles and pixelSpacing | ||
* @param {Object} eventData | ||
* @param {Object} measurementData | ||
* @returns {void} | ||
*/ | ||
export default function calculateLongestAndShortestDiameters( | ||
eventData, | ||
measurementData | ||
) { | ||
const { rowPixelSpacing, columnPixelSpacing } = eventData.image; | ||
const { | ||
start, | ||
end, | ||
perpendicularStart, | ||
perpendicularEnd, | ||
} = measurementData.handles; | ||
|
||
// Calculate the long axis length | ||
const dx = (start.x - end.x) * (columnPixelSpacing || 1); | ||
const dy = (start.y - end.y) * (rowPixelSpacing || 1); | ||
let length = Math.sqrt(dx * dx + dy * dy); | ||
|
||
// Calculate the short axis length | ||
const wx = | ||
(perpendicularStart.x - perpendicularEnd.x) * (columnPixelSpacing || 1); | ||
const wy = | ||
(perpendicularStart.y - perpendicularEnd.y) * (rowPixelSpacing || 1); | ||
let width = Math.sqrt(wx * wx + wy * wy); | ||
|
||
if (!width) { | ||
width = 0; | ||
} | ||
|
||
// Length is always longer than width | ||
if (width > length) { | ||
const tempW = width; | ||
const tempL = length; | ||
|
||
length = tempW; | ||
width = tempL; | ||
} | ||
|
||
// Set measurement text to show lesion table | ||
measurementData.longestDiameter = length.toFixed(1); | ||
measurementData.shortestDiameter = width.toFixed(1); | ||
} |
111 changes: 111 additions & 0 deletions
111
src/tools/annotation/bidirectionalTool/utils/calculateLongestAndShortestDiameters.test.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,111 @@ | ||
import calculateLongestAndShortestDiameters from './calculateLongestAndShortestDiameters.js'; | ||
|
||
let measurementData = {}; | ||
let eventData = {}; | ||
|
||
describe('CalculateLongestAndShortestDiameters.js', () => { | ||
beforeEach(() => { | ||
console.error = jest.fn(); | ||
console.error.mockClear(); | ||
console.warn = jest.fn(); | ||
console.warn.mockClear(); | ||
|
||
measurementData = { | ||
handles: { | ||
start: { | ||
x: 290.6229508196721, | ||
y: 272.7868852459016, | ||
}, | ||
end: { | ||
x: 361.96721311475403, | ||
y: 191.99999999999997, | ||
}, | ||
perpendicularStart: { | ||
x: 346.49180327868845, | ||
y: 250.22950819672127, | ||
}, | ||
perpendicularEnd: { | ||
x: 306.0983606557376, | ||
y: 214.55737704918027, | ||
}, | ||
}, | ||
}; | ||
eventData = { | ||
image: {}, | ||
}; | ||
}); | ||
|
||
it('should calculates long/short diameters', () => { | ||
eventData = { | ||
image: { | ||
rowPixelSpacing: 0.876953125, | ||
columnPixelSpacing: 0.876953125, | ||
}, | ||
}; | ||
|
||
calculateLongestAndShortestDiameters(eventData, measurementData); | ||
|
||
expect(measurementData.longestDiameter).toEqual('94.5'); | ||
expect(measurementData.shortestDiameter).toEqual('47.3'); | ||
}); | ||
|
||
it('should return values with scale of 1', () => { | ||
calculateLongestAndShortestDiameters(eventData, measurementData); | ||
|
||
expect(measurementData.shortestDiameter).toMatch(/\d*\.\d$/); | ||
expect(measurementData.longestDiameter).toMatch(/\d*\.\d$/); | ||
}); | ||
|
||
it('should use a default pixelSpacing of 1 when pixelSpacing is undefined', () => { | ||
calculateLongestAndShortestDiameters(eventData, measurementData); | ||
|
||
expect(measurementData.longestDiameter).toEqual('107.8'); | ||
expect(measurementData.shortestDiameter).toEqual('53.9'); | ||
}); | ||
|
||
it('should get longest and shortest diameters defined even with undefined handles', () => { | ||
measurementData.handles = { | ||
start: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
end: { | ||
x: 4, | ||
y: 4, | ||
}, | ||
perpendicularStart: {}, | ||
perpendicularEnd: {}, | ||
}; | ||
|
||
calculateLongestAndShortestDiameters(eventData, measurementData); | ||
|
||
expect(measurementData.shortestDiameter).toEqual('0.0'); | ||
expect(measurementData.longestDiameter).toEqual('5.7'); | ||
}); | ||
|
||
it('should make shortestDiameter always small than longestDiameter', () => { | ||
measurementData.handles = { | ||
start: { | ||
x: 10, | ||
y: 10, | ||
}, | ||
end: { | ||
x: 5, | ||
y: 5, | ||
}, | ||
perpendicularStart: { | ||
x: 12, | ||
y: 12, | ||
}, | ||
perpendicularEnd: { | ||
x: 5, | ||
y: 5, | ||
}, | ||
}; | ||
|
||
calculateLongestAndShortestDiameters(eventData, measurementData); | ||
|
||
expect(measurementData.shortestDiameter).toEqual('7.1'); | ||
expect(measurementData.longestDiameter).toEqual('9.9'); | ||
}); | ||
}); |