|
36 | 36 | import bdv.util.BdvHandlePanel;
|
37 | 37 | import bdv.util.BdvOptions;
|
38 | 38 | import bdv.util.BdvOverlay;
|
| 39 | +import bdv.util.BdvOverlaySource; |
39 | 40 | import bdv.viewer.Source;
|
40 | 41 | import net.imglib2.FinalInterval;
|
41 | 42 | import net.imglib2.FinalRealInterval;
|
@@ -581,4 +582,37 @@ public static void removeCard(BdvHandle bdvh, Object key) {
|
581 | 582 | SwingUtilities.invokeLater(() -> bdvh.getCardPanel().removeCard(key));
|
582 | 583 | }
|
583 | 584 |
|
| 585 | + /** |
| 586 | + * Helper function that maintains the number of timepoints of a bdv when addinf an overlay |
| 587 | + * see |
| 588 | + * @param bdvh |
| 589 | + * @param overlay |
| 590 | + * @param name |
| 591 | + * @return |
| 592 | + * @param <T> |
| 593 | + */ |
| 594 | + public static <T extends BdvOverlay> BdvOverlaySource<T> addOverlay(BdvHandle bdvh, T overlay, String name) { |
| 595 | + // Store |
| 596 | + int nTimepoints = bdvh.getViewerPanel().state().getNumTimepoints(); |
| 597 | + int currentTimePoint = bdvh.getViewerPanel().state().getCurrentTimepoint(); |
| 598 | + BdvOverlaySource<T> bos = BdvFunctions.showOverlay(overlay, name, BdvOptions.options().addTo(bdvh)); |
| 599 | + bdvh.getViewerPanel().state().setNumTimepoints(nTimepoints); |
| 600 | + bdvh.getViewerPanel().state().setCurrentTimepoint(currentTimePoint); |
| 601 | + return bos; |
| 602 | + } |
| 603 | + |
| 604 | + /** |
| 605 | + * Helper function that maintains the number of timepoints of a bdv when removing an overlay |
| 606 | + * @param overlay |
| 607 | + */ |
| 608 | + public static void removeOverlay(BdvOverlaySource<?> overlay) { |
| 609 | + // Store |
| 610 | + BdvHandle bdvh = overlay.getBdvHandle(); |
| 611 | + int nTimepoints = bdvh.getViewerPanel().state().getNumTimepoints(); |
| 612 | + int currentTimePoint = bdvh.getViewerPanel().state().getCurrentTimepoint(); |
| 613 | + overlay.removeFromBdv(); |
| 614 | + bdvh.getViewerPanel().state().setNumTimepoints(nTimepoints); |
| 615 | + bdvh.getViewerPanel().state().setCurrentTimepoint(currentTimePoint); |
| 616 | + } |
| 617 | + |
584 | 618 | }
|
0 commit comments