Skip to content
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

5 drawing list #278

Merged
merged 26 commits into from
Oct 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d010331
Added getDrawList and updateDraw methods.
ivmartel Oct 11, 2016
837ccba
Added slice and frame info in draw list.
ivmartel Oct 12, 2016
0266705
Draw fixing.
ivmartel Oct 13, 2016
01e7b18
Improved table display for jquery-mobile.
ivmartel Oct 13, 2016
113db68
Added edit mode option. Extracted functions.
ivmartel Oct 13, 2016
87980fb
Remove trash at the start of the dragend event.
ivmartel Oct 14, 2016
88847a6
Fix function declared in loop.
ivmartel Oct 14, 2016
7185319
Fix variable already defined.
ivmartel Oct 14, 2016
23a61be
Started integration in static. Renamed div.
ivmartel Oct 16, 2016
bbfb827
Moved gui specific code to viewers.
ivmartel Oct 17, 2016
419b68e
Fix bad if.
ivmartel Oct 17, 2016
99d5566
Better terminology.
ivmartel Oct 17, 2016
622d0f6
Using html5 input with color.
ivmartel Oct 18, 2016
4f4f9f2
Save label information in state.
ivmartel Oct 19, 2016
24662a0
Add safety checks.
ivmartel Oct 19, 2016
bca5368
Listen to floodfill and livewire draw events.
ivmartel Oct 19, 2016
d3dd4b1
Still fiddling with shape colour...
ivmartel Oct 19, 2016
9d44083
Merge remote-tracking branch 'refs/remotes/origin/master' into 5-draw…
ivmartel Oct 19, 2016
b7f36ec
Better var naming.
ivmartel Oct 20, 2016
c19c009
Better jquery-mobile responsive table.
ivmartel Oct 20, 2016
545987e
Using tool style and not the app one.
ivmartel Oct 20, 2016
282ef29
Added id to floodfill and livewire created ROI.
ivmartel Oct 20, 2016
eae750b
Loop optimisation.
ivmartel Oct 20, 2016
4641f8a
Added table translation functions.
ivmartel Oct 23, 2016
44a0a95
Added draw translations.
ivmartel Oct 23, 2016
74984ae
Fix DICOM tags for mobile.
ivmartel Oct 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ body { font-family: Verdana, Arial, Helvetica, sans-serif; }
.infoLayer canvas { margin: 0; padding: 2px; }

/* Tag list */
table.tagList { border-collapse: collapse; }
table.tagList thead td { font-weight: bold; }
table.tagList td { border: 1px solid grey; padding: 2px; }
.tags .highlighted { background: #f87217; }
table.tagsTable { border-collapse: collapse; }
table.tagsTable thead th { text-transform: uppercase;
font-weight: bold; opacity: 0.5;}
table.drawsTable { border-collapse: collapse; }
table.drawsTable td { vertical-align: middle; }
table.drawsTable thead th { text-transform: uppercase;
font-weight: bold; opacity: 0.5;}
.highlighted { background: #f87217; }
.tags form { width: 50%; }
12 changes: 11 additions & 1 deletion locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
"history": "History",
"image": "Image",
"info": "Info",
"downloadState": "Download state"
"downloadState": "Download state",
"drawList": "Annotations",
"search": "Search",
"id": "ID",
"slice": "Slice",
"frame": "Frame",
"type": "Type",
"color": "Color",
"label": "Label",
"description": "Description",
"editMode": "Edit Mode"
},
"colour": {
"Yellow": {
Expand Down
12 changes: 11 additions & 1 deletion locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
"history": "Historique",
"image": "Image",
"info": "Info",
"downloadState": "Télécharger state"
"downloadState": "Télécharger state",
"drawList": "Annotations",
"search": "Recherche",
"id": "ID",
"slice": "Coupe",
"frame": "Frame",
"type": "Type",
"color": "Couleur",
"label": "Label",
"description": "Description",
"editMode": "Mode Edition"
},
"colour": {
"Yellow": {
Expand Down
87 changes: 86 additions & 1 deletion src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ dwv.App = function ()
// Dicom tags gui
var tagsGui = null;

var drawListGui = null;

// Image layer
var imageLayer = null;
// Draw layers
Expand Down Expand Up @@ -128,6 +130,12 @@ dwv.App = function ()
*/
this.getScale = function () { return scale / windowScale; };

/**
* Get the window scale.
* @return {Number} The window scale.
*/
this.getWindowScale = function () { return windowScale; };

/**
* Get the scale center.
* @return {Object} The coordinates of the scale center.
Expand Down Expand Up @@ -248,6 +256,9 @@ dwv.App = function ()
var toolClass = toolName;
if (typeof dwv.tool[toolClass] !== "undefined") {
toolList[toolClass] = new dwv.tool[toolClass](this);
if (typeof toolList[toolClass].addEventListener !== "undefined") {
toolList[toolClass].addEventListener(fireEvent);
}
}
else {
console.warn("Could not initialise unknown tool: "+toolName);
Expand Down Expand Up @@ -294,6 +305,14 @@ dwv.App = function ()
if ( config.gui.indexOf("tags") !== -1 ) {
tagsGui = new dwv.gui.DicomTags(this);
}
// Draw list
if ( config.gui.indexOf("drawList") !== -1 ) {
drawListGui = new dwv.gui.DrawList(this);
// update list on draw events
this.addEventListener("draw-create", drawListGui.update);
this.addEventListener("draw-change", drawListGui.update);
this.addEventListener("draw-delete", drawListGui.update);
}
// version number
if ( config.gui.indexOf("version") !== -1 ) {
dwv.gui.appendVersionHtml(this.getVersion());
Expand Down Expand Up @@ -795,6 +814,72 @@ dwv.App = function ()
translateLayers();
};

/**
* Get a list of drawing details.
* @return {Object} A list of draw details including id, slice, frame...
*/
this.getDrawDetailsList = function ()
{
var list = [];
var size = image.getGeometry().getSize();
for ( var z = 0; z < size.getNumberOfSlices(); ++z ) {

for ( var f = 0; f < image.getNumberOfFrames(); ++f ) {

var collec = this.getDrawLayer(z,f).getChildren();
for ( var i = 0; i < collec.length; ++i ) {
var shape = collec[i].getChildren()[0];
var label = collec[i].getChildren()[1];
var text = label.getChildren()[0];
var type = shape.className;
if (type === "Line" && shape.closed()) {
type = "Roi";
}
if (type === "Rect") {
type = "Rectangle";
}
list.push( {
"id": collec[i].id(),
//"id": i,
"slice": z,
"frame": f,
"type": type,
"color": shape.stroke(),
"label": text.textExpr,
"description": text.longText
});
}
}
}
// return
return list;
};

/**
* Update a drawing.
* @param {Object} drawDetails Details of the drawing to update.
*/
this.updateDraw = function (drawDetails)
{
var layer = this.getDrawLayer(drawDetails.slice, drawDetails.frame);
//var collec = layer.getChildren()[drawDetails.id];
var collec = layer.getChildren( function (node) {
return node.id() === drawDetails.id;
})[0];
// shape
var shape = collec.getChildren()[0];
shape.stroke(drawDetails.color);
// label
var label = collec.getChildren()[1];
var text = label.getChildren()[0];
text.fill(drawDetails.color);
text.textExpr = drawDetails.label;
text.longText = drawDetails.description;
text.setText(dwv.utils.replaceFlags(text.textExpr, text.quant));
// udpate layer
this.getDrawLayer().draw();
};

// Handler Methods -----------------------------------------------------------

/**
Expand Down Expand Up @@ -1434,7 +1519,7 @@ dwv.App = function ()
viewController = new dwv.ViewController(view);
// append the DICOM tags table
if ( tagsGui ) {
tagsGui.initialise(data.info);
tagsGui.update(data.info);
}
// store image
originalImage = view.getImage();
Expand Down
123 changes: 94 additions & 29 deletions src/app/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,46 @@ dwv.State = function (app)
var nSlices = app.getImage().getGeometry().getSize().getNumberOfSlices();
var nFrames = app.getImage().getNumberOfFrames();
var drawings = [];
var drawingsDetails = [];
for ( var k = 0; k < nSlices; ++k ) {
drawings[k] = [];
for ( var f = 0; f < nFrames; ++f ) {
// getChildren always return, so drawings will have the good size
var groups = app.getDrawLayer(k,f).getChildren();
// remove anchors
for ( var i = 0; i < groups.length; ++i ) {
var anchors = groups[i].find(".anchor");
for ( var a = 0; a < anchors.length; ++a ) {
anchors[a].remove();
drawings[k] = [];
drawingsDetails[k] = [];
for ( var f = 0; f < nFrames; ++f ) {
// getChildren always return, so drawings will have the good size
var groups = app.getDrawLayer(k,f).getChildren();
var details = [];
// remove anchors
for ( var i = 0; i < groups.length; ++i ) {
var anchors = groups[i].find(".anchor");
for ( var a = 0; a < anchors.length; ++a ) {
anchors[a].remove();
}
var texts = groups[i].find(".text");
for ( var b = 0; b < texts.length; ++b ) {
details.push({
"id": groups[i].id(),
"textExpr": texts[b].textExpr,
"longText": texts[b].longText,
"quant": texts[b].quant
});
}
}
drawings[k].push(groups);
drawingsDetails[k].push(details);
}
drawings[k].push(groups);
}
}
// return a JSON string
return JSON.stringify( {
"version": "0.1",
"window-center": app.getViewController().getWindowLevel().center,
"version": "0.2",
"window-center": app.getViewController().getWindowLevel().center,
"window-width": app.getViewController().getWindowLevel().width,
"position": app.getViewController().getCurrentPosition(),
"scale": app.getScale(),
"scaleCenter": app.getScaleCenter(),
"translation": app.getTranslation(),
"drawings": drawings
"drawings": drawings,
// new in v0.2
"drawingsDetails": drawingsDetails
} );
};
/**
Expand All @@ -54,14 +69,17 @@ dwv.State = function (app)
this.fromJSON = function (json, eventCallback) {
var data = JSON.parse(json);
if (data.version === "0.1") {
readV01(data, eventCallback);
readV01(data, eventCallback);
}
else if (data.version === "0.2") {
readV02(data, eventCallback);
}
else {
throw new Error("Unknown state file format version: '"+data.version+"'.");
throw new Error("Unknown state file format version: '"+data.version+"'.");
}
};
/**
* Read an application state from an Object.
* Read an application state from an Object in v0.1 format.
* @param {Object} data The Object representation of the state.
* @param {Object} eventCallback The callback to associate to draw commands.
*/
Expand All @@ -78,21 +96,68 @@ dwv.State = function (app)
return node.name() === "shape";
};
for ( var k = 0 ; k < nSlices; ++k ) {
for ( var f = 0; f < nFrames; ++f ) {
for ( var i = 0 ; i < data.drawings[k][f].length; ++i ) {
var group = Kinetic.Node.create(data.drawings[k][f][i]);
var shape = group.getChildren( isShape )[0];
var cmd = new dwv.tool.DrawGroupCommand(
group, shape.className,
app.getDrawLayer(k,f) );
if ( typeof eventCallback !== "undefined" ) {
cmd.onExecute = eventCallback;
cmd.onUndo = eventCallback;
for ( var f = 0; f < nFrames; ++f ) {
for ( var i = 0 ; i < data.drawings[k][f].length; ++i ) {
var group = Kinetic.Node.create(data.drawings[k][f][i]);
var shape = group.getChildren( isShape )[0];
var cmd = new dwv.tool.DrawGroupCommand(
group, shape.className,
app.getDrawLayer(k,f) );
if ( typeof eventCallback !== "undefined" ) {
cmd.onExecute = eventCallback;
cmd.onUndo = eventCallback;
}
cmd.execute();
app.addToUndoStack(cmd);
}
cmd.execute();
app.addToUndoStack(cmd);
}
}
}
/**
* Read an application state from an Object in v0.2 format.
* @param {Object} data The Object representation of the state.
* @param {Object} eventCallback The callback to associate to draw commands.
*/
function readV02(data, eventCallback) {
// display
app.getViewController().setWindowLevel(data["window-center"], data["window-width"]);
app.getViewController().setCurrentPosition(data.position);
app.zoom(data.scale, data.scaleCenter.x, data.scaleCenter.y);
app.translate(data.translation.x, data.translation.y);
// drawings
var nSlices = app.getImage().getGeometry().getSize().getNumberOfSlices();
var nFrames = app.getImage().getNumberOfFrames();
var isShape = function (node) {
return node.name() === "shape";
};
var isLabel = function (node) {
return node.name() === "label";
};
for ( var k = 0 ; k < nSlices; ++k ) {
for ( var f = 0; f < nFrames; ++f ) {
for ( var i = 0 ; i < data.drawings[k][f].length; ++i ) {
var group = Kinetic.Node.create(data.drawings[k][f][i]);
var shape = group.getChildren( isShape )[0];
var cmd = new dwv.tool.DrawGroupCommand(
group, shape.className,
app.getDrawLayer(k,f) );
if ( typeof eventCallback !== "undefined" ) {
cmd.onExecute = eventCallback;
cmd.onUndo = eventCallback;
}
// text (new in v0.2)
// TODO Verify ID?
var details = data.drawingsDetails[k][f][i];
var label = group.getChildren( isLabel )[0];
var text = label.getText();
text.textExpr = details.textExpr;
text.longText = details.longText;
text.quant = details.quant;
// execute
cmd.execute();
app.addToUndoStack(cmd);
}
}
}
}
}; // State class
6 changes: 3 additions & 3 deletions src/app/toolboxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ dwv.ToolboxController = function (toolbox)

/**
* Set the tool line colour.
* @param {String} name The name of the colour.
* @param {String} colour The colour.
*/
this.setLineColour = function (name)
this.setLineColour = function (colour)
{
toolbox.getSelectedTool().setLineColour(name);
toolbox.getSelectedTool().setLineColour(colour);
};

/**
Expand Down
16 changes: 8 additions & 8 deletions src/dicom/dicomParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,23 +1331,23 @@ dwv.dicom.DicomElementsWrapper = function (dicomElements) {
}
// name
if ( dictElement !== null ) {
row[dwv.i18n("basics.name")] = dictElement[2];
row.name = dictElement[2];
}
else {
row[dwv.i18n("basics.name")] = "Unknown Tag & Data";
row.name = "Unknown Tag & Data";
}
// value
if ( dicomElement.tag.name !== "x7FE00010" ) {
row[dwv.i18n("basics.value")] = dicomElement.value;
row.value = dicomElement.value;
}
else {
row[dwv.i18n("basics.value")] = "...";
row.value = "...";
}
// others
row[dwv.i18n("basics.group")] = dicomElement.tag.group;
row[dwv.i18n("basics.element")] = dicomElement.tag.element;
row[dwv.i18n("basics.vr")] = dicomElement.vr;
row[dwv.i18n("basics.vl")] = dicomElement.vl;
row.group = dicomElement.tag.group;
row.element = dicomElement.tag.element;
row.vr = dicomElement.vr;
row.vl = dicomElement.vl;

table.push( row );
}
Expand Down
Loading