ini.trakem2.persistence
Class Loader

java.lang.Object
  extended by ini.trakem2.persistence.Loader
Direct Known Subclasses:
DBLoader, FSLoader

public abstract class Loader
extends java.lang.Object

Handle all data-related issues with a virtualization engine, including load/unload and saving, saving as and overwriting.


Nested Class Summary
protected  class Loader.ImageLoadingLock
           
 
Field Summary
static int AREA_AVERAGING
           
static int BICUBIC
           
static int BILINEAR
           
protected  boolean changes
          Keep track of whether there are any unsaved changes.
protected  java.lang.Object db_lock
           
static int ERROR_PATH_NOT_FOUND
           
static int GAUSSIAN
           
static java.awt.image.IndexColorModel GRAY_LUT
          Whether incremental garbage collection is enabled.
protected  java.util.Set<Displayable> hs_unloadable
           
protected  Cache mawts
           
protected  int MAX_RETRIES
           
static long MIN_FREE_BYTES
          The minimal number of memory bytes that should always be free.
protected  boolean mipmaps_regen
          If mipmaps regeneration is enabled or not.
static java.lang.String[] modes
           
static int NEAREST_NEIGHBOR
           
static java.awt.image.BufferedImage NOT_FOUND
           
protected  ij.io.Opener opener
           
static int PREPROCESSED
           
static java.awt.image.BufferedImage REGENERATING
           
protected static java.lang.Runtime RUNTIME
           
protected static java.util.Vector<Loader> v_loaders
           
 
Constructor Summary
protected Loader()
           
 
Method Summary
 void addCrossLink(long project_id, long id1, long id2)
           
 void addedPatchFrom(java.lang.String path, Patch patch)
          Subclasses can override this method to register the URL of the imported image.
 void addJob(Bureaucrat burro)
          Adds a new job to monitor.
 Patch addNewImage(ij.ImagePlus imp)
           
 Patch addNewImage(ij.ImagePlus imp, double x, double y)
          Mipmaps for this image are generated asynchronously.
abstract  boolean addToDatabase(DBObject ob)
           
 void adjustChannels(Patch p, int old_channels)
           
 TemplateThing askForXMLTemplate(Project project)
          Ask for the user to provide a template XML file to extract a root TemplateThing.
 void cache(Displayable d, ij.ImagePlus imp)
          Add to the cache, or if already there, make it be the last (to be flushed the last).
 void cache(Patch p, ij.ImagePlus imp)
           
 void cacheAWT(long id, java.awt.Image awt)
           
 void cacheImagePlus(long id, ij.ImagePlus imp)
          Cache any ImagePlus, as long as a unique id is assigned to it there won't be problems; use getNextId to obtain a unique id.
static boolean canReadAndWriteTo(java.lang.String dir)
           
 boolean checkMipMapFileExists(Patch p, double magnification)
          Does nothing and returns false unless overriden.
 void commitLargeUpdate()
           
static long computeDesirableMinFreeBytes()
          150 Mb per processor, which is ~2x 67 Mb, the size of a 32-bit 4096x4096 image.
protected static long countObjects(LayerSet ls)
           
protected static java.awt.image.BufferedImage createARGBImage(int width, int height, int[] pix)
           
<I> ij.ImagePlus
createFlyThrough(java.util.List<? extends Region<I>> regions, double magnification, int type, java.lang.String dir)
          Returns an ImageStack, one slice per region.
<I> ij.ImagePlus
createLazyFlyThrough(java.util.List<? extends Region<I>> regions, double magnification, int type, Displayable active)
          Each slice is generated on demand, one slice per Region instance.
protected  java.io.InputStream createZippedStream(ij.ImagePlus imp)
          Returns the ImagePlus as a zipped InputStream of bytes; the InputStream has to be closed by whoever is calling this method.
static void debug()
           
 void decache(ij.ImagePlus imp)
          Throw away all awts that depend on this image, so that they will be recreated next time they are needed.
 void decacheAWT(long id)
          Removes from the cache all awt images bond to the given id.
 void decacheImagePlus(long id)
           
 void decacheImagePlus(long[] id)
           
 java.lang.Object deserialize(java.lang.String path)
          Attempts to find a file containing a serialized object.
 void destroy()
          Release all memory and unregister itself.
static void destroyPreloader(ControlWindow master)
           
 void doGUILater(boolean swing, java.lang.Runnable fn)
          Execute a GUI-related task later, in the event dispatch thread context if @param swing is true.
<T> java.util.concurrent.Future<T>
doLater(java.util.concurrent.Callable<T> fn)
           
protected static int[] embedAlpha(int[] pix, byte[] alpha)
          Embed the alpha-byte into an int[], changes the int[] in place and returns it
protected static int[] embedAlpha(int[] pix, byte[] alpha, byte[] outside)
           
 Bureaucrat enhanceContrast(java.util.Collection<Displayable> patches, Patch reference)
          Homogenize contrast for all patches, optionally using the @param reference Patch (can be null).
 Bureaucrat enhanceContrast(java.util.Collection<Layer> layers)
          Homogenize contrast layer-wise, for all given layers.
protected static boolean enoughFreeMemory(long n_bytes)
          Measure whether there are at least 'n_bytes' free.
 long estimateImageFileSize(Patch p, int level)
           
protected  java.lang.String export(Project project, java.io.File fxml)
           
protected  java.lang.String export(Project project, java.io.File fxml, boolean export_images)
          Exports the project and its images (optional); if export_images is true, it will be asked for confirmation anyway -beware: for FSLoader, images are not exported since it doesn't own them; only their path.
 java.lang.String exportImage(Patch patch, ij.ImagePlus imp, java.lang.String path, boolean overwrite)
          Returns the path to the saved image, or null if not saved.
 java.lang.String exportImage(Patch patch, java.lang.String path, boolean overwrite)
           
abstract  java.awt.geom.Area fetchArea(long area_list_id, long layer_id)
           
 java.awt.Image fetchAWTImage(Patch p, int level, int max_level)
           
abstract  java.util.ArrayList<?> fetchBallPoints(long id)
           
abstract  double[][][] fetchBezierArrays(long id)
           
 java.awt.Image fetchDataImage(Patch p, double mag)
          Calls fetchImage(p, mag) unless overriden.
 java.awt.Image fetchImage(Patch p)
           
 java.awt.Image fetchImage(Patch p, double mag)
          Fetch a suitable awt.Image for the given magnification.
 ij.process.ByteProcessor fetchImageMask(Patch p)
          Returns null.
abstract  ij.ImagePlus fetchImagePlus(Patch p)
           
 ij.ImagePlus fetchImagePlus(Stack p)
           
 ij.process.ImageProcessor fetchImageProcessor(Patch p)
          Returns null unless overriden.
abstract  java.lang.Object[] fetchLabel(DLabel label)
           
protected  java.awt.Image fetchMipMapAWT(Patch patch, int level, long n_bytes)
          Does nothing and returns null unless overriden.
abstract  ij.ImagePlus fetchOriginal(Patch patch)
          Used for the revert command.
abstract  java.util.ArrayList<?> fetchPipePoints(long id)
           
static void flush(ij.ImagePlus imp)
          Workaround for ImageJ's ImagePlus.flush() method which calls the System.gc() unnecessarily.
