Last active
June 9, 2017 20:14
-
-
Save mutterer/00b3fde529b3a5a1ea83181cafd4bf06 to your computer and use it in GitHub Desktop.
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
// cuts a closed freehand selection | |
// into 2 free line selections | |
// after selecting two points | |
// click and drag to move selection along area | |
// press shift to define first point | |
// drag to define second point, release to split | |
// see https://www.youtube.com/watch?v=qrZgbqSFv68 | |
var shift=1; | |
var firstPointSet=false; | |
macro "Area_cutting Tool - C00cO11cc" { | |
roiManager('add'); | |
p1=-1; | |
p2=-1; | |
getCursorLoc(x,y,z,m); | |
getSelectionCoordinates(xc,yc); | |
Overlay.remove(); | |
while (m&16!=0) { | |
getCursorLoc(x,y,z,m); | |
d = 1024; | |
pp=-1; | |
for (i=0;i<xc.length;i++) { | |
di = sqrt((xc[i]-x)*(xc[i]-x)+(yc[i]-y)*(yc[i]-y)); | |
if (di<d) { | |
d=di; | |
pp=i; | |
} | |
} | |
setColor('red'); | |
Overlay.drawEllipse(xc[pp]-5,yc[pp]-5,10,10); | |
Overlay.show(); | |
wait(20); | |
if (m&shift!=0) { | |
Overlay.remove(); | |
Overlay.drawEllipse(xc[pp]-5,yc[pp]-5,10,10); | |
Overlay.show(); | |
firstPointSet=true; | |
wait(20); | |
p1=pp; | |
} | |
for (r=1*firstPointSet;r<Overlay.size;r++){ | |
Overlay.removeSelection(r); | |
} | |
} | |
setColor('green'); | |
Overlay.drawEllipse(xc[pp]-5,yc[pp]-5,10,10); | |
Overlay.show(); | |
p2 = pp; | |
firstPointSet=false; | |
a = minOf(p1,p2); | |
b = maxOf(p1,p2); | |
xcb = Array.copy(xc); | |
ycb = Array.copy(yc); | |
xcb2 = Array.copy(xc); | |
ycb2 = Array.copy(yc); | |
s1x = Array.trim(Array.rotate(xc,-1*a),b-a); | |
s1y = Array.trim(Array.rotate(yc,-1*a),b-a); | |
makeSelection("polyline",s1x,s1y); | |
roiManager('add'); | |
s2x = Array.concat(Array.trim(Array.rotate(xcb,xcb.length-b),xcb.length-b),Array.trim(xcb2,a)); | |
s2y = Array.concat(Array.trim(Array.rotate(ycb,xcb.length-b),xcb.length-b),Array.trim(ycb2,a)); | |
makeSelection("polyline",s2x,s2y); | |
roiManager('add'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment