ini.trakem2.persistence
Class FSLoader

java.lang.Object
  extended by ini.trakem2.persistence.Loader
      extended by ini.trakem2.persistence.FSLoader

public final class FSLoader
extends Loader

A class to rely on memory only; except images which are rolled from a folder or their original location and flushed when memory is needed for more. Ideally there would be a given folder for storing items temporarily of permanently as the "project folder", but I haven't implemented it.


Nested Class Summary
 
Nested classes/interfaces inherited from class ini.trakem2.persistence.Loader
Loader.ImageLoadingLock
 
Field Summary
static java.util.regex.Pattern ABS_PATH
           
static java.util.concurrent.ScheduledExecutorService autosaver
           
static java.lang.String[] MIPMAP_FORMATS
           
static int MIPMAP_JPEG
           
static int MIPMAP_PNG
           
static int MIPMAP_TIFF
           
static java.util.concurrent.ExecutorService repainter
           
 
Fields inherited from class ini.trakem2.persistence.Loader
AREA_AVERAGING, BICUBIC, BILINEAR, changes, db_lock, ERROR_PATH_NOT_FOUND, GAUSSIAN, GRAY_LUT, hs_unloadable, mawts, MAX_RETRIES, MIN_FREE_BYTES, mipmaps_regen, modes, NEAREST_NEIGHBOR, NOT_FOUND, opener, PREPROCESSED, REGENERATING, RUNTIME, v_loaders
 
Constructor Summary
FSLoader()
          Used to open a project from an existing XML file.
FSLoader(java.lang.String storage_folder)
          Used to create a new project, NOT from an XML file.
 
Method Summary
 void addedPatchFrom(java.lang.String path, Patch patch)
          All backslashes are converted to slashes to avoid havoc in MSWindows.
 boolean addToDatabase(DBObject ob)
           
static java.lang.String asSafePath(java.lang.String name)
          Takes a String and returns a copy with the following conversions: / to -, space to _, and \ to -.
 boolean checkMipMapFileExists(Patch p, double magnification)
          Checks if the mipmap file for the Patch and closest upper level to the desired magnification exists.
static java.awt.image.BufferedImage convertToBufferedImage(ij.process.ByteProcessor bp)
           
static java.lang.String createIdPath(java.lang.String sid, java.lang.String filename, java.lang.String ext)
          For sid=12345 creates 12/34/5.${filename}.jpg Will be fine with other filename-valid chars in sid.
static java.lang.String createMipMapRelPath(Patch p, java.lang.String ext)
          For Patch id=12345 creates 12/34/5.${filename}.jpg
 void destroy()
          Release all memory and unregister itself.
 long estimateImageFileSize(Patch p, int level)
          Compute the number of bytes that the ImagePlus of a Patch will take.
 java.awt.geom.Area fetchArea(long area_list_id, long layer_id)
          Loaded in full from XML file
 java.util.ArrayList<?> fetchBallPoints(long id)
          Loaded in full from XML file
 double[][][] fetchBezierArrays(long id)
          Loaded in full from XML file
 java.awt.Image fetchDataImage(Patch p, double mag)
          Waits until a proper image of the desired size or larger can be returned, which is never the Loader.REGENERATING image.
 java.lang.Object fetchImage(Patch p, int format)
          So far accepts Layer.IMAGEPLUS and Layer.IMAGEPROCESSOR as format.
 ij.process.ByteProcessor fetchImageMask(Patch p)
          Returns the alpha mask image from a file, or null if none stored.
 ij.ImagePlus fetchImagePlus(Patch p)
           
 ij.ImagePlus fetchImagePlus(Stack stack)
           
 ij.process.ImageProcessor fetchImageProcessor(Patch p)
          Fetch the ImageProcessor in a synchronized manner, so that there are no conflicts in retrieving the ImageProcessor for a specific stack slice, for example.
 java.lang.Object[] fetchLabel(DLabel label)
          Loaded in full from XML file
 java.awt.Image fetchMipMap(Patch patch, int level, long n_bytes)
          Does the actual fetching of the file.
