Guest User

Untitled

a guest
Apr 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. // EXAMPLE using ImageDisplay listener
  2. // This will handle ALL ROIs on the display, so one would like to
  3. // "filter" specific ROIs. f.e. by using the ROI property "Name".
  4. class CCircleRestrict
  5. {
  6. number x0,y0
  7. object Init( object self, number cx, number cy ){ x0 = cx; y0 = cy; return self; }
  8. void OnRestrict( object self, number e_fl, ImageDisplay idisp, number r_fl, number r_fl2, ROI theROI )
  9. {
  10. if ( theROI.ROIGetName() != "special" ) return; // Skip, if it isn't "our" ROI
  11. if ( !theROI.ROIIsOval() ) return; // Skip, if it isn't an oval ROI
  12. // get size of ROI ( as currently dragged by user )
  13. number t, l, b, r
  14. theROI.ROIGetOval( t, l, b, r )
  15. number radius = max( b - t, r - l ) / 2
  16. // Re-Set the ROI centered on x0/y0 with the new radius
  17. theROI.ROISetOval( y0 - radius, x0 - radius, y0 + radius, x0 + radius )
  18. }
  19. }
  20.  
  21. // Main script "attaches" the display listener to
  22. void main()
  23. {
  24. // Create and show test image
  25. number size = 512
  26. number r1 = 20
  27. number r2 = 20
  28. number off = 100
  29. image test := realImage( "Test", 4, size, size )
  30. test.ShowImage()
  31. imageDisplay disp = test.ImageGetImageDisplay(0)
  32. // Add two oval ROIs, name one of them "special" for identification
  33. ROI specialROI = NewROI()
  34. specialROI.ROISetName( "special" )
  35. specialROI.ROISetOval( size/2 - r1, size/2 - r1, size/2 + r1, size/2 + r1 )
  36. specialROI.ROISetVolatile(0)
  37. specialROI.ROISetColor(0.1,0.9,0.1)
  38. disp.ImageDisplayAddROI(specialROI)
  39. ROI otherROI = NewROI()
  40. otherROI.ROISetOval( off + size/2 - r2, off + size/2 - r2, off + size/2 + r2, off + size/2 + r2 )
  41. otherROI.ROISetVolatile(0)
  42. disp.ImageDisplayAddROI(otherROI)
  43. // Create listener object and attach listener to display
  44. object dispListener = Alloc(CCircleRestrict).Init( size/2, size/2 )
  45. disp.ImageDisplayAddEventListener( dispListener, "roi_property_changed:OnRestrict" )
  46. }
  47.  
  48. EGUPerformActionWithAllShownImages( "Delete" )
  49. main()
  50. EGUPerformActionWithAllShownImages( "Arrange" )
  51.  
  52. // EXAMPLE using ROI listener
  53. // This will handle changes a specific ROI, regardless of the display(s) it is on
  54. class CCircleRestrict
  55. {
  56. number x0,y0
  57. object Init( object self, number cx, number cy ){ x0 = cx; y0 = cy; return self; }
  58. void OnRestrict( object self, ROI theROI )
  59. {
  60. if ( !theROI.ROIIsOval() ) return; // Skip, if it isn't an oval ROI
  61. // get size of ROI ( as currently dragged by user )
  62. number t, l, b, r
  63. theROI.ROIGetOval( t, l, b, r )
  64. number radius = max( b - t, r - l ) / 2
  65. // Re-Set the ROI centered on x0/y0 with the new radius
  66. theROI.ROISetOval( y0 - radius, x0 - radius, y0 + radius, x0 + radius )
  67. }
  68. }
  69.  
  70. // Main script "attaches" the listener to the ROI
  71. void main()
  72. {
  73. // Create and show test image
  74. number size = 512
  75. number r1 = 20
  76. number r2 = 20
  77. number off = 100
  78. image test := realImage( "Test", 4, size, size )
  79. test.ShowImage()
  80. imageDisplay disp = test.ImageGetImageDisplay(0)
  81. // Add two oval ROIs
  82. ROI specialROI = NewROI()
  83. specialROI.ROISetOval( size/2 - r1, size/2 - r1, size/2 + r1, size/2 + r1 )
  84. specialROI.ROISetVolatile(0)
  85. specialROI.ROISetColor(0.1,0.9,0.1)
  86. disp.ImageDisplayAddROI(specialROI)
  87. ROI otherROI = NewROI()
  88. otherROI.ROISetOval( off + size/2 - r2, off + size/2 - r2, off + size/2 + r2, off + size/2 + r2 )
  89. otherROI.ROISetVolatile(0)
  90. disp.ImageDisplayAddROI(otherROI)
  91. // Create listener object and attach listener to specific ROI
  92. object roiListener = Alloc(CCircleRestrict).Init( size/2, size/2 )
  93. ConnectObject( specialROI.ROIGetID(), "changed", "EventID_Name", roiListener, "OnRestrict" )
  94. }
  95.  
  96. EGUPerformActionWithAllShownImages( "Delete" )
  97. main()
  98. EGUPerformActionWithAllShownImages( "Arrange" )
  99.  
  100. void OnRestrict( object self, ROI theROI )
  101. {
  102. ar = 2
  103. if ( !theROI.ROIIsOval() ) return; // Skip, if it isn't an oval ROI
  104. // get size of ROI ( as currently dragged by user )
  105. number t, l, b, r
  106. theROI.ROIGetOval( t, l, b, r )
  107. number w = r - l
  108. number h = b - t
  109. number newW = max( W, AR*H )
  110. number newH = newW/AR
  111. // Re-Set the ROI centered on x0/y0 with the new radius
  112. theROI.ROISetOval( y0 - newH/2, x0 - newW/2, y0 + newH/2, x0 + newW/2 )
  113. }
Add Comment
Please, Sign In to add comment