Skip to content

Commit

Permalink
Support adding roi measurements and evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
hackermd committed Nov 29, 2020
1 parent 1ead560 commit 8ca5d86
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 48 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dicom-microscopy-viewer",
"version": "0.20.1",
"version": "0.21.0",
"description": "Interactive web-based viewer for DICOM Microscopy Images",
"main": "build/dicom-microscopy-viewer.js",
"scripts": {
Expand Down
59 changes: 55 additions & 4 deletions src/roi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const _uid = Symbol('uid');
const _scoord3d = Symbol('scoord3d');
const _properties = Symbol('properties');

const _name = Symbol('name');
const _value = Symbol('value');


/** A region of interest (ROI)
*
* @class
Expand All @@ -16,7 +20,7 @@ class ROI {
* @param {Object} options - Options for construction of ROI
* @param {Scoord3D} options.scoord3d - Spatial 3D coordinates
* @param {string} options.uid - Unique idenfifier
* @param {Object} options.properties - Qualititative evaluations
* @param {Object} options.properties - Properties (name-value pairs)
*/
constructor(options) {
if (!('scoord3d' in options)) {
Expand All @@ -34,8 +38,23 @@ class ROI {
this[_uid] = options.uid;
}
this[_scoord3d] = options.scoord3d;
this[_properties] = options.properties;
// TODO: store SOPInstanceUID, SOPClassUID and FrameNumbers as reference
if ('properties' in options) {
if (!(typeof(options.properties) === 'object')) {
throw new Error('properties of ROI must be an object')
}
this[_properties] = options.properties;
if (this[_properties].evaluations === undefined) {
this[_properties]['evaluations'] = []
}
if (this[_properties].measurements === undefined) {
this[_properties]['measurements'] = []
}
} else {
this[_properties] = {};
this[_properties]['evaluations'] = []
this[_properties]['measurements'] = []
}
console.log(this[_properties])
}

/** Gets unique identifier of region of interest.
Expand All @@ -62,6 +81,38 @@ class ROI {
return this[_properties];
}

/** Gets measurements of region of interest.
*
* @returns {Object[]} Measurements
*/
get measurements() {
return this[_properties].measurements;
}

/** Gets qualitative evaluations of region of interest.
*
* @returns {Object[]} QualitativeEvaluations
*/
get evaluations() {
return this[_properties].evaluations;
}

/** Adds a measurement.
*
* @params {Object} item - NUM content item representing a measurement
*/
addMeasurement(item) {
this[_properties]['measurements'].push(item);
}

/** Adds a qualitative evaluation.
*
* @params {Object} item - CODE content item representing a qualitative evaluation
*/
addEvaluation(item) {
this[_properties]['evaluations'].push(item);
}

}

export { ROI };
export { Property, ROI };
36 changes: 36 additions & 0 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,42 @@ class VolumeImageViewer {
return _getROIFromFeature(feature, this[_pyramidMetadata]);
}

/** Adds a measurement to a region of interest.
*
* @param {string} uid - Unique identifier of the region of interest
* @param {Object} item - NUM content item representing a measurement
*/
addROIMeasurement(uid, item) {
const meaning = item.ConceptNameCodeSequence[0].CodeMeaning
console.info(`add measurement "${meaning}" to ROI ${uid}`)
this[_features].forEach(feature => {
const id = feature.getId();
if (id === uid) {
const properties = feature.getProperties();
properties['measurements'].push(item);
feature.setProperties(properties, true);
}
})
}

/** Adds a qualitative evaluation to a region of interest.
*
* @param {string} uid - Unique identifier of the region of interest
* @param {Object} item - CODE content item representing a qualitative evaluation
*/
addROIEvaluation(uid, item) {
const meaning = item.ConceptNameCodeSequence[0].CodeMeaning
console.info(`add qualitative evaluation "${meaning}" to ROI ${uid}`)
this[_features].forEach(feature => {
const id = feature.getId();
if (id === uid) {
const properties = feature.getProperties();
properties['evaluations'].push(item);
feature.setProperties(properties, true);
}
})
}

/** Pops the most recently annotated regions of interest.
*
* @returns {ROI} Regions of interest.
Expand Down
Loading

0 comments on commit 8ca5d86

Please sign in to comment.