~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/hugin_base/algorithms/assistant_makefile/AssistantMakefilelibExport.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file AssistantMakefilelibExport.cpp
 
3
 * @brief
 
4
 *  
 
5
 * @author Thomas Modes
 
6
 */
 
7
 
 
8
/*  This is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2 of the License, or (at your option) any later version.
 
12
 *
 
13
 *  This software is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public
 
19
 *  License along with this software; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 *
 
22
 */
 
23
 
 
24
#include "AssistantMakefilelibExport.h"
 
25
 
 
26
#include <makefilelib/char_type.h>
 
27
#include <iostream>
 
28
#include <stdexcept>
 
29
#include <fstream>
 
30
#include <sstream>
 
31
#include <locale>
 
32
#include <makefilelib/Comment.h>
 
33
#include <makefilelib/Variable.h>
 
34
#include <makefilelib/VariableDef.h>
 
35
#include <makefilelib/VariableRef.h>
 
36
#include <makefilelib/MakefileItem.h>
 
37
#include <makefilelib/Makefile.h>
 
38
#include <makefilelib/AutoVariable.h>
 
39
#include <makefilelib/Newline.h>
 
40
#include <makefilelib/Rule.h>
 
41
#include <makefilelib/Conditional.h>
 
42
#include <makefilelib/Manager.h>
 
43
#include <makefilelib/Anything.h>
 
44
 
 
45
#include <panodata/PanoramaData.h>
 
46
#include <hugin_utils/utils.h>
 
47
#include "algorithms/optimizer/ImageGraph.h"
 
48
 
 
49
namespace HuginBase
 
50
{
 
51
using namespace makefile;
 
52
using namespace std;
 
53
using namespace vigra;
 
54
namespace mf = makefile;
 
55
 
 
56
/// Automates an very often occuring sequence
 
57
#define  newVarDef(var, name, ...) \
 
58
mf::Variable* var = mgr.own(new mf::Variable(name, __VA_ARGS__)); \
 
59
var->getDef().add();
 
60
 
 
61
void AssistantMakefilelibExport::echoInfo(Rule& inforule, const std::string& info)
 
62
{
 
63
#ifdef _WINDOWS
 
64
    inforule.addCommand("echo " + info, false);
 
65
#else
 
66
    inforule.addCommand("echo '" + info + "'", false);
 
67
#endif
 
68
}
 
69
 
 
70
bool AssistantMakefilelibExport::createItems()
 
71
{
 
72
    // we use this Variable for initializing pointers that get an object only under certain conditions
 
73
    mf::Variable* nullvar = mgr.own(new mf::Variable("NOT_DEFINED", "This_variable_has_not_been_defined"));
 
74
 
 
75
    mgr.own_add((new Comment(
 
76
        "makefile for automatic panorama generating, created by hugin using the new makefilelib")));
 
77
 
 
78
#ifdef _WINDOWS
 
79
    mgr.own_add(new Comment("Force using cmd.exe"));
 
80
    mf::Variable* winshell = mgr.own(new mf::Variable("SHELL", getenv("ComSpec")));
 
81
    winshell->getDef().add();
 
82
#endif
 
83
 
 
84
    //----------
 
85
    // set the tool commands
 
86
    mgr.own_add(new Comment("Tool configuration"));
 
87
    newVarDef(vicpfind, "ICPFIND", progs.icpfind)
 
88
    newVarDef(vceleste, "CELESTE", progs.celeste)
 
89
    newVarDef(vcheckpto, "CHECKPTO", progs.checkpto)
 
90
    newVarDef(vcpclean, "CPCLEAN", progs.cpclean)
 
91
    newVarDef(vautooptimiser, "AUTOOPTIMISER", progs.autooptimiser)
 
92
    newVarDef(vpanomodify, "PANO_MODIFY", progs.pano_modify)
 
93
 
 
94
    newVarDef(vproject, "PROJECT", projectFile, Makefile::MAKE);
 
95
    newVarDef(vprojectShell, "PROJECT_SHELL", projectFile,Makefile::SHELL)
 
96
 
 
97
    Rule* all = mgr.own(new Rule());
 
98
    all->addTarget("all");
 
99
    all->addPrereq(vproject->getRef());
 
100
 
 
101
    mf::string outinproject=cstr(" -o ")+vprojectShell->getRef()+cstr(" ")+vprojectShell->getRef();
 
102
    bool runicp=(pano.getNrOfCtrlPoints()==0);
 
103
    if(!runicp)
 
104
    {
 
105
        //we check, if all images are connected
 
106
        //if not, we run also icpfind
 
107
        CPGraph graph;
 
108
        createCPGraph(pano, graph);
 
109
        CPComponents comps;
 
110
        runicp=findCPComponents(graph, comps)>1;
 
111
    };
 
112
    //build commandline for icpfind
 
113
    if(runicp)
 
114
    {
 
115
        //create cp find
 
116
        echoInfo(*all,"Finding control points...");
 
117
        all->addCommand(vicpfind->getRef()+outinproject);
 
118
        //building celeste command
 
119
        if(runCeleste)
 
120
        {
 
121
            mf::string celesteCommand=vceleste->getRef()+" ";
 
122
            valuestream.str("");    // clear the streams buffer
 
123
            valuestream << " -t " << celesteThreshold;
 
124
            celesteCommand+=valuestream.str()+" ";
 
125
            if(celesteSmallRadius)
 
126
                celesteCommand+="-r 1 ";
 
127
            echoInfo(*all,"Remove control points in clouds...");
 
128
            all->addCommand(celesteCommand+cstr(" -o ")+vprojectShell->getRef()+cstr(" -i ")+vprojectShell->getRef());
 
129
        };
 
130
        //building cpclean command
 
131
        if(runCPClean)
 
132
        {
 
133
            all->addCommand(vcheckpto->getRef()+" "+vprojectShell->getRef());
 
134
            echoInfo(*all,"Statistical cleaning of control points...");
 
135
            all->addCommand(vcpclean->getRef()+outinproject);
 
136
        };
 
137
    };
 
138
    //now optimise all
 
139
    all->addCommand(vcheckpto->getRef()+" "+vprojectShell->getRef());
 
140
    echoInfo(*all,"Optimise project...");
 
141
    all->addCommand(vautooptimiser->getRef()+" -a -m -l -s"+outinproject);
 
142
    // if necessary scale down final pano
 
143
    echoInfo(*all,"Setting output options...");
 
144
    valuestream.str("");
 
145
    if(scale<1)
 
146
    {
 
147
        valuestream << " --canvas=" << hugin_utils::roundi(scale*100) << "%%";
 
148
    };
 
149
    all->addCommand(vpanomodify->getRef()+valuestream.str()+cstr(" --crop=AUTO")+outinproject);
 
150
    all->add();
 
151
    return true;
 
152
}
 
153
 
 
154
}; //namespace
 
155