Hugin trunk 0.1
Loading...
Searching...
No Matches
CachedImageRemapper.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
27#include "CachedImageRemapper.h"
28
29#include <vigra/basicimageview.hxx>
30#include <vigra/copyimage.hxx>
32
33
34namespace HuginBase {
35
40
43 const PanoramaOptions & popts,
44 unsigned int imgNr,
45 vigra::Rect2D outputROI,
47{
48 // always map to HDR mode. curve and exposure is applied in preview window, for speed
51 opts.outputExposureValue = 0.0;
52
53 // return old image, if already in cache and if it has changed since the last rendering
54 if (set_contains(m_images, imgNr)) {
55 // return cached image if the parameters of the image have not changed
57 if (oldParam == pano.getSrcImage(imgNr)
58 && m_panoOpts[imgNr].getHFOV() == opts.getHFOV()
59 && m_panoOpts[imgNr].getWidth() == opts.getWidth()
60 && m_panoOpts[imgNr].getHeight() == opts.getHeight()
61 && m_panoOpts[imgNr].getProjection() == opts.getProjection()
62 && m_panoOpts[imgNr].getProjectionParameters() == opts.getProjectionParameters()
63 )
64 {
65 DEBUG_DEBUG("using cached remapped image " << imgNr);
66 return m_images[imgNr];
67 }
68 }
69
71
72 // remap image
73 DEBUG_DEBUG("remapping image " << imgNr);
74
75 // load image
76 const SrcPanoImage & img = pano.getImage(imgNr);
77
78 ImageCache::EntryPtr e = ImageCache::getInstance().getSmallImage(img.getFilename().c_str());
79 if ( (e->image8->width() == 0) && (e->image16->width() == 0) && (e->imageFloat->width() == 0) ) {
80 throw std::runtime_error("could not retrieve small source image for preview generation");
81 }
82 vigra::Size2D srcImgSize;
83 if (e->image8->width() > 0)
84 srcImgSize = e->image8->size();
85 else if (e->image16->width() > 0)
86 srcImgSize = e->image16->size();
87 else
88 srcImgSize = e->imageFloat->size();
89
91 remapped->m_ICCProfile = *(e->iccProfile);
93 // adjust distortion parameters for small preview image
95
96 vigra::FImage srcFlat;
97 // use complete image, by supplying an empty mask image
98 vigra::BImage srcMask;
99
100 if (img.getVigCorrMode() & SrcPanoImage::VIGCORR_FLATFIELD) {
101 ImageCache::EntryPtr e = ImageCache::getInstance().getSmallImage(img.getFlatfieldFilename().c_str());
102 if (!e) {
103 delete remapped;
104 throw std::runtime_error("could not retrieve flatfield image for preview generation");
105 }
106 if (e->image8->width()) {
107 srcFlat.resize(e->image8->size());
108 vigra::copyImage(srcImageRange(*(e->image8),
109 vigra::RGBToGrayAccessor<vigra::RGBValue<vigra::UInt8> >()),
110 vigra::destImage(srcFlat));
111 } else if (e->image16->width()) {
112 srcFlat.resize(e->image16->size());
113 vigra::copyImage(srcImageRange(*(e->image16),
114 vigra::RGBToGrayAccessor<vigra::RGBValue<vigra::UInt16> >()),
115 vigra::destImage(srcFlat));
116 } else {
117 srcFlat.resize(e->imageFloat->size());
118 vigra::copyImage(srcImageRange(*(e->imageFloat),
119 vigra::RGBToGrayAccessor<vigra::RGBValue<float> >()),
120 vigra::destImage(srcFlat));
121 }
122 }
123 progress->setMessage("remapping");
124
125 // compute the bounding output rectangle here!
126 vigra::Rect2D outROI = estimateOutputROI(pano, opts, imgNr);
127 DEBUG_DEBUG("srcPanoImg size: " << srcPanoImg.getSize() << " pano roi:" << outROI);
128
129 if (e->imageFloat->width()) {
130 // remap image
131 remapImage(*(e->imageFloat),
132 srcMask,
133 srcFlat,
135 opts,
136 outROI,
137 *remapped,
138 progress);
139 } else if (e->image16->width()) {
140 // remap image
141 remapImage(*(e->image16),
142 srcMask,
143 srcFlat,
145 opts,
146 outROI,
147 *remapped,
148 progress);
149 } else {
150 remapImage(*(e->image8),
151 srcMask,
152 srcFlat,
154 opts,
155 outROI,
156 *remapped,
157 progress);
158 }
159
160 m_images[imgNr] = remapped;
161 m_imagesParam[imgNr] = pano.getSrcImage(imgNr);
162 m_panoOpts[imgNr] = opts;
163 return remapped;
164}
165
166
168{
169 DEBUG_DEBUG("Clear remapped cache");
170 for(std::map<unsigned int, MRemappedImage*>::iterator it = m_images.begin();
171 it != m_images.end(); ++it)
172 {
173 delete (*it).second;
174 }
175 // remove all images
176 m_images.clear();
177 m_imagesParam.clear();
178}
179
181{
182 DEBUG_DEBUG("Remove " << imgNr << " from remapped cache");
183 if (set_contains(m_images, imgNr)) {
184 delete (m_images[imgNr]);
185 m_images.erase(imgNr);
186 m_imagesParam.erase(imgNr);
187 }
188}
189
190
191} //namespace
@ VIGCORR_FLATFIELD
flatfield correction
EntryPtr getSmallImage(const std::string &filename)
get an small image.
static ImageCache & getInstance()
get the global ImageCache object
std::shared_ptr< Entry > EntryPtr
a shared pointer to the entry
Definition ImageCache.h:112
void softFlush()
a soft version of flush.
struct to hold a image state for stitching
vigra::ImageImportInfo::ICCProfile m_ICCProfile
Model for a panorama.
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
Panorama image options.
const std::vector< double > & getProjectionParameters() const
Get the optional projection parameters.
unsigned int getWidth() const
PanoramaOptions::ProjectionFormat getProjection() const
unsigned int getHeight() const
get panorama height
void invalidate()
invalidates all images
virtual MRemappedImage * getRemapped(const PanoramaData &pano, const PanoramaOptions &opts, unsigned int imgNr, vigra::Rect2D outputROI, AppBase::ProgressDisplay *progress)
create a remapped pano image.
Nona::RemappedPanoImage< vigra::FRGBImage, vigra::BImage > MRemappedImage
std::map< unsigned, PanoramaOptions > m_panoOpts
std::map< unsigned, SrcPanoImage > m_imagesParam
std::map< unsigned, MRemappedImage * > m_images
All variables of a source image.
void resize(const vigra::Size2D &size, VariableMap *potentialLinkedVars)
"resize" image, adjusts all distortion coefficients for usage with a source image of size size potent...
#define DEBUG_DEBUG(msg)
Definition utils.h:68
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
vigra::Rect2D estimateOutputROI(const PanoramaData &pano, const PanoramaOptions &opts, unsigned i, const double maxLength)
bool set_contains(const _Container &c, const typename _Container::key_type &key)
Definition stl_utils.h:74
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41