Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[d5c5e9]: src / hugin1 / nona_gui / nona_gui.cpp Maximize Restore History

Download this file

nona_gui.cpp    299 lines (248 with data), 8.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// -*- c-basic-offset: 4 -*-
/** @file wx_nona.cpp
*
* @brief stitcher, with wxwindows progress display
*
* @author Pablo d'Angelo <pablo.dangelo@web.de>
*
* $Id$
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <hugin_config.h>
#include <hugin_version.h>
#include "panoinc_WX.h"
#include "panoinc.h"
#include <fstream>
#include <sstream>
#include <vigra/error.hxx>
#include "PT/Stitcher.h"
#include "base_wx/MyProgressDialog.h"
#include <tiffio.h>
// somewhere SetDesc gets defined.. this breaks wx/cmdline.h on OSX
#ifdef SetDesc
#undef SetDesc
#endif
#include <wx/cmdline.h>
using namespace vigra;
using namespace PT;
using namespace std;
/** The application class for nona gui
*
* it contains the main frame.
*/
class nonaApp : public wxApp
{
public:
/** ctor.
*/
nonaApp();
/** dtor.
*/
virtual ~nonaApp();
/** pseudo constructor. with the ability to fail gracefully.
*/
virtual bool OnInit();
/** just for testing purposes */
virtual int OnExit();
#ifdef __WXMAC__
/** the wx calls this method when the app gets "Open file" AppleEvent */
void nonaApp::MacOpenFile(const wxString &fileName);
#endif
private:
wxLocale m_locale;
#ifdef __WXMAC__
wxString m_macFileNameToOpenOnStart;
#endif
};
nonaApp::nonaApp()
{
// suppress tiff warnings
TIFFSetWarningHandler(0);
DEBUG_TRACE("ctor");
}
nonaApp::~nonaApp()
{
DEBUG_TRACE("dtor");
DEBUG_TRACE("dtor end");
}
bool nonaApp::OnInit()
{
SetAppName(wxT("nona_gui"));
wxString exePath;
wxFileName::SplitPath( argv[0], &exePath, NULL, NULL );
m_locale.Init(wxLANGUAGE_DEFAULT);
// add local Paths
m_locale.AddCatalogLookupPathPrefix(exePath + wxT("/locale"));
#if defined __WXMSW__
m_locale.AddCatalogLookupPathPrefix(wxT("./locale"));
#elif (defined __WXMAC__ && defined HUGIN_OSX_BUNDLED)
// TODO: add localisation init
#else
DEBUG_INFO("add locale path: " << INSTALL_LOCALE_DIR);
m_locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
#endif
// set the name of locale recource to look for
m_locale.AddCatalog(wxT("hugin"));
#if 0
#ifdef wxUSE_UNIX
wxLog *logger=new wxLogStream(&cerr);
wxLog::SetActiveTarget(logger);
#endif
#endif
// parse arguments
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("show this help message"),
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_OPTION, wxT("o"), wxT("output"), wxT("output file") },
{ wxCMD_LINE_OPTION, wxT("t"), wxT("threads"), wxT("number of threads"),
wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_PARAM, NULL, NULL, _T("<project> <images>"),
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + wxCMD_LINE_PARAM_MULTIPLE },
{ wxCMD_LINE_NONE }
};
wxCmdLineParser parser(cmdLineDesc, argc, argv);
switch ( parser.Parse() ) {
case -1: // -h or --help was given, and help displayed so exit
return false;
break;
case 0: // all is well
break;
default:
wxLogError(_("Syntax error in parameters detected, aborting."));
return false;
break;
}
bool imgsFromCmdline = false;
wxString scriptFile;
#ifdef __WXMAC__
m_macFileNameToOpenOnStart = wxT("");
wxYield();
scriptFile = m_macFileNameToOpenOnStart;
#endif
if( parser.GetParamCount() == 0 && wxIsEmpty(scriptFile))
{
wxFileDialog dlg(0,_("Specify project source project file"),
wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")),
wxT(""), wxT(""),
wxOPEN, wxDefaultPosition);
dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")));
if (dlg.ShowModal() == wxID_OK) {
wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later
scriptFile = dlg.GetPath();
} else { // bail
return false;
}
} else if(wxIsEmpty(scriptFile)) {
scriptFile = parser.GetParam(0);
if ( parser.GetParamCount() > 1) {
// load images.
imgsFromCmdline = true;
}
}
DEBUG_DEBUG("input file is " << (const char *)scriptFile.mb_str())
wxFileName fname(scriptFile);
if ( !fname.FileExists() ) {
wxLogError( _("Could not find project file:") + scriptFile);
return false;
}
wxString path = fname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
wxString outname;
if ( !parser.Found(wxT("o"), &outname) ) {
// ask for output.
wxFileDialog dlg(0,_("Specify output image filename"),
wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")),
wxT(""), wxT(""),
wxSAVE, wxDefaultPosition);
dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")));
if (dlg.ShowModal() == wxID_OK) {
wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later
outname = dlg.GetPath();
} else { // bail
wxLogError( _("No project files specified"));
return false;
}
}
DEBUG_DEBUG("output file specified is " << (const char *)outname.mb_str());
long nThreads = wxThread::GetCPUCount();
parser.Found(wxT("t"), & nThreads);
if (nThreads <= 0) nThreads = 1;
vigra_ext::ThreadManager::get().setNThreads((unsigned) nThreads);
wxString basename;
wxString outpath;
wxFileName::SplitPath(outname, &outpath, &basename, NULL);
//utils::StreamMultiProgressDisplay pdisp(cout);
MyProgressDialog pdisp(_("Stitching Panorama"), wxT(""), NULL, wxPD_ELAPSED_TIME | wxPD_AUTO_HIDE | wxPD_APP_MODAL );
Panorama pano;
PanoramaMemento newPano;
ifstream prjfile((const char *)scriptFile.mb_str());
if (prjfile.bad()) {
wxLogError( wxString::Format(_("could not open script : %s"), scriptFile.c_str()) );
return false;
}
if (newPano.loadPTScript(prjfile, (const char *)path.mb_str())) {
pano.setMemento(newPano);
} else {
wxLogError( wxString::Format(_("error while parsing panos tool script: %s"), scriptFile.c_str()) );
return false;
}
if (imgsFromCmdline) {
if (parser.GetParamCount() -1 != pano.getNrOfImages()) {
wxLogError(_("Wrong number of images specified on command line"));
return false;
}
for (size_t i = 0; i < pano.getNrOfImages(); i++) {
pano.setImageFilename(i, (const char *)parser.GetParam(i+1).mb_str());
}
}
PanoramaOptions opts = pano.getOptions();
// check for some options
int w = opts.getWidth();
int h = opts.getHeight();
cout << (const char *)wxString::Format(wxT("%s"), _("output image size: ")).mb_str() << w << "x" << h << std::endl;
wxString outfile;
if ( outpath != wxT("") ) {
outfile = outpath + wxFileName::GetPathSeparator() + basename;
} else {
outfile = basename;
}
DEBUG_DEBUG("output name: " << (const char *)outfile.mb_str());
try {
// stitch panorama
UIntSet simgs = pano.getActiveImages();
PT::stitchPanorama(pano, opts,
pdisp, (const char *)outfile.mb_str(), simgs);
} catch (std::exception & e) {
cerr << "caught exception: " << e.what() << std::endl;
return false;
}
return false;
}
int nonaApp::OnExit()
{
DEBUG_TRACE("");
return 0;
}
#ifdef __WXMAC__
// wx calls this method when the app gets "Open file" AppleEvent
void nonaApp::MacOpenFile(const wxString &fileName)
{
m_macFileNameToOpenOnStart = fileName;
}
#endif
// make wxwindows use this class as the main application
IMPLEMENT_APP(nonaApp)