1 // -*- c-basic-offset: 4 -*-
2 /** @file PanoramaOptions.h
3  *
4  *  @author Pablo d'Angelo <pablo.dangelo@web.de>
5  *
6  *  $Id$
7  *
8  *  This is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2 of the License, or (at your option) any later version.
12  *
13  *  This software is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public
19  *  License along with this software. If not, see
20  *  <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 #ifndef _PANODATA_PANORAMAMEMENTO_H
25 #define _PANODATA_PANORAMAMEMENTO_H
26 
27 #include <hugin_config.h>
28 #include <hugin_shared.h>
29 
30 #include <string>
31 #include <vector>
32 
33 #include <vigra/diff2d.hxx>
34 
35 extern "C" {
36 
37     #ifdef __INTEL__
38     #define __INTELMEMO__
39     #undef __INTEL__
40     #endif
41 
42     // Define __NO_SYSTEM__ in order to turn off including of windows.h in pano13/panorama.h
43     #define __NO_SYSTEM__
44     #include <pano13/panorama.h>
45 
46     #ifdef __INTELMEMO__
47     #define __INTEL__
48     #undef __INTELMEMO__
49     #endif
50 
51     // remove stupid #defines from the evil windows.h
52 
53 #ifdef DIFFERENCE
54 #undef DIFFERENCE
55 #endif
56 #ifdef min
57 #undef min
58 #endif
59 #ifdef max
60 #undef max
61 #endif
62 #ifdef MIN
63 #undef MIN
64 #endif
65 #ifdef MAX
66 #undef MAX
67 #endif
68 
69 }
70 
71 #include <vigra_ext/Interpolators.h>
72 
73 namespace HuginBase {
74 
75 /** Panorama image options
76  *
77  *  this holds the settings for the final panorama
78  */
79 class IMPEX PanoramaOptions
80 {
81 
82     public:
83         /** Projection of final panorama
84          */
85         enum ProjectionFormat {
86             RECTILINEAR = 0,
87             CYLINDRICAL = 1,
88             EQUIRECTANGULAR = 2,
89             FULL_FRAME_FISHEYE = 3,
90             STEREOGRAPHIC = 4,
91             MERCATOR = 5,
92             TRANSVERSE_MERCATOR = 6,
93             SINUSOIDAL = 7,
94             LAMBERT = 8,
95             LAMBERT_AZIMUTHAL = 9,
96             ALBERS_EQUAL_AREA_CONIC = 10,
97             MILLER_CYLINDRICAL = 11,
98             PANINI = 12,
99             ARCHITECTURAL = 13,
100             ORTHOGRAPHIC = 14,
101             EQUISOLID = 15,
102             EQUI_PANINI = 16,
103             BIPLANE = 17,
104             TRIPLANE = 18,
105             GENERAL_PANINI = 19,
106             THOBY_PROJECTION = 20,
107             HAMMER_AITOFF = 21,
108         };
109 
110         /** PTStitcher acceleration */
111         enum PTStitcherAcceleration {
112             NO_SPEEDUP,
113             MAX_SPEEDUP,
114             MEDIUM_SPEEDUP  // for projects with morphing.
115         };
116 
117         /** Fileformat
118          */
119         enum FileFormat {
120             JPEG = 0,
121             JPEG_m,
122             PNG,
123             PNG_m,
124             TIFF,
125             TIFF_m,
126             TIFF_mask,
127             TIFF_multilayer,
128             TIFF_multilayer_mask,
129             PICT,
130             PSD,
131             PSD_m,
132             PSD_mask,
133             PAN,
134             IVR,
135             IVR_java,
136             VRML,
137             QTVR,
138             HDR,
139             HDR_m,
140             EXR,
141             EXR_m,
142             FILEFORMAT_NULL
143         };
144 
145         /** output mode */
146         enum OutputMode {
147             OUTPUT_LDR=0,
148             OUTPUT_HDR
149         };
150 
151         enum HDRMergeType {
152             HDRMERGE_AVERAGE=0,
153             HDRMERGE_DEGHOST=1
154         };
155 
156         /** blenders */
157         enum BlendingMechanism {
158             NO_BLEND=0,
159             PTBLENDER_BLEND=1,
160             ENBLEND_BLEND=2,
161             SMARTBLEND_BLEND=3,
162             PTMASKER_BLEND=4,
163             INTERNAL_BLEND=5
164         };
165 
166         ///
167         enum Remapper {
168             NONA=0,
169             PTMENDER
170         };
171 
172         /** type of color correction
173          */
174         enum ColorCorrection {
175             NONE = 0,
176             BRIGHTNESS_COLOR,
177             BRIGHTNESS,
178             COLOR
179         };
180 
181     public:
PanoramaOptions()182         PanoramaOptions()
183         {
184             reset();
185         };
186 
~PanoramaOptions()187         virtual ~PanoramaOptions() {};
188 
reset()189         virtual void reset()
190         {
191             m_projectionFormat = EQUIRECTANGULAR;
192             m_hfov = 360;
193             m_size = vigra::Size2D(3000, 1500);
194             m_roi = vigra::Rect2D(m_size);
195             tiff_saveROI = true;
196             tiffCompression = "LZW";
197             quality = 100;
198             colorCorrection = NONE;
199             colorReferenceImage = 0;
200             optimizeReferenceImage = 0;
201             interpolator = vigra_ext::INTERP_CUBIC;
202             // featherWidth = 10;
203             outputFormat = TIFF_m;
204             blendMode = ENBLEND_BLEND;
205             hdrMergeMode = HDRMERGE_AVERAGE;
206             remapper = NONA;
207             remapUsingGPU = false;
208             saveCoordImgs = false;
209             huberSigma = 2;
210             photometricHuberSigma = 2/255.0;
211             outputMode = OUTPUT_LDR;
212 
213             outputLDRBlended = true;
214             outputLDRLayers = false;
215             outputLDRExposureRemapped = false;
216             outputLDRExposureLayers = false;
217             outputLDRExposureLayersFused = false;
218             outputLDRStacks = false;
219             outputLDRExposureBlended = false;
220             outputHDRBlended = false;
221             outputHDRLayers = false;
222             outputHDRStacks = false;
223 
224             outputLayersCompression = "LZW";
225             outputImageType = "tif";
226             outputImageTypeCompression = "LZW";
227             outputImageTypeHDR= "exr";
228             outputImageTypeHDRCompression = "LZW";
229 
230             enblendOptions = "";
231             enfuseOptions  = "";
232             hdrmergeOptions = "";
233             verdandiOptions = "";
234 
235             outputEMoRParams.resize(5,0.0f);
236             outputExposureValue = 0.0;
237             outputRangeCompression = 0.0;
238             outputPixelType = "";
239 
240             panoProjectionFeaturesQuery(m_projectionFormat, &m_projFeatures);
241             resetProjectionParameters();
242 
243             outputStacksMinOverlap = 0.7;
244             outputLayersExposureDiff = 0.5;
245         }
246 
247     public:
248         ///
249         void printScriptLine(std::ostream & o,bool forPTOptimizer=false) const;
250 
251         /// return string name of output file format
252         static const std::string & getFormatName(FileFormat f);
253 
254         /** returns the FileFormat corrosponding to name.
255          *
256          *  if name is not recognized, FileFormat::TIFF is returned
257          */
258         static FileFormat getFormatFromName(const std::string & name);
259 
260         /** return the extension used by the current output format */
261         const std::string & getOutputExtension() const;
262 
263     public:
264         /** set panorama width
265          *  keep the HFOV, if keepView=true
266          */
267         void setWidth(unsigned int w, bool keepView = true);
268 
269         /** set panorama height
270          *
271          *  This changes the panorama vfov
272          */
273         void setHeight(unsigned int h);
274 
275         /* get panorama width */
getWidth()276         unsigned int getWidth() const
277             { return m_size.x; }
278 
279         /** get panorama height */
getHeight()280         unsigned int getHeight() const
281             {return m_size.y;}
282 
283         /// get size of output image
getSize()284         vigra::Size2D getSize() const
285             { return m_size; }
286 
287         ///
getROI()288         const vigra::Rect2D & getROI() const
289             { return m_roi; }
290 
291         ///
setROI(const vigra::Rect2D & val)292         void setROI(const vigra::Rect2D & val)
293             { m_roi = val & vigra::Rect2D(m_size); }
294 
295         /** set the Projection format and adjust the hfov/vfov
296          *  if nessecary
297          */
298         void setProjection(ProjectionFormat f);
299 
300         /** sets the optional parameters to their default values */
301         void resetProjectionParameters();
302 
303         ///
getProjection()304         PanoramaOptions::ProjectionFormat getProjection() const
305             { return m_projectionFormat; };
306 
307         /** Get the optional projection parameters */
getProjectionParameters()308         const std::vector<double> & getProjectionParameters() const
309             { return m_projectionParams; }
310 
311         /** set the optional parameters (they need to be of the correct size) */
312         void setProjectionParameters(const std::vector<double> & params);
313 
314         /** true, if FOV calcuations are supported for projection \p f */
315         bool fovCalcSupported(ProjectionFormat f) const;
316 
317         /** set the horizontal field of view.
318          *  also updates the image height (keep pano
319          *  field of view similar.)
320          */
321         void setHFOV(double h, bool keepView=true);
322 
323         ///
getHFOV()324         double getHFOV() const
325             { return m_hfov; }
326 
327         ///
328         void setVFOV(double v);
329 
330         ///
331         double getVFOV() const;
332 
333         /** get maximum possible hfov with current projection */
getMaxHFOV()334         double getMaxHFOV() const
335             { return m_projFeatures.maxHFOV; }
336 
337         /** get maximum possible vfov with current projection */
getMaxVFOV()338         double getMaxVFOV() const
339             { return m_projFeatures.maxVFOV; }
340 
341     public:
342         //TODO: Write accessor methods; make instance variables private unless absolutely neccesary for backward-compatibility.
343 
344         FileFormat outputFormat;
345 
346         // jpeg options
347         int quality;
348 
349         // TIFF options
350         std::string tiffCompression;
351         bool tiff_saveROI;
352 
353         ColorCorrection colorCorrection;
354         unsigned int colorReferenceImage;
355 
356         // misc options
357         vigra_ext::Interpolator interpolator;
358 
359         unsigned int optimizeReferenceImage;
360         // unsigned int featherWidth;
361 
362         BlendingMechanism blendMode;
363         HDRMergeType hdrMergeMode;
364         Remapper remapper;
365         bool remapUsingGPU;
366 
367         bool saveCoordImgs;
368 
369         double huberSigma;
370 
371         double photometricHuberSigma;
372 
373         // modes related to high dynamic range output
374         OutputMode outputMode;
375 
376         bool outputLDRBlended;         ///< save blended panorama (LDR)
377         bool outputLDRLayers;          ///< save remapped layers (LDR)
378         bool outputLDRExposureRemapped;///< save remapped layers (no exposure adjustment)
379         bool outputLDRExposureLayers;  ///< save blended exposure layers, do not perform fusion (no exposure adjustment)
380         bool outputLDRExposureLayersFused; ///< save blended exposure layers which are then fused (no exposure adjustment)
381         bool outputLDRStacks;          /// < save exposure fused stacks (no exposure adjustment)
382         bool outputLDRExposureBlended; ///< save blended exposure layers created from fused image stacks (no exposure adjustment)
383         bool outputHDRBlended;         ///< save blended panorama (HDR)
384         bool outputHDRLayers;          ///< save remapped layers (HDR)
385         bool outputHDRStacks;          ///< save image stacks (HDR)
386 
387         std::string outputLayersCompression;
388         std::string outputImageType;
389         std::string outputImageTypeCompression;
390         std::string outputImageTypeHDR;
391         std::string outputImageTypeHDRCompression;
392 
393         std::string enblendOptions;
394         std::string enfuseOptions;
395         std::string hdrmergeOptions;
396         std::string verdandiOptions;
397 
398         // select the exposure of the output images in LDR mode.
399         double outputExposureValue;
400         std::vector<float> outputEMoRParams;
401         double outputRangeCompression;
402 
403         // choose pixel type for output images.
404         std::string outputPixelType;
405 
406         // parameters for generating output layers and stacks
407         double outputStacksMinOverlap;
408         double outputLayersExposureDiff;
409 
410         pano_projection_features m_projFeatures;
411 
412     private:
413         static const std::string fileformatNames[];
414         static const std::string fileformatExt[];
415         double m_hfov;
416         double m_vfov;
417     //    unsigned int m_width;
418     //    unsigned int m_height;
419         ProjectionFormat m_projectionFormat;
420 
421         std::vector<double> m_projectionParams;
422         vigra::Size2D m_size;
423         vigra::Rect2D m_roi;
424 };
425 
426 
427 } // namespace
428 #endif // _H
429