Skip to content

Commit

Permalink
tile caching optimizations
Browse files Browse the repository at this point in the history
latest image-provider-omero
  • Loading branch information
Manuel Stritt committed Jul 13, 2017
1 parent 92616c4 commit 7629df0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 59 deletions.
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ configurations {

dependencies {
compile 'com.actelion.research:lib-orbit-common:1.2.5'
// compile 'com.actelion.research:image-provider-omero:1.4.11'
compile 'com.actelion.research:image-provider-omero:1.4.12'
compile 'com.actelion.research:map-reduce-generic:1.0.8'
// compile 'com.actelion.research:map-reduce-exec-spark:1.0.2'
// compile 'com.actelion.research:mapReduceExecGrid:1.0.1.1'
compile 'com.actelion.research:map-reduce-exec-spark:1.0.2'

compile(group: 'com.actelion.research', name: 'OrbitImageAnalysisAct', version: '0.1.8') {
exclude(module: 'orbit-image-analysis')
}
// compile 'com.actelion.research:mapReduceExecGrid:1.0.1.1'
// compile(group: 'com.actelion.research', name: 'OrbitImageAnalysisAct', version: '0.1.8') {
// exclude(module: 'orbit-image-analysis')
// }

// only used for image-provider-omero development
// compile(group: 'omero', name: 'blitz', version: '5.2.7-ice36-b40') { // 5.2.7-ice36-b40 5.3.0-ice36-b59
Expand Down Expand Up @@ -211,14 +211,14 @@ dependencies {
compile (group: 'org.codelibs', name:'jcifs', version:'1.3.18.1') { // for SmbUtils (exclude javax.servlet-api because Spark needs a different version)
exclude (group:'javax.servlet', module: 'servlet-api')
}
compile (group: 'ome', name:'formats-gpl', version:'5.5.2') {
compile (group: 'ome', name:'formats-gpl', version:'5.5.3') {
exclude (module: 'blitz')
}
compile (group: 'net.imglib2', name: 'imglib2', version: '3.2.1') // to avoid jpeg2000 problem: NoSuchMethodError: jj2000.j2k.fileformat.reader.FileFormatReader.<init>

// compile 'io.scif:scifio:0.30.0' // only java 1.8
// compile 'io.scif:scifio-bf-compat:2.0.0'
compile 'org.codehaus.groovy:groovy-all:2.4.10'
compile 'org.codehaus.groovy:groovy-all:2.4.12'
compile 'org.codehaus.gpars:gpars:1.2.1'
compile 'com.fifesoft:rsyntaxtextarea:2.6.1'
compile 'com.fifesoft:autocomplete:2.6.1'
Expand All @@ -229,7 +229,7 @@ dependencies {
compile (group: 'sc.fiji', name: 'legacy-imglib1', version: '2.0.0-SNAPSHOT') { //1.1.5 2.0.0-SNAPSHOT for graph_cut
transitive = false
}
compile 'org.xerial:sqlite-jdbc:3.16.1'
compile 'org.xerial:sqlite-jdbc:3.19.3'
testCompile 'junit:junit:[4.0,)'
}

Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### A versatile image analysis software for biological image-based quantification.

#####News:
* 2.65: mumford-shah based segmentation algorithm included, 16bit downscaling bugfix, bioformats 5.5.3
* 2.54: >8bit,<16bit bugfix (fluo rendering), only for Omero 5.3.x!
* 2.53: Using bioformats 5.4.0, multichannel (fluo) support, multi series support, works with Omero 5.3.x, Ice36
* 2.52: Using bioformats 5.4.0, multichannel (fluo) support, multi series support, works with Omero 5.2.x, Ice36
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public HueColorChooser(float initialHue) {
colorCanvas = new JPanel();
colorCanvas.setBackground(Color.getHSBColor(hsb[0],hsb[1],hsb[2]));
colorCanvas.setPreferredSize(new Dimension(200,200));
colorCanvas.setOpaque(true);

btnCancel.addActionListener(new ActionListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package com.actelion.research.orbit.imageAnalysis.utils;

import com.actelion.research.orbit.exceptions.OrbitImageServletException;
import com.actelion.research.orbit.imageAnalysis.dal.DALConfig;
import com.actelion.research.orbit.imageAnalysis.imaging.GBlur;
import com.actelion.research.orbit.imageAnalysis.imaging.ManipulationUtils;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.Weigher;
import imageJ.Colour_Deconvolution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -38,7 +38,6 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;


Expand All @@ -50,8 +49,6 @@ public abstract class OrbitTiledImage2 extends PlanarImage implements RenderedIm
protected int numBands = 0;
protected String filename = "";
public static Cache<PointAndName, Raster> tileCache = null;
public static AtomicInteger cacheTileWidth = new AtomicInteger(OrbitUtils.TILE_SIZE);
public static AtomicInteger cacheTileHeight = new AtomicInteger(OrbitUtils.TILE_SIZE);
private static final ReentrantReadWriteLock cacheLock = new ReentrantReadWriteLock();
private static final boolean doCacheLock = false;
private boolean useCache = !ScaleoutMode.SCALEOUTMODE.get();
Expand All @@ -75,23 +72,22 @@ public abstract class OrbitTiledImage2 extends PlanarImage implements RenderedIm
protected abstract Raster getTileData(int tileX, int tileY, float[] channelContributions, boolean analysis);


private static void initCache(int tileWidth, int tileHeight) {
logger.info("(re-)creating tile cache ["+tileWidth+"x"+tileHeight+"]");
private static void initCache() {
logger.info("(re-)creating tile cache");
if (doCacheLock) OrbitTiledImage2.cacheLock.writeLock().lock();
try {
cacheTileWidth.set(tileWidth);
cacheTileHeight.set(tileHeight);

long mem = Runtime.getRuntime().maxMemory();
int tileX = cacheTileWidth.get();
int tileY = cacheTileHeight.get();
int maxSize = (int) ((mem * 0.5d) / (tileX * tileY * 3L * 4L)); // 3 bands, each a 32bit int

//System.out.println("OrbitTiledImage2.tileCache: maxObjects="+maxSize+" freeMem: "+RawUtils.formatFileSize(memFree));
tileCache = CacheBuilder.
newBuilder().
maximumSize(maxSize).
expireAfterWrite(15, TimeUnit.MINUTES).
//recordStats().
expireAfterWrite(7, TimeUnit.MINUTES).
maximumWeight(mem/2).
weigher(new Weigher<PointAndName, Raster>() {
@Override
public int weigh(PointAndName key, Raster raster) {
return raster.getWidth()*raster.getHeight() * 3 * 4;
}
}).
build();

} finally {
Expand All @@ -100,14 +96,11 @@ private static void initCache(int tileWidth, int tileHeight) {
}

public OrbitTiledImage2() {

logCacheStats();
}

public OrbitTiledImage2(String filename) throws Exception {
if (logger.isDebugEnabled()) {
if (OrbitTiledImage2.tileCache != null)
logger.trace("cachesize: " + OrbitTiledImage2.tileCache.size());
}
logCacheStats();

this.filename = filename.replaceAll("/data/orbit", "");

Expand All @@ -131,6 +124,15 @@ public OrbitTiledImage2(String filename) throws Exception {
}
}

private static void logCacheStats() {
if (logger.isTraceEnabled()) {
if (OrbitTiledImage2.tileCache != null) {
//logger.trace("cachesize: " + OrbitTiledImage2.tileCache.size() + " stats: " + OrbitTiledImage2.tileCache.stats().toString());
logger.trace("cachesize: " + OrbitTiledImage2.tileCache.size());
}
}
}

/**
* used for classificaiton / analysis
*/
Expand Down Expand Up @@ -231,14 +233,8 @@ public Raster getTile(int tileX, int tileY, double gamma, double contrast, doubl

// re-init cache disabled. Too many problems due to different tile sizes (e.g. overview vs normal)
// -> only init once...
if (useCache && (OrbitTiledImage2.tileCache == null /*|| tileSizeChanged(tile.getWidth(),tile.getHeight())*/)) {
// System.out.println("reason for init: useCache="+useCache+"; cache="+OrbitTiledImage2.tileCache);
// if (OrbitTiledImage2.tileCache!=null) {
// System.out.println("width="+OrbitTiledImage2.cacheTileWidth.get()+":"+tile.getWidth());
// System.out.println("height="+OrbitTiledImage2.cacheTileHeight.get()+":"+tile.getHeight());
// }

initCache(tile.getWidth(), tile.getHeight());
if (useCache && (OrbitTiledImage2.tileCache == null)) {
initCache();
}

// the put is a "read" method because the cache is not rebuild (and put/get is threadsafe)
Expand All @@ -254,24 +250,7 @@ public Raster getTile(int tileX, int tileY, double gamma, double contrast, doubl
return tile;
}

/**
* Checks if the tilesize is different than the cache assumes (for max cache size computation).
* Workaround for LocalImageProvider: here TILE_SIZE_DEFAULT is assumed for tileSize, even if certain levels (e.g. overview plane) will have a different size.
* This is to avoid unnecessary cache-recreations.
* @param tileWidth
* @param tileHeight
* @return
*/
private boolean tileSizeChanged(int tileWidth, int tileHeight) {
if (DALConfig.isLocalImageProvider()) {
tileWidth = OrbitUtils.TILE_SIZE_DEFAULT;
tileHeight = OrbitUtils.TILE_SIZE_DEFAULT;
}
boolean sizeChanged = OrbitTiledImage2.cacheTileWidth.get() != tileWidth || OrbitTiledImage2.cacheTileHeight.get() != tileHeight;
return sizeChanged;
}



public static BufferedImage createImage(Raster r, BufferedImage bi, SampleModel sampleModel, ColorModel colorModel) {
if (bi != null) return bi;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import java.util.List;

public class OrbitUtils {
// label: OrbitImageAnalysis264
// label: OrbitImageAnalysis265
public static final String VERSION_STR = getVersion() + (ScaleoutMode.SCALEOUTMODE.get() ? "G" : "") + (OrbitUtils.DEVELOPMENTMODE ? " DEVELOPMENT" : "");
public static final boolean DEVELOPMENTMODE = true;
public static final boolean DEVELOPMENTMODE = false;
public static final boolean TILEMODE = false;
public static final boolean OFFLINE_MODE = false;
public static final boolean DARKUI = true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.64
2.65

0 comments on commit 7629df0

Please sign in to comment.