PanoToolsOptimizerWrapper.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00029 #include <hugin_config.h>
00030 
00031 #include <sstream>
00032 #include <hugin_utils/utils.h>
00033 
00034 // libpano includes ------------------------------------------------------------
00035 
00036 #include <stdlib.h>
00037 
00038 #ifdef _WIN32
00039 // include windows.h with sensible defines, otherwise
00040 // panotools might include with its stupid, commonly
00041 // named macros all over the place.
00042 #define _STLP_VERBOSE_AUTO_LINK
00043 //#define _USE_MATH_DEFINES
00044 #define NOMINMAX
00045 #define VC_EXTRALEAN
00046 #include <windows.h>
00047 #undef DIFFERENCE
00048 #endif
00049 
00050 #include "PanoToolsInterface.h"
00051 #include "PanoToolsOptimizerWrapper.h"
00052 
00053 //------------------------------------------------------------------------------
00054 
00055 //#define DEBUG_WRITE_OPTIM_OUTPUT
00056 //#define DEBUG_WRITE_OPTIM_OUTPUT_FILE "hugin_debug_optim_results.txt"
00057 
00058 namespace HuginBase { namespace PTools {
00059 
00060 unsigned int optimize(PanoramaData& pano,
00061                       const char * userScript)
00062 {
00063     char * script = 0;
00064     unsigned int retval = 0;
00065 
00066     if (userScript == 0) {
00067         std::ostringstream scriptbuf;
00068         UIntSet allImg;
00069         fill_set(allImg,0, unsigned(pano.getNrOfImages()-1));
00070         pano.printPanoramaScript(scriptbuf, pano.getOptimizeVector(), pano.getOptions(), allImg, true);
00071         script = strdup(scriptbuf.str().c_str());
00072     } else {
00073         script = const_cast<char *>(userScript);
00074     }
00075 
00076     OptInfo             opt;
00077         AlignInfo       ainf;
00078 
00079     if (ParseScript( script, &ainf ) == 0)
00080         {
00081                 if( CheckParams( &ainf ) == 0 )
00082                 {
00083                         ainf.fcn        = fcnPano;
00084                         
00085                         SetGlobalPtr( &ainf ); 
00086                         
00087                         opt.numVars             = ainf.numParam;
00088                         opt.numData             = ainf.numPts;
00089                         opt.SetVarsToX          = SetLMParams;
00090                         opt.SetXToVars          = SetAlignParams;
00091                         opt.fcn                 = ainf.fcn;
00092                         *opt.message            = 0;
00093 
00094                         RunLMOptimizer( &opt );
00095                         ainf.data               = opt.message;
00096             // get results from align info.
00097 #ifdef DEBUG_WRITE_OPTIM_OUTPUT
00098             fullPath path;
00099             StringtoFullPath(&path, DEBUG_WRITE_OPTIM_OUTPUT_FILE );
00100 
00101                     ainf.data           = opt.message;
00102             WriteResults( script, &path, &ainf, distSquared, 0);
00103 #endif
00104             pano.updateVariables( GetAlignInfoVariables(ainf) );
00105             pano.updateCtrlPointErrors( GetAlignInfoCtrlPoints(ainf) );
00106                 } else {
00107             std::cerr << "Bad params" << std::endl;
00108             retval = 2;
00109         }
00110                 DisposeAlignInfo( &ainf );
00111     } else {
00112         std::cerr << "Bad params" << std::endl;
00113         retval = 1;
00114     }
00115     if (! userScript) {
00116         free(script);
00117     }
00118     return retval;
00119 }
00120 
00121 }} //namespace

Generated on Thu Apr 24 01:25:38 2014 for Hugintrunk by  doxygen 1.3.9.1