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 ------------------------------
44template <typename TImageContainer, typename TImageFactory>
47DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPage(const Point & aPoint)
49 if (myCacheImagesPtr==NULL)
52 if (myCacheImagesPtr->domain().isInside(aPoint))
53 return myCacheImagesPtr;
58template <typename TImageContainer, typename TImageFactory>
61DGtal::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;
72template <typename TImageContainer, typename TImageFactory>
75DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::getPageToDetach()
77 return myCacheImagesPtr;
80template <typename TImageContainer, typename TImageFactory>
83DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::updateCache(const Domain &aDomain)
85 myCacheImagesPtr = myImageFactory->requestImage(aDomain);
88template <typename TImageContainer, typename TImageFactory>
91DGtal::ImageCacheReadPolicyLAST<TImageContainer, TImageFactory>::clearCache()
93 myCacheImagesPtr = NULL;
96// ----------------------- Specialization DGtal::CACHE_READ_POLICY_FIFO ------------------------------
98template <typename TImageContainer, typename TImageFactory>
101DGtal::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];
113template <typename TImageContainer, typename TImageFactory>
116DGtal::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];
128template <typename TImageContainer, typename TImageFactory>
131DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::getPageToDetach()
133 TImageContainer *pageToDetach = NULL;
135 if (myFIFOCacheImages.size() >= myFIFOSizeMax)
137 pageToDetach = myFIFOCacheImages.front();
138 myFIFOCacheImages.pop_front();
144template <typename TImageContainer, typename TImageFactory>
147DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::updateCache(const Domain &aDomain)
149 myFIFOCacheImages.push_back(myImageFactory->requestImage(aDomain));
152template <typename TImageContainer, typename TImageFactory>
155DGtal::ImageCacheReadPolicyFIFO<TImageContainer, TImageFactory>::clearCache()
157 myFIFOCacheImages.clear();
160// ----------------------- Specialization DGtal::CACHE_WRITE_POLICY_WT ------------------------------
162template <typename TImageContainer, typename TImageFactory>
165DGtal::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
172template <typename TImageContainer, typename TImageFactory>
175DGtal::ImageCacheWritePolicyWT<TImageContainer, TImageFactory>::flushPage(TImageContainer * anImageContainer)
177 boost::ignore_unused_variable_warning(anImageContainer);
180// ----------------------- Specialization DGtal::CACHE_WRITE_POLICY_WB ------------------------------
182template <typename TImageContainer, typename TImageFactory>
185DGtal::ImageCacheWritePolicyWB<TImageContainer, TImageFactory>::writeInPage(TImageContainer * anImageContainer, const Point & aPoint, const Value &aValue)
187 anImageContainer->setValue(aPoint, aValue);
190template <typename TImageContainer, typename TImageFactory>
193DGtal::ImageCacheWritePolicyWB<TImageContainer, TImageFactory>::flushPage(TImageContainer * anImageContainer)
195 myImageFactory->flushImage(anImageContainer); // DGtal::CACHE_WRITE_POLICY_WB
199///////////////////////////////////////////////////////////////////////////////