A null pointer as argument is accepted.
 void flushMipMaps(boolean forget_dir_mipmaps)
          Does nothing unless overriden.
 void flushMipMaps(long id)
          Does nothing unless overriden.
 Bureaucrat generateLayerMipMaps(Layer[] la, int starting_level)
          Does nothing unless overriden.
 Bureaucrat generateMipMaps(java.util.ArrayList<Displayable> al)
          Returns generateMipMaps(al, false).
 Bureaucrat generateMipMaps(java.util.ArrayList<Displayable> al, boolean overwrite)
          Does nothing and returns null unless overriden.
protected  boolean generateMipMaps(Patch patch)
          Does nothing and returns false unless overriden.
 java.lang.String getAbsolutePath(Patch patch)
          Returns null unless overriden.
 java.lang.String getAlphaPath(Patch p)
           
 java.awt.Image getCached(long id, int level)
           
 java.awt.Image getCachedAWT(long id, int level)
           
 java.awt.Image getCachedClosestAboveImage(Patch p, double mag)
          Above or equal in size.
 java.awt.Image getCachedClosestBelowImage(Patch p, double mag)
          Below, not equal.
 ij.ImagePlus getCachedImagePlus(long id)
          Simply reads from the cache, does no reloading at all.
 int getClosestMipMapLevel(Patch patch, int level, int max_level)
          Does nothing and returns zero unless overriden.
static long getCurrentMemory()
           
 java.awt.Dimension getDimensions(Patch p)
           
static java.awt.Dimension getDimensions(java.lang.String path)
          Read out the width,height of an image using LOCI BioFormats.
 java.lang.String getFileName(Patch p)
          Equivalent to File.getName(), but subtracts the slice info from it if any.
 java.awt.Image getFlatAWTImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, java.util.List<? extends Displayable> al_displ, boolean quality, java.awt.Color background)
           
 java.awt.Image getFlatAWTImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, java.util.List<? extends Displayable> al_displ, boolean quality, java.awt.Color background, Displayable active)
           
 ij.ImagePlus getFlatImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, boolean quality)
           
 ij.ImagePlus getFlatImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, java.util.List<? extends Displayable> al_displ)
           
 ij.ImagePlus getFlatImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, java.util.List<? extends Displayable> al_displ, boolean quality)
           
 ij.ImagePlus getFlatImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, java.util.List<? extends Displayable> al_displ, boolean quality, java.awt.Color background)
          Returns a screenshot of the given layer for the given magnification and srcRect.
 ij.ImagePlus getFlatImage(Layer layer, java.awt.Rectangle srcRect_, double scale, int c_alphas, int type, java.lang.Class<?> clazz, java.util.List<? extends Displayable> al_displ, boolean quality, java.awt.Color background, Displayable active)
           
 ij.ImagePlus getFlatImage(Selection selection, double scale, int c_alphas, int type, boolean quality, java.awt.Color background)
           
static int getHighestMipMapLevel(double size)
           
static int getHighestMipMapLevel(Patch p)
          Returns the highest mipmap level for which a mipmap image may have been generated given the dimensions of the Patch.
 java.lang.String getImageFilePath(Patch p)
          Returns null unless overriden.
 java.lang.String getImageStorageFolder()
           
protected  java.lang.String getInternalFileName(Patch p)
          Equivalent to File.getName(), does not subtract the slice info from it.
 javax.swing.JPopupMenu getJobsPopup(Display display)
           
 int getMipMapFormat()
          Does nothing unless overriden.
static int getMipMapLevel(double mag, double size)
          Transform mag to nearest scale level that delivers an equally sized or larger image.
Requires 0 < mag <= 1.0
Returns -1 if the magnification is NaN or negative or zero.
As explanation:
mag = 1 / Math.pow(2, level)
so that 100% is 0, 50% is 1, 25% is 2, and so on, but represented in values between 0 and 1.
 java.lang.String getMipMapsFolder()
          Returns null unless overriden.
static int getMode(java.lang.String mode)
           
abstract  long getNextId()
          Retrieve next id from a sequence for a new DBObject to be added.
 long getNextTempId()
          Retrieve next id from a sequence for a temporary Object to be added.
protected  Loader.ImageLoadingLock getOrMakeImageLoadingLock(long id, int level)
           
protected  Loader.ImageLoadingLock getOrMakeImageLoadingLock(java.lang.String key)
           
 java.lang.String getParentFolder()
          Does nothing unless overriden.
 java.lang.String getPath(Patch patch)
          Returns null unless overriden.
protected  java.util.Map<java.lang.Long,java.lang.String> getPathsCopy()
           
 java.lang.String getPreprocessorScriptPath(Patch p)
           
 java.lang.String getStorageFolder()
          Returns the user's home folder unless overriden.
 java.lang.String getUNUId()
          Get the Universal Near-Unique Id for the project hosted by this loader.
 java.lang.String getUNUIdFolder()
           
protected  void handleCacheError(java.lang.Throwable t)
          Must be called within the context of the db_lock.
 java.lang.String handlePathlessImage(ij.ImagePlus imp)
           
 boolean hasChanges()
          Whether any changes need to be saved.
 Bureaucrat importGrid(Layer layer)
           
 Bureaucrat importGrid(Layer layer, java.lang.String dir)
          Import a grid of images and put them in the layer.
 Bureaucrat importImage(Layer layer, double x, double y, java.lang.String path, boolean synch_mipmap_generation)
          Import an image into the given layer, in a separate task thread.
 Patch importImage(Project project, double x, double y)
           
 Patch importImage(Project project, double x, double y, java.lang.String path, boolean synch_mipmap_generation)
          Import a new image at the given coordinates; does not puts it into any layer, unless it's a stack -in which case importStack is called with the current front layer of the given project as target.
 Bureaucrat importImages(Layer ref_layer)
           
 Bureaucrat importImages(Layer ref_layer, java.lang.String abs_text_file_path_, java.lang.String column_separator_, double layer_thickness_, double calibration_, boolean homogenize_contrast_, float scale_)
          Import images from the given text file, which is expected to contain 4 columns:
- column 1: image file path (if base_dir is not null, it will be prepended)
- column 2: x coord
- column 3: y coord
- column 4: z coord (layer_thickness will be multiplied to it if not zero)
This function implements the "Import from text file" command.
 Bureaucrat importLabelsAsAreaLists(Layer layer)
           
 Bureaucrat importLabelsAsAreaLists(Layer first_layer, java.lang.String path_, double base_x_, double base_y_, float alpha_, boolean add_background_)
          If base_x or base_y are Double.MAX_VALUE, then those values are asked for in a GenericDialog.
 Patch importNextImage(Project project, double x, double y)
           
 Bureaucrat importSequenceAsGrid(Layer layer)
           
 Bureaucrat importSequenceAsGrid(Layer layer, java.lang.String dir)
           
 Bureaucrat importSequenceAsGrid(Layer first_layer, java.lang.String dir, java.lang.String[] image_file_names)
          Import a sequence of images as a grid, and put them in the layer.
 Bureaucrat importStack(Layer first_layer, double x, double y, ij.ImagePlus imp_stack_, boolean ask_for_data, java.lang.String filepath_, boolean one_patch_per_layer_)
          Imports an image stack from a multitiff file and places each slice in the proper layer, creating new layers as it goes.
 Bureaucrat importStack(Layer first_layer, ij.ImagePlus imp_stack_, boolean ask_for_data)
           
 Bureaucrat importStack(Layer first_layer, ij.ImagePlus imp_stack_, boolean ask_for_data, java.lang.String filepath_)
           
