Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
58 namespace HuginBase { namespace PTools {
59 
60 unsigned 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;
68  UIntSet allImg;
69  fill_set(allImg,0, unsigned(pano.getNrOfImages()-1));
70  pano.printPanoramaScript(scriptbuf, pano.getOptimizeVector(), pano.getOptions(), allImg, true);
71  script = strdup(scriptbuf.str().c_str());
72  } else {
73  script = const_cast<char *>(userScript);
74  }
75 
76  OptInfo opt;
77  AlignInfo ainf;
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 
94  RunLMOptimizer( &opt );
95  ainf.data = opt.message;
96  // get results from align info.
97 #ifdef DEBUG_WRITE_OPTIM_OUTPUT
98  fullPath path;
99  StringtoFullPath(&path, DEBUG_WRITE_OPTIM_OUTPUT_FILE );
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  }
110  DisposeAlignInfo( &ainf );
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
virtual const OptimizeVector & getOptimizeVector() const =0
return the optimize settings stored inside panorama
VariableMapVector GetAlignInfoVariables(const AlignInfo &gl)
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
wraps around PTOptimizer
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
virtual void updateCtrlPointErrors(const CPVector &controlPoints)=0
update control points distances.
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
Model for a panorama.
Definition: PanoramaData.h:81
CPVector GetAlignInfoCtrlPoints(const AlignInfo &gl)
unsigned int optimize(PanoramaData &pano, const char *userScript)
optimize the images imgs, for variables optvec, using vars as start.
void fill_set(_Container &c, typename _Container::key_type begin, typename _Container::key_type end)
Definition: stl_utils.h:81
virtual std::size_t getNrOfImages() const =0
number of images.
virtual void updateVariables(const VariableMapVector &vars)=0
Set the variables.