Hugin trunk 0.1
Loading...
Searching...
No Matches
PanoToolsOptimizerWrapper.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
29#include <hugin_config.h>
30
31#include <sstream>
32#include <hugin_utils/utils.h>
33
34// libpano includes ------------------------------------------------------------
35
36#include <stdlib.h>
37
38#ifdef _WIN32
39// include windows.h with sensible defines, otherwise
40// panotools might include with its stupid, commonly
41// named macros all over the place.
42#define _STLP_VERBOSE_AUTO_LINK
43//#define _USE_MATH_DEFINES
44#define NOMINMAX
45#define VC_EXTRALEAN
46#include <windows.h>
47#undef DIFFERENCE
48#endif
49
50#include "PanoToolsInterface.h"
52
53//------------------------------------------------------------------------------
54
55//#define DEBUG_WRITE_OPTIM_OUTPUT
56//#define DEBUG_WRITE_OPTIM_OUTPUT_FILE "hugin_debug_optim_results.txt"
57
58namespace HuginBase { namespace PTools {
59
60unsigned int optimize(PanoramaData& pano,
61 const char * userScript)
62{
63 char * script = 0;
64 unsigned int retval = 0;
65
66 if (userScript == 0) {
67 std::ostringstream scriptbuf;
69 fill_set(allImg,0, unsigned(pano.getNrOfImages()-1));
71 script = strdup(scriptbuf.str().c_str());
72 } else {
73 script = const_cast<char *>(userScript);
74 }
75
78
79 if (ParseScript( script, &ainf ) == 0)
80 {
81 if( CheckParams( &ainf ) == 0 )
82 {
83 ainf.fcn = fcnPano;
84
85 SetGlobalPtr( &ainf );
86
87 opt.numVars = ainf.numParam;
88 opt.numData = ainf.numPts;
89 opt.SetVarsToX = SetLMParams;
90 opt.SetXToVars = SetAlignParams;
91 opt.fcn = ainf.fcn;
92 *opt.message = 0;
93
95 ainf.data = opt.message;
96 // get results from align info.
97#ifdef DEBUG_WRITE_OPTIM_OUTPUT
98 fullPath path;
100
101 ainf.data = opt.message;
102 WriteResults( script, &path, &ainf, distSquared, 0);
103#endif
106 } else {
107 std::cerr << "Bad params" << std::endl;
108 retval = 2;
109 }
111 } else {
112 std::cerr << "Bad params" << std::endl;
113 retval = 1;
114 }
115 if (! userScript) {
116 free(script);
117 }
118 return retval;
119}
120
121}} //namespace
wraps around PTOptimizer
Model for a panorama.
virtual const OptimizeVector & getOptimizeVector() const =0
return the optimize settings stored inside panorama
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
virtual void updateCtrlPointErrors(const CPVector &controlPoints)=0
update control points distances.
virtual void printPanoramaScript(std::ostream &o, const OptimizeVector &optvars, const PanoramaOptions &options, const UIntSet &imgs, bool forPTOptimizer, const std::string &stripPrefix="") const =0
create an optimizer script
virtual void updateVariables(const VariableMapVector &vars)=0
Set the variables.
virtual std::size_t getNrOfImages() const =0
number of images.
VariableMapVector GetAlignInfoVariables(const AlignInfo &gl)
unsigned int optimize(PanoramaData &pano, const char *userScript)
optimize the images imgs, for variables optvec, using vars as start.
CPVector GetAlignInfoCtrlPoints(const AlignInfo &gl)
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::set< unsigned int > UIntSet
void fill_set(_Container &c, typename _Container::key_type begin, typename _Container::key_type end)
Definition stl_utils.h:81
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