protected abstract  Patch importStackAsPatches(Project project, Layer first_layer, double x, double y, ij.ImagePlus stack, boolean as_copy, java.lang.String filepath)
           
protected  Patch importStackAsPatches(Project project, Layer first_layer, ij.ImagePlus stack, boolean as_copy, java.lang.String filepath)
           
 void insertXMLOptions(java.lang.StringBuilder sb_body, java.lang.String indent)
           
 boolean isAsynchronous()
          Test whether this Loader needs recurrent calls to a "save" of some sort, such as for the FSLoader.
 boolean isCached(Patch p, double mag)
          Returns true if there is a cached awt image for the given mag and Patch id.
 boolean isImagePlusCached(Patch p)
           
 boolean isMipMapsRegenerationEnabled()
          Whether mipmaps should be generated.
static boolean isSignalImage(java.awt.Image awt)
          Returns true if the awt is a signaling image like NOT_FOUND or REGENERATING.
 boolean isSnapPaintable(long id)
          Check if an awt exists to paint as a snap.
 boolean isUnloadable(Displayable p)
           
protected  void makeAllPathsRelativeTo(java.lang.String xml_path, Project project)
           
 ij.process.ImageProcessor makeFlatImage(int type, Layer layer, java.awt.Rectangle srcRect, double scale, java.util.ArrayList<Patch> patches, java.awt.Color background)
          Creates an ImageProcessor of the specified type.
 Bureaucrat makeFlatImage(Layer[] layer, java.awt.Rectangle srcRect, double scale, int c_alphas, int type, boolean force_to_file, boolean quality)
           
 Bureaucrat makeFlatImage(Layer[] layer, java.awt.Rectangle srcRect, double scale, int c_alphas, int type, boolean force_to_file, boolean quality, java.awt.Color background)
          If the srcRect is null, makes a flat 8-bit or RGB image of the entire layer.
static java.awt.image.IndexColorModel makeGrayLut()
           
protected  java.lang.String makePatchesDir(java.io.File fxml)
           
 Bureaucrat makePrescaledTiles(Layer[] layer, java.lang.Class<?> clazz, java.awt.Rectangle srcRect, double max_scale_, int c_alphas, int type)
           
 Bureaucrat makePrescaledTiles(Layer[] layer, java.lang.Class<?> clazz, java.awt.Rectangle srcRect, double max_scale_, int c_alphas, int type, java.lang.String target_dir, boolean from_original_images)
          Generate 256x256 tiles, as many as necessary, to cover the given srcRect, starting at max_scale.
 java.lang.String makeProjectName()
           
 java.lang.String makeRelativePath(java.lang.String path)
          Returns @param path unless overriden.
 Bureaucrat maskBorders(java.util.Collection<Displayable> patches, int left, int top, int right, int bottom)
          Make the border have an alpha of zero.
 java.util.ArrayList<java.util.concurrent.Future<?>> maskBorders(int left, int top, int right, int bottom, java.util.Collection<Displayable> patches)
          Make the border have an alpha of zero.
 Bureaucrat maskBordersLayerWise(java.util.Collection<Layer> layers, int left, int top, int right, int bottom)
          Make the border have an alpha of zero.
static double maxDim(Displayable d)
           
static long measureSize(ij.ImagePlus imp)
           
protected  ij.ImagePlus openImage(java.lang.String path)
          Fixes paths before presenting them to the file system, in an OS-dependent manner.
protected  ij.ImagePlus openImagePlus(java.lang.String path)
          Tries up to MAX_RETRIES to open an ImagePlus at path if there is an OutOfMemoryError.
 ij.ImagePlus openStack()
          A dialog to open a stack, making sure there is enough memory for it.
static void preload(java.util.Collection<Patch> patches, double mag, boolean repaint)
          Disabled when on low memory condition, or when num_preloader_threads is smaller than 1.
static java.util.concurrent.FutureTask<java.awt.Image> preload(Patch p, double mag, boolean repaint)
          Returns null when on low memory condition.
protected  void preProcess(Patch p, ij.ImagePlus imp, long image_n_bytes)
           
 void printCache()
           
static void printCaches()
           
static void printCacheStatus()
           
static void printMemState()
           
 void queueForMipmapRemoval(Patch p, boolean yes)
          Does nothing unless overriden.
 void quitJob(java.lang.String name)
          Names as generated for popup menu items in the getJobsPopup method.
 void recoverOOME()
          Recover from an OutOfMemoryError: release 1/2 of all memory AND execute the garbage collector.
 void recreateBuckets(java.util.Collection<Layer> col)
           
 void recreateBuckets(Layer[] la)
          Recreate buckets for each Layer, one thread per layer, in as many threads as CPUs.
 Bureaucrat regenerateMipMaps(java.util.Collection<? extends Displayable> patches)
          Does nothing and returns null unless overriden.
 java.util.concurrent.Future<java.lang.Boolean> regenerateMipMaps(Patch patch)
          Does nothing and returns null unless overriden.
 void releaseAll()
          Empties the caches.
static void releaseAllCaches()
           
 long releaseMemory(long min_free_bytes)
          Free up to @param min_free_bytes.
protected  long releaseMemory2()
          Deprecated. 
 boolean releaseToFit(int width, int height, int type, float factor)
          Ensure there is at least width * height * factor * type{8-bit: 1; 16-bit: 3; 32-bit or RGB: 4}
 boolean releaseToFit(long n_bytes)
          Release enough memory so that as many bytes as passed as argument can be loaded.
 boolean removeAlphaMask(Patch p)
          Does nothing unless overriden.
 boolean removeCrossLink(long id1, long id2)
          Remove a link between two objects.
abstract  boolean removeFromDatabase(DBObject ob)
           
 void removeFromUnloadable(Displayable p)
           
protected  void removeImageLoadingLock(Loader.ImageLoadingLock pl)
           
 void removeJob(Bureaucrat burro)
           
 java.util.concurrent.Future<java.lang.Boolean> removeMipMaps(Patch patch)
          Does nothing unless overriden.
protected  void restorePaths(java.util.Map<java.lang.Long,java.lang.String> copy, java.lang.String mipmaps_folder, java.lang.String storage_folder)
           
 void rollback()
           
 java.lang.String save(Project project)
          Calls saveAs() unless overriden.
 java.lang.String saveAs(Project project)
          Save the project under a different name by choosing from a dialog, and exporting all images (will popup a YesNoCancelDialog to confirm exporting images.)
 java.lang.String saveAs(Project project, java.lang.String xmlpath, boolean export_images)
          Exports to an XML file chosen by the user in a dialog if @param xmlpath is null.
 java.lang.String saveAs(java.lang.String path, boolean overwrite)
          Meant to be overriden -- as is, will call saveAs(project, path, export_images = getClass() != FSLoader.class ).
 Bureaucrat saveTask(Project project, java.lang.String command)
          Run save or saveAs in a Bureaucract that blocks user input to the project being saved.
static ij.process.ImageProcessor scaleImage(ij.ImagePlus imp, double mag, boolean quality)
           
