00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "wx/wxprec.h"
00025
00026 #ifndef WX_PRECOMP
00027 # include "wx/wx.h"
00028 #endif
00029
00030 #include <boost/program_options.hpp>
00031 #include <iostream>
00032 #include <fstream>
00033 #include <sstream>
00034
00035 #include "lux.h"
00036 #include "api.h"
00037 #include "error.h"
00038 #include "osfunc.h"
00039 #include "epsilon.h"
00040
00041 #include "wxluxapp.h"
00042 #include "wxluxgui.h"
00043
00044 using namespace lux;
00045 namespace po = boost::program_options;
00046
00047 IMPLEMENT_APP(LuxGuiApp)
00048
00049
00050 bool LuxGuiApp::OnInit() {
00051
00052 srand(time(NULL));
00053
00054
00055 setlocale(LC_ALL, "C");
00056
00057 luxInit();
00058
00059 if(ProcessCommandLine()) {
00060 m_guiFrame = new LuxGui((wxFrame*)NULL, m_openglEnabled, m_copyLog2Console);
00061 m_guiFrame->Show(true);
00062 SetTopWindow(m_guiFrame);
00063 m_guiFrame->SetRenderThreads(m_threads);
00064 if(!m_inputFile.IsEmpty())
00065 m_guiFrame->RenderScenefile(m_inputFile);
00066 return true;
00067 } else {
00068 return false;
00069 }
00070 }
00071
00072 void InfoDialogBox(const std::string &msg, const std::string &caption = "LuxRender") {
00073 wxMessageBox(wxString(msg.c_str(), wxConvUTF8),
00074 wxString(caption.c_str(), wxConvUTF8),
00075 wxOK | wxICON_INFORMATION);
00076 }
00077
00078
00079 bool LuxGuiApp::ProcessCommandLine() {
00080 try {
00081 const int line_length = 150;
00082
00083
00084 po::options_description generic("Generic options", line_length);
00085 generic.add_options()
00086 ("version,v", "Print version string")
00087 ("help,h", "Produce help message")
00088 ("debug,d", "Enable debug mode")
00089 ("fixedseed,f", "Disable random seed mode")
00090 ("minepsilon,e", po::value< float >(), "Set minimum epsilon")
00091 ("maxepsilon,E", po::value< float >(), "Set maximum epsilon")
00092 ("verbosity,V", po::value< int >(), "Log output verbosity")
00093 ;
00094
00095
00096
00097
00098 po::options_description config("Configuration", line_length);
00099 config.add_options()
00100 ("threads,t", po::value < int >(), "Specify the number of threads that Lux will run in parallel.")
00101 ("useserver,u", po::value< std::vector<std::string> >()->composing(), "Specify the adress of a rendering server to use.")
00102 ("serverinterval,i", po::value < int >(), "Specify the number of seconds between requests to rendering servers.")
00103 ("logconsole,l", "Copy the output of the log tab to the console.")
00104 ;
00105
00106
00107
00108 po::options_description hidden("Hidden options", line_length);
00109 hidden.add_options()
00110 ("input-file", po::value < vector < string > >(), "input file")
00111 ;
00112
00113 #ifdef LUX_USE_OPENGL
00114 generic.add_options()
00115 ("noopengl", "Disable OpenGL to display the image")
00116 ;
00117 #else
00118 hidden.add_options()
00119 ("noopengl", "Disable OpenGL to display the image")
00120 ;
00121 #endif // LUX_USE_OPENGL
00122
00123 po::options_description cmdline_options(line_length);
00124 cmdline_options.add(generic).add(config).add(hidden);
00125
00126 po::options_description config_file_options(line_length);
00127 config_file_options.add(config).add(hidden);
00128
00129 po::options_description visible("Allowed options", line_length);
00130 visible.add(generic).add(config);
00131
00132 po::positional_options_description p;
00133
00134 p.add("input-file", -1);
00135
00136 po::variables_map vm;
00137 #if wxUSE_UNICODE == 1
00138 store(po::wcommand_line_parser(wxApp::argc, wxApp::argv).
00139 options(cmdline_options).positional(p).run(), vm);
00140 #else // ANSI
00141 store(po::command_line_parser(wxApp::argc, wxApp::argv).
00142 options(cmdline_options).positional(p).run(), vm);
00143 #endif // Unicode/ANSI
00144
00145 std::ifstream ifs("luxrender.cfg");
00146 store(parse_config_file(ifs, config_file_options), vm);
00147 notify(vm);
00148
00149 if(vm.count("help")) {
00150
00151
00152 std::stringstream ss;
00153 ss << "Usage: luxrender [options] file..." << std::endl;
00154 visible.print(ss);
00155 ss << std::endl;
00156 InfoDialogBox(ss.str());
00157 return false;
00158 }
00159
00160 if (vm.count("verbosity"))
00161 luxLogFilter = vm["verbosity"].as<int>();
00162
00163 if(vm.count("version")) {
00164
00165 std::stringstream ss;
00166 ss << "Lux version " << LUX_VERSION_STRING << " of " << __DATE__ << " at " << __TIME__ << std::endl;
00167 InfoDialogBox(ss.str());
00168 return false;
00169 }
00170
00171 if(vm.count("logconsole"))
00172 m_copyLog2Console = true;
00173 else
00174 m_copyLog2Console = false;
00175
00176 if(vm.count("threads")) {
00177 m_threads = vm["threads"].as < int >();
00178 } else {
00179
00180 m_threads = osHardwareConcurrency();
00181 if (m_threads == 0)
00182 m_threads = 1;
00183 }
00184
00185 if(vm.count("debug")) {
00186 luxError(LUX_NOERROR, LUX_INFO, "Debug mode enabled");
00187 luxEnableDebugMode();
00188 }
00189
00190 if (vm.count("fixedseed"))
00191 luxDisableRandomMode();
00192
00193 int serverInterval;
00194 if(vm.count("serverinterval")) {
00195 serverInterval = vm["serverinterval"].as<int>();
00196 luxSetNetworkServerUpdateInterval(serverInterval);
00197 } else {
00198 serverInterval = luxGetNetworkServerUpdateInterval();
00199 }
00200
00201 if(vm.count("useserver")) {
00202 std::stringstream ss;
00203
00204 std::vector<std::string> names = vm["useserver"].as<std::vector<std::string> >();
00205
00206 for(std::vector<std::string>::iterator i = names.begin(); i < names.end(); i++) {
00207 ss.str("");
00208 ss << "Connecting to server '" <<(*i) << "'";
00209 luxError(LUX_NOERROR, LUX_INFO, ss.str().c_str());
00210
00211
00212 luxAddServer((*i).c_str());
00213 }
00214
00215 m_useServer = true;
00216
00217 ss.str("");
00218 ss << "Server requests interval: " << serverInterval << " secs";
00219 luxError(LUX_NOERROR, LUX_INFO, ss.str().c_str());
00220 } else {
00221 m_useServer = false;
00222 }
00223
00224 if(vm.count("noopengl")) {
00225 m_openglEnabled = false;
00226 } else {
00227 #ifdef LUX_USE_OPENGL
00228 #if wxUSE_GLCANVAS == 1
00229 m_openglEnabled = true;
00230 #else
00231 m_openglEnabled = false;
00232 luxError(LUX_NOERROR, LUX_INFO, "GUI: wxWidgets without suppport for OpenGL canvas - will not be used.");
00233 #endif // wxUSE_GLCANVAS
00234 #else
00235 m_openglEnabled = false;
00236 luxError(LUX_NOERROR, LUX_INFO, "GUI: OpenGL support was not compiled in - will not be used.");
00237 #endif // LUX_USE_OPENGL
00238 }
00239
00240
00241 if (vm.count("minepsilon")) {
00242 const float mine = vm["minepsilon"].as<float>();
00243 if (vm.count("maxepsilon")) {
00244 const float maxe = vm["maxepsilon"].as<float>();
00245 luxSetEpsilon(mine, maxe);
00246 } else
00247 luxSetEpsilon(mine, DEFAULT_EPSILON_MAX);
00248 } else {
00249 if (vm.count("maxepsilon")) {
00250 const float maxe = vm["maxepsilon"].as<float>();
00251 luxSetEpsilon(DEFAULT_EPSILON_MIN, maxe);
00252 } else
00253 luxSetEpsilon(DEFAULT_EPSILON_MIN, DEFAULT_EPSILON_MAX);
00254 }
00255
00256 if(vm.count("input-file")) {
00257 const std::vector < std::string > &v = vm["input-file"].as < vector < string > >();
00258 if(v.size() > 1) {
00259 luxError(LUX_SYSTEM, LUX_SEVERE, "More than one file passed on command line : rendering the first one.");
00260 }
00261
00262 m_inputFile = wxString(v[0].c_str(), wxConvUTF8);
00263 } else {
00264 m_inputFile.Clear();
00265 }
00266
00267 return true;
00268 } catch(std::exception &e) {
00269 std::cout << e.what() << std::endl;
00270 return false;
00271 }
00272 }