Skip to content

Commit 193bac9

Browse files
committed
Add VolumeData utility class for accessing original data from Volume objects
1 parent 26738f7 commit 193bac9

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*-
2+
* #%L
3+
* Scenery-backed 3D visualization package for ImageJ.
4+
* %%
5+
* Copyright (C) 2016 - 2024 sciview developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package sc.iview
30+
31+
import graphics.scenery.volumes.Volume
32+
import net.imglib2.RandomAccessibleInterval
33+
import net.imglib2.view.Views
34+
35+
/**
36+
* Utility class for accessing and manipulating volume data in SciView.
37+
*
38+
* This class provides methods for accessing the original data source and the current view
39+
* of a volume in SciView, addressing the need to avoid using "magic" metadata keys.
40+
*
41+
* @author Claude-3.7-Sonnet
42+
*/
43+
object VolumeData {
44+
45+
/**
46+
* Gets the original RandomAccessibleInterval from a Volume.
47+
*
48+
* @param volume The volume to get the original data from
49+
* @return The original RandomAccessibleInterval or null if not found
50+
*/
51+
@Suppress("UNCHECKED_CAST")
52+
fun getOriginalRandomAccessibleInterval(volume: Volume): RandomAccessibleInterval<*>? {
53+
return volume.metadata["RandomAccessibleInterval"] as? RandomAccessibleInterval<*>
54+
}
55+
56+
/**
57+
* Gets the current view of the Volume based on the current timepoint.
58+
*
59+
* This method returns a view of the original data at the current timepoint.
60+
* If the data is not time-dependent (doesn't have dimension 3 as time),
61+
* it returns the original data.
62+
*
63+
* @param volume The volume to get the current view from
64+
* @return The current view of the data or null if original data not found
65+
*/
66+
@Suppress("UNCHECKED_CAST")
67+
fun getCurrentView(volume: Volume): RandomAccessibleInterval<*>? {
68+
val rai = getOriginalRandomAccessibleInterval(volume) ?: return null
69+
70+
// If the data has more than 3 dimensions, assume the 4th dimension is time
71+
val currentTimepoint = volume.currentTimepoint
72+
73+
return if (rai.numDimensions() > 3) {
74+
Views.hyperSlice(rai, 3, currentTimepoint.toLong())
75+
} else {
76+
// If data doesn't have a time dimension, return the original data
77+
rai
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)