static ij.process.ImageProcessor scaleImage(ij.ImagePlus imp, int level, boolean quality)
           
 boolean serialize(java.lang.Object ob, java.lang.String path)
          Serializes the given object into the path.
 void setChanged(boolean changed)
           
static void setDesirableMinFreeBytes(long n_bytes)
          If the number of minimally free memory bytes (100 Mb times the number of CPU cores) is too low for your (giant) images, set it to a larger value here.
static void setHeapFraction(float fraction)
           
 java.lang.String setImageFile(Patch p, ij.ImagePlus imp)
          Does nothing and returns null unless overridden.
 Bureaucrat setMinAndMax(java.util.Collection<? extends Displayable> patches, double min, double max)
           
 boolean setMipMapFormat(int format)
          Does nothing unless overriden.
 void setMipMapsRegeneration(boolean b)
           
 void setPreprocessorScriptPath(Patch p, java.lang.String path)
          Set a preprocessor script that will be executed on the ImagePlus of the Patch when loading it, before TrakEM2 sees it at all.
 void setPreprocessorScriptPathSilently(Patch p, java.lang.String path)
          Set a preprocessor script that will be executed on the ImagePlus of the Patch when loading it, before TrakEM2 sees it at all.
 void setupMenuItems(javax.swing.JMenu menu, Project project)
          Does nothing unless overriden.
static void setupPreloader(ControlWindow master)
          Uses maximum 4 concurrent threads: higher thread number does not improve performance.
static void setupPreloaderThreads(int count)
          Set to zero to disable; maximum recommended is 4 if you have more than 4 CPUs.
 void startLargeUpdate()
           
 void storeAlphaMask(Patch p, ij.process.ByteProcessor fp)
          Does nothing unless overriden.
 void tagForMipmapRemoval(Patch p, boolean yes)
          Does nothing unless overriden.
protected  ij.ImagePlus unzipTiff(java.io.InputStream i_stream, java.lang.String title)
          Retrieves a zipped ImagePlus from the given InputStream.
abstract  boolean updateInDatabase(DBObject ob, java.util.Set<java.lang.String> keys)
           
abstract  boolean updateInDatabase(DBObject ob, java.lang.String key)
           
 Bureaucrat updateMipMapsFormat(int old_format, int new_format)
          Does nothing unless overriden.
 boolean usesMipMapsFolder()
          Does nothing and returns false unless overriden.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db_lock

protected final java.lang.Object db_lock

opener

protected ij.io.Opener opener

MAX_RETRIES

protected final int MAX_RETRIES
See Also:
Constant Field Values

changes

protected boolean changes
Keep track of whether there are any unsaved changes.


ERROR_PATH_NOT_FOUND

public static final int ERROR_PATH_NOT_FOUND
See Also:
Constant Field Values

GRAY_LUT

public static final java.awt.image.IndexColorModel GRAY_LUT
Whether incremental garbage collection is enabled.


hs_unloadable

protected final java.util.Set<Displayable> hs_unloadable

NOT_FOUND

public static final java.awt.image.BufferedImage NOT_FOUND

REGENERATING

public static final java.awt.image.BufferedImage REGENERATING

mawts

protected final transient Cache mawts

v_loaders

protected static transient java.util.Vector<Loader> v_loaders

RUNTIME

protected static final java.lang.Runtime RUNTIME

MIN_FREE_BYTES

public static long MIN_FREE_BYTES
The minimal number of memory bytes that should always be free.


PREPROCESSED

public static final int PREPROCESSED
See Also:
Constant Field Values

mipmaps_regen

protected boolean mipmaps_regen
If mipmaps regeneration is enabled or not.


NEAREST_NEIGHBOR

public static final int NEAREST_NEIGHBOR
See Also:
Constant Field Values

BILINEAR

public static final int BILINEAR
See Also:
Constant Field Values

BICUBIC

public static final int BICUBIC
See Also:
Constant Field Values

GAUSSIAN

public static final int GAUSSIAN
See Also:
Constant Field Values

AREA_AVERAGING

public static final int AREA_AVERAGING
See Also:
Constant Field Values

modes

public static final java.lang.String[] modes
Constructor Detail

Loader

protected Loader()
Method Detail

makeGrayLut

public static final java.awt.image.IndexColorModel makeGrayLut()

isSignalImage

public static boolean isSignalImage(java.awt.Image awt)
Returns true if the awt is a signaling image like NOT_FOUND or REGENERATING.


setHeapFraction

public static final void setHeapFraction(float fraction)

debug

public static void debug()

destroy

public void destroy()
Release all memory and unregister itself. Child Loader classes should call this method in their destroy() methods.


getNextId

public abstract long getNextId()
Retrieve next id from a sequence for a new DBObject to be added.


getNextTempId

public long getNextTempId()
Retrieve next id from a sequence for a temporary Object to be added. Is negative.


askForXMLTemplate

public TemplateThing askForXMLTemplate(Project project)
Ask for the user to provide a template XML file to extract a root TemplateThing.


startLargeUpdate

public void startLargeUpdate()

commitLargeUpdate

public void commitLargeUpdate()

rollback

public void rollback()

fetchBezierArrays

public abstract double[][][] fetchBezierArrays(long id)

fetchPipePoints

public abstract java.util.ArrayList<?> fetchPipePoints(long id)

fetchBallPoints

public abstract java.util.ArrayList<?> fetchBallPoints(long id)

fetchArea

public abstract java.awt.geom.Area fetchArea(long area_list_id,
                                             long layer_id)

addToDatabase

public abstract boolean addToDatabase(DBObject ob)

updateInDatabase

public abstract boolean updateInDatabase(DBObject ob,
                                         java.lang.String key)

updateInDatabase

public abstract boolean updateInDatabase(DBObject ob,
                                         java.util.Set<java.lang.String> keys)

removeFromDatabase

public abstract boolean removeFromDatabase(DBObject ob)

addCrossLink

public void addCrossLink(long project_id,
                         long id1,
                         long id2)

removeCrossLink

public boolean removeCrossLink(long id1,
                               long id2)
Remove a link between two objects. Returns true always in this empty method.


cache

public void cache(Displayable d,
                  ij.ImagePlus imp)
Add to the cache, or if already there, make it be the last (to be flushed the last).


cache

public void cache(Patch p,
                  ij.ImagePlus imp)

cacheImagePlus

public void cacheImagePlus(long id,
                           ij.ImagePlus imp)
Cache any ImagePlus, as long as a unique id is assigned to it there won't be problems; use getNextId to obtain a unique id.


decacheImagePlus

public void decacheImagePlus(long id)

decacheImagePlus

public void decacheImagePlus(long[] id)

unzipTiff

protected ij.ImagePlus unzipTiff(java.io.InputStream i_stream,
                                 java.lang.String title)
Retrieves a zipped ImagePlus from the given InputStream. The stream is not closed and must be closed elsewhere. No error checking is done as to whether the stream actually contains a zipped tiff file.


getCurrentMemory

public static final long getCurrentMemory()

enoughFreeMemory

protected static final boolean enoughFreeMemory(long n_bytes)
Measure whether there are at least 'n_bytes' free.


releaseToFit

public final boolean releaseToFit(int width,
                                  int height,
                                  int type,
                                  float factor)
Ensure there is at least width * height * factor * type{8-bit: 1; 16-bit: 3; 32-bit or RGB: 4}

Returns:
true if that much was released. If that much was already free, it will return false.

releaseToFit

public final boolean releaseToFit(long n_bytes)
Release enough memory so that as many bytes as passed as argument can be loaded.

Returns:
true if that many have been released; but if less needed to be released, it will return false.

printCacheStatus

public static void printCacheStatus()

printCache

public void printCache()

printCaches

public static void printCaches()

computeDesirableMinFreeBytes

public static long computeDesirableMinFreeBytes()
150 Mb per processor, which is ~2x 67 Mb, the size of a 32-bit 4096x4096 image.


setDesirableMinFreeBytes

public static void setDesirableMinFreeBytes(long n_bytes)
If the number of minimally free memory bytes (100 Mb times the number of CPU cores) is too low for your (giant) images, set it to a larger value here.


measureSize

public static final long measureSize(ij.ImagePlus imp)

releaseMemory

public final long releaseMemory(long min_free_bytes)
Free up to @param min_free_bytes. Locks on db_lock.


releaseMemory2

@Deprecated
protected final long releaseMemory2()
Deprecated. 


releaseAllCaches

public static void releaseAllCaches()

releaseAll

public void releaseAll()
Empties the caches.


decacheAWT

public void decacheAWT(long id)
Removes from the cache all awt images bond to the given id.


getCachedAWT

public java.awt.Image getCachedAWT(long id,
                                   int level)

cacheAWT

public void cacheAWT(long id,
                     java.awt.Image awt)

getMipMapLevel

public static final int getMipMapLevel(double mag,
                                       double size)
Transform mag to nearest scale level that delivers an equally sized or larger image.
Requires 0 < mag <= 1.0
Returns -1 if the magnification is NaN or negative or zero.
As explanation:
mag = 1 / Math.pow(2, level)
so that 100% is 0, 50% is 1, 25% is 2, and so on, but represented in values between 0 and 1.


maxDim

public static final double maxDim(Displayable d)

isImagePlusCached

public boolean isImagePlusCached(Patch p)

isCached

public boolean isCached(Patch p,
                        double mag)
Returns true if there is a cached awt image for the given mag and Patch id.


getCached

public java.awt.Image getCached(long id,
                                int level)

getCachedClosestAboveImage

public java.awt.Image getCachedClosestAboveImage(Patch p,
                                                 double mag)
Above or equal in size.


getCachedClosestBelowImage

public java.awt.Image getCachedClosestBelowImage(Patch p,
                                                 double mag)
Below, not equal.


getOrMakeImageLoadingLock

protected final Loader.ImageLoadingLock getOrMakeImageLoadingLock(long id,
                                                                  int level)

getOrMakeImageLoadingLock

protected final Loader.ImageLoadingLock getOrMakeImageLoadingLock(java.lang.String key)

removeImageLoadingLock

protected final void removeImageLoadingLock(Loader.ImageLoadingLock pl)

fetchDataImage

public java.awt.Image fetchDataImage(Patch p,
                                     double mag)
Calls fetchImage(p, mag) unless overriden.


fetchImage

public java.awt.Image fetchImage(Patch p)

fetchImage

public java.awt.Image fetchImage(Patch p,
                                 double mag)
Fetch a suitable awt.Image for the given magnification. If the mag is bigger than 1.0, it will return as if was 1.0. Will return Loader.NOT_FOUND if, err, not found (probably an Exception will print along).


fetchAWTImage

public final java.awt.Image fetchAWTImage(Patch p,
                                          int level,
                                          int max_level)

fetchImageMask

public ij.process.ByteProcessor fetchImageMask(Patch p)
Returns null.


getAlphaPath

public java.lang.String getAlphaPath(Patch p)

storeAlphaMask

public void storeAlphaMask(Patch p,
                           ij.process.ByteProcessor fp)
Does nothing unless overriden.


removeAlphaMask

public boolean removeAlphaMask(Patch p)
Does nothing unless overriden.


getCachedImagePlus

public ij.ImagePlus getCachedImagePlus(long id)
Simply reads from the cache, does no reloading at all. If the ImagePlus is not found in the cache, it returns null and the burden is on the calling method to do reconstruct it if necessary. This is intended for the LayerStack.


fetchImagePlus

public abstract ij.ImagePlus fetchImagePlus(Patch p)

fetchImageProcessor

public ij.process.ImageProcessor fetchImageProcessor(Patch p)
Returns null unless overriden.


fetchImagePlus

public ij.ImagePlus fetchImagePlus(Stack p)

fetchLabel

public abstract java.lang.Object[] fetchLabel(DLabel label)

createZippedStream

protected java.io.InputStream createZippedStream(ij.ImagePlus imp)
                                          throws java.lang.Exception
Returns the ImagePlus as a zipped InputStream of bytes; the InputStream has to be closed by whoever is calling this method.

Throws:
java.lang.Exception

openStack

public ij.ImagePlus openStack()
A dialog to open a stack, making sure there is enough memory for it.


importSequenceAsGrid

public Bureaucrat importSequenceAsGrid(Layer layer)

importSequenceAsGrid

public Bureaucrat importSequenceAsGrid(Layer layer,
                                       java.lang.String dir)

importSequenceAsGrid

public Bureaucrat importSequenceAsGrid(Layer first_layer,
                                       java.lang.String dir,
                                       java.lang.String[] image_file_names)
Import a sequence of images as a grid, and put them in the layer. If the directory (@param dir) is null, it'll be asked for. The image_file_names can be null, and in any case it's only the names, not the paths.


importGrid

public Bureaucrat importGrid(Layer layer)

importGrid

public Bureaucrat importGrid(Layer layer,
                             java.lang.String dir)
Import a grid of images and put them in the layer. If the directory (@param dir) is null, it'll be asked for.


importImages

public Bureaucrat importImages(Layer ref_layer)

importImages

public Bureaucrat importImages(Layer ref_layer,
                               java.lang.String abs_text_file_path_,
                               java.lang.String column_separator_,
                               double layer_thickness_,
                               double calibration_,
                               boolean homogenize_contrast_,
                               float scale_)
Import images from the given text file, which is expected to contain 4 columns:
- column 1: image file path (if base_dir is not null, it will be prepended)
- column 2: x coord
- column 3: y coord
- column 4: z coord (layer_thickness will be multiplied to it if not zero)
This function implements the "Import from text file" command. Layers will be automatically created as needed inside the LayerSet to which the given ref_layer belongs..
The text file can contain comments that start with the # sign.
Images will be imported in parallel, using as many cores as your machine has.

Parameters:
calibration_ - transforms the read coordinates into pixel coordinates, including x,y,z, and layer thickness.
scale_ - Between 0 and 1. When lower than 1, a preprocessor script is created for the imported images, to scale them down.

importLabelsAsAreaLists

public Bureaucrat importLabelsAsAreaLists(Layer layer)

importLabelsAsAreaLists

public Bureaucrat importLabelsAsAreaLists(Layer first_layer,
                                          java.lang.String path_,
                                          double base_x_,
                                          double base_y_,
                                          float alpha_,
                                          boolean add_background_)
If base_x or base_y are Double.MAX_VALUE, then those values are asked for in a GenericDialog.


recreateBuckets

public void recreateBuckets(java.util.Collection<Layer> col)

recreateBuckets

public void recreateBuckets(Layer[] la)
Recreate buckets for each Layer, one thread per layer, in as many threads as CPUs.


fetchOriginal

public abstract ij.ImagePlus fetchOriginal(Patch patch)
Used for the revert command.


makeFlatImage

public Bureaucrat makeFlatImage(Layer[] layer,
                                java.awt.Rectangle srcRect,
                                double scale,
                                int c_alphas,
                                int type,
                                boolean force_to_file,
                                boolean quality)

makeFlatImage

public Bureaucrat makeFlatImage(Layer[] layer,
                                java.awt.Rectangle srcRect,
                                double scale,
                                int c_alphas,
                                int type,
                                boolean force_to_file,
                                boolean quality,
                                java.awt.Color background)
If the srcRect is null, makes a flat 8-bit or RGB image of the entire layer. Otherwise just of the srcRect. Checks first for enough memory and frees some if feasible.


getFlatImage

public ij.ImagePlus getFlatImage(Layer layer,
                                 java.awt.Rectangle srcRect_,
                                 double scale,
                                 int c_alphas,
                                 int type,
                                 java.lang.Class<?> clazz,
                                 boolean quality)

getFlatImage

public ij.ImagePlus getFlatImage(Layer layer,
                                 java.awt.Rectangle srcRect_,
                                 double scale,
                                 int c_alphas,
                                 int type,
                                 java.lang.Class<?> clazz,
                                 java.util.List<? extends Displayable> al_displ)

getFlatImage

public ij.ImagePlus getFlatImage(Layer layer,
                                 java.awt.Rectangle srcRect_,
                                 double scale,
                                 int c_alphas,
                                 int type,
                                 java.lang.Class<?> clazz,
                                 java.util.List<? extends Displayable> al_displ,
                                 boolean quality)

getFlatImage

public ij.ImagePlus getFlatImage(Selection selection,
                                 double scale,
                                 int c_alphas,
                                 int type,
                                 boolean quality,
                                 java.awt.Color background)

getFlatImage

public ij.ImagePlus getFlatImage(Layer layer,
                                 java.awt.Rectangle srcRect_,
                                 double scale,
                                 int c_alphas,
                                 int type,
                                 java.lang.Class<?> clazz,
                                 java.util.List<? extends Displayable> al_displ,
                                 boolean quality,
                                 java.awt.Color background)
Returns a screenshot of the given layer for the given magnification and srcRect. Returns null if the was not enough memory to create it.

Parameters:
al_displ - The Displayable objects to paint. If null, all those matching Class clazz are included. If the 'quality' flag is given, then the flat image is created at a scale of 1.0, and later scaled down using the Image.getScaledInstance method with the SCALE_AREA_AVERAGING flag.

getFlatImage

public ij.ImagePlus getFlatImage(Layer layer,
                                 java.awt.Rectangle srcRect_,
                                 double scale,
                                 int c_alphas,
                                 int type,
                                 java.lang.Class<?> clazz,
                                 java.util.List<? extends Displayable> al_displ,
                                 boolean quality,
                                 java.awt.Color background,
                                 Displayable active)

getFlatAWTImage

public java.awt.Image getFlatAWTImage(Layer layer,
                                      java.awt.Rectangle srcRect_,
                                      double scale,
                                      int c_alphas,
                                      int type,
                                      java.lang.Class<?> clazz,
                                      java.util.List<? extends Displayable> al_displ,
                                      boolean quality,
                                      java.awt.Color background)

getFlatAWTImage

public java.awt.Image getFlatAWTImage(Layer layer,
                                      java.awt.Rectangle srcRect_,
                                      double scale,
                                      int c_alphas,
                                      int type,
                                      java.lang.Class<?> clazz,
                                      java.util.List<? extends Displayable> al_displ,
                                      boolean quality,
                                      java.awt.Color background,
                                      Displayable active)

makeFlatImage

public ij.process.ImageProcessor makeFlatImage(int type,
                                               Layer layer,
                                               java.awt.Rectangle srcRect,
                                               double scale,
                                               java.util.ArrayList<Patch> patches,
                                               java.awt.Color background)
Creates an ImageProcessor of the specified type.


makePrescaledTiles

public Bureaucrat makePrescaledTiles(Layer[] layer,
                                     java.lang.Class<?> clazz,
                                     java.awt.Rectangle srcRect,
                                     double max_scale_,
                                     int c_alphas,
                                     int type)

makePrescaledTiles

public Bureaucrat makePrescaledTiles(Layer[] layer,
                                     java.lang.Class<?> clazz,
                                     java.awt.Rectangle srcRect,
                                     double max_scale_,
                                     int c_alphas,
                                     int type,
                                     java.lang.String target_dir,
                                     boolean from_original_images)
Generate 256x256 tiles, as many as necessary, to cover the given srcRect, starting at max_scale. Designed to be slow but memory-capable. filename = z + "/" + row + "_" + column + "_" + s + ".jpg"; row and column run from 0 to n stepsize 1 that is, row = y / ( 256 * 2^s ) and column = x / ( 256 * 2^s ) z : z-level (slice) x,y: the row and column s: scale, which is 1 / (2^s), in integers: 0, 1, 2 ...  var MAX_S = Math.floor( Math.log( MAX_Y + 1 ) / Math.LN2 ) - Math.floor( Math.log( Y_TILE_SIZE ) / Math.LN2 ) - 1; The module should not be more than 5 At al levels, there should be an even number of rows and columns, except for the coarsest level. The coarsest level should be at least 5x5 tiles. Best results obtained when the srcRect approaches or is a square. Black space will pad the right and bottom edges when the srcRect is not exactly a square. Only the area within the srcRect is ever included, even if actual data exists beyond.

Returns:
The watcher thread, for joining purposes, or null if the dialog is canceled or preconditions are not passed.
Throws:
java.lang.IllegalArgumentException - if the type is not ImagePlus.GRAY8 or Imageplus.COLOR_RGB.

addedPatchFrom

public void addedPatchFrom(java.lang.String path,
                           Patch patch)
Subclasses can override this method to register the URL of the imported image.


importImage

public Bureaucrat importImage(Layer layer,
                              double x,
                              double y,
                              java.lang.String path,
                              boolean synch_mipmap_generation)
Import an image into the given layer, in a separate task thread.


importImage

public Patch importImage(Project project,
                         double x,
                         double y)

importImage

public Patch importImage(Project project,
                         double x,
                         double y,
                         java.lang.String path,
                         boolean synch_mipmap_generation)
Import a new image at the given coordinates; does not puts it into any layer, unless it's a stack -in which case importStack is called with the current front layer of the given project as target. If a path is not provided it will be asked for.


importNextImage

public Patch importNextImage(Project project,
                             double x,
                             double y)

importStack

public Bureaucrat importStack(Layer first_layer,
                              ij.ImagePlus imp_stack_,
                              boolean ask_for_data)

importStack

public Bureaucrat importStack(Layer first_layer,
                              ij.ImagePlus imp_stack_,
                              boolean ask_for_data,
                              java.lang.String filepath_)

importStack

public Bureaucrat importStack(Layer first_layer,
                              double x,
                              double y,
                              ij.ImagePlus imp_stack_,
                              boolean ask_for_data,
                              java.lang.String filepath_,
                              boolean one_patch_per_layer_)
Imports an image stack from a multitiff file and places each slice in the proper layer, creating new layers as it goes. If the given stack is null, popup a file dialog to choose one


