Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenerateThumbnail.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
12  /* This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This software is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public
23  * License along with this software. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  */
27 
28 #include "GenerateThumbnail.h"
32 
33 bool GenerateThumbnail(const std::string pto_filename, const wxSize size, vigra::BRGBImage& panoImage, vigra::BImage& panoMask, vigra::ImageImportInfo::ICCProfile& iccProfile)
34 {
35  // read pto file
37  if (!pano.ReadPTOFile(pto_filename, hugin_utils::getPathPrefix(pto_filename)))
38  {
39  return false;
40  };
41  // check that all images are available
42  for (long i = 0; i < pano.getNrOfImages(); ++i)
43  {
44  if (!hugin_utils::FileExists(pano.getImage(i).getFilename()))
45  {
46  return false;
47  };
48  };
49  if (pano.getActiveImages().empty())
50  {
51  // no active images in pto file
52  return false;
53  }
54  // calculate scale factor
56  const vigra::Rect2D roi(opts.getROI());
57  const double scale = std::max(roi.width() * 1.0 / size.GetWidth(), roi.height() * 1.0 / size.GetHeight());
58  opts.setWidth(opts.getWidth() / scale);
59  // TO DO: check that images has enough pixel
60  vigra::Rect2D newROI(opts.getROI());
61  newROI.addSize(vigra::Size2D(std::min(size.GetWidth() - newROI.width(), 0), std::min(size.GetHeight() - newROI.height(), 0)));
62  opts.setROI(newROI);
63  // now remapped and stitch images
65  //prepare some settings
66  opts.tiff_saveROI = false;
67  opts.outputFormat = HuginBase::PanoramaOptions::PNG;
68  opts.outputImageType = "png";
70  opts.remapUsingGPU = false;
71  if (pano.getImage(0).getResponseType() == HuginBase::BaseSrcPanoImage::RESPONSE_EMOR)
72  {
73  // get the emor parameters.
74  opts.outputEMoRParams = pano.getSrcImage(0).getEMoRParams();
75  }
76  else
77  {
78  // clear the parameters to indicatate these should not be used
79  opts.outputEMoRParams.clear();
80  };
82  HuginBase::Nona::SetAdvancedOption(advOptions, "saveIntermediateImages", false);
83  HuginBase::Nona::SetAdvancedOption(advOptions, "hardSeam", true);
86  remapper.setAdvancedOptions(advOptions);
87  // create panorama canvas
88  vigra::BRGBImage preview(opts.getWidth(), opts.getHeight());
89  vigra::BImage previewMask(opts.getWidth(), opts.getHeight());
90  // finally stitch and merge images
91  stitcher.init(opts, pano.getActiveImages());
92  stitcher.stitch(opts, pano.getActiveImages(), std::string(), preview, previewMask, remapper, advOptions);
93  // HuginBase::Nona::WeightedStitcher is using the full canvas size
94  // so we copy out only the crop portion into the final image data
95  panoImage.resize(stitcher.GetPanoROI().size());
96  panoMask.resize(panoImage.size());
97  vigra::copyImage(vigra::srcImageRange(preview, stitcher.GetPanoROI()), vigra::destImage(panoImage));
98  vigra::copyImage(vigra::srcImageRange(previewMask, stitcher.GetPanoROI()), vigra::destImage(panoMask));
99  iccProfile = stitcher.GetICCProfile();
100  delete pdisp;
101  return true;
102 }
generate thumbnail from given pto file
bool FileExists(const std::string &filename)
checks if file exists
Definition: utils.cpp:362
Dummy progress display, without output.
vigra::ImageImportInfo::ICCProfile GetICCProfile() const
Definition: Stitcher.h:625
void stitch(const PanoramaOptions &opts, const UIntSet &imgSet, const std::string &filename, ImageType &panoImage, AlphaType &alpha, SingleImageRemapper< ImageType, AlphaType > &remapper, const AdvancedOptions &advOptions)
Definition: Stitcher.h:473
SrcPanoImage getSrcImage(unsigned imgNr) const
get a description of a source image
Definition: Panorama.cpp:1620
vigra::Rect2D GetPanoROI() const
Definition: Stitcher.h:621
void init(const PanoramaOptions &opts, const UIntSet &images)
Definition: Stitcher.h:92
Model for a panorama.
Definition: Panorama.h:152
empirical model of response
Definition: SrcPanoImage.h:100
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
Definition: utils.cpp:184
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
bool ReadPTOFile(const std::string &filename, const std::string &prefix="")
read pto file from the given filename into Panorama object it does some checks on the file and issues...
Definition: Panorama.cpp:2023
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
Definition: ROIImage.h:287
UIntSet getActiveImages() const
get active images
Definition: Panorama.cpp:1585
Contains various routines used for stitching panoramas.
const PanoramaOptions & getOptions() const
returns the options for this panorama
Definition: Panorama.h:481
void setAdvancedOptions(const HuginBase::Nona::AdvancedOptions advancedOptions)
Definition: ImageRemapper.h:60
static T max(T x, T y)
Definition: svm.cpp:65
bool GenerateThumbnail(const std::string pto_filename, const wxSize size, vigra::BRGBImage &panoImage, vigra::BImage &panoMask, vigra::ImageImportInfo::ICCProfile &iccProfile)
generate thumbnail image for given pto_filename
std::map< std::string, std::string > AdvancedOptions
void copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc)
Definition: openmp_vigra.h:305
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
functor to create a remapped image, loads image from disk
Definition: ImageRemapper.h:75
Panorama image options.
static T min(T x, T y)
Definition: svm.cpp:62
void SetAdvancedOption(AdvancedOptions &opts, const std::string &name, const bool value)
store the option with name in AdvancedOptions