Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. /*
  2. * Assign a selected annotation to be a child of whichever TMA core contains its centroid.
  3. *
  4. * This can be useful whenever an annotation is drawn *slightly* overlapping the core,
  5. * and so is not automatically assigned to be a child of the core - but it should be.
  6. *
  7. * @author Pete Bankhead
  8. */
  9.  
  10. // Ensure annotation is selected!
  11. annotation = getSelectedObject()
  12. if (annotation == null || !annotation.isAnnotation()) {
  13. println("Ensure an annotation is selected!")
  14. return
  15. }
  16.  
  17. // Get the hierarchy for later
  18. hierarchy = getCurrentHierarchy()
  19.  
  20. // Little sanity check - make sure the annotation is directly below the hierarchy root
  21. if (annotation.getParent() != hierarchy.getRootObject()) {
  22. println("Selected annotation is not a direct child of the root object!")
  23. return
  24. }
  25.  
  26. // Get the annotation centroid location
  27. roi = annotation.getROI()
  28. x = roi.getCentroidX()
  29. y = roi.getCentroidY()
  30.  
  31. // Loop through the TMA cores
  32. for (core in getTMACoreList()) {
  33. // Check if the core ROI contains the annotation centroid
  34. if (core.getROI().contains(x, y)) {
  35. // Add annotation to the core
  36. core.addPathObject(annotation)
  37. println("Annotation added to " + core)
  38. // Call off the search
  39. break
  40. }
  41. }
  42.  
  43. // Fire general update event to ensure everything gets synchronized & shown
  44. hierarchy.fireHierarchyChangedEvent(this)/*
  45. * Assign a selected annotation to be a child of whichever TMA core contains its centroid.
  46. *
  47. * This can be useful whenever an annotation is drawn *slightly* overlapping the core,
  48. * and so is not automatically assigned to be a child of the core - but it should be.
  49. */
  50.  
  51. // Ensure annotation is selected!
  52. annotation = getSelectedObject()
  53. if (annotation == null || !annotation.isAnnotation()) {
  54. println("Ensure an annotation is selected!")
  55. return
  56. }
  57.  
  58. // Get the hierarchy for later
  59. hierarchy = getCurrentHierarchy()
  60.  
  61. // Little sanity check - make sure the annotation is directly below the hierarchy root
  62. if (annotation.getParent() != hierarchy.getRootObject()) {
  63. println("Selected annotation is not a direct child of the root object!")
  64. return
  65. }
  66.  
  67. // Get the annotation centroid location
  68. roi = annotation.getROI()
  69. x = roi.getCentroidX()
  70. y = roi.getCentroidY()
  71.  
  72. // Loop through the TMA cores
  73. for (core in getTMACoreList()) {
  74. // Check if the core ROI contains the annotation centroid
  75. if (core.getROI().contains(x, y)) {
  76. // Add annotation to the core
  77. core.addPathObject(annotation)
  78. println("Annotation added to " + core)
  79. // Call off the search
  80. break
  81. }
  82. }
  83.  
  84. // Fire general update event to ensure everything gets synchronized & shown
  85. hierarchy.fireHierarchyChangedEvent(this)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement