Skip to content

Commit

Permalink
Merge branch '292-free-hand'. Fixes #292.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Dec 9, 2016
2 parents ec9b62e + afb8747 commit 7d3fa4c
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
3 changes: 3 additions & 0 deletions locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
},
"Arrow": {
"name": "Arrow"
},
"FreeHand": {
"name": "Free hand"
}
},
"io": {
Expand Down
3 changes: 3 additions & 0 deletions locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
},
"Arrow": {
"name": "Pointeur"
},
"FreeHand": {
"name": "Main levée"
}
},
"io": {
Expand Down
117 changes: 117 additions & 0 deletions src/tools/freeHand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// namespaces
var dwv = dwv || {};
dwv.tool = dwv.tool || {};
//external
var Kinetic = Kinetic || {};

/**
* FreeHand factory.
* @constructor
*/
dwv.tool.FreeHandFactory = function ()
{
/**
* Get the number of points needed to build the shape.
* @return {Number} The number of points.
*/
this.getNPoints = function () { return 1000; };
/**
* Get the timeout between point storage.
* @return {Number} The timeout in milliseconds.
*/
this.getTimeout = function () { return 25; };
};

/**
* Create a roi shape to be displayed.
* @param {Array} points The points from which to extract the line.
* @param {Object} style The drawing style.
* @param {Object} image The associated image.
*/
dwv.tool.FreeHandFactory.prototype.create = function (points, style /*, image*/)
{
// points stored the kineticjs way
var arr = [];
for( var i = 0; i < points.length; ++i )
{
arr.push( points[i].getX() );
arr.push( points[i].getY() );
}
// draw shape
var kshape = new Kinetic.Line({
points: arr,
stroke: style.getLineColour(),
strokeWidth: style.getScaledStrokeWidth(),
name: "shape",
tension: 0.5
});

// text
var ktext = new Kinetic.Text({
fontSize: style.getScaledFontSize(),
fontFamily: style.getFontFamily(),
fill: style.getLineColour(),
name: "text"
});
ktext.textExpr = "";
ktext.longText = "";
ktext.quant = null;
ktext.setText(ktext.textExpr);

// label
var klabel = new Kinetic.Label({
x: points[0].getX(),
y: points[0].getY() + 10,
name: "label"
});
klabel.add(ktext);
klabel.add(new Kinetic.Tag());

// return group
var group = new Kinetic.Group();
group.name("freeHand-group");
group.add(kshape);
group.add(klabel);
group.visible(true); // dont inherit
return group;
};

/**
* Update a FreeHand shape.
* @param {Object} anchor The active anchor.
* @param {Object} image The associated image.
*/
dwv.tool.UpdateFreeHand = function (anchor /*, image*/)
{
// parent group
var group = anchor.getParent();
// associated shape
var kline = group.getChildren( function (node) {
return node.name() === 'shape';
})[0];
// associated label
var klabel = group.getChildren( function (node) {
return node.name() === 'label';
})[0];

// update self
var point = group.getChildren( function (node) {
return node.id() === anchor.id();
})[0];
point.x( anchor.x() );
point.y( anchor.y() );
// update the roi point and compensate for possible drag
// (the anchor id is the index of the point in the list)
var points = kline.points();
points[anchor.id()] = anchor.x() - kline.x();
points[anchor.id()+1] = anchor.y() - kline.y();
kline.points( points );

// update text
var ktext = klabel.getText();
ktext.quant = null;
ktext.setText(dwv.utils.replaceFlags(ktext.textExpr, ktext.quant));
// update position
var textPos = { 'x': points[0] + kline.x(), 'y': points[1] + kline.y() + 10 };
klabel.position( textPos );
};
2 changes: 1 addition & 1 deletion viewers/mobile/applauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function startApp() {
"loaders": ["File", "Url", "GoogleDrive", "Dropbox"],
"tools": ["Scroll", "WindowLevel", "ZoomAndPan", "Draw", "Livewire", "Filter", "Floodfill"],
"filters": ["Threshold", "Sharpen", "Sobel"],
"shapes": ["Arrow", "Line", "Protractor", "Rectangle", "Roi", "Ellipse"],
"shapes": ["Arrow", "Line", "Protractor", "Rectangle", "Roi", "Ellipse", "FreeHand"],
"isMobile": true
//"defaultCharacterSet": "chinese"
});
Expand Down
1 change: 1 addition & 0 deletions viewers/mobile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<script type="text/javascript" src="../../src/tools/ellipse.js"></script>
<script type="text/javascript" src="../../src/tools/filter.js"></script>
<script type="text/javascript" src="../../src/tools/floodfill.js"></script>
<script type="text/javascript" src="../../src/tools/freeHand.js"></script>
<script type="text/javascript" src="../../src/tools/line.js"></script>
<script type="text/javascript" src="../../src/tools/livewire.js"></script>
<script type="text/javascript" src="../../src/tools/protractor.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion viewers/static/applauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function startApp() {
"loaders": ["File", "Url"],
"tools": ["Scroll", "WindowLevel", "ZoomAndPan", "Draw", "Livewire", "Filter", "Floodfill"],
"filters": ["Threshold", "Sharpen", "Sobel"],
"shapes": ["Arrow", "Line", "Protractor", "Rectangle", "Roi", "Ellipse"],
"shapes": ["Arrow", "Line", "Protractor", "Rectangle", "Roi", "Ellipse", "FreeHand"],
"isMobile": false
});

Expand Down

0 comments on commit 7d3fa4c

Please sign in to comment.