Skip to content

Commit a9a72da

Browse files
authored
Merge pull request #207 from bigdataprocessor/new-bdv-img-loader-api
Removes deprecated API in bigdataviewer-image-loaders
2 parents 288ba38 + a140fa2 commit a9a72da

File tree

2 files changed

+65
-60
lines changed

2 files changed

+65
-60
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<license.copyrightOwners>EMBL</license.copyrightOwners>
8383

8484
<!-- BIOP -->
85-
<bigdataviewer-image-loaders.version>0.8.1</bigdataviewer-image-loaders.version>
85+
<bigdataviewer-image-loaders.version>0.10.0</bigdataviewer-image-loaders.version>
8686

8787
<!-- EMBL CBA -->
8888
<imaris-writer.version>1.0.6</imaris-writer.version>

src/main/java/de/embl/cba/bdp2/open/bioformats/BioFormatsCachedCellImgCreator.java

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@
3535
import bdv.spimdata.WrapBasicImgLoader;
3636
import bdv.viewer.Source;
3737
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;
4142
import de.embl.cba.bdp2.open.CachedCellImgCreator;
4243
import loci.formats.IFormatReader;
43-
import loci.formats.MetadataTools;
44-
import loci.formats.meta.IMetadata;
4544
import mpicbg.spim.data.generic.AbstractSpimData;
4645
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
4746
import net.imglib2.RandomAccessibleInterval;
48-
import net.imglib2.cache.img.CachedCellImg;
4947
import net.imglib2.cache.img.optional.CacheOptions;
5048
import net.imglib2.type.NativeType;
5149
import net.imglib2.type.numeric.ARGBType;
@@ -55,10 +53,11 @@
5553
import ome.units.quantity.Length;
5654
import ome.units.unit.Unit;
5755
import org.apache.commons.io.FilenameUtils;
56+
import spimdata.util.Displaysettings;
5857

5958
import java.io.File;
60-
import java.io.IOException;
6159
import java.util.ArrayList;
60+
import java.util.Collections;
6261
import java.util.List;
6362

6463
public class BioFormatsCachedCellImgCreator < R extends RealType< R > & NativeType< R > > implements CachedCellImgCreator< R >
@@ -74,76 +73,82 @@ public class BioFormatsCachedCellImgCreator < R extends RealType< R > & NativeTy
7473

7574
public BioFormatsCachedCellImgCreator( String filePath, int series ) {
7675

77-
imageName = FilenameUtils.removeExtension( new File( filePath ).getName() ); // + "_S"+series;
76+
File f = new File( filePath );
77+
imageName = FilenameUtils.removeExtension( f.getName() ); // + "_S"+series;
7878

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.
8780

88-
try ( IFormatReader reader = opener.getReaderPool().acquire() ) {
81+
boolean disable_memo = false;
82+
boolean pyramidize = false;
8983

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
9194

92-
seriesCount = opener.getNewReader().getSeriesCount();
95+
AbstractSpimData<?> spimData = OpenersToSpimData.getSpimData(Collections.singletonList(openerSettings));
9396

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)
9599

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
100110

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();
104115

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 );
110119

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);
112121

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;
118127

119-
channelColors = new ARGBType[sizeC];
128+
channelColors = new ARGBType[sizeC];
120129

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
122131

123-
List<RandomAccessibleInterval<R>> raisXYZCT = new ArrayList<>();
132+
List<RandomAccessibleInterval<R>> raisXYZCT = new ArrayList<>();
124133

125-
int[] cacheSizeXYZ = new int[3];
134+
int[] cacheSizeXYZ = new int[3];
126135

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);
137144
}
145+
((VolatileCachedCellImg) raisXYZC.get(0)).getCellGrid().cellDimensions(cacheSizeXYZ);
146+
raisXYZCT.add(Views.stack(raisXYZC));
147+
}
138148

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 );
140151

141-
raiXYCZT = Views.stack( raisXYZCT );
142-
} catch (IOException e) {
143-
e.printStackTrace();
144-
} catch (Exception e) {
145-
e.printStackTrace();
146-
}
147152
}
148153

149154
@Override

0 commit comments

Comments
 (0)