Hugin trunk 0.1
Loading...
Searching...
No Matches
hpi.cpp
Go to the documentation of this file.
1
17/* This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public
19 * License as published by the Free Software Foundation; either
20 * version 2 of the License, or (at your option) any later version.
21 *
22 * This software is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public
28 * License along with this software. If not, see
29 * <http://www.gnu.org/licenses/>.
30 *
31 * KFJ 2011-01-18
32 *
33 */
34
35// uncomment this if you want diagnostics:
36// #define HPI_VERBOSE
37
38// first pull in the Python interface classes
40
41// pull in the declaration of callhpi() to ensure it's consistent
42// with the definition below
44
45// callhpi() is a variadic function, so we need stdarg.h
46// This is old-fashioned and may become deprecated, but for
47// now it's very convenient.
48#include <stdarg.h>
49
50namespace hpi
51{
54
55int callhpi ( const char* plugin_name ,
56 int argc ,
57 ... )
58{
60 va_start ( arglist , argc ) ;
61
62 // activate the python interface if it's not on already
63 if ( ! hpi_instance.activate() )
64 {
65 // trouble
66 fprintf ( stderr , "HPI ERROR: failed to activate Python interface\n" ) ;
67 va_end ( arglist ) ;
68 return -20 ;
69 }
70
71 // we want to build a python argument list with argc + 1 arguments,
72 // + 1 because the first argument is the plugin name:
73 python_arglist pyarglist ( argc + 1 ) ;
74 pyarglist.add ( plugin_name ) ;
75
76 for ( int argno = 0 ; argno < argc ; argno++ )
77 {
78 // extract the type name
79 const char* type_name = va_arg ( arglist , const char* ) ;
80 // extract the pointer to argument object
81 void* pvalue = va_arg ( arglist , void* ) ;
82 // make a python object from this information
83 PyObject* pyarg = pyarglist.make_hsi_object ( type_name , pvalue ) ;
84 // try add it to the arglist
85 if ( ! pyarglist.add ( pyarg ) )
86 {
87 // oops... this went wrong
88 va_end ( arglist ) ;
89 return -21 ;
90 }
91 }
92 va_end ( arglist ) ; // we're done with that
93
94 // seems we're okay. get the argument tuple out
95 PyObject* arg_tuple = pyarglist.yield() ;
96 if ( ! arg_tuple )
97 {
98 // oops... this went wrong
99 return -22 ;
100 }
101
102 // now let's call the thing. This is done by passing the argument
103 // tuple to hpi_dispatch, a Python function defined in hpi.py
104 // this function interprets the first argument as a plugin name
105 // and calls that plugin with the remaining parameters.
106 return hpi_instance.call_hpi ( "hpi_dispatch" , arg_tuple );
107}
108
109} // namespace hsi
110
111// When I didn't yet have an entry point from hugin to call hpi,
112// I used the next bit as my main() code. For now this is left
113// inside, it may be handy later on.
114
115#ifdef standalone
116
117#include <fstream>
118
119using namespace std;
120using namespace HuginBase;
121using namespace hugin_utils;
122using namespace AppBase;
123
124// we use this function to make a panorama from a pto file
125// so we have something to pass to the hsi module. Later on,
126// this function will disappear and the calls will generate
127// from hugin
128
129HuginBase::Panorama* pano_open ( const char* infile )
130{
131 string input ( infile ) ;
132
133 ifstream prjfile(input.c_str());
134
135 if (!prjfile.good())
136 {
137 fprintf ( stderr ,
138 "could not open script %s\n" ,
139 input.c_str() ) ;
140 return NULL;
141 }
142
144
145 pano->setFilePrefix ( getPathPrefix ( input ) );
146 AppBase::DocumentData::ReadWriteError err = pano->readData(prjfile);
147
148 if (err != DocumentData::SUCCESSFUL)
149 {
150 fprintf ( stderr ,
151 "%s %s\n%s %d\n" ,
152 "error while parsing panos tool script:" ,
153 input.c_str() ,
154 "DocumentData::ReadWriteError code:" ,
155 err ) ;
156 delete pano ;
157 return NULL ;
158 }
159 fprintf ( stderr , "opened pano: %p\n" , pano ) ;
160 return pano ;
161}
162
163// demo-main that opens the pto named in argv[1] and passes
164// the Panorama pointer to a function named by argv[2]
165// in the hsi module
166
167int main ( int argc , char* argv[] )
168{
169 HuginBase::Panorama* pano = pano_open ( argv[1] ) ;
170 if ( ! pano )
171 {
172 fprintf(stderr, "Failed to open pano\n");
173 return 1;
174 }
175
176 int success = hsi::callhpi ( argv[2] , 1 , "HuginBase::Panorama*" , pano ) ;
177
178 return success ;
179}
180#endif // standalone
int main(int argc, char *argv[])
Definition Main.cpp:167
Model for a panorama.
Definition Panorama.h:153
void setFilePrefix(std::string prefix)
sets the path prefix of the images reffered with relative paths
Definition Panorama.h:664
helper class to generated PyObject from C/C++/hugin classes
Definition hpi_classes.h:89
a class which encapsulates the python interface.
Definition hpi_classes.h:51
bool activate()
: loads the necessary modules hsi and hpi.
int call_hpi(const char *hpi_func, PyObject *pArgs)
call a routine in the hsi module with a bunch of parameters.
C++ call interface to hpi.
core classes of the hpi interface, not for user code
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
Definition hpi.cpp:51
int callhpi(const char *plugin_name, int argc,...)
simplified call interface to the Python Plugin facility.
Definition hpi.cpp:55
static python_interface hpi_instance
this is where we keep the single instance of class python_interface
Definition hpi.cpp:53
namespace for various utils
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