00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "hugin_script_interface/hpi_classes.h"
00040
00041
00042
00043 #include "hugin_script_interface/hpi.h"
00044
00045
00046
00047
00048 #include <stdarg.h>
00049
00050 namespace hpi
00051 {
00053 static python_interface hpi_instance;
00054
00055 int callhpi ( const char* plugin_name ,
00056 int argc ,
00057 ... )
00058 {
00059 va_list arglist ;
00060 va_start ( arglist , argc ) ;
00061
00062
00063 if ( ! hpi_instance.activate() )
00064 {
00065
00066 fprintf ( stderr , "HPI ERROR: failed to activate Python interface\n" ) ;
00067 va_end ( arglist ) ;
00068 return -20 ;
00069 }
00070
00071
00072
00073 python_arglist pyarglist ( argc + 1 ) ;
00074 pyarglist.add ( plugin_name ) ;
00075
00076 for ( int argno = 0 ; argno < argc ; argno++ )
00077 {
00078
00079 const char* type_name = va_arg ( arglist , const char* ) ;
00080
00081 void* pvalue = va_arg ( arglist , void* ) ;
00082
00083 PyObject* pyarg = pyarglist.make_hsi_object ( type_name , pvalue ) ;
00084
00085 if ( ! pyarglist.add ( pyarg ) )
00086 {
00087
00088 va_end ( arglist ) ;
00089 return -21 ;
00090 }
00091 }
00092 va_end ( arglist ) ;
00093
00094
00095 PyObject* arg_tuple = pyarglist.yield() ;
00096 if ( ! arg_tuple )
00097 {
00098
00099 return -22 ;
00100 }
00101
00102
00103
00104
00105
00106 return hpi_instance.call_hpi ( "hpi_dispatch" , arg_tuple );
00107 }
00108
00109 }
00110
00111
00112
00113
00114
00115 #ifdef standalone
00116
00117 #include <fstream>
00118
00119 using namespace std;
00120 using namespace HuginBase;
00121 using namespace hugin_utils;
00122 using namespace AppBase;
00123
00124
00125
00126
00127
00128
00129 HuginBase::Panorama* pano_open ( const char* infile )
00130 {
00131 string input ( infile ) ;
00132
00133 ifstream prjfile(input.c_str());
00134
00135 if (!prjfile.good())
00136 {
00137 fprintf ( stderr ,
00138 "could not open script %s\n" ,
00139 input.c_str() ) ;
00140 return NULL;
00141 }
00142
00143 HuginBase::Panorama* pano = new HuginBase::Panorama ;
00144
00145 pano->setFilePrefix ( getPathPrefix ( input ) );
00146 AppBase::DocumentData::ReadWriteError err = pano->readData(prjfile);
00147
00148 if (err != DocumentData::SUCCESSFUL)
00149 {
00150 fprintf ( stderr ,
00151 "%s %s\n%s %d\n" ,
00152 "error while parsing panos tool script:" ,
00153 input.c_str() ,
00154 "DocumentData::ReadWriteError code:" ,
00155 err ) ;
00156 delete pano ;
00157 return NULL ;
00158 }
00159 fprintf ( stderr , "opened pano: %p\n" , pano ) ;
00160 return pano ;
00161 }
00162
00163
00164
00165
00166
00167 int main ( int argc , char* argv[] )
00168 {
00169 HuginBase::Panorama* pano = pano_open ( argv[1] ) ;
00170 if ( ! pano )
00171 {
00172 fprintf(stderr, "Failed to open pano\n");
00173 return 1;
00174 }
00175
00176 int success = hsi::callhpi ( argv[2] , 1 , "HuginBase::Panorama*" , pano ) ;
00177
00178 return success ;
00179 }
00180 #endif // standalone