DGtal  0.9.2
ImageCache.h
1 
17 #pragma once
18 
31 #if defined(ImageCache_RECURSES)
32 #error Recursive header files inclusion detected in ImageCache.h
33 #else // defined(ImageCache_RECURSES)
34 
35 #define ImageCache_RECURSES
36 
37 #if !defined ImageCache_h
38 
39 #define ImageCache_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/ConceptUtils.h"
46 #include "DGtal/images/CImage.h"
47 #include "DGtal/images/CImageFactory.h"
48 #include "DGtal/images/CImageCacheReadPolicy.h"
49 #include "DGtal/images/CImageCacheWritePolicy.h"
50 #include "DGtal/base/Alias.h"
52 
53 namespace DGtal
54 {
55 
56 // CACHE_READ_POLICY_LAST, CACHE_READ_POLICY_FIFO, CACHE_READ_POLICY_LRU, CACHE_READ_POLICY_NEIGHBORS // read policies
57 // CACHE_WRITE_POLICY_WT, CACHE_WRITE_POLICY_WB // write policies
58 
60 // Template class ImageCache
76 template <typename TImageContainer, typename TImageFactory, typename TReadPolicy, typename TWritePolicy>
78 {
79 
80  // ----------------------- Types ------------------------------
81 
82 public:
84 
90 
92  typedef TImageContainer ImageContainer;
93  typedef typename ImageContainer::Domain Domain;
94  typedef typename ImageContainer::Point Point;
95  typedef typename ImageContainer::Value Value;
96 
97  typedef TImageFactory ImageFactory;
98 
99  typedef TReadPolicy ReadPolicy;
100  typedef TWritePolicy WritePolicy;
101 
102  // ----------------------- Standard services ------------------------------
103 
104 public:
105 
112  ImageCache(Alias<ImageFactory> anImageFactory, Alias<ReadPolicy> aReadPolicy, Alias<WritePolicy> aWritePolicy):
113  myImageFactoryPtr(&anImageFactory), myReadPolicy(&aReadPolicy), myWritePolicy(&aWritePolicy)
114  {
115  myReadPolicy->clearCache();
116 
117  cacheMissRead = 0;
118  cacheMissWrite = 0;
119  }
120 
126  {
127  }
128 
129 private:
130 
131  ImageCache( const ImageCache & other );
132 
133  ImageCache & operator=( const ImageCache & other );
134 
135  // ----------------------- Interface --------------------------------------
136 public:
137 
139 
140 
142 
143 
145 
150  void selfDisplay ( std::ostream & out ) const;
151 
156  bool isValid() const
157  {
158  return (myImageFactoryPtr->isValid());
159  }
160 
170  bool read(const Point & aPoint, Value &aValue) const;
171 
180  ImageContainer * getPage(const Domain & aDomain) const;
181 
191  bool write(const Point & aPoint, const Value &aValue);
192 
198  void update(const Domain &aDomain);
199 
203  unsigned int getCacheMissRead()
204  {
205  return cacheMissRead;
206  }
207 
211  unsigned int getCacheMissWrite()
212  {
213  return cacheMissWrite;
214  }
215 
220  {
221  cacheMissRead++;
222  }
223 
228  {
229  cacheMissWrite++;
230  }
231 
236  {
237  myReadPolicy->clearCache();
238 
239  cacheMissRead = 0;
240  cacheMissWrite = 0;
241  }
242 
243  // ------------------------- Protected Datas ------------------------------
244 private:
248  //ImageCache() {}
249 
250  // ------------------------- Private Datas --------------------------------
251 protected:
252 
254  ImageFactory * myImageFactoryPtr;
255 
257  ReadPolicy * myReadPolicy;
258  WritePolicy * myWritePolicy;
259 
260 private:
261 
263  unsigned int cacheMissRead;
264  unsigned int cacheMissWrite;
265 
266  // ------------------------- Internals ------------------------------------
267 private:
268 
269 }; // end of class ImageCache
270 
271 
278 template <typename TImageContainer, typename TImageFactory, typename TReadPolicy, typename TWritePolicy>
279 std::ostream&
280 operator<< ( std::ostream & out, const ImageCache<TImageContainer, TImageFactory, TReadPolicy, TWritePolicy> & object );
281 
282 } // namespace DGtal
283 
284 
286 // Includes inline functions.
287 #include "DGtal/images/ImageCachePolicies.h"
288 #include "DGtal/images/ImageCache.ih"
289 
290 // //
292 
293 #endif // !defined ImageCache_h
294 
295 #undef ImageCache_RECURSES
296 #endif // else defined(ImageCache_RECURSES)
ImageCache< TImageContainer, TImageFactory, TReadPolicy, TWritePolicy > Self
Definition: ImageCache.h:83
unsigned int getCacheMissWrite()
Definition: ImageCache.h:211
TImageContainer ImageContainer
Types copied from the container.
Definition: ImageCache.h:92
TReadPolicy ReadPolicy
Definition: ImageCache.h:99
ImageContainer::Value Value
Definition: ImageCache.h:95
ImageContainer::Point Point
Definition: ImageCache.h:94
unsigned int getCacheMissRead()
Definition: ImageCache.h:203
bool isValid() const
Definition: ImageCache.h:156
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:182
bool read(const Point &aPoint, Value &aValue) const
TWritePolicy WritePolicy
Definition: ImageCache.h:100
ImageCache & operator=(const ImageCache &other)
void incCacheMissRead()
Definition: ImageCache.h:219
ImageContainer * getPage(const Domain &aDomain) const
ImageFactory * myImageFactoryPtr
Alias on the image factory.
Definition: ImageCache.h:254
ReadPolicy * myReadPolicy
Specialized caches.
Definition: ImageCache.h:257
ImageCache(Alias< ImageFactory > anImageFactory, Alias< ReadPolicy > aReadPolicy, Alias< WritePolicy > aWritePolicy)
Definition: ImageCache.h:112
WritePolicy * myWritePolicy
Definition: ImageCache.h:258
Aim: Defines the concept describing an image factory.
Definition: CImageFactory.h:90
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: implements an images cache with 'read and write' policies.
Definition: ImageCache.h:77
bool write(const Point &aPoint, const Value &aValue)
void update(const Domain &aDomain)
Aim: Defines the concept describing a cache write policy.
TImageFactory ImageFactory
Definition: ImageCache.h:97
ImageContainer::Domain Domain
Definition: ImageCache.h:93
unsigned int cacheMissWrite
Definition: ImageCache.h:264
void clearCacheAndResetCacheMisses()
Definition: ImageCache.h:235
void incCacheMissWrite()
Definition: ImageCache.h:227
void selfDisplay(std::ostream &out) const
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:102
unsigned int cacheMissRead
cache miss values
Definition: ImageCache.h:263
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
Aim: Defines the concept describing a cache read policy.