protected  java.awt.Image fetchMipMapAWT(Patch patch, int level, long n_bytes)
          Loads the file containing the scaled image corresponding to the given level (or the maximum possible level, if too large) and returns it as an awt.Image, or null if not found.
 ij.ImagePlus fetchOriginal(Patch patch)
          Loads and returns the original image, which is not cached, or returns null if it's not different than the working image.
 java.util.ArrayList<?> fetchPipePoints(long id)
          Loaded in full from XML file
 boolean fixStorageFolders()
          Convert old-style storage folders to new style.
 void flushMipMaps(boolean forget_dir_mipmaps)
          Remove all mipmap images from the cache, and optionally set the dir_mipmaps to null.
 void flushMipMaps(long id)
          Remove from the cache all images of level larger than zero corresponding to the given patch id.
 Bureaucrat generateMipMaps(java.util.Collection<Displayable> patches, boolean overwrite)
          Generate image pyramids and store them into files under the dir_mipmaps for each Patch object in the Project.
protected  boolean generateMipMaps(Patch patch)
          Given an image and its source file name (without directory prepended), generate a pyramid of images until reaching an image not smaller than 32x32 pixels.
Such images are stored as jpeg 85% quality in a folder named trakem2.mipmaps.
The Patch id and the right extension will be appended to the filename in all cases.
Any equally named files will be overwritten.
 java.lang.String getAbsolutePath(Patch patch)
          With slice info appended at the end; only if it exists, otherwise null.
 java.lang.String getAbsolutePath(java.lang.String path)
          Return an absolute path made from path: if it's already absolute, retursn itself; otherwise, the parent folder of all relative paths of this Loader is prepended.
 java.lang.String getAlphaPath(Patch p)
           
 int getClosestMipMapLevel(Patch patch, int level, int max_level)
          Return the closest level to @param level that exists as a file.
 java.lang.String getImageFilePath(Patch p)
          Returns null unless overriden.
 java.lang.String getImageStorageFolder()
          Returns a folder proven to be writable for images can be stored into.
 java.lang.String getMasksFolder()
           
 int getMipMapFormat()
          Any of: MIPMAP_JPEG, MIPMAP_PNG
 java.lang.String getMipMapsFolder()
          Returns the path to the directory hosting the file image pyramids.
 long getNextId()
          Get the next unique id, not shared by any other object within the same project.
static Project getOpenProject(java.lang.String project_file_path)
           
 java.lang.String getParentFolder()
          Return the path to the folder containing the project XML file.
 java.lang.String getPath(Patch patch)
          Returns the stored path for the given Patch image, which may be relative and may contain slice information appended.
protected  java.util.Map<java.lang.Long,java.lang.String> getPathsCopy()
           
 java.lang.String getProjectXMLPath()
           
 java.lang.String getStorageFolder()
          Return the folder selected by a user to store files into; it's also the parent folder of the UNUId folder, and the recommended folder to store the XML file into.
 java.lang.String getUNUId()
          Get the Universal Near-Unique Id for the project hosted by this loader.
 java.lang.String getUNUIdFolder()
          Returns the near-unique folder for the project hosted by this FSLoader.
static java.lang.Object grabPixels(java.awt.image.BufferedImage bi)
          Returns the array of pixels, whose type depends on the bi.getType(); for example, for a BufferedImage.TYPE_BYTE_INDEXED, returns a byte[].
 java.lang.String handlePathlessImage(ij.ImagePlus imp)
          Returns the path where the imp is saved to: the storage folder plus a name.
protected  Patch importStackAsPatches(Project project, Layer first_layer, double x, double y, ij.ImagePlus imp_stack, boolean as_copy, java.lang.String filepath)
          Returns the last Patch.
 void insertXMLOptions(java.lang.StringBuilder sb_body, java.lang.String indent)
          Specific options for the Loader which exist as attributes to the Project XML node.
static boolean isRelativePath(java.lang.String path)
           
static boolean isURL(java.lang.String path)
           
protected  void makeAllPathsRelativeTo(java.lang.String xml_path, Project project)
          Try to make all paths in ht_paths be relative to the given xml_path.
 java.lang.String makeProjectName()
           
 java.lang.String makeRelativePath(java.lang.String path)
          Takes the given path and tries to makes it relative to this instance's project_file_path, if possible.
 java.lang.Object[] openFSProject(java.lang.String path, boolean open_displays)
          Returns TMLHandler.getProjectData() .
 void parseXMLOptions(java.util.HashMap<java.lang.String,java.lang.String> ht_attributes)
          Specific options for the Loader which exist as attributes to the Project XML node.
 void queueForMipmapRemoval(Patch p, boolean yes)
          Queue/unqueue for mipmap removal on shutdown without saving.
 Bureaucrat regenerateMipMaps(java.util.Collection<? extends Displayable> patches)
          Order the regeneration of all mipmaps for the Patch instances in @param patches, setting up a task that blocks input until all completed.
 java.util.concurrent.Future<java.lang.Boolean> regenerateMipMaps(Patch patch)
          Queue the regeneration of mipmaps for the Patch; returns immediately, having submitted the job to an executor queue; returns a Future if the task was submitted, null if not.
 boolean removeAlphaMask(Patch p)
          Remove the file containing the given Patch's alpha mask.
 boolean removeFromDatabase(DBObject ob)
           
 java.util.concurrent.Future<java.lang.Boolean> removeMipMaps(Patch p)
          Gets data from the Patch and queues a new task to do the file removal in a separate task manager thread.
 boolean removeSerializedFeatures(Patch patch)
          Remove the file, if it exists, with serialized features for patch.
 boolean removeSerializedPointMatches(Patch patch)
          Remove the file, if it exists, with serialized point matches for patch.
protected  void restorePaths(java.util.Map<java.lang.Long,java.lang.String> copy, java.lang.String mipmaps_folder, java.lang.String storage_folder)
           
 java.lang.String save(Project project)
          Overwrites the XML file.
 java.lang.String saveAs(Project project)
          The saveAs called from menus via saveTask.
 java.lang.String saveAs(java.lang.String path, boolean overwrite)
          Meant for programmatic access, such as calls to project.saveAs(path, overwrite) which call exactly this method.
 java.lang.String setImageFile(Patch p, ij.ImagePlus imp)
          Returns the absolute path to a file that contains the given ImagePlus image - which may be the path as described in the ImagePlus FileInfo object itself, or a totally new file.
 boolean setMipMapFormat(int format)
          Does nothing unless overriden.
 void setupMenuItems(javax.swing.JMenu menu, Project project)
          Adds a "Save" and "Save as" menu items.
 void storeAlphaMask(Patch p, ij.process.ByteProcessor fp)
          Does nothing unless overriden.
 void tagForMipmapRemoval(Patch p, boolean yes)
          Queue/unqueue for mipmap removal on shutdown without saving.
 boolean updateInDatabase(DBObject ob, java.util.Set<java.lang.String> keys)
           
 boolean updateInDatabase(DBObject ob, java.lang.String key)
           
 Bureaucrat updateMipMapsFormat(int old_format, int new_format)
          Removes all mipmap files and recreates them with the currently set mipmaps format.
 boolean usesMipMapsFolder()
          Does nothing and returns false unless overriden.
 
Methods inherited from class ini.trakem2.persistence.Loader
addCrossLink, addJob, addNewImage, addNewImage, adjustChannels, askForXMLTemplate, cache, cache, cacheAWT, cacheImagePlus, canReadAndWriteTo, commitLargeUpdate, computeDesirableMinFreeBytes, countObjects, createARGBImage, createFlyThrough, createLazyFlyThrough, createZippedStream, debug, decache, decacheAWT, decacheImagePlus, decacheImagePlus, deserialize, destroyPreloader, doGUILater, doLater, embedAlpha, embedAlpha, enhanceContrast, enhanceContrast, enoughFreeMemory, export, export, exportImage, exportImage, fetchAWTImage, fetchImage, fetchImage, flush, generateLayerMipMaps, generateMipMaps, generateMipMaps, getCached, getCachedAWT, getCachedClosestAboveImage, getCachedClosestBelowImage, getCachedImagePlus, getCurrentMemory, getDimensions, getDimensions, getFileName, getFlatAWTImage, getFlatAWTImage, getFlatImage, getFlatImage, getFlatImage, getFlatImage, getFlatImage, getFlatImage, getHighestMipMapLevel, getHighestMipMapLevel, getInternalFileName, getJobsPopup, getMipMapLevel, getMode, getNextTempId, getOrMakeImageLoadingLock, getOrMakeImageLoadingLock, getPreprocessorScriptPath, handleCacheError, hasChanges, importGrid, importGrid, importImage, importImage, importImage, importImages, importImages, importLabelsAsAreaLists, importLabelsAsAreaLists, importNextImage, importSequenceAsGrid, importSequenceAsGrid, importSequenceAsGrid, importStack, importStack, importStack, importStackAsPatches, isAsynchronous, isCached, isImagePlusCached, isMipMapsRegenerationEnabled, isSignalImage, isSnapPaintable, isUnloadable, makeFlatImage, makeFlatImage, makeFlatImage, makeGrayLut, makePatchesDir, makePrescaledTiles, makePrescaledTiles, maskBorders, maskBorders, maskBordersLayerWise, maxDim, measureSize, openImage, openImagePlus, openStack, preload, preload, preProcess, printCache, printCaches, printCacheStatus, printMemState, quitJob, recoverOOME, recreateBuckets, recreateBuckets, releaseAll, releaseAllCaches, releaseMemory, releaseMemory2, releaseToFit, releaseToFit, removeCrossLink, removeFromUnloadable, removeImageLoadingLock, removeJob, rollback, saveAs, saveTask, scaleImage, scaleImage, serialize, setChanged, setDesirableMinFreeBytes, setHeapFraction, setMinAndMax, setMipMapsRegeneration, setPreprocessorScriptPath, setPreprocessorScriptPathSilently, setupPreloader, setupPreloaderThreads, startLargeUpdate, unzipTiff
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ABS_PATH

public static final java.util.regex.Pattern ABS_PATH

repainter

public static java.util.concurrent.ExecutorService repainter

autosaver

public static java.util.concurrent.ScheduledExecutorService autosaver

MIPMAP_FORMATS

public static final java.lang.String[] MIPMAP_FORMATS

MIPMAP_JPEG

public static final int MIPMAP_JPEG
See Also:
Constant Field Values

MIPMAP_PNG

public static final int MIPMAP_PNG
See Also:
Constant Field Values

MIPMAP_TIFF

public static final int MIPMAP_TIFF
See Also:
Constant Field Values
Constructor Detail

FSLoader

public FSLoader()
Used to open a project from an existing XML file.


FSLoader

public FSLoader(java.lang.String storage_folder)
         throws java.lang.Exception
Used to create a new project, NOT from an XML file. Throws an Exception if the loader cannot read and write to the storage folder.

Throws:
java.lang.Exception
Method Detail

getProjectXMLPath

public java.lang.String getProjectXMLPath()

getStorageFolder

public java.lang.String getStorageFolder()
Return the folder selected by a user to store files into; it's also the parent folder of the UNUId folder, and the recommended folder to store the XML file into.

Overrides:
getStorageFolder in class Loader

getImageStorageFolder

public java.lang.String getImageStorageFolder()
Returns a folder proven to be writable for images can be stored into.

Overrides:
getImageStorageFolder in class Loader

openFSProject

public java.lang.Object[] openFSProject(java.lang.String path,
                                        boolean open_displays)
Returns TMLHandler.getProjectData() . If the path is null it'll be asked for.


getOpenProject

public static final Project getOpenProject(java.lang.String project_file_path)

destroy

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

Overrides:
destroy in class Loader

getNextId

public long getNextId()
Get the next unique id, not shared by any other object within the same project.

Specified by:
getNextId in class Loader

fetchBezierArrays

public double[][][] fetchBezierArrays(long id)
Loaded in full from XML file

Specified by:
fetchBezierArrays in class Loader

fetchPipePoints

public java.util.ArrayList<?> fetchPipePoints(long id)
Loaded in full from XML file

Specified by:
fetchPipePoints in class Loader

fetchBallPoints

public java.util.ArrayList<?> fetchBallPoints(long id)
Loaded in full from XML file

Specified by:
fetchBallPoints in class Loader

fetchArea

public java.awt.geom.Area fetchArea(long area_list_id,
                                    long layer_id)
Loaded in full from XML file

Specified by:
fetchArea in class Loader

fetchImagePlus

public ij.ImagePlus fetchImagePlus(Patch p)
Specified by:
fetchImagePlus in class Loader

fetchImageProcessor

public ij.process.ImageProcessor fetchImageProcessor(Patch p)
Fetch the ImageProcessor in a synchronized manner, so that there are no conflicts in retrieving the ImageProcessor for a specific stack slice, for example. Note that the min and max is not set -- it's your burden to call setMinAndMax(p.getMin(), p.getMax()) on the returned ImageProcessor.

Overrides:
fetchImageProcessor in class Loader

fetchImage

public java.lang.Object fetchImage(Patch p,
                                   int format)
So far accepts Layer.IMAGEPLUS and Layer.IMAGEPROCESSOR as format.


fetchImageMask

public ij.process.ByteProcessor fetchImageMask(Patch p)
Returns the alpha mask image from a file, or null if none stored.

Overrides:
fetchImageMask in class Loader

getAlphaPath

public java.lang.String getAlphaPath(Patch p)
Overrides:
getAlphaPath in class Loader

storeAlphaMask

public void storeAlphaMask(Patch p,
                           ij.process.ByteProcessor fp)
Description copied from class: Loader
Does nothing unless overriden.

Overrides:
storeAlphaMask in class Loader

getMasksFolder

public final java.lang.String getMasksFolder()

removeAlphaMask

public final boolean removeAlphaMask(Patch p)
Remove the file containing the given Patch's alpha mask.

Overrides:
removeAlphaMask in class Loader

fetchLabel

public java.lang.Object[] fetchLabel(DLabel label)
Loaded in full from XML file

Specified by:
fetchLabel in class Loader

fetchOriginal

public ij.ImagePlus fetchOriginal(Patch patch)
Loads and returns the original image, which is not cached, or returns null if it's not different than the working image.

Specified by:
fetchOriginal in class Loader

addToDatabase

public boolean addToDatabase(DBObject ob)
Specified by:
addToDatabase in class Loader

updateInDatabase

public boolean updateInDatabase(DBObject ob,
                                java.lang.String key)
Specified by:
updateInDatabase in class Loader

updateInDatabase

public boolean updateInDatabase(DBObject ob,
                                java.util.Set<java.lang.String> keys)
Specified by:
updateInDatabase in class Loader

removeFromDatabase

public boolean removeFromDatabase(DBObject ob)
Specified by:
removeFromDatabase in class Loader

setImageFile

public java.lang.String setImageFile(Patch p,
                                     ij.ImagePlus imp)
Returns the absolute path to a file that contains the given ImagePlus image - which may be the path as described in the ImagePlus FileInfo object itself, or a totally new file. If the Patch p current image path is different than its original image path, then the file is overwritten if it exists already.

Overrides:
setImageFile in class Loader

getAbsolutePath

public java.lang.String getAbsolutePath(Patch patch)
With slice info appended at the end; only if it exists, otherwise null.

Overrides:
getAbsolutePath in class Loader

getAbsolutePath

public java.lang.String getAbsolutePath(java.lang.String path)
Return an absolute path made from path: if it's already absolute, retursn itself; otherwise, the parent folder of all relative paths of this Loader is prepended.


getImageFilePath

public final java.lang.String getImageFilePath(Patch p)
Description copied from class: Loader
Returns null unless overriden. This is intended for FSLoader projects.

Overrides:
getImageFilePath in class Loader

isURL

public static final boolean isURL(java.lang.String path)

isRelativePath

public static final boolean isRelativePath(java.lang.String path)

addedPatchFrom

public void addedPatchFrom(java.lang.String path,
                           Patch patch)
All backslashes are converted to slashes to avoid havoc in MSWindows.

Overrides:
addedPatchFrom in class Loader

asSafePath

public static java.lang.String asSafePath(java.lang.String name)
Takes a String and returns a copy with the following conversions: / to -, space to _, and \ to -.


save

public java.lang.String save(Project project)
Overwrites the XML file. If some images do not exist in the file system, a directory with the same name of the XML file plus an "_images" tag appended will be created and images saved there.

Overrides:
save in class Loader

saveAs

public java.lang.String saveAs(Project project)
The saveAs called from menus via saveTask.

Overrides:
saveAs in class Loader

saveAs

public java.lang.String saveAs(java.lang.String path,
                               boolean overwrite)
Meant for programmatic access, such as calls to project.saveAs(path, overwrite) which call exactly this method.

Overrides:
saveAs in class Loader

getPath

public java.lang.String getPath(Patch patch)
Returns the stored path for the given Patch image, which may be relative and may contain slice information appended.

Overrides:
getPath in class Loader

getPathsCopy

protected java.util.Map<java.lang.Long,java.lang.String> getPathsCopy()
Overrides:
getPathsCopy in class Loader

makeAllPathsRelativeTo

protected void makeAllPathsRelativeTo(java.lang.String xml_path,
                                      Project project)
Try to make all paths in ht_paths be relative to the given xml_path. This is intended for making all paths relative when saving to XML for the first time. dir_storage and dir_mipmaps remain untouched--otherwise, after a saveAs, images would not be found.

Overrides:
makeAllPathsRelativeTo in class Loader

restorePaths

protected void restorePaths(java.util.Map<java.lang.Long,java.lang.String> copy,
                            java.lang.String mipmaps_folder,
                            java.lang.String storage_folder)
Overrides:
restorePaths in class Loader

makeRelativePath

public java.lang.String makeRelativePath(java.lang.String path)
Takes the given path and tries to makes it relative to this instance's project_file_path, if possible. Otherwise returns the argument as is.

Overrides:
makeRelativePath in class Loader

setupMenuItems

public void setupMenuItems(javax.swing.JMenu menu,
                           Project project)
Adds a "Save" and "Save as" menu items.

Overrides:
setupMenuItems in class Loader

importStackAsPatches

protected Patch importStackAsPatches(Project project,
                                     Layer first_layer,
                                     double x,
                                     double y,
                                     ij.ImagePlus imp_stack,
                                     boolean as_copy,
                                     java.lang.String filepath)
Returns the last Patch.

Specified by:
importStackAsPatches in class Loader

parseXMLOptions

public void parseXMLOptions(java.util.HashMap<java.lang.String,java.lang.String> ht_attributes)
Specific options for the Loader which exist as attributes to the Project XML node.


regenerateMipMaps

public Bureaucrat regenerateMipMaps(java.util.Collection<? extends Displayable> patches)
Order the regeneration of all mipmaps for the Patch instances in @param patches, setting up a task that blocks input until all completed.

Overrides:
regenerateMipMaps in class Loader

insertXMLOptions

public void insertXMLOptions(java.lang.StringBuilder sb_body,
                             java.lang.String indent)
Specific options for the Loader which exist as attributes to the Project XML node.

Overrides:
insertXMLOptions in class Loader

getParentFolder

public final java.lang.String getParentFolder()
Return the path to the folder containing the project XML file.

Overrides:
getParentFolder in class Loader

getMipMapsFolder

public java.lang.String getMipMapsFolder()
Returns the path to the directory hosting the file image pyramids.

Overrides:
getMipMapsFolder in class Loader

grabPixels

public static final java.lang.Object grabPixels(java.awt.image.BufferedImage bi)
Returns the array of pixels, whose type depends on the bi.getType(); for example, for a BufferedImage.TYPE_BYTE_INDEXED, returns a byte[].


convertToBufferedImage

public static final java.awt.image.BufferedImage convertToBufferedImage(ij.process.ByteProcessor bp)

queueForMipmapRemoval

public void queueForMipmapRemoval(Patch p,
                                  boolean yes)
Queue/unqueue for mipmap removal on shutdown without saving.

Overrides:
queueForMipmapRemoval in class Loader

tagForMipmapRemoval

public void tagForMipmapRemoval(Patch p,
                                boolean yes)
Queue/unqueue for mipmap removal on shutdown without saving.

Overrides:
tagForMipmapRemoval in class Loader

generateMipMaps

protected boolean generateMipMaps(Patch patch)
Given an image and its source file name (without directory prepended), generate a pyramid of images until reaching an image not smaller than 32x32 pixels.
Such images are stored as jpeg 85% quality in a folder named trakem2.mipmaps.
The Patch id and the right extension will be appended to the filename in all cases.
Any equally named files will be overwritten.

Overrides:
generateMipMaps in class Loader

removeSerializedFeatures

public boolean removeSerializedFeatures(Patch patch)
Remove the file, if it exists, with serialized features for patch. Returns true when no such file or on success; false otherwise.


removeSerializedPointMatches

public boolean removeSerializedPointMatches(Patch patch)
Remove the file, if it exists, with serialized point matches for patch. Returns true when no such file or on success; false otherwise.


generateMipMaps

public Bureaucrat generateMipMaps(java.util.Collection<Displayable> patches,
                                  boolean overwrite)
Generate image pyramids and store them into files under the dir_mipmaps for each Patch object in the Project. The method is multithreaded, using as many processors as available to the JVM.

Parameters:
al - : the list of Patch instances to generate mipmaps for.
overwrite - : whether to overwrite any existing mipmaps, or save only those that don't exist yet for whatever reason. This flag provides the means for minimal effort mipmap regeneration.)

getUNUIdFolder

public java.lang.String getUNUIdFolder()
Returns the near-unique folder for the project hosted by this FSLoader.

Overrides:
getUNUIdFolder in class Loader

flushMipMaps

public void flushMipMaps(boolean forget_dir_mipmaps)
Remove all mipmap images from the cache, and optionally set the dir_mipmaps to null.

Overrides:
flushMipMaps in class Loader

flushMipMaps

public void flushMipMaps(long id)
Remove from the cache all images of level larger than zero corresponding to the given patch id.

Overrides:
flushMipMaps in class Loader

removeMipMaps

public java.util.concurrent.Future<java.lang.Boolean> removeMipMaps(Patch p)
Gets data from the Patch and queues a new task to do the file removal in a separate task manager thread.

Overrides:
removeMipMaps in class Loader

usesMipMapsFolder

public boolean usesMipMapsFolder()
Description copied from class: Loader
Does nothing and returns false unless overriden.

Overrides:
usesMipMapsFolder in class Loader

getClosestMipMapLevel

public int getClosestMipMapLevel(Patch patch,
                                 int level,
                                 int max_level)
Return the closest level to @param level that exists as a file. If no valid path is found for the patch, returns ERROR_PATH_NOT_FOUND.

Overrides:
getClosestMipMapLevel in class Loader

checkMipMapFileExists

public boolean checkMipMapFileExists(Patch p,
                                     double magnification)
Checks if the mipmap file for the Patch and closest upper level to the desired magnification exists.

Overrides:
checkMipMapFileExists in class Loader

fetchMipMapAWT

protected java.awt.Image fetchMipMapAWT(Patch patch,
                                        int level,
                                        long n_bytes)
Loads the file containing the scaled image corresponding to the given level (or the maximum possible level, if too large) and returns it as an awt.Image, or null if not found. Will also regenerate the mipmaps, i.e. recreate the pre-scaled jpeg images if they are missing. Does NOT release memory, avoiding locking on the db_lock.

Overrides:
fetchMipMapAWT in class Loader

fetchMipMap

public final java.awt.Image fetchMipMap(Patch patch,
                                        int level,
                                        long n_bytes)
Does the actual fetching of the file. Returns null if the file does not exist. Does NOT pre-release memory from the cache; call releaseToFit to do that.


regenerateMipMaps

public final java.util.concurrent.Future<java.lang.Boolean> regenerateMipMaps(Patch patch)
Queue the regeneration of mipmaps for the Patch; returns immediately, having submitted the job to an executor queue; returns a Future if the task was submitted, null if not.

Overrides:
regenerateMipMaps in class Loader

estimateImageFileSize

public long estimateImageFileSize(Patch p,
                                  int level)
Compute the number of bytes that the ImagePlus of a Patch will take. Assumes a large header of 1024 bytes. If the image is saved as a grayscale jpeg the returned bytes will be 5 times as expected, because jpeg images are opened as int[] and then copied to a byte[] if all channels have the same values for all pixels.

Overrides:
estimateImageFileSize in class Loader

makeProjectName

public java.lang.String makeProjectName()
Overrides:
makeProjectName in class Loader

handlePathlessImage

public java.lang.String handlePathlessImage(ij.ImagePlus imp)
Returns the path where the imp is saved to: the storage folder plus a name.

Overrides:
handlePathlessImage in class Loader

fixStorageFolders

public boolean fixStorageFolders()
Convert old-style storage folders to new style.


createMipMapRelPath

public static final java.lang.String createMipMapRelPath(Patch p,
                                                         java.lang.String ext)
For Patch id=12345 creates 12/34/5.${filename}.jpg


createIdPath

public static final java.lang.String createIdPath(java.lang.String sid,
                                                  java.lang.String filename,
                                                  java.lang.String ext)
For sid=12345 creates 12/34/5.${filename}.jpg Will be fine with other filename-valid chars in sid.


getUNUId

public java.lang.String getUNUId()
Description copied from class: Loader
Get the Universal Near-Unique Id for the project hosted by this loader.

Overrides:
getUNUId in class Loader

fetchDataImage

public java.awt.Image fetchDataImage(Patch p,
                                     double mag)
Waits until a proper image of the desired size or larger can be returned, which is never the Loader.REGENERATING image. If no image can be loaded, returns Loader.NOT_FOUND. If the Patch is undergoing mipmap regeneration, it waits until done.

Overrides:
fetchDataImage in class Loader

fetchImagePlus

public ij.ImagePlus fetchImagePlus(Stack stack)
Overrides:
fetchImagePlus in class Loader

getMipMapFormat

public final int getMipMapFormat()
Any of: MIPMAP_JPEG, MIPMAP_PNG

Overrides:
getMipMapFormat in class Loader

setMipMapFormat

public final boolean setMipMapFormat(int format)
Description copied from class: Loader
Does nothing unless overriden.

Overrides:
setMipMapFormat in class Loader

updateMipMapsFormat

public Bureaucrat updateMipMapsFormat(int old_format,
                                      int new_format)
Removes all mipmap files and recreates them with the currently set mipmaps format.

Overrides:
updateMipMapsFormat in class Loader
Parameters:
old_format - Any of MIPMAP_JPEG, MIPMAP_PNG in which files were saved before.