35
35
import bdv .spimdata .WrapBasicImgLoader ;
36
36
import bdv .viewer .Source ;
37
37
import bdv .viewer .SourceAndConverter ;
38
- import ch .epfl .biop .bdv .img .legacy .bioformats .BioFormatsBdvOpener ;
39
- import ch .epfl .biop .bdv .img .legacy .bioformats .BioFormatsToSpimData ;
40
- import ch .epfl .biop .bdv .img .legacy .bioformats .BioFormatsTools ;
38
+ import ch .epfl .biop .bdv .img .OpenersImageLoader ;
39
+ import ch .epfl .biop .bdv .img .OpenersToSpimData ;
40
+ import ch .epfl .biop .bdv .img .bioformats .BioFormatsOpener ;
41
+ import ch .epfl .biop .bdv .img .opener .OpenerSettings ;
41
42
import de .embl .cba .bdp2 .open .CachedCellImgCreator ;
42
43
import loci .formats .IFormatReader ;
43
- import loci .formats .MetadataTools ;
44
- import loci .formats .meta .IMetadata ;
45
44
import mpicbg .spim .data .generic .AbstractSpimData ;
46
45
import mpicbg .spim .data .generic .sequence .AbstractSequenceDescription ;
47
46
import net .imglib2 .RandomAccessibleInterval ;
48
- import net .imglib2 .cache .img .CachedCellImg ;
49
47
import net .imglib2 .cache .img .optional .CacheOptions ;
50
48
import net .imglib2 .type .NativeType ;
51
49
import net .imglib2 .type .numeric .ARGBType ;
55
53
import ome .units .quantity .Length ;
56
54
import ome .units .unit .Unit ;
57
55
import org .apache .commons .io .FilenameUtils ;
56
+ import spimdata .util .Displaysettings ;
58
57
59
58
import java .io .File ;
60
- import java .io .IOException ;
61
59
import java .util .ArrayList ;
60
+ import java .util .Collections ;
62
61
import java .util .List ;
63
62
64
63
public class BioFormatsCachedCellImgCreator < R extends RealType < R > & NativeType < R > > implements CachedCellImgCreator < R >
@@ -74,76 +73,82 @@ public class BioFormatsCachedCellImgCreator < R extends RealType< R > & NativeTy
74
73
75
74
public BioFormatsCachedCellImgCreator ( String filePath , int series ) {
76
75
77
- imageName = FilenameUtils .removeExtension ( new File ( filePath ).getName () ); // + "_S"+series;
76
+ File f = new File ( filePath );
77
+ imageName = FilenameUtils .removeExtension ( f .getName () ); // + "_S"+series;
78
78
79
- BioFormatsBdvOpener opener = BioFormatsBdvOpener .getOpener ()
80
- .location ( filePath )
81
- .auto ()
82
- .cornerPositionConvention ()
83
- .micrometer ()
84
- .cacheBounded ( 100 ) // TODO : is this value ok ?
85
- .positionReferenceFrameLength ( new Length ( 1 , UNITS .MICROMETER ) ) // Compulsory
86
- .voxSizeReferenceFrameLength ( new Length ( 1 , UNITS .MICROMETER ) );
79
+ // Up to you tischi! if you want to memoize and or lazy downscale - probably safer to disable pyramidize. Keeping memoisation is usually a good idea.
87
80
88
- try ( IFormatReader reader = opener .getReaderPool ().acquire () ) {
81
+ boolean disable_memo = false ;
82
+ boolean pyramidize = false ;
89
83
90
- IMetadata meta = (IMetadata ) (reader .getMetadataStore ());
84
+ OpenerSettings openerSettings =
85
+ OpenerSettings .BioFormats ()
86
+ .location (f )
87
+ .setSerie (series )
88
+ .micrometer ()
89
+ .pyramidize (pyramidize ) // Up to you!
90
+ .useBFMemo (!disable_memo )
91
+ .positionReferenceFrameLength ( new Length ( 1 , UNITS .MICROMETER ) ) // Compulsory
92
+ .voxSizeReferenceFrameLength ( new Length ( 1 , UNITS .MICROMETER ) )
93
+ .context (null ); // Let's hope no context is required
91
94
92
- seriesCount = opener . getNewReader (). getSeriesCount ( );
95
+ AbstractSpimData <?> spimData = OpenersToSpimData . getSpimData ( Collections . singletonList ( openerSettings ) );
93
96
94
- AbstractSpimData <?> spimData = BioFormatsToSpimData .getSpimData (opener );
97
+ // ------- Below is a not so nice way to get the number of series - it would be better to just ignore the number of series check
98
+ // The problem is that there's plenty of unchecked casts - pyramidisation breaks this (but it's fixable if needed)
95
99
96
- final AbstractSequenceDescription < ?, ?, ? > seq = spimData .getSequenceDescription ();
97
- final int numTimepoints = seq .getTimePoints ().size ();
98
- final VolatileGlobalCellCache cache = ( VolatileGlobalCellCache ) ( (ViewerImgLoader ) seq .getImgLoader () ).getCacheControl ();
99
- cache .clearCache ();
100
+ OpenersImageLoader imgLoader = (OpenersImageLoader ) spimData .getSequenceDescription ().getImgLoader ();
101
+ BioFormatsOpener opener = (BioFormatsOpener ) imgLoader .openers .get (0 );
102
+ try {
103
+ IFormatReader reader = opener .getPixelReader ().acquire ();
104
+ seriesCount = reader .getSeriesCount ();
105
+ opener .getPixelReader ().recycle (reader );
106
+ } catch (Exception e ) {
107
+ throw new RuntimeException (e );
108
+ }
109
+ // ------- End of not clean part. Consider removing getseriescount
100
110
101
- WrapBasicImgLoader .wrapImgLoaderIfNecessary ( spimData );
102
- final ArrayList <SourceAndConverter < ? >> sources = new ArrayList <>();
103
- BigDataViewer .initSetups ( spimData , new ArrayList <>(), sources );
111
+ final AbstractSequenceDescription < ?, ?, ? > seq = spimData .getSequenceDescription ();
112
+ final int numTimepoints = seq .getTimePoints ().size ();
113
+ final VolatileGlobalCellCache cache = ( VolatileGlobalCellCache ) ( (ViewerImgLoader ) seq .getImgLoader () ).getCacheControl ();
114
+ cache .clearCache ();
104
115
105
- // Count all the setups before the one of the series of interest
106
- int firstSetup = 0 ;
107
- for (int i = 0 ; i <series ; i ++) {
108
- firstSetup +=meta .getChannelCount (i );
109
- }
116
+ WrapBasicImgLoader .wrapImgLoaderIfNecessary ( spimData );
117
+ final ArrayList <SourceAndConverter < ? >> sources = new ArrayList <>();
118
+ BigDataViewer .initSetups ( spimData , new ArrayList <>(), sources );
110
119
111
- RandomAccessibleInterval <R > modelRAI = (RandomAccessibleInterval <R >) sources .get (firstSetup ).getSpimSource ().getSource (0 ,0 );
120
+ RandomAccessibleInterval <R > modelRAI = (RandomAccessibleInterval <R >) sources .get (0 ).getSpimSource ().getSource (0 ,0 );
112
121
113
- sizeX = modelRAI .dimension (0 ); // limited to 2GPixels in one dimension
114
- sizeY = modelRAI .dimension (1 );
115
- sizeZ = modelRAI .dimension (2 );
116
- sizeC = meta . getChannelCount ( series );
117
- sizeT = numTimepoints ;
122
+ sizeX = modelRAI .dimension (0 ); // limited to 2GPixels in one dimension
123
+ sizeY = modelRAI .dimension (1 );
124
+ sizeZ = modelRAI .dimension (2 );
125
+ sizeC = seq . getViewSetups (). size (); // One channel per view setup
126
+ sizeT = numTimepoints ;
118
127
119
- channelColors = new ARGBType [sizeC ];
128
+ channelColors = new ARGBType [sizeC ];
120
129
121
- // TODO : sanity check identical size in XYZCT for all channels. Currently assuming selecting one series does the trick
130
+ // TODO : sanity check identical size in XYZCT for all channels. Currently assuming selecting one series does the trick
122
131
123
- List <RandomAccessibleInterval <R >> raisXYZCT = new ArrayList <>();
132
+ List <RandomAccessibleInterval <R >> raisXYZCT = new ArrayList <>();
124
133
125
- int [] cacheSizeXYZ = new int [3 ];
134
+ int [] cacheSizeXYZ = new int [3 ];
126
135
127
- for (int iTime = 0 ; iTime <sizeT ;iTime ++) {
128
- List <RandomAccessibleInterval <R >> raisXYZC = new ArrayList <>();
129
- for (int iChannel = 0 ; iChannel <sizeC ;iChannel ++) {
130
- Source <R > source = (Source <R >) sources .get (firstSetup +iChannel ).getSpimSource ();
131
- channelColors [iChannel ] = BioFormatsTools .getColorFromMetadata (meta , series , iChannel );
132
- raisXYZC .add (source .getSource (iTime ,0 ));
133
- source .getVoxelDimensions ().dimensions (voxelSize );
134
- }
135
- ((VolatileCachedCellImg ) raisXYZC .get (0 )).getCellGrid ().cellDimensions (cacheSizeXYZ );
136
- raisXYZCT .add (Views .stack (raisXYZC ));
136
+ for (int iTime = 0 ; iTime <sizeT ;iTime ++) {
137
+ List <RandomAccessibleInterval <R >> raisXYZC = new ArrayList <>();
138
+ for (int iChannel = 0 ; iChannel <sizeC ;iChannel ++) {
139
+ Source <R > source = (Source <R >) sources .get (iChannel ).getSpimSource ();
140
+ int [] rgba = seq .getViewSetups ().get (iChannel ).getAttribute (Displaysettings .class ).color ;
141
+ channelColors [iChannel ] = new ARGBType (ARGBType .rgba (rgba [0 ], rgba [1 ], rgba [2 ], rgba [3 ]));
142
+ raisXYZC .add (source .getSource (iTime ,0 ));
143
+ source .getVoxelDimensions ().dimensions (voxelSize );
137
144
}
145
+ ((VolatileCachedCellImg ) raisXYZC .get (0 )).getCellGrid ().cellDimensions (cacheSizeXYZ );
146
+ raisXYZCT .add (Views .stack (raisXYZC ));
147
+ }
138
148
139
- cacheSize = new int []{cacheSizeXYZ [0 ], cacheSizeXYZ [1 ], cacheSizeXYZ [2 ],1 ,1 };
149
+ cacheSize = new int []{cacheSizeXYZ [0 ], cacheSizeXYZ [1 ], cacheSizeXYZ [2 ],1 ,1 };
150
+ raiXYCZT = Views .stack ( raisXYZCT );
140
151
141
- raiXYCZT = Views .stack ( raisXYZCT );
142
- } catch (IOException e ) {
143
- e .printStackTrace ();
144
- } catch (Exception e ) {
145
- e .printStackTrace ();
146
- }
147
152
}
148
153
149
154
@ Override
0 commit comments