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.
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.
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/>.
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
24 * Implementation of inline methods defined in ImageCachePolicies.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
33 //////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////
36 // IMPLEMENTATION of inline methods.
37 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
40 // ----------------------- Standard services ------------------------------
42 // ----------------------- Specialization DGtal::CACHE_READ_POLICY_LAST ------------------------------
44 template <typename TImageContainer, typename TImageFactory>
47 DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPage(const Point & aPoint)
49 if (myCacheImagesPtr==NULL)
52 if (myCacheImagesPtr->domain().isInside(aPoint))
53 return myCacheImagesPtr;
58 template <typename TImageContainer, typename TImageFactory>
61 DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPage(const Domain & aDomain)
63 if (myCacheImagesPtr==NULL)
66 if ( (myCacheImagesPtr->domain().lowerBound() == aDomain.lowerBound()) && (myCacheImagesPtr->domain().upperBound() == aDomain.upperBound()) )
67 return myCacheImagesPtr;
72 template <typename TImageContainer, typename TImageFactory>
75 DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPageToDetach()
77 return myCacheImagesPtr;
80 template <typename TImageContainer, typename TImageFactory>
83 DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::updateCache(const Domain &aDomain)
85 myCacheImagesPtr = myImageFactory->requestImage(aDomain);
88 template <typename TImageContainer, typename TImageFactory>
91 DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::clearCache()
93 myCacheImagesPtr = NULL;
96 // ----------------------- Specialization DGtal::CACHE_READ_POLICY_FIFO ------------------------------
98 template <typename TImageContainer, typename TImageFactory>
101 DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPage(const Point & aPoint)
103 if (myFIFOCacheImages.empty())
106 for (unsigned int i=0; i<myFIFOCacheImages.size(); i++)
107 if (myFIFOCacheImages[i]->domain().isInside(aPoint))
108 return myFIFOCacheImages[i];
113 template <typename TImageContainer, typename TImageFactory>
116 DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPage(const Domain & aDomain)
118 if (myFIFOCacheImages.empty())
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];
128 template <typename TImageContainer, typename TImageFactory>
131 DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPageToDetach()
133 TImageContainer *pageToDetach = NULL;
135 if (myFIFOCacheImages.size() >= myFIFOSizeMax)
137 pageToDetach = myFIFOCacheImages.front();
138 myFIFOCacheImages.pop_front();
144 template <typename TImageContainer, typename TImageFactory>
147 DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::updateCache(const Domain &aDomain)
149 myFIFOCacheImages.push_back(myImageFactory->requestImage(aDomain));
152 template <typename TImageContainer, typename TImageFactory>
155 DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::clearCache()
157 myFIFOCacheImages.clear();
160 // ----------------------- Specialization DGtal::CACHE_WRITE_POLICY_WT ------------------------------
162 template <typename TImageContainer, typename TImageFactory>
165 DGtal::ImageCacheWritePolicyWT<TImageContainer, TImageFactory>::writeInPage(TImageContainer * anImageContainer, const Point & aPoint, const Value &aValue)
167 anImageContainer->setValue(aPoint, aValue);
169 myImageFactory->flushImage(anImageContainer); // DGtal::CACHE_WRITE_POLICY_WT
172 template <typename TImageContainer, typename TImageFactory>
175 DGtal::ImageCacheWritePolicyWT<TImageContainer, TImageFactory>::flushPage(TImageContainer * anImageContainer)
177 boost::ignore_unused_variable_warning(anImageContainer);
180 // ----------------------- Specialization DGtal::CACHE_WRITE_POLICY_WB ------------------------------
182 template <typename TImageContainer, typename TImageFactory>
185 DGtal::ImageCacheWritePolicyWB<TImageContainer, TImageFactory>::writeInPage(TImageContainer * anImageContainer, const Point & aPoint, const Value &aValue)
187 anImageContainer->setValue(aPoint, aValue);
190 template <typename TImageContainer, typename TImageFactory>
193 DGtal::ImageCacheWritePolicyWB<TImageContainer, TImageFactory>::flushPage(TImageContainer * anImageContainer)
195 myImageFactory->flushImage(anImageContainer); // DGtal::CACHE_WRITE_POLICY_WB
199 ///////////////////////////////////////////////////////////////////////////////