PerformanceCache
Performance cache for drag operations.
This module provides caching to enable smooth drag operations by reusing intermediate computations when the brush moves within a cached region.
Classes
- class PerformanceCache
Cache for intermediate computations during drag operations.
This cache stores gradient computations and threshold data to speed up consecutive brush operations during drag events.
Caching tiers: - Tier 1 (Gradient): Long-lived, persists until slice changes - Tier 2 (Thresholds): Medium-lived, reused when seed intensity similar - Tier 3 (ROI): Short-lived, cleared on mouse release
Methods:
- __init__()
Initialize the cache.
- computeOrGetCached()
Compute segmentation mask, using cache when possible.
- getOrComputeGradient()
Get cached gradient or compute new one.
- isValidFor()
Check if ROI cache is valid for given seed and radius.
- onMouseRelease()
Called when mouse is released - clear short-lived caches.
- invalidate()
Invalidate all caches (e.g., when parameters change).
- clear()
Clear all caches completely.
Functions
- computeOrGetCached()
Compute segmentation mask, using cache when possible.
- Args:
volumeArray: Full volume array. seedIjk: Seed point (i, j, k). params: Segmentation parameters. intensityAnalyzer: IntensityAnalyzer instance. segmentationFunc: Function to run segmentation.
- Returns:
Binary mask array.
- getOrComputeGradient()
Get cached gradient or compute new one.
The gradient is cached per slice and reused when the brush moves within the same slice. This significantly speeds up watershed and level set algorithms.
- Args:
volumeArray: Full volume array (z, y, x). sliceIndex: Current slice index (z). volumeId: Volume node ID for invalidation. computeFunc: Function to compute gradient from slice.
- Returns:
Gradient magnitude array for the slice.
- isValidFor()
Check if ROI cache is valid for given seed and radius.
- Args:
seedIjk: Seed point (i, j, k). radiusVoxels: Radius in voxels.
- Returns:
True if cache can be used.
- onMouseRelease()
Called when mouse is released - clear short-lived caches.
- invalidate()
Invalidate all caches (e.g., when parameters change).
- clear()
Clear all caches completely.
- reset()
Reset all statistics.
- log_summary()
Log cache statistics summary.