DGtal 1.3.0
Loading...
Searching...
No Matches
ImageCachePolicies.ih
1/**
2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 **/
16
17/**
18 * @file ImageCachePolicies.ih
19 * @author Martial Tola (\c martial.tola@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
21 *
22 * @date 2013/02/06
23 *
24 * Implementation of inline methods defined in ImageCachePolicies.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32
33//////////////////////////////////////////////////////////////////////////////
34
35///////////////////////////////////////////////////////////////////////////////
36// IMPLEMENTATION of inline methods.
37///////////////////////////////////////////////////////////////////////////////
38
39///////////////////////////////////////////////////////////////////////////////
40// ----------------------- Standard services ------------------------------
41
42// ----------------------- Specialization DGtal::CACHE_READ_POLICY_LAST ------------------------------
43
44template <typename TImageContainer, typename TImageFactory>
45inline
46TImageContainer *
47DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPage(const Point & aPoint)
48{
49 if (myCacheImagesPtr==NULL)
50 return NULL;
51
52 if (myCacheImagesPtr->domain().isInside(aPoint))
53 return myCacheImagesPtr;
54
55 return NULL;
56}
57
58template <typename TImageContainer, typename TImageFactory>
59inline
60TImageContainer *
61DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPage(const Domain & aDomain)
62{
63 if (myCacheImagesPtr==NULL)
64 return NULL;
65
66 if ( (myCacheImagesPtr->domain().lowerBound() == aDomain.lowerBound()) && (myCacheImagesPtr->domain().upperBound() == aDomain.upperBound()) )
67 return myCacheImagesPtr;
68
69 return NULL;
70}
71
72template <typename TImageContainer, typename TImageFactory>
73inline
74TImageContainer *
75DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPageToDetach()
76{
77 return myCacheImagesPtr;
78}
79
80template <typename TImageContainer, typename TImageFactory>
81inline
82void
83DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::updateCache(const Domain &aDomain)
84{
85 myCacheImagesPtr = myImageFactory->requestImage(aDomain);
86}
87
88template <typename TImageContainer, typename TImageFactory>
89inline
90void
91DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::clearCache()
92{
93 myCacheImagesPtr = NULL;
94}
95
96// ----------------------- Specialization DGtal::CACHE_READ_POLICY_FIFO ------------------------------
97
98template <typename TImageContainer, typename TImageFactory>
99inline
100TImageContainer *
101DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPage(const Point & aPoint)
102{
103 if (myFIFOCacheImages.empty())
104 return NULL;
105
106 for (unsigned int i=0; i<myFIFOCacheImages.size(); i++)
107 if (myFIFOCacheImages[i]->domain().isInside(aPoint))
108 return myFIFOCacheImages[i];
109
110 return NULL;
111}
112
113template <typename TImageContainer, typename TImageFactory>
114inline
115TImageContainer *
116DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPage(const Domain & aDomain)
117{
118 if (myFIFOCacheImages.empty())
119 return NULL;
120
121 for (unsigned int i=0; i<myFIFOCacheImages.size(); i++)
122 if ( (myFIFOCacheImages[i]->domain().lowerBound() == aDomain.lowerBound()) && (myFIFOCacheImages[i]->domain().upperBound() == aDomain.upperBound()) )
123 return myFIFOCacheImages[i];
124
125 return NULL;
126}
127
128template <typename TImageContainer, typename TImageFactory>
129inline
130TImageContainer *
131DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPageToDetach()
132{
133 TImageContainer *pageToDetach = NULL;
134
135 if (myFIFOCacheImages.size() >= myFIFOSizeMax)
136 {
137 pageToDetach = myFIFOCacheImages.front();
138 myFIFOCacheImages.pop_front();
139 }
140
141 return pageToDetach;
142}
143
144template <typename TImageContainer, typename TImageFactory>
145inline
146void
147DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::updateCache(const Domain &aDomain)
148{
149 myFIFOCacheImages.push_back(myImageFactory->requestImage(aDomain));
150}
151
152template <typename TImageContainer, typename TImageFactory>
153inline
154void
155DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::clearCache()
156{
157 myFIFOCacheImages.clear();
158}
159
160// ----------------------- Specialization DGtal::CACHE_WRITE_POLICY_WT ------------------------------
161
162template <typename TImageContainer, typename TImageFactory>
163inline
164void
165DGtal::ImageCacheWritePolicyWT<TImageContainer, TImageFactory>::writeInPage(TImageContainer * anImageContainer, const Point & aPoint, const Value &aValue)
166{
167 anImageContainer->setValue(aPoint, aValue);
168
169 myImageFactory->flushImage(anImageContainer); // DGtal::CACHE_WRITE_POLICY_WT
170}
171
172template <typename TImageContainer, typename TImageFactory>
173inline
174void
175DGtal::ImageCacheWritePolicyWT<TImageContainer, TImageFactory>::flushPage(TImageContainer * anImageContainer)
176{
177 boost::ignore_unused_variable_warning(anImageContainer);
178}
179
180// ----------------------- Specialization DGtal::CACHE_WRITE_POLICY_WB ------------------------------
181
182template <typename TImageContainer, typename TImageFactory>
183inline
184void
185DGtal::ImageCacheWritePolicyWB<TImageContainer, TImageFactory>::writeInPage(TImageContainer * anImageContainer, const Point & aPoint, const Value &aValue)
186{
187 anImageContainer->setValue(aPoint, aValue);
188}
189
190template <typename TImageContainer, typename TImageFactory>
191inline
192void
193DGtal::ImageCacheWritePolicyWB<TImageContainer, TImageFactory>::flushPage(TImageContainer * anImageContainer)
194{
195 myImageFactory->flushImage(anImageContainer); // DGtal::CACHE_WRITE_POLICY_WB
196}
197
198// //
199///////////////////////////////////////////////////////////////////////////////
200
201