handlePathlessImage

public java.lang.String handlePathlessImage(ij.ImagePlus imp)

importStackAsPatches

protected Patch importStackAsPatches(Project project,
                                     Layer first_layer,
                                     ij.ImagePlus stack,
                                     boolean as_copy,
                                     java.lang.String filepath)

importStackAsPatches

protected abstract Patch importStackAsPatches(Project project,
                                              Layer first_layer,
                                              double x,
                                              double y,
                                              ij.ImagePlus stack,
                                              boolean as_copy,
                                              java.lang.String filepath)

export

protected java.lang.String export(Project project,
                                  java.io.File fxml)

export

protected java.lang.String export(Project project,
                                  java.io.File fxml,
                                  boolean export_images)
Exports the project and its images (optional); if export_images is true, it will be asked for confirmation anyway -beware: for FSLoader, images are not exported since it doesn't own them; only their path.


countObjects

protected static long countObjects(LayerSet ls)

save

public java.lang.String save(Project project)
Calls saveAs() unless overriden. Returns full path to the xml file.


saveAs

public java.lang.String saveAs(Project project)
Save the project under a different name by choosing from a dialog, and exporting all images (will popup a YesNoCancelDialog to confirm exporting images.)


saveAs

public java.lang.String saveAs(Project project,
                               java.lang.String xmlpath,
                               boolean export_images)
Exports to an XML file chosen by the user in a dialog if @param xmlpath is null. Images exist already in the file system, so none are exported. Returns the full path to the xml file.


makeAllPathsRelativeTo

protected void makeAllPathsRelativeTo(java.lang.String xml_path,
                                      Project project)

getPathsCopy

protected java.util.Map<java.lang.Long,java.lang.String> getPathsCopy()

restorePaths

protected void restorePaths(java.util.Map<java.lang.Long,java.lang.String> copy,
                            java.lang.String mipmaps_folder,
                            java.lang.String storage_folder)

saveAs

public java.lang.String saveAs(java.lang.String path,
                               boolean overwrite)
Meant to be overriden -- as is, will call saveAs(project, path, export_images = getClass() != FSLoader.class ).


makePatchesDir

protected java.lang.String makePatchesDir(java.io.File fxml)

exportImage

public java.lang.String exportImage(Patch patch,
                                    java.lang.String path,
                                    boolean overwrite)

exportImage

public java.lang.String exportImage(Patch patch,
                                    ij.ImagePlus imp,
                                    java.lang.String path,
                                    boolean overwrite)
Returns the path to the saved image, or null if not saved.


hasChanges

public boolean hasChanges()
Whether any changes need to be saved.


setChanged

public void setChanged(boolean changed)

getPath

public java.lang.String getPath(Patch patch)
Returns null unless overriden. This is intended for FSLoader projects.


getAbsolutePath

public java.lang.String getAbsolutePath(Patch patch)
Returns null unless overriden. This is intended for FSLoader projects.


getImageFilePath

public java.lang.String getImageFilePath(Patch p)
Returns null unless overriden. This is intended for FSLoader projects.


setupMenuItems

public void setupMenuItems(javax.swing.JMenu menu,
                           Project project)
Does nothing unless overriden.


saveTask

public Bureaucrat saveTask(Project project,
                           java.lang.String command)
Run save or saveAs in a Bureaucract that blocks user input to the project being saved.


isAsynchronous

public boolean isAsynchronous()
Test whether this Loader needs recurrent calls to a "save" of some sort, such as for the FSLoader.


decache

public void decache(ij.ImagePlus imp)
Throw away all awts that depend on this image, so that they will be recreated next time they are needed.


preProcess

protected final void preProcess(Patch p,
                                ij.ImagePlus imp,
                                long image_n_bytes)

addJob

public void addJob(Bureaucrat burro)
Adds a new job to monitor.


removeJob

public void removeJob(Bureaucrat burro)

getJobsPopup

public javax.swing.JPopupMenu getJobsPopup(Display display)

quitJob

public void quitJob(java.lang.String name)
Names as generated for popup menu items in the getJobsPopup method. If the name is null, it will cancel the last one. Runs in a separate thread so that it can immediately return.


printMemState

public static final void printMemState()

openImage

protected final ij.ImagePlus openImage(java.lang.String path)
Fixes paths before presenting them to the file system, in an OS-dependent manner.


openImagePlus

protected final ij.ImagePlus openImagePlus(java.lang.String path)
Tries up to MAX_RETRIES to open an ImagePlus at path if there is an OutOfMemoryError.


getInternalFileName

protected final java.lang.String getInternalFileName(Patch p)
Equivalent to File.getName(), does not subtract the slice info from it.


getFileName

public final java.lang.String getFileName(Patch p)
Equivalent to File.getName(), but subtracts the slice info from it if any.


isSnapPaintable

public boolean isSnapPaintable(long id)
Check if an awt exists to paint as a snap.


setMipMapsRegeneration

public void setMipMapsRegeneration(boolean b)

isMipMapsRegenerationEnabled

public boolean isMipMapsRegenerationEnabled()
Whether mipmaps should be generated. This depends on both the internal flag (whether the user wants to use mipmaps) and on whether there is a writable mipmaps folder available.


flushMipMaps

public void flushMipMaps(boolean forget_dir_mipmaps)
Does nothing unless overriden.


flushMipMaps

public void flushMipMaps(long id)
Does nothing unless overriden.


generateMipMaps

protected boolean generateMipMaps(Patch patch)
Does nothing and returns false unless overriden.


removeMipMaps

public java.util.concurrent.Future<java.lang.Boolean> removeMipMaps(Patch patch)
Does nothing unless overriden.


generateMipMaps

public Bureaucrat generateMipMaps(java.util.ArrayList<Displayable> al)
Returns generateMipMaps(al, false).


generateMipMaps

public Bureaucrat generateMipMaps(java.util.ArrayList<Displayable> al,
                                  boolean overwrite)
Does nothing and returns null unless overriden.


usesMipMapsFolder

public boolean usesMipMapsFolder()
Does nothing and returns false unless overriden.


getClosestMipMapLevel

public int getClosestMipMapLevel(Patch patch,
                                 int level,
                                 int max_level)
Does nothing and returns zero unless overriden.


fetchMipMapAWT

protected java.awt.Image fetchMipMapAWT(Patch patch,
                                        int level,
                                        long n_bytes)
Does nothing and returns null unless overriden.


checkMipMapFileExists

public boolean checkMipMapFileExists(Patch p,
                                     double magnification)
Does nothing and returns false unless overriden.


adjustChannels

public void adjustChannels(Patch p,
                           int old_channels)

handleCacheError

protected final void handleCacheError(java.lang.Throwable t)
Must be called within the context of the db_lock.


scaleImage

public static ij.process.ImageProcessor scaleImage(ij.ImagePlus imp,
                                                   double mag,
                                                   boolean quality)

scaleImage

public static ij.process.ImageProcessor scaleImage(ij.ImagePlus imp,
                                                   int level,
                                                   boolean quality)

serialize

public boolean serialize(java.lang.Object ob,
                         java.lang.String path)
Serializes the given object into the path. Returns false on failure.


deserialize

public java.lang.Object deserialize(java.lang.String path)
Attempts to find a file containing a serialized object. Returns null if no suitable file is found, or an error occurs while deserializing.


insertXMLOptions

public void insertXMLOptions(java.lang.StringBuilder sb_body,
                             java.lang.String indent)

enhanceContrast

public Bureaucrat enhanceContrast(java.util.Collection<Layer> layers)
Homogenize contrast layer-wise, for all given layers.


enhanceContrast

public Bureaucrat enhanceContrast(java.util.Collection<Displayable> patches,
                                  Patch reference)
Homogenize contrast for all patches, optionally using the @param reference Patch (can be null).


setMinAndMax

public Bureaucrat setMinAndMax(java.util.Collection<? extends Displayable> patches,
                               double min,
                               double max)

estimateImageFileSize

public long estimateImageFileSize(Patch p,
                                  int level)

flush

public static final void flush(ij.ImagePlus imp)
Workaround for ImageJ's ImagePlus.flush() method which calls the System.gc() unnecessarily.
A null pointer as argument is accepted.


getStorageFolder

public java.lang.String getStorageFolder()
Returns the user's home folder unless overriden.


getImageStorageFolder

public java.lang.String getImageStorageFolder()

getMipMapsFolder

public java.lang.String getMipMapsFolder()
Returns null unless overriden.


addNewImage

public Patch addNewImage(ij.ImagePlus imp)

addNewImage

public Patch addNewImage(ij.ImagePlus imp,
                         double x,
                         double y)
Mipmaps for this image are generated asynchronously.


makeProjectName

public java.lang.String makeProjectName()

setupPreloaderThreads

public static void setupPreloaderThreads(int count)
Set to zero to disable; maximum recommended is 4 if you have more than 4 CPUs.


setupPreloader

public static final void setupPreloader(ControlWindow master)
Uses maximum 4 concurrent threads: higher thread number does not improve performance.


destroyPreloader

public static final void destroyPreloader(ControlWindow master)

preload

public static void preload(java.util.Collection<Patch> patches,
                           double mag,
                           boolean repaint)
Disabled when on low memory condition, or when num_preloader_threads is smaller than 1.


preload

public static final java.util.concurrent.FutureTask<java.awt.Image> preload(Patch p,
                                                                            double mag,
                                                                            boolean repaint)
Returns null when on low memory condition.


getHighestMipMapLevel

public static final int getHighestMipMapLevel(Patch p)
Returns the highest mipmap level for which a mipmap image may have been generated given the dimensions of the Patch. The minimum that this method may return is zero.


getHighestMipMapLevel

public static final int getHighestMipMapLevel(double size)

getMode

public static final int getMode(java.lang.String mode)

generateLayerMipMaps

public Bureaucrat generateLayerMipMaps(Layer[] la,
                                       int starting_level)
Does nothing unless overriden.


recoverOOME

public void recoverOOME()
Recover from an OutOfMemoryError: release 1/2 of all memory AND execute the garbage collector.


canReadAndWriteTo

public static boolean canReadAndWriteTo(java.lang.String dir)

setImageFile

public java.lang.String setImageFile(Patch p,
                                     ij.ImagePlus imp)
Does nothing and returns null unless overridden.


isUnloadable

public boolean isUnloadable(Displayable p)

removeFromUnloadable

public void removeFromUnloadable(Displayable p)

createARGBImage

protected static final java.awt.image.BufferedImage createARGBImage(int width,
                                                                    int height,
                                                                    int[] pix)

embedAlpha

protected static final int[] embedAlpha(int[] pix,
                                        byte[] alpha)
Embed the alpha-byte into an int[], changes the int[] in place and returns it


embedAlpha

protected static final int[] embedAlpha(int[] pix,
                                        byte[] alpha,
                                        byte[] outside)

queueForMipmapRemoval

public void queueForMipmapRemoval(Patch p,
                                  boolean yes)
Does nothing unless overriden.


tagForMipmapRemoval

public void tagForMipmapRemoval(Patch p,
                                boolean yes)
Does nothing unless overriden.


getUNUId

public java.lang.String getUNUId()
Get the Universal Near-Unique Id for the project hosted by this loader.


getUNUIdFolder

public java.lang.String getUNUIdFolder()

regenerateMipMaps

public java.util.concurrent.Future<java.lang.Boolean> regenerateMipMaps(Patch patch)
Does nothing and returns null unless overriden.


regenerateMipMaps

public Bureaucrat regenerateMipMaps(java.util.Collection<? extends Displayable> patches)
Does nothing and returns null unless overriden.


getDimensions

public static java.awt.Dimension getDimensions(java.lang.String path)
Read out the width,height of an image using LOCI BioFormats.


getDimensions

public java.awt.Dimension getDimensions(Patch p)

setPreprocessorScriptPath

public void setPreprocessorScriptPath(Patch p,
                                      java.lang.String path)
Set a preprocessor script that will be executed on the ImagePlus of the Patch when loading it, before TrakEM2 sees it at all. Does NOT automatically regenerate mipmaps. To remove the script, set it to null.


setPreprocessorScriptPathSilently

public void setPreprocessorScriptPathSilently(Patch p,
                                              java.lang.String path)
Set a preprocessor script that will be executed on the ImagePlus of the Patch when loading it, before TrakEM2 sees it at all. To remove the script, set it to null.


getPreprocessorScriptPath

public java.lang.String getPreprocessorScriptPath(Patch p)

makeRelativePath

public java.lang.String makeRelativePath(java.lang.String path)
Returns @param path unless overriden.


getParentFolder

public java.lang.String getParentFolder()
Does nothing unless overriden.


doLater

public <T> java.util.concurrent.Future<T> doLater(java.util.concurrent.Callable<T> fn)

doGUILater

public void doGUILater(boolean swing,
                       java.lang.Runnable fn)
Execute a GUI-related task later, in the event dispatch thread context if @param swing is true.


maskBordersLayerWise

public Bureaucrat maskBordersLayerWise(java.util.Collection<Layer> layers,
                                       int left,
                                       int top,
                                       int right,
                                       int bottom)
Make the border have an alpha of zero.


maskBorders

public Bureaucrat maskBorders(java.util.Collection<Displayable> patches,
                              int left,
                              int top,
                              int right,
                              int bottom)
Make the border have an alpha of zero.


maskBorders

public java.util.ArrayList<java.util.concurrent.Future<?>> maskBorders(int left,
                                                                       int top,
                                                                       int right,
                                                                       int bottom,
                                                                       java.util.Collection<Displayable> patches)
Make the border have an alpha of zero.

Returns:
the list of Future that represent the regeneration of the mipmaps of each Patch.

createFlyThrough

public <I> ij.ImagePlus createFlyThrough(java.util.List<? extends Region<I>> regions,
                                         double magnification,
                                         int type,
                                         java.lang.String dir)
Returns an ImageStack, one slice per region.


createLazyFlyThrough

public <I> ij.ImagePlus createLazyFlyThrough(java.util.List<? extends Region<I>> regions,
                                             double magnification,
                                             int type,
                                             Displayable active)
Each slice is generated on demand, one slice per Region instance.


setMipMapFormat

public boolean setMipMapFormat(int format)
Does nothing unless overriden.


getMipMapFormat

public int getMipMapFormat()
Does nothing unless overriden.


updateMipMapsFormat

public Bureaucrat updateMipMapsFormat(int old_format,
                                      int new_format)
Does nothing unless overriden.