[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/huginapp/ImageCache.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _HUGINAPP_IMAGECACHE_H
00025 #define _HUGINAPP_IMAGECACHE_H
00026 
00027 #include <hugin_shared.h>
00028 #include <map>
00029 #include <boost/shared_ptr.hpp>
00030 #include <vigra/stdimage.hxx>
00031 #include <vigra/imageinfo.hxx>
00032 #include <hugin_utils/utils.h>
00033 #include <appbase/ProgressDisplayOld.h>
00034 
00035 #define HUGIN_IMGCACHE_MAPPING_INTEGER        0l
00036 #define HUGIN_IMGCACHE_MAPPING_FLOAT          1l
00037 
00038 
00039 namespace HuginBase {
00040     
00049 class IMPEX ImageCache
00050 {
00051 
00052     public:
00054         typedef boost::shared_ptr<vigra::BRGBImage> ImageCacheRGB8Ptr;
00055         typedef boost::shared_ptr<vigra::UInt16RGBImage> ImageCacheRGB16Ptr;
00056         typedef boost::shared_ptr<vigra::FRGBImage> ImageCacheRGBFloatPtr;
00057         typedef boost::shared_ptr<vigra::BImage> ImageCache8Ptr;
00058 
00060         struct IMPEX Entry
00061         {
00062             ImageCacheRGB8Ptr image8;
00063             ImageCacheRGB16Ptr image16;
00064             ImageCacheRGBFloatPtr imageFloat;
00065             ImageCache8Ptr mask;
00066 
00067             std::string origType;
00068             int lastAccess;
00069 
00070             public:
00072                 Entry()
00073                   : image8(ImageCacheRGB8Ptr(new vigra::BRGBImage)),
00074                     image16(ImageCacheRGB16Ptr(new vigra::UInt16RGBImage)),
00075                     imageFloat(ImageCacheRGBFloatPtr(new vigra::FRGBImage)),
00076                     mask(ImageCache8Ptr(new vigra::BImage))
00077                 {
00078                       DEBUG_TRACE("Constructing an empty ImageCache::Entry");
00079                 };
00080 
00082                 Entry(ImageCacheRGB8Ptr & img, 
00083                       ImageCacheRGB16Ptr & img16,
00084                       ImageCacheRGBFloatPtr & imgFloat,
00085                       ImageCache8Ptr & imgMask,
00086                       const std::string & typ)
00087                   : image8(img), image16(img16), imageFloat(imgFloat), mask(imgMask), origType(typ), lastAccess(0)
00088                 { 
00089                         DEBUG_TRACE("Constructing ImageCache::Entry");
00090                 };
00091 
00093                 ~Entry()
00094                 {
00095                     DEBUG_TRACE("Deleting ImageCacheEntry");
00096                 };
00097 
00099                 ImageCacheRGB8Ptr get8BitImage();
00100         };
00101 
00103         typedef boost::shared_ptr<Entry> EntryPtr;
00104 
00105 
00106     private:
00107         // ctor. private, nobody execpt us can create an instance.
00108         ImageCache()
00109                         : m_progress(NULL), m_accessCounter(0), upperBound(100*1024*1024l)
00110         {};
00111         
00112     public:
00115         virtual ~ImageCache()
00116         {
00117                 images.clear();
00118                 instance = NULL;
00119         }
00120 
00122         static ImageCache & getInstance();
00123         
00124     private:
00125         static ImageCache* instance;
00126 
00127         
00128     public:
00135         EntryPtr getImage(const std::string & filename);
00136 
00142         EntryPtr getSmallImage(const std::string & filename);
00143 
00144 
00148         void removeImage(const std::string & filename);
00149 
00155         void flush();
00156 
00161         void softFlush();
00164                 void SetUpperLimit(long newUpperLimit) { upperBound=newUpperLimit; };
00165 
00166     private:
00167         long upperBound;
00168 
00169         template <class SrcPixelType,
00170                   class DestIterator, class DestAccessor>
00171         void importAndConvertImage(const vigra::ImageImportInfo& info,
00172                                    vigra::pair<DestIterator, DestAccessor> dest,
00173                                    const std::string& type);
00174         
00175     //    template <class SrcPixelType,
00176     //              class DestIterator, class DestAccessor>
00177     //    void importAndConvertGrayImage(const ImageImportInfo& info,
00178     //                                   vigra::pair<DestIterator, DestAccessor> dest,
00179     //                                   wxString type);
00180         
00181     //    template <class SrcPixelType,
00182     //              class DestIterator, class DestAccessor>
00183     //    void importAndConvertGrayAlphaImage(const ImageImportInfo & info,
00184     //                                        vigra::pair<DestIterator, DestAccessor> dest,
00185     //                                        wxString type);
00186         
00187         template <class SrcPixelType,
00188                   class DestIterator, class DestAccessor,
00189                   class MaskIterator, class MaskAccessor>
00190             void importAndConvertAlphaImage(const vigra::ImageImportInfo & info,
00191                                         vigra::pair<DestIterator, DestAccessor> dest,
00192                                         vigra::pair<MaskIterator, MaskAccessor> mask,
00193                                         const std::string & type);
00194         
00195         
00196     public:
00198         void setProgressDisplay(AppBase::MultiProgressDisplay* disp)
00199             { m_progress = disp; }
00200         
00202         void clearProgressDisplay(AppBase::MultiProgressDisplay* disp)
00203             { m_progress = NULL; }
00204         
00205         
00206     private:
00207         std::map<std::string, EntryPtr> images;
00208 
00209         // our progress display
00210         AppBase::MultiProgressDisplay* m_progress;
00211 
00212         int m_accessCounter;
00213         
00214         
00215     public:
00229     //    const vigra::BImage & getPyramidImage(const std::string& filename,
00230     //                                          int level);
00231 
00232     private:
00233         // key for your pyramid map.
00234         struct PyramidKey
00235         {
00236             std::string filename;
00237             int level;
00238             
00239             public:
00240                 PyramidKey(const std::string& str, int lv)
00241                   : filename(str), level(lv)
00242                 {};
00243             
00244                 std::string toString()
00245                     { return filename + hugin_utils::lexical_cast<std::string>(level); }
00246         };
00247         
00248         std::map<std::string, vigra::BImage *> pyrImages;
00249 };
00250 
00251 
00252 } //namespace
00253 #endif // _IMAGECACHE_H

Generated on Mon Sep 20 01:01:25 2010 for Hugintrunk by doxygen 1.3.9.1