HuginBase::ImageCache Class Reference

This is a cache for all the images we use. More...

#include <ImageCache.h>

List of all members.

Public Types

typedef boost::shared_ptr<
vigra::BRGBImage > 
ImageCacheRGB8Ptr
 use reference counted pointers
typedef boost::shared_ptr<
vigra::UInt16RGBImage > 
ImageCacheRGB16Ptr
typedef boost::shared_ptr<
vigra::FRGBImage > 
ImageCacheRGBFloatPtr
typedef boost::shared_ptr<
vigra::BImage > 
ImageCache8Ptr
typedef boost::shared_ptr<
Entry
EntryPtr
 a shared pointer to the entry
typedef boost::shared_ptr<
Request
RequestPtr
 Reference counted request for an image to load.

Public Member Functions

virtual ~ImageCache ()
 dtor.
EntryPtr getImage (const std::string &filename)
 get a image.
EntryPtr getImageIfAvailable (const std::string &filename)
 Get an image if already loaded.
EntryPtr getSmallImage (const std::string &filename)
 get an small image.
EntryPtr getSmallImageIfAvailable (const std::string &filename)
 Get a small image if already loaded.
RequestPtr requestAsyncImage (const std::string &filename)
 Request an image be loaded.
RequestPtr requestAsyncSmallImage (const std::string &filename)
 Request a small image be loaded.
void removeImage (const std::string &filename)
 remove a specific image (and dependant images) from the cache
void flush ()
 release all images in the cache.
void softFlush ()
 a soft version of flush.
void SetUpperLimit (long newUpperLimit)
 sets the upper limit, which is used by softFlush()
void postEvent (RequestPtr request, EntryPtr entry)
 Pass on a loaded event for any images loaded asynchronously.
void setProgressDisplay (AppBase::MultiProgressDisplay *disp)
void clearProgressDisplay (AppBase::MultiProgressDisplay *disp)

Static Public Member Functions

ImageCachegetInstance ()
 get the global ImageCache object

Public Attributes

void(* asyncLoadCompleteSignal )(RequestPtr, EntryPtr)
 Signal for when a asynchronous load completes.

Private Member Functions

 ImageCache ()
void spawnAsyncThread ()
 Start a background thread to load an image.

Static Private Member Functions

template<class SrcPixelType, class DestIterator, class DestAccessor>
void importAndConvertImage (const vigra::ImageImportInfo &info, vigra::pair< DestIterator, DestAccessor > dest, const std::string &type)
template<class SrcPixelType, class DestIterator, class DestAccessor, class MaskIterator, class MaskAccessor>
void importAndConvertAlphaImage (const vigra::ImageImportInfo &info, vigra::pair< DestIterator, DestAccessor > dest, vigra::pair< MaskIterator, MaskAccessor > mask, const std::string &type)
void loadSafely (RequestPtr request, EntryPtr large=EntryPtr())
 Load a requested image in a way that will work in parallel.
EntryPtr loadImageSafely (const std::string &filename)
 Load a full size image, in a way that will work in parallel.
EntryPtr loadSmallImageSafely (EntryPtr entry)
 Load a small image, in a way that will work in parallel.

Private Attributes

long upperBound
std::map< std::string, EntryPtrimages
AppBase::MultiProgressDisplaym_progress
int m_accessCounter
std::map< std::string, RequestPtrm_requests
std::map< std::string, RequestPtrm_smallRequests
std::map< std::string, vigra::BImage * > pyrImages

Static Private Attributes

ImageCacheinstance = NULL


Detailed Description

This is a cache for all the images we use.

is a singleton for easy access from everywhere. The cache is used as an image source, that needs to know how to reproduce the requested images, in case that they have been deleted.

Definition at line 55 of file ImageCache.h.


Member Typedef Documentation

typedef boost::shared_ptr<Entry> HuginBase::ImageCache::EntryPtr
 

a shared pointer to the entry

Definition at line 109 of file ImageCache.h.

Referenced by getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), loadImageSafely(), loadSafely(), loadSmallImageSafely(), and spawnAsyncThread().

typedef boost::shared_ptr<vigra::BImage> HuginBase::ImageCache::ImageCache8Ptr
 

Definition at line 63 of file ImageCache.h.

Referenced by loadImageSafely().

typedef boost::shared_ptr<vigra::UInt16RGBImage> HuginBase::ImageCache::ImageCacheRGB16Ptr
 

Definition at line 61 of file ImageCache.h.

Referenced by loadImageSafely(), and loadSmallImageSafely().

typedef boost::shared_ptr<vigra::BRGBImage> HuginBase::ImageCache::ImageCacheRGB8Ptr
 

use reference counted pointers

Definition at line 60 of file ImageCache.h.

Referenced by loadImageSafely(), and loadSmallImageSafely().

typedef boost::shared_ptr<vigra::FRGBImage> HuginBase::ImageCache::ImageCacheRGBFloatPtr
 

Definition at line 62 of file ImageCache.h.

Referenced by loadImageSafely(), and loadSmallImageSafely().

typedef boost::shared_ptr<Request> HuginBase::ImageCache::RequestPtr
 

Reference counted request for an image to load.

Hold on to this when you want an image to load. If you no longer want the image, just delete it. Deleting it before the image loads lets other images load next.

Connect to the ready signal to respond to the image loading. To keep the image loaded, keep the EntryPtr given to the signal handler.

It is reference counted, so you can freely copy and delete it.

Definition at line 152 of file ImageCache.h.

Referenced by requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().


Constructor & Destructor Documentation

HuginBase::ImageCache::ImageCache  )  [inline, private]
 

Definition at line 156 of file ImageCache.h.

Referenced by getInstance().

virtual HuginBase::ImageCache::~ImageCache  )  [inline, virtual]
 

dtor.

Definition at line 164 of file ImageCache.h.


Member Function Documentation

void HuginBase::ImageCache::clearProgressDisplay AppBase::MultiProgressDisplay disp  )  [inline]
 

Definition at line 316 of file ImageCache.h.

void HuginBase::ImageCache::flush  ) 
 

release all images in the cache.

useful on project load, or maybe before stitching really big pictures

Definition at line 158 of file ImageCache.cpp.

References images, and pyrImages.

ImageCache::EntryPtr HuginBase::ImageCache::getImage const std::string filename  ) 
 

get a image.

it will be loaded if its not already in the cache

Hold the EntryPtr as long as the image data is needed!

If it isn't vital that the real image is obtained immediately, use getImageIfAvailable instead. This means you can keep the UI responsive while the real image is fetched from a disk or network and decoded.

Definition at line 503 of file ImageCache.cpp.

References EntryPtr, images, loadImageSafely(), m_accessCounter, m_progress, AppBase::MultiProgressDisplay::popTask(), and AppBase::MultiProgressDisplay::pushTask().

Referenced by PreviewColorPickerTool::CalcCorrectionForImage(), getSmallImage(), LensCalFrame::OnFindLines(), and postEvent().

ImageCache::EntryPtr HuginBase::ImageCache::getImageIfAvailable const std::string filename  ) 
 

Get an image if already loaded.

If not already in the cache, the pointer returned is 0.

Hold a non-zero EntryPtr as long as the image data is needed.

If you really need the image immediately, use getImage() instead.

Definition at line 704 of file ImageCache.cpp.

References EntryPtr, images, and m_accessCounter.

Referenced by postEvent(), and spawnAsyncThread().

ImageCache & HuginBase::ImageCache::getInstance  )  [static]
 

get the global ImageCache object

Definition at line 294 of file ImageCache.cpp.

References ImageCache(), and instance.

Referenced by PreviewColorPickerTool::CalcCorrectionForImage(), LensCalFrame::LensCalFrame(), loadSafely(), LensCalFrame::OnFindLines(), LensCalFrame::OnRemoveImage(), and LensCalFrame::~LensCalFrame().

ImageCache::EntryPtr HuginBase::ImageCache::getSmallImage const std::string filename  ) 
 

get an small image.

This image is 512x512 pixel maximum and can be used for icons and different previews. It is directly derived from the original.

If it isn't vital that the real image is obtained immediately, use getSmallImageIfAvailable instead. This means you can keep the UI responsive while the real image is fetched, decoded, and scaled.

Definition at line 718 of file ImageCache.cpp.

References DEBUG_DEBUG, DEBUG_INFO, EntryPtr, getImage(), images, loadSmallImageSafely(), m_accessCounter, m_progress, AppBase::MultiProgressDisplay::popTask(), AppBase::MultiProgressDisplay::pushTask(), softFlush(), and makefile::string.

Referenced by postEvent().

ImageCache::EntryPtr HuginBase::ImageCache::getSmallImageIfAvailable const std::string filename  ) 
 

Get a small image if already loaded.

The EntryPtr returned is 0 if the image isn't loaded yet.

This image is 512x512 pixels maximum and can be used for icons and different previews. It is directly derived from the original.

If you really need the image immediately, use getSmallImage() instead.

Definition at line 804 of file ImageCache.cpp.

References EntryPtr, images, m_accessCounter, softFlush(), and makefile::string.

Referenced by postEvent().

template<class SrcPixelType, class DestIterator, class DestAccessor, class MaskIterator, class MaskAccessor>
void HuginBase::ImageCache::importAndConvertAlphaImage const vigra::ImageImportInfo &  info,
vigra::pair< DestIterator, DestAccessor >  dest,
vigra::pair< MaskIterator, MaskAccessor >  mask,
const std::string type
[static, private]
 

Definition at line 485 of file ImageCache.cpp.

References vigra::importImageAlpha(), celeste::max(), and vigra_ext::transformImage().

template<class SrcPixelType, class DestIterator, class DestAccessor>
void HuginBase::ImageCache::importAndConvertImage const vigra::ImageImportInfo &  info,
vigra::pair< DestIterator, DestAccessor >  dest,
const std::string type
[static, private]
 

Definition at line 381 of file ImageCache.cpp.

References celeste::max(), and vigra_ext::transformImage().

ImageCache::EntryPtr HuginBase::ImageCache::loadImageSafely const std::string filename  )  [static, private]
 

Load a full size image, in a way that will work in parallel.

If the image cannot be loaded, the pointer returned is 0.

Definition at line 535 of file ImageCache.cpp.

References DEBUG_DEBUG, DEBUG_ERROR, DEBUG_FATAL, vigra_ext::destImage(), EntryPtr, ImageCache8Ptr, ImageCacheRGB16Ptr, ImageCacheRGB8Ptr, ImageCacheRGBFloatPtr, vigra::importImageAlpha(), celeste::info(), and vigra_ext::srcImageRange().

Referenced by getImage(), and loadSafely().

void HuginBase::ImageCache::loadSafely RequestPtr  request,
EntryPtr  large = EntryPtr()
[static, private]
 

Load a requested image in a way that will work in parallel.

When done, it sends an event with the newly created EntryPtr and request.

Parameters:
RequestPtr request for the image to load.
large EntryPtr for the large image when a small image is to be generated from it. Use a 0 pointer (the default) to generate a full size image.

Definition at line 956 of file ImageCache.cpp.

References asyncLoadCompleteSignal, DEBUG_ERROR, EntryPtr, getInstance(), loadImageSafely(), and loadSmallImageSafely().

Referenced by spawnAsyncThread().

ImageCache::EntryPtr HuginBase::ImageCache::loadSmallImageSafely EntryPtr  entry  )  [static, private]
 

Load a small image, in a way that will work in parallel.

If the image cannot be loaded, the pointer returned is 0.

Parameters:
entry Large image to scale down.

Definition at line 747 of file ImageCache.cpp.

References EntryPtr, ImageCacheRGB16Ptr, ImageCacheRGB8Ptr, ImageCacheRGBFloatPtr, and vigra_ext::reduceNTimes().

Referenced by getSmallImage(), and loadSafely().

void HuginBase::ImageCache::postEvent RequestPtr  request,
EntryPtr  entry
 

Pass on a loaded event for any images loaded asynchronously.

Call from the main GUI thread when an ImageLoadedEvent occurs. The ImageLoadedEvent originates from async_load_thread.

Parameters:
request The RequestPtr from the ImageLoadedEvent.
entry the EntryPtr from the ImageLoadedEvent.

Definition at line 858 of file ImageCache.cpp.

References getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), images, m_requests, m_smallRequests, spawnAsyncThread(), and makefile::string.

void HuginBase::ImageCache::removeImage const std::string filename  ) 
 

remove a specific image (and dependant images) from the cache

Definition at line 129 of file ImageCache.cpp.

References images, pyrImages, makefile::string, and HuginBase::ImageCache::PyramidKey::toString().

ImageCache::RequestPtr HuginBase::ImageCache::requestAsyncImage const std::string filename  ) 
 

Request an image be loaded.

This function returns quickly even when the image is not cached.

Returns:
Object to keep while you want the image. Connect to its ready signal to be notified when the image is ready.

Definition at line 820 of file ImageCache.cpp.

References m_requests, m_smallRequests, RequestPtr, and spawnAsyncThread().

ImageCache::RequestPtr HuginBase::ImageCache::requestAsyncSmallImage const std::string filename  ) 
 

Request a small image be loaded.

This function returns quickly even when the image is not cached.

Returns:
Object to keep while you want the image. Connect to its ready signal to be notified when it is ready.

Definition at line 839 of file ImageCache.cpp.

References m_requests, m_smallRequests, RequestPtr, and spawnAsyncThread().

void HuginBase::ImageCache::setProgressDisplay AppBase::MultiProgressDisplay disp  )  [inline]
 

Definition at line 312 of file ImageCache.h.

Referenced by LensCalFrame::LensCalFrame(), and LensCalFrame::~LensCalFrame().

void HuginBase::ImageCache::SetUpperLimit long  newUpperLimit  )  [inline]
 

sets the upper limit, which is used by softFlush()

Definition at line 257 of file ImageCache.h.

Referenced by LensCalFrame::LensCalFrame().

void HuginBase::ImageCache::softFlush  ) 
 

a soft version of flush.

Releases some images if they go over a certain threshold

Definition at line 171 of file ImageCache.cpp.

References cout, DEBUG_ASSERT, DEBUG_DEBUG, images, pyrImages, and upperBound.

Referenced by getSmallImage(), getSmallImageIfAvailable(), and LensCalFrame::OnRemoveImage().

void HuginBase::ImageCache::spawnAsyncThread  )  [private]
 

Start a background thread to load an image.

Definition at line 922 of file ImageCache.cpp.

References DEBUG_DEBUG, EntryPtr, getImageIfAvailable(), loadSafely(), m_requests, m_smallRequests, and RequestPtr.

Referenced by postEvent(), requestAsyncImage(), and requestAsyncSmallImage().


Member Data Documentation

void(* HuginBase::ImageCache::asyncLoadCompleteSignal)(RequestPtr, EntryPtr)
 

Signal for when a asynchronous load completes.

If you use the requestAsync functions, ensure there is something connected to this signal. The signal is raised in another thread, so the handler must be thread safe.

The signal handler must pass the request and entry to postEvent from the main thread when it is safe. For example, it you can wrap the request and entry in some wxEvent and the main thread can handle it later.

Referenced by loadSafely().

std::map<std::string, EntryPtr> HuginBase::ImageCache::images [private]
 

Definition at line 321 of file ImageCache.h.

Referenced by flush(), getImage(), getImageIfAvailable(), getSmallImage(), getSmallImageIfAvailable(), postEvent(), removeImage(), and softFlush().

ImageCache * HuginBase::ImageCache::instance = NULL [static, private]
 

Definition at line 126 of file ImageCache.cpp.

Referenced by getInstance().

int HuginBase::ImageCache::m_accessCounter [private]
 

Definition at line 326 of file ImageCache.h.

Referenced by getImage(), getImageIfAvailable(), getSmallImage(), and getSmallImageIfAvailable().

AppBase::MultiProgressDisplay* HuginBase::ImageCache::m_progress [private]
 

Definition at line 324 of file ImageCache.h.

Referenced by getImage(), and getSmallImage().

std::map<std::string, RequestPtr> HuginBase::ImageCache::m_requests [private]
 

Definition at line 329 of file ImageCache.h.

Referenced by postEvent(), requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().

std::map<std::string, RequestPtr> HuginBase::ImageCache::m_smallRequests [private]
 

Definition at line 332 of file ImageCache.h.

Referenced by postEvent(), requestAsyncImage(), requestAsyncSmallImage(), and spawnAsyncThread().

std::map<std::string, vigra::BImage *> HuginBase::ImageCache::pyrImages [private]
 

Definition at line 391 of file ImageCache.h.

Referenced by flush(), removeImage(), and softFlush().

long HuginBase::ImageCache::upperBound [private]
 

Definition at line 281 of file ImageCache.h.

Referenced by softFlush().


The documentation for this class was generated from the following files:
Generated on Sun Apr 20 01:25:51 2014 for Hugintrunk by  doxygen 1.3.9.1