//------------------------------------------------------------------------ //chr safe to remove? bool CGunTurret::IsTargetCloaked(IActor *pActor) const { // cloak check if(m_turretparams.find_cloaked) return false; bool cloaked = false; // if destinationId assigned, target can always be found if(m_destinationId && pActor->GetEntityId() == m_destinationId) return false; if(cloaked && m_turretparams.light_fov != 0.f) { // if cloaked, target can only be found with searchlight // check if target inside light cone const Matrix34 &weaponTM = GetEntity()->GetSlotWorldTM(eIGS_ThirdPerson); Vec3 wpos(weaponTM.GetTranslation()); Vec3 wdir(weaponTM.GetColumn1()); Vec3 tpos(GetTargetPos(pActor->GetEntity())); float epsilon = 0.8f; Quat rot = Quat::CreateRotationAA(epsilon*0.5f*DEG2RAD(m_turretparams.light_fov), weaponTM.GetColumn2()); Vec3 a = wpos + m_turretparams.mg_range*(wdir*rot); Vec3 b = wpos + m_turretparams.mg_range*(wdir*rot.GetInverted()); bool inside = Overlap::PointInTriangle(tpos, wpos, a, b, weaponTM.GetColumn2()); if(inside) { rot = Quat::CreateRotationAA(0.5f*DEG2RAD(m_turretparams.light_fov), weaponTM.GetColumn0()); a = wpos + m_turretparams.mg_range*(wdir*rot); b = wpos + m_turretparams.mg_range*(wdir*rot.GetInverted()); inside = Overlap::PointInTriangle(tpos, wpos, a, b, weaponTM.GetColumn0()); } cloaked = !inside; if(g_pGameCVars->i_debug_turrets == eGTD_Search) { IRenderAuxGeom *pGeom = gEnv->pRenderer->GetIRenderAuxGeom(); pGeom->SetRenderFlags(e_Def3DPublicRenderflags); float color[] = {1,1,1,1}; Vec3 points[] = {wpos, a, b}; pGeom->DrawPolyline(points, 3, true, ColorB(0,255,0,255)); if(inside) gEnv->pRenderer->Draw2dLabel(200,200,1.4f,color,false,"target inside cone"); } } return cloaked; }
void MainWindow::on_actionDepth_Map_snaphot_triggered() { QDir wdir(workingDir); if (!wdir.exists()) { QDir().mkdir(workingDir); } const QString filename = workingDir + utils::getTimestampFileName(QString("/depthmap"),"png"); depthMapBuilder.saveDepthMap(filename.toStdString()); updateActions(); }
static string FileDialog(bool save, Window &parent, const string &path, const lstring &filter) { string dir = path; dir.replace("/", "\\"); string filterList; for(auto &filterItem : filter) { lstring part; part.split("(", filterItem); if(part.size() != 2) continue; part[1].rtrim<1>(")"); part[1].replace(" ", ""); part[1].transform(",", ";"); filterList.append(string(filterItem, "\t", part[1], "\t")); } utf16_t wfilter(filterList); utf16_t wdir(dir); wchar_t wfilename[PATH_MAX + 1] = L""; wchar_t *p = wfilter; while(*p != L'\0') { if(*p == L'\t') *p = L'\0'; p++; } if(path.empty() == false) { //clear COMDLG32 MRU (most recently used) file list //this is required in order for lpstrInitialDir to be honored in Windows 7 and above registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/LastVisitedPidlMRU/"); registry::remove("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ComDlg32/OpenSavePidlMRU/"); } OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = &parent != &Window::None ? parent.p.hwnd : 0; ofn.lpstrFilter = wfilter; ofn.lpstrInitialDir = wdir; ofn.lpstrFile = wfilename; ofn.nMaxFile = PATH_MAX; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = L""; bool result = (save == false ? GetOpenFileName(&ofn) : GetSaveFileName(&ofn)); if(result == false) return ""; string name = (const char*)utf8_t(wfilename); name.transform("\\", "/"); return name; }
void MainWindow::on_actionSnapshot_triggered() { QDir wdir(workingDir); if (!wdir.exists()) { QDir().mkdir(workingDir); } for (int i = 0; i < camNumber; ++i) { const QString filename = workingDir + utils::getTimestampFileName(QString("/snap_%1").arg(i),"png"); if (camera[i].canTakeSnapshoot()) { camera[i].takeSnapshoot(filename.toStdString()); } } updateActions(); }
//------------------------------------------------------------------------------ bool make_dir(const char* dir) { int type = get_path_type(dir); if (type == path_type_dir) return true; str<> next; path::get_directory(dir, next); if (!next.empty() && !path::is_root(next.c_str())) if (!make_dir(next.c_str())) return false; if (*dir) { wstr<280> wdir(dir); return (CreateDirectoryW(wdir.c_str(), nullptr) == TRUE); } return true; }
void WsGateService::RunService(){ WsGateService::g_signaled = false; // On Windows, always set out working dir to ../ relatively seen from // the binary's path. path p(m_sModulePath); string wdir(p.branch_path().branch_path().string()); chdir(wdir.c_str()); char *argv[] = { strdup("wsgate"), strdup("-c"), strdup("etc/wsgate.ini"), NULL }; int r = _service_main(3, argv); if (0 != r) { m_ServiceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; m_ServiceStatus.dwServiceSpecificExitCode = r; } free(argv[0]); free(argv[1]); free(argv[2]); }
/************************************************************************* Neural network training using modified Levenberg-Marquardt with exact Hessian calculation and regularization. Subroutine trains neural network with restarts from random positions. Algorithm is well suited for small and medium scale problems (hundreds of weights). INPUT PARAMETERS: Network - neural network with initialized geometry XY - training set NPoints - training set size Decay - weight decay constant, >=0.001 Decay term 'Decay*||Weights||^2' is added to error function. If you don't know what Decay to choose, use 0.001. Restarts - number of restarts from random position, >0. If you don't know what Restarts to choose, use 2. OUTPUT PARAMETERS: Network - trained neural network. Info - return code: * -9, if internal matrix inverse subroutine failed * -2, if there is a point with class number outside of [0..NOut-1]. * -1, if wrong parameters specified (NPoints<0, Restarts<1). * 2, if task has been solved. Rep - training report -- ALGLIB -- Copyright 10.03.2009 by Bochkanov Sergey *************************************************************************/ void mlptrainlm(multilayerperceptron& network, const ap::real_2d_array& xy, int npoints, double decay, int restarts, int& info, mlpreport& rep) { int nin; int nout; int wcount; double lmftol; double lmsteptol; int i; int j; int k; int mx; double v; double e; double enew; double xnorm2; double stepnorm; ap::real_1d_array g; ap::real_1d_array d; ap::real_2d_array h; ap::real_2d_array hmod; ap::real_2d_array z; bool spd; double nu; double lambda; double lambdaup; double lambdadown; int cvcnt; double cvrelcnt; lbfgsreport internalrep; lbfgsstate state; ap::real_1d_array x; ap::real_1d_array y; ap::real_1d_array wbase; double wstep; ap::real_1d_array wdir; ap::real_1d_array wt; ap::real_1d_array wx; int pass; ap::real_1d_array wbest; double ebest; mlpproperties(network, nin, nout, wcount); lambdaup = 10; lambdadown = 0.3; lmftol = 0.001; lmsteptol = 0.001; // // Test for inputs // if( npoints<=0||restarts<1 ) { info = -1; return; } if( mlpissoftmax(network) ) { for(i = 0; i <= npoints-1; i++) { if( ap::round(xy(i,nin))<0||ap::round(xy(i,nin))>=nout ) { info = -2; return; } } } decay = ap::maxreal(decay, mindecay); info = 2; // // Initialize data // rep.ngrad = 0; rep.nhess = 0; rep.ncholesky = 0; // // General case. // Prepare task and network. Allocate space. // mlpinitpreprocessor(network, xy, npoints); g.setbounds(0, wcount-1); h.setbounds(0, wcount-1, 0, wcount-1); hmod.setbounds(0, wcount-1, 0, wcount-1); wbase.setbounds(0, wcount-1); wdir.setbounds(0, wcount-1); wbest.setbounds(0, wcount-1); wt.setbounds(0, wcount-1); wx.setbounds(0, wcount-1); ebest = ap::maxrealnumber; // // Multiple passes // for(pass = 1; pass <= restarts; pass++) { // // Initialize weights // mlprandomize(network); // // First stage of the hybrid algorithm: LBFGS // ap::vmove(&wbase(0), &network.weights(0), ap::vlen(0,wcount-1)); minlbfgs(wcount, ap::minint(wcount, 5), wbase, 0.0, 0.0, 0.0, ap::maxint(25, wcount), 0, state); while(minlbfgsiteration(state)) { // // gradient // ap::vmove(&network.weights(0), &state.x(0), ap::vlen(0,wcount-1)); mlpgradbatch(network, xy, npoints, state.f, state.g); // // weight decay // v = ap::vdotproduct(&network.weights(0), &network.weights(0), ap::vlen(0,wcount-1)); state.f = state.f+0.5*decay*v; ap::vadd(&state.g(0), &network.weights(0), ap::vlen(0,wcount-1), decay); // // next iteration // rep.ngrad = rep.ngrad+1; } minlbfgsresults(state, wbase, internalrep); ap::vmove(&network.weights(0), &wbase(0), ap::vlen(0,wcount-1)); // // Second stage of the hybrid algorithm: LM // // Initialize H with identity matrix, // G with gradient, // E with regularized error. // mlphessianbatch(network, xy, npoints, e, g, h); v = ap::vdotproduct(&network.weights(0), &network.weights(0), ap::vlen(0,wcount-1)); e = e+0.5*decay*v; ap::vadd(&g(0), &network.weights(0), ap::vlen(0,wcount-1), decay); for(k = 0; k <= wcount-1; k++) { h(k,k) = h(k,k)+decay; } rep.nhess = rep.nhess+1; lambda = 0.001; nu = 2; while(true) { // // 1. HMod = H+lambda*I // 2. Try to solve (H+Lambda*I)*dx = -g. // Increase lambda if left part is not positive definite. // for(i = 0; i <= wcount-1; i++) { ap::vmove(&hmod(i, 0), &h(i, 0), ap::vlen(0,wcount-1)); hmod(i,i) = hmod(i,i)+lambda; } spd = spdmatrixcholesky(hmod, wcount, true); rep.ncholesky = rep.ncholesky+1; if( !spd ) { lambda = lambda*lambdaup*nu; nu = nu*2; continue; } if( !spdmatrixcholeskysolve(hmod, g, wcount, true, wdir) ) { lambda = lambda*lambdaup*nu; nu = nu*2; continue; } ap::vmul(&wdir(0), ap::vlen(0,wcount-1), -1); // // Lambda found. // 1. Save old w in WBase // 1. Test some stopping criterions // 2. If error(w+wdir)>error(w), increase lambda // ap::vadd(&network.weights(0), &wdir(0), ap::vlen(0,wcount-1)); xnorm2 = ap::vdotproduct(&network.weights(0), &network.weights(0), ap::vlen(0,wcount-1)); stepnorm = ap::vdotproduct(&wdir(0), &wdir(0), ap::vlen(0,wcount-1)); stepnorm = sqrt(stepnorm); enew = mlperror(network, xy, npoints)+0.5*decay*xnorm2; if( ap::fp_less(stepnorm,lmsteptol*(1+sqrt(xnorm2))) ) { break; } if( ap::fp_greater(enew,e) ) { lambda = lambda*lambdaup*nu; nu = nu*2; continue; } // // Optimize using inv(cholesky(H)) as preconditioner // if( !rmatrixtrinverse(hmod, wcount, true, false) ) { // // if matrix can't be inverted then exit with errors // TODO: make WCount steps in direction suggested by HMod // info = -9; return; } ap::vmove(&wbase(0), &network.weights(0), ap::vlen(0,wcount-1)); for(i = 0; i <= wcount-1; i++) { wt(i) = 0; } minlbfgs(wcount, wcount, wt, 0.0, 0.0, 0.0, 5, 0, state); while(minlbfgsiteration(state)) { // // gradient // for(i = 0; i <= wcount-1; i++) { v = ap::vdotproduct(&state.x(i), &hmod(i, i), ap::vlen(i,wcount-1)); network.weights(i) = wbase(i)+v; } mlpgradbatch(network, xy, npoints, state.f, g); for(i = 0; i <= wcount-1; i++) { state.g(i) = 0; } for(i = 0; i <= wcount-1; i++) { v = g(i); ap::vadd(&state.g(i), &hmod(i, i), ap::vlen(i,wcount-1), v); } // // weight decay // grad(x'*x) = A'*(x0+A*t) // v = ap::vdotproduct(&network.weights(0), &network.weights(0), ap::vlen(0,wcount-1)); state.f = state.f+0.5*decay*v; for(i = 0; i <= wcount-1; i++) { v = decay*network.weights(i); ap::vadd(&state.g(i), &hmod(i, i), ap::vlen(i,wcount-1), v); } // // next iteration // rep.ngrad = rep.ngrad+1; } minlbfgsresults(state, wt, internalrep); // // Accept new position. // Calculate Hessian // for(i = 0; i <= wcount-1; i++) { v = ap::vdotproduct(&wt(i), &hmod(i, i), ap::vlen(i,wcount-1)); network.weights(i) = wbase(i)+v; } mlphessianbatch(network, xy, npoints, e, g, h); v = ap::vdotproduct(&network.weights(0), &network.weights(0), ap::vlen(0,wcount-1)); e = e+0.5*decay*v; ap::vadd(&g(0), &network.weights(0), ap::vlen(0,wcount-1), decay); for(k = 0; k <= wcount-1; k++) { h(k,k) = h(k,k)+decay; } rep.nhess = rep.nhess+1; // // Update lambda // lambda = lambda*lambdadown; nu = 2; } // // update WBest // v = ap::vdotproduct(&network.weights(0), &network.weights(0), ap::vlen(0,wcount-1)); e = 0.5*decay*v+mlperror(network, xy, npoints); if( ap::fp_less(e,ebest) ) { ebest = e; ap::vmove(&wbest(0), &network.weights(0), ap::vlen(0,wcount-1)); } } // // copy WBest to output // ap::vmove(&network.weights(0), &wbest(0), ap::vlen(0,wcount-1)); }
int main(int argc, const char *argv[]) { // Pick up configuration parameters boost::program_options::variables_map vm; bool bTest, bBuild, bPackage; bTest = bBuild = bPackage = false; unsigned int iLogRotationSize; std::string sWorkingDir; std::string sStageDir; std::string sInstallPrefix; std::string sPackageName; std::string sPackageControlFile; std::string sArchitecture; std::string sSection; std::string sCfgfile; std::string sRosVersion; std::string sPriority; std::string sLogFile; std::string sLogFilter; std::string sLogFormat; std::string sDebianLocation; std::string sDebianType; std::string sDBHost; std::string sDBDatabase; uint32_t uiDBPort; std::string sDBUser; std::string sDBPassword; boost::filesystem::path idir; // capture the directory from which urpackager was run. // we return the user to this directory when we exit. idir = boost::filesystem::initial_path(); // work is run out of the users home directory sWorkingDir = getenv("HOME"); if (sWorkingDir.empty()) // not a popular linux version configuration sWorkingDir = getenv("USERPROFILE"); if (sWorkingDir.empty()) { std::cout << "The user running this utility must have a home directory" << std::endl; return (ERROR_FILESYSTEM); } // If this is the first time run, configuration file and control files will not exist sWorkingDir += "/.urpackager"; boost::filesystem::path wdir(sWorkingDir); if (!boost::filesystem::is_directory(wdir)) { // First time the utility was run by this user. if (!boost::filesystem::create_directory(wdir)) { std::cout << "Unable to write to the user's home directory" << std::endl; return (ERROR_FILESYSTEM); } boost::filesystem::current_path(wdir); boost::filesystem::create_directory("./pkgcontrol"); boost::filesystem::create_directory("./log"); urpackagerConfFileCreate(); std::cout << "This is the first time you have run \"urpackager.\"" << std::endl; std::cout << "Edit the file '~/.urpackager/urpackager.conf'" << std::endl; return (EXEC_SUCCESS); } boost::filesystem::current_path(wdir); // get run parameters try { /** Define and parse the program options */ boost::program_options::options_description generic("Generic Options", 255); // command line only options generic.add_options() ("help,h", "Print help messages") ("version,v", "Version 1.0.0"); boost::program_options::options_description config("Configuration Options"); // command line or configuration file and environment config.add_options() ("package", boost::program_options::value<std::string>(), "The name of the package for which to create a debian") ("architecture", boost::program_options::value<std::string>(), "Architecture for which you wish to create a debian file") ("section", boost::program_options::value<std::string>()->default_value("amd64"), "repository section for which you wish to create a debian file") ("test", boost::program_options::value<bool>()->default_value(false), "prints out variables but does no work") ("stagedir", boost::program_options::value<std::string>()->default_value("unique_path"), "The directory under which the debian manifest will be temporarily created") ("installprefix", boost::program_options::value<std::string>()->default_value("/opt/magni/v4"), "Prefix directory into which files will be (default) installed") ("config", boost::program_options::value<std::string>()->default_value("./urpackager.conf"), "The configuration file") ("log.file", boost::program_options::value<std::string>()->default_value("./log/urpackager.log"), "The log file") ("log.filter", boost::program_options::value<std::string>()->default_value("INFO"), "The log level") ("log.rotationsize", boost::program_options::value<int>()->default_value(100), "The maximum size for the log file in MB") ("log.format", boost::program_options::value<std::string>()->default_value("[%TimeStamp%]: %Message%"), "The format log messages take") ("ros.version", boost::program_options::value<std::string>()->default_value("indigo"), "The version of ROS this build - appended to <run_depend> package names") ("debian.type", boost::program_options::value<std::string>()->default_value("deb"), "Package either a binary (type = \"deb\") or a micro binary (type = \"udeb\")") ("debian.location", boost::program_options::value<std::string>(), "Directory into which to place the debian file") ("database.host", boost::program_options::value<std::string>(), "The host where the urpackage db is running") ("database.database", boost::program_options::value<std::string>(), "The mysql schema") ("database.port", boost::program_options::value<int>(), "The port on which the database is listening") ("database.user", boost::program_options::value<std::string>(), "The user of the database") ("database.password", boost::program_options::value<std::string>(), "Password to log into the database"); boost::program_options::options_description hidden("Hidden"); // command line or configuration file/environment but not shown hidden.add_options()("administrator", boost::program_options::value<std::string>(), "Administration capabilities"); boost::program_options::options_description cmdline_options; cmdline_options.add(generic).add(config).add(hidden); boost::program_options::options_description cfgfile_options; cfgfile_options.add(config).add(hidden); boost::program_options::options_description visible("Allowed options"); visible.add(generic).add(config); boost::program_options::store(boost::program_options::parse_command_line(argc, argv, cmdline_options), vm); // can throw /* --help option */ if (vm.count("help")) { std::cout << "Foo help...." << std::endl << config << std::endl; graceful_exit(idir, EXEC_SUCCESS); } if (vm.count("version")) { std::cout << "urpackager Version 1.0.0" << std::endl << config << std::endl; graceful_exit(idir, EXEC_SUCCESS); } if (vm.count("package")) { sPackageName = vm["package"].as<std::string>(); } if (vm.count("architecture")) { sArchitecture = vm["architecture"].as<std::string>(); } if (vm.count("section")) { sSection = vm["section"].as<std::string>(); } if (vm.count("test")) { bTest = vm["test"].as<bool>(); } if (vm.count("stagedir")) { sStageDir = vm["stagedir"].as<std::string>(); } if (vm.count("installprefix")) { sInstallPrefix = vm["installprefix"].as<std::string>(); } if (vm.count("config")) sCfgfile = (const std::string&) vm["config"].as<std::string>(); std::ifstream cfgfile(sCfgfile.c_str(), std::ios::in); if (cfgfile.fail()) std::cout << "Config file failed to open" << std::endl; boost::program_options::store(parse_config_file(cfgfile, cfgfile_options, true), vm); cfgfile.close(); boost::program_options::notify(vm); // throws on error, so do after help in case // there are any problems } catch (boost::program_options::error& e) { std::cerr << "ERROR: " << e.what() << std::endl << std::endl; graceful_exit(idir, ERROR_COMMAND_LINE); } try { if (vm.count("log.file")) sLogFile = (const std::string&) vm["log.file"].as<std::string>(); if (vm.count("log.filter")) sLogFilter = (const std::string&) vm["log.filter"].as<std::string>(); if (vm.count("log.rotationsize")) iLogRotationSize = (int) vm["log.rotationsize"].as<int>(); if (vm.count("log.format")) sLogFormat = (const std::string&) vm["log.format"].as<std::string>(); if (vm.count("debian.location")) sDebianLocation = (const std::string&) vm["debian.location"].as<std::string>(); if (vm.count("debian.type")) sDebianType = (const std::string&) vm["debian.type"].as<std::string>(); if (vm.count("ros.version")) sRosVersion = (const std::string&) vm["ros.version"].as<std::string>(); if (sPackageName.empty()) { std::cout << "Execution of this utility requires a package name" << std::endl; graceful_exit(idir, ERROR_COMMAND_LINE); } if (sArchitecture.empty()) { sPackageControlFile = sWorkingDir + "/pkgcontrol/" + sPackageName + ".pkgctl"; } else { sPackageControlFile = sWorkingDir + "/pkgcontrol/" + sPackageName + "." + sArchitecture + ".pkgctl"; } if (vm.count("database.host")) sDBHost = (const std::string&) vm["database.host"].as<std::string>(); if (vm.count("database.database")) sDBDatabase = (const std::string&) vm["database.database"].as<std::string>(); if (vm.count("database.port")) uiDBPort = (unsigned int) vm["database.port"].as<int>(); if (vm.count("database.user")) sDBUser = (const std::string&) vm["database.user"].as<std::string>(); if (vm.count("database.password")) sDBPassword = (const std::string&) vm["database.password"].as<std::string>(); } catch (std::exception& e) { std::cerr << "Unhandled Exception reached after applying all options: " << e.what() << ", application will now exit" << std::endl; graceful_exit(idir, ERROR_UNHANDLED_EXCEPTION); } /* Ready to run the utility * */ ur::PackageControl pc(sPackageControlFile); pc.readControlFile(); pc.setStageBase(sStageDir); ur::PackageXML px; px.readFile(pc.getPackageXML()); if(bTest) { graceful_exit(idir, EXEC_SUCCESS); } ur::DebianPackage pkg(pc, px, sArchitecture, sSection, sDebianType, sDebianLocation, sDBHost, sDBDatabase, sDBUser, sDBPassword, uiDBPort); pkg.createStageDirectory(); pkg.stageManifest(); pkg.writeDebianControleFile(); pkg.generateChecksums(); pkg.generateDebianPackage(); pkg.moveDebianPackage(); pkg.deleteStaging(); return (EXEC_SUCCESS); }
//------------------------------------------------------------------------------ bool remove_dir(const char* dir) { wstr<280> wdir(dir); return (RemoveDirectoryW(wdir.c_str()) == TRUE); }
//------------------------------------------------------------------------------ bool set_current_dir(const char* dir) { wstr<280> wdir(dir); return (SetCurrentDirectoryW(wdir.c_str()) == TRUE); }