81 #ifdef DRWN_USE_PTHREADS    82     pthread_mutex_t _mutex; 
    86     unsigned _dbImagesLocked;
    87     unsigned _dbImagesLoaded;
    98     drwnImageCache(
bool bGreyImages = GREY_IMAGES, 
bool bBigMemory = BIG_MEMORY);
   100     drwnImageCache(
const vector<string>& filenames, 
bool bGreyImages = GREY_IMAGES,
   101         bool bBigMemory = BIG_MEMORY);
   106     void initialize(
const vector<string>& filenames);
   109     void append(
const string& filename);
   116     bool empty()
 const { 
return (_imagesLoaded == 0); }
   118     size_t size()
 const { 
return _imagesLoaded; }
   120     size_t numLocked()
 const { 
return _imagesLoaded - _free_list.size(); }
   122     size_t memory()
 const { 
return _memoryUsed; }
   125     const string& 
filename(
unsigned indx)
 const { 
return _filenames[indx]; }
   128     int index(
const string& filename)
 const {
   129         vector<string>::const_iterator it = find(_filenames.begin(), _filenames.end(), filename);
   130         if (it == _filenames.end()) 
return -1;
   131         return (
int)(it - _filenames.begin());
   135     void lock(
unsigned indx);
   137     void lock(
const string& filename) { 
lock((
unsigned)index(filename)); }
   140     inline const cv::Mat& 
get(
unsigned indx) 
const { 
return _images[indx]; }
   142     inline const cv::Mat& 
get(
const string& filename) 
const {
   143         return _images[(unsigned)index(filename)];
   147     void unlock(
unsigned indx);
   149     void unlock(
const string& filename) { 
unlock((
unsigned)index(filename)); }
   152     cv::Mat copy(
unsigned indx);
   154     cv::Mat 
copy(
const string& filename) { 
return copy((
unsigned)index(filename)); }
   158     void enforceLimits();
   161     virtual cv::Mat load(
const string& filename) 
const;
 vector< string > _filenames
image filenames 
Definition: drwnImageCache.h:67
size_t _imagesLoaded
number of images loaded 
Definition: drwnImageCache.h:78
size_t numLocked() const
returns number of locked images in the cache 
Definition: drwnImageCache.h:120
vector< list< unsigned >::iterator > _free_list_map
ref to location in _free_list 
Definition: drwnImageCache.h:70
const string & filename(unsigned indx) const
return the filename for image indx 
Definition: drwnImageCache.h:125
Caches images in memory up to a maximum number of images or memory limit. 
Definition: drwnImageCache.h:65
static bool GREY_IMAGES
default setting for caching images in greyscale 
Definition: drwnImageCache.h:93
static size_t MAX_MEMORY
maximum number of bytes used at any one time 
Definition: drwnImageCache.h:92
vector< unsigned > _lock_counter
allows for multiple locks 
Definition: drwnImageCache.h:71
size_t _memoryUsed
bytes used by loaded images 
Definition: drwnImageCache.h:79
vector< cv::Mat > _images
loaded images 
Definition: drwnImageCache.h:69
size_t size() const
returns number of images stored in the cache 
Definition: drwnImageCache.h:118
size_t memory() const
returns memory used by in-memory images 
Definition: drwnImageCache.h:122
void unlock(const string &filename)
marks an image as free 
Definition: drwnImageCache.h:149
static size_t MAX_IMAGES
maximum number of images in memory at any one time 
Definition: drwnImageCache.h:91
bool _bBigMemoryModel
load all images into memory (ignores MAX_IMAGES and MAX_MEMORY) 
Definition: drwnImageCache.h:77
bool empty() const
returns true if the cache is empty (but may still be initialized with filenames) 
Definition: drwnImageCache.h:116
cv::Mat copy(const string &filename)
copies an image without locking it (caller must free the image) 
Definition: drwnImageCache.h:154
bool _bGreyImages
store images in greyscale (instead of RGB) 
Definition: drwnImageCache.h:76
int index(const string &filename) const
returns the index for filename (slow) 
Definition: drwnImageCache.h:128
list< unsigned > _free_list
index of images that can be safely released in least-recently-used order 
Definition: drwnImageCache.h:74
void lock(const string &filename)
lock an image for use (loads if not already in the cache) 
Definition: drwnImageCache.h:137
static bool BIG_MEMORY
default setting for big memory mode 
Definition: drwnImageCache.h:94