DGtal 1.4.0
Loading...
Searching...
No Matches
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)
35#define ImageCache_RECURSES
36
37#if !defined ImageCache_h
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
53namespace 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
76template <typename TImageContainer, typename TImageFactory, typename TReadPolicy, typename TWritePolicy>
78{
79
80 // ----------------------- Types ------------------------------
81
82public:
84
90
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
104public:
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
129private:
130
131 ImageCache( const ImageCache & other );
132
133 ImageCache & operator=( const ImageCache & other );
134
135 // ----------------------- Interface --------------------------------------
136public:
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 {
222 }
223
228 {
230 }
231
236 {
237 myReadPolicy->clearCache();
238
239 cacheMissRead = 0;
240 cacheMissWrite = 0;
241 }
242
243 // ------------------------- Protected Datas ------------------------------
244private:
248 //ImageCache() {}
249
250 // ------------------------- Private Datas --------------------------------
251protected:
252
255
259
260private:
261
263 unsigned int cacheMissRead;
264 unsigned int cacheMissWrite;
265
266 // ------------------------- Internals ------------------------------------
267private:
268
269}; // end of class ImageCache
270
271
278template <typename TImageContainer, typename TImageFactory, typename TReadPolicy, typename TWritePolicy>
279std::ostream&
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)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition Alias.h:183
Aim: implements an images cache with 'read and write' policies.
Definition ImageCache.h:78
void clearCacheAndResetCacheMisses()
Definition ImageCache.h:235
bool read(const Point &aPoint, Value &aValue) const
TWritePolicy WritePolicy
Definition ImageCache.h:100
unsigned int cacheMissWrite
Definition ImageCache.h:264
ImageCache(const ImageCache &other)
ImageCache(Alias< ImageFactory > anImageFactory, Alias< ReadPolicy > aReadPolicy, Alias< WritePolicy > aWritePolicy)
Definition ImageCache.h:112
ImageCache< TImageContainer, TImageFactory, TReadPolicy, TWritePolicy > Self
Definition ImageCache.h:83
bool isValid() const
Definition ImageCache.h:156
unsigned int getCacheMissRead()
Definition ImageCache.h:203
ImageContainer::Point Point
Definition ImageCache.h:94
ImageCache & operator=(const ImageCache &other)
void update(const Domain &aDomain)
bool write(const Point &aPoint, const Value &aValue)
void incCacheMissWrite()
Definition ImageCache.h:227
WritePolicy * myWritePolicy
Definition ImageCache.h:258
ImageFactory * myImageFactoryPtr
Alias on the image factory.
Definition ImageCache.h:254
ImageContainer * getPage(const Domain &aDomain) const
void incCacheMissRead()
Definition ImageCache.h:219
ReadPolicy * myReadPolicy
Specialized caches.
Definition ImageCache.h:257
TImageFactory ImageFactory
Definition ImageCache.h:97
BOOST_CONCEPT_ASSERT((concepts::CImageCacheReadPolicy< TReadPolicy >))
ImageContainer::Domain Domain
Definition ImageCache.h:93
unsigned int cacheMissRead
cache miss values
Definition ImageCache.h:263
BOOST_CONCEPT_ASSERT((concepts::CImageCacheWritePolicy< TWritePolicy >))
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
unsigned int getCacheMissWrite()
Definition ImageCache.h:211
ImageContainer::Value Value
Definition ImageCache.h:95
BOOST_CONCEPT_ASSERT((concepts::CImageFactory< TImageFactory >))
TReadPolicy ReadPolicy
Definition ImageCache.h:99
TImageContainer ImageContainer
Types copied from the container.
Definition ImageCache.h:92
void selfDisplay(std::ostream &out) const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Aim: Defines the concept describing a cache read policy.
Aim: Defines the concept describing a cache write policy.
Aim: Defines the concept describing an image factory.
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition CImage.h:103
const Point aPoint(3, 4)