Created
December 11, 2016 13:42
-
-
Save petebankhead/27176fa565c5f0e37eafc047b709b451 to your computer and use it in GitHub Desktop.
Assign a selected annotation to be a child of whichever TMA core contains its centroid
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
/* | |
* Assign a selected annotation to be a child of whichever TMA core contains its centroid. | |
* | |
* This can be useful whenever an annotation is drawn *slightly* overlapping the core, | |
* and so is not automatically assigned to be a child of the core - but it should be. | |
* | |
* @author Pete Bankhead | |
*/ | |
// Ensure annotation is selected! | |
annotation = getSelectedObject() | |
if (annotation == null || !annotation.isAnnotation()) { | |
println("Ensure an annotation is selected!") | |
return | |
} | |
// Get the hierarchy for later | |
hierarchy = getCurrentHierarchy() | |
// Little sanity check - make sure the annotation is directly below the hierarchy root | |
if (annotation.getParent() != hierarchy.getRootObject()) { | |
println("Selected annotation is not a direct child of the root object!") | |
return | |
} | |
// Get the annotation centroid location | |
roi = annotation.getROI() | |
x = roi.getCentroidX() | |
y = roi.getCentroidY() | |
// Loop through the TMA cores | |
for (core in getTMACoreList()) { | |
// Check if the core ROI contains the annotation centroid | |
if (core.getROI().contains(x, y)) { | |
// Add annotation to the core | |
core.addPathObject(annotation) | |
println("Annotation added to " + core) | |
// Call off the search | |
break | |
} | |
} | |
// Fire general update event to ensure everything gets synchronized & shown | |
hierarchy.fireHierarchyChangedEvent(this)/* | |
* Assign a selected annotation to be a child of whichever TMA core contains its centroid. | |
* | |
* This can be useful whenever an annotation is drawn *slightly* overlapping the core, | |
* and so is not automatically assigned to be a child of the core - but it should be. | |
*/ | |
// Ensure annotation is selected! | |
annotation = getSelectedObject() | |
if (annotation == null || !annotation.isAnnotation()) { | |
println("Ensure an annotation is selected!") | |
return | |
} | |
// Get the hierarchy for later | |
hierarchy = getCurrentHierarchy() | |
// Little sanity check - make sure the annotation is directly below the hierarchy root | |
if (annotation.getParent() != hierarchy.getRootObject()) { | |
println("Selected annotation is not a direct child of the root object!") | |
return | |
} | |
// Get the annotation centroid location | |
roi = annotation.getROI() | |
x = roi.getCentroidX() | |
y = roi.getCentroidY() | |
// Loop through the TMA cores | |
for (core in getTMACoreList()) { | |
// Check if the core ROI contains the annotation centroid | |
if (core.getROI().contains(x, y)) { | |
// Add annotation to the core | |
core.addPathObject(annotation) | |
println("Annotation added to " + core) | |
// Call off the search | |
break | |
} | |
} | |
// Fire general update event to ensure everything gets synchronized & shown | |
hierarchy.fireHierarchyChangedEvent(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment