[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

hugin1/base_wx/ImageCache.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _IMAGECACHE_H
00025 #define _IMAGECACHE_H
00026 
00027 #include <hugin_shared.h>
00028 #include <map>
00029 #include <panoinc_WX.h>
00030 #include <PT/RemappedPanoImage.h>
00031 
00032 #include <common/utils.h>
00033 #include <boost/shared_ptr.hpp>
00034 
00035 #ifdef _Hgn1_REMAPPEDPANOIMAGE_H
00036 #include <huginapp/ImageCache.h>
00037 #include <huginapp/CachedImageRemapper.h>
00038 
00039 typedef HuginBase::ImageCache::ImageCacheRGB8Ptr    ImageCacheRGB8Ptr;
00040 typedef HuginBase::ImageCache::ImageCacheRGB16Ptr   ImageCacheRGB16Ptr;
00041 typedef HuginBase::ImageCache::ImageCacheRGBFloatPtr ImageCacheRGBFloatPtr;
00042 typedef HuginBase::ImageCache::ImageCache8Ptr       ImageCache8Ptr;
00043 
00044 using HuginBase::ImageCache;
00045 using HuginBase::SmallRemappedImageCache;
00046 
00047 WXIMPEX wxImage imageCacheEntry2wxImage(ImageCache::EntryPtr e);
00048 
00049 #else
00050 
00051 // use reference counted pointers
00052 typedef boost::shared_ptr<vigra::BRGBImage> ImageCacheRGB8Ptr;
00053 typedef boost::shared_ptr<vigra::UInt16RGBImage> ImageCacheRGB16Ptr;
00054 typedef boost::shared_ptr<vigra::FRGBImage> ImageCacheRGBFloatPtr;
00055 typedef boost::shared_ptr<vigra::BImage> ImageCache8Ptr;
00056 
00057 
00062 struct ImageKey
00063 {
00065     std::string name;
00067     std::string producer;
00069     int accesses;
00070 
00071     bool operator==(const ImageKey& o) const
00072         { return name == o.name && producer == o.producer; }
00073 };
00074 
00075 
00087 class ImageCache
00088 {
00089 public:
00090 
00092     class Entry
00093     {
00094         public:
00095 
00096             ImageCacheRGB8Ptr image8;
00097             ImageCacheRGB16Ptr image16;
00098             ImageCacheRGBFloatPtr imageFloat;
00099             ImageCache8Ptr mask;
00100 
00101             std::string origType;
00102             int lastAccess;
00103 
00104             Entry()
00105             : image8(ImageCacheRGB8Ptr(new vigra::BRGBImage)),
00106               image16(ImageCacheRGB16Ptr(new vigra::UInt16RGBImage)),
00107               imageFloat(ImageCacheRGBFloatPtr(new vigra::FRGBImage)),
00108               mask(ImageCache8Ptr(new vigra::BImage))
00109             {
00110                 DEBUG_TRACE("Constructing an empty ImageCache::Entry");
00111             };
00112 
00113             Entry(ImageCacheRGB8Ptr & img, 
00114                   ImageCacheRGB16Ptr & img16,
00115                   ImageCacheRGBFloatPtr & imgFloat,
00116                   ImageCache8Ptr & imgMask, const std::string & typ)
00117             : image8(img), image16(img16), imageFloat(imgFloat), mask(imgMask), origType(typ), lastAccess(0)
00118             { 
00119                 DEBUG_TRACE("Constructing ImageCache::Entry");
00120             };
00121 
00122             ~Entry()
00123             {
00124                 DEBUG_TRACE("Deleting ImageCacheEntry");
00125             }
00126 
00132             ImageCacheRGB8Ptr get8BitImage();
00133     };
00134 
00136     typedef boost::shared_ptr<Entry> EntryPtr;
00137 
00140     virtual ~ImageCache();
00141 
00143     static ImageCache & getInstance();
00144 
00151     EntryPtr getImage(const std::string & filename);
00152 
00158     EntryPtr getSmallImage(const std::string & filename);
00159 
00160 
00164     void removeImage(const std::string & filename);
00165 
00171     void flush();
00172 
00177     void softFlush();
00178 
00179     void setProgressDisplay(utils::MultiProgressDisplay * disp)
00180         {
00181             m_progress = disp;
00182         }
00183 
00197 //    const vigra::BImage & getPyramidImage(const std::string & filename,
00198 //                                          int level);
00199 
00200 private:
00203     ImageCache();
00204 
00205     static ImageCache * instance;
00206 
00207     std::map<std::string, EntryPtr> images;
00208 
00209     // key for your pyramid map.
00210     struct PyramidKey{
00211         PyramidKey(const std::string & str, int lv)
00212             : filename(str), level(lv) { }
00213         std::string toString()
00214             { return filename + utils::lexical_cast<std::string>(level); }
00215         std::string filename;
00216         int level;
00217     };
00218     std::map<std::string, vigra::BImage *> pyrImages;
00219 
00220     // our progress display
00221     utils::MultiProgressDisplay * m_progress;
00222 
00223     int m_accessCounter;
00224 };
00225 
00226 
00232 class SmallRemappedImageCache : public PT::SingleImageRemapper<vigra::FRGBImage,
00233                                 vigra::BImage>
00234 {
00235     typedef PT::RemappedPanoImage<vigra::FRGBImage, vigra::BImage> MRemappedImage;
00236 public:
00237     virtual ~SmallRemappedImageCache();
00238 
00239 #if 0
00240     virtual
00241     MRemappedImage *
00242     getRemapped(const std::string & filename,
00243                 const vigra::Diff2D & origSrcSize,
00244                 const vigra::Diff2D & srcSize,
00245                 PT::VariableMap srcVars,
00246                 PT::Lens::LensProjectionFormat srcProj,
00247                 PT::ImageOptions imgOpts,
00248                 const vigra::Diff2D &destSize,
00249                 PT::PanoramaOptions::ProjectionFormat destProj,
00250                 double destHFOV,
00251                 utils::MultiProgressDisplay & progress);
00252 #endif
00253 
00254 #ifdef _Hgn1_REMAPPEDPANOIMAGE_H
00255     virtual
00256     MRemappedImage *
00257     getRemapped(const HuginBase::PanoramaData & pano, const HuginBase::PanoramaOptions & opts,
00258                 unsigned int imgNr, AppBase::MultiProgressDisplay& progress);
00259 #else
00260     virtual
00261     MRemappedImage *
00262     getRemapped(const PT::Panorama & pano, const PT::PanoramaOptions & opts,
00263                 unsigned int imgNr, utils::MultiProgressDisplay & progress);
00264 #endif
00265     
00266     virtual     void
00267         release(MRemappedImage * d)
00268         {
00269                 // NOP, will be done by invalidate..
00270         }
00272     void invalidate();
00273 
00275     void invalidate(unsigned int imgNr);
00276 
00277 protected:
00278     std::map<unsigned, MRemappedImage*> m_images;
00279     // descriptions of the remapped image. useful to determine
00280     // if it has to be updated or not
00281     std::map<unsigned, PT::SrcPanoImage> m_imagesParam;
00282     std::map<unsigned, PT::PanoramaOptions> m_panoOpts;
00283 };
00284 
00288 wxImage imageCacheEntry2wxImage(ImageCache::EntryPtr e);
00289 
00290 #endif // if _Hgn1_REMAPPEDPANOIMAGE_H else
00291 
00292 #endif // _IMAGECACHE_H

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