void Engine::addEffect(unsigned int id, const std::string& name, const osg::Matrixd& mx, const std::string& attributes) { if (!_effectsImplementationCallback.valid()) return; removeEffect(id); osg::ref_ptr<GenericAttribute> attr(new GenericAttribute); attr->setUserValue("name", name); StringUtils::Tokens tokens = StringUtils::instance()->tokenize(attributes, ";"); StringUtils::Tokens::iterator itr = tokens.begin(); for (; itr != tokens.end(); ++itr) { std::string attribute = *itr; StringUtils::Tokens t = StringUtils::instance()->tokenize(attribute, "="); if (t.size() != 2) continue; std::string attributeName = t.at(0); std::string attributeValue = t.at(1); std::string::value_type ch = attributeValue.at(0); attributeValue.erase(attributeValue.begin()); switch (ch) { case 'F': attr->setUserValue(attributeName, (float)atof(attributeValue.c_str())); break; case 'S': attr->setUserValue(attributeName, attributeValue); break; case 'I': attr->setUserValue(attributeName, (int)atoi(attributeValue.c_str())); break; } } osg::ref_ptr<osg::Node> effectImplementation = _effectsImplementationCallback->create(id, name, attr); if (!effectImplementation.valid()) return; Effect effect = new osg::MatrixTransform; effect->setMatrix(mx); effect->addChild(effectImplementation); _effects[id] = effect; _effectsRoot->addChild(effect); }
std::string FileSystem::path(FileSystem::PathType type, const std::string& path) { switch (type) { case Plugins: { // CR ---------------------------------------------------------------------------------- #if defined (__linux) || defined (__APPLE__) char * oig_root = NULL; std::string igplugin_path; oig_root = getenv("OPENIG_LIBRARY_PATH"); if (!oig_root) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Env variable OPENIG_LIBRARY_PATH doesn't exist!!!" << std::endl; #if !defined(BUILD_64) || defined (__APPLE__) igplugin_path = "/usr/local/lib/plugins"; #else igplugin_path = "/usr/local/lib64/plugins"; #endif } else { igplugin_path = oig_root; igplugin_path += "/plugins"; } return igplugin_path+"/"+path; #elif defined (_WIN32) char* c_oig_root; std::string oig_root; size_t requiredSize; bool var_present = false; //Use win32 safe version of getenv() getenv_s(&requiredSize, NULL, 0, "OPENIG_LIBRARY_PATH"); if (requiredSize == 0) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Env variable OPENIG_LIBRARY_PATH doesn't exist!!!, setting requiredsize to 14 for default path!!!" << std::endl; requiredSize = 14; } else var_present = true; c_oig_root = (char*)malloc(requiredSize * sizeof(char)); if (!c_oig_root) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Failed to allocate memory for OPENIG_LIBRARY_PATH variable!!, exiting!!!" << std::endl; exit(1); } if (var_present) { // Get the value of the LIB environment variable. getenv_s(&requiredSize, c_oig_root, requiredSize, "OPENIG_LIBRARY_PATH"); oig_root = c_oig_root; oig_root += "\\plugins"; } else //Fallback path to try in event of no env var setting. oig_root = "..\\plugins"; free(c_oig_root); return oig_root + "/" + path; #endif // CR ---------------------------------------------------------------------------------- } break; case Resources: { #if defined (__linux) || defined (__APPLE__) char * oig_root = NULL; std::string igres_path; oig_root = getenv("OPENIG_RESOURCE_PATH"); if (!oig_root) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Env variable OPENIG_RESOURCE_PATH doesn't exist!!!" << std::endl; igres_path = "/usr/local/openig/resources"; } else { igres_path = oig_root; } return igres_path.empty() ? path : igres_path; #elif defined (_WIN32) char* c_oig_root; std::string oig_root; size_t requiredSize; bool var_present = false; //Use win32 safe version of getenv() getenv_s(&requiredSize, NULL, 0, "OPENIG_RESOURCE_PATH"); if (requiredSize == 0) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Env variable OPENIG_RESOURCE_PATH doesn't exist!!!, setting requiredsize to 14 for default path!!!" << std::endl; requiredSize = 14; } else var_present = true; c_oig_root = (char*)malloc(requiredSize * sizeof(char)); if (!c_oig_root) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Failed to allocate memory for OPENIG_RESOURCE_PATH variable!!, exiting!!!" << std::endl; exit(1); } if (var_present) { // Get the value of the LIB environment variable. getenv_s(&requiredSize, c_oig_root, requiredSize, "OPENIG_RESOURCE_PATH"); oig_root = c_oig_root; } else //Fallback path to try in event of no env var setting. oig_root = path; free(c_oig_root); return oig_root; #endif } break; case Data: { #if defined (__linux) || defined (__APPLE__) char * oig_root = NULL; std::string igdata_path; oig_root = getenv("OPENIG_DATA_PATH"); if (!oig_root) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Env variable OPENIG_DATA_PATH doesn't exist!!!" << std::endl; igdata_path = "/usr/local/openig/database"; } else { igdata_path = oig_root; } return igdata_path.empty() ? path : igdata_path; #elif defined (_WIN32) char* c_oig_root; std::string oig_root; size_t requiredSize; bool var_present = false; //Use win32 safe version of getenv() getenv_s(&requiredSize, NULL, 0, "OPENIG_DATA_PATH"); if (requiredSize == 0) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Env variable OPENIG_DATA_PATH doesn't exist!!!, setting requiredsize to 14 for default path!!!" << std::endl; requiredSize = 14; } else var_present = true; c_oig_root = (char*)malloc(requiredSize * sizeof(char)); if (!c_oig_root) { osg::notify(osg::NOTICE) << "ImageGenerator Core: Failed to allocate memory for OPENIG_DATA_PATH variable!!, exiting!!!" << std::endl; exit(1); } if (var_present) { // Get the value of the LIB environment variable. getenv_s(&requiredSize, c_oig_root, requiredSize, "OPENIG_DATA_PATH"); oig_root = c_oig_root; } else //Fallback path to try in event of no env var setting. oig_root = path; free(c_oig_root); return oig_root; #endif } break; case PathList: { if (path.size() > 2) { StringUtils::Tokens tokens = StringUtils::instance()->tokenize(path, "{}"); if (tokens.size()) { std::string paths = tokens.at(0); tokens.erase(tokens.begin()); if (tokens.size()) { osg::notify(osg::NOTICE) << "ImageGenerator Core: FileSystem: PathList: " << paths << std::endl; std::string file = tokens.at(0); tokens = StringUtils::instance()->tokenize(paths, ";"); StringUtils::TokensIterator itr = tokens.begin(); for (; itr != tokens.end(); ++itr) { std::string onePath = *itr; osg::notify(osg::NOTICE) << "\tChecking: " << onePath << std::endl; OpenIG::Base::StringUtils::Tokens singlePathTokens = StringUtils::instance()->tokenize(onePath, "/"); OpenIG::Base::StringUtils::TokensIterator sp_itr = singlePathTokens.begin(); std::ostringstream completePath; if (onePath.at(0) == '/' || onePath.at(0) == '\\') completePath << "/"; for (; sp_itr != singlePathTokens.end(); ++sp_itr) { std::string& token = *sp_itr; if (token.size() && token.at(0) == '$') { token = StringUtils::instance()->env(token); } completePath << token << "/"; } onePath = completePath.str(); osg::notify(osg::NOTICE) << "\t\tChecking: " << onePath << std::endl; if (!fileExists(onePath + "/" + file)) { StringUtils::Tokens ftokens = StringUtils::instance()->tokenize(file, "."); StringUtils::TokensIterator fitr = ftokens.begin(); std::string partialFileName = *fitr; do { if (fileExists(onePath + "/" + partialFileName)) { osg::notify(osg::NOTICE) << "\tFound valid file: " << (onePath + "/" + partialFileName) << std::endl; osg::notify(osg::NOTICE) << "\tFound valid path: " << (onePath + "/" + file) << std::endl; return onePath + "/" + file; } ++fitr; if (fitr != ftokens.end()) partialFileName += "." + *fitr; } while (fitr != ftokens.end()); } else { osg::notify(osg::NOTICE) << "\tFound valid path: " << (onePath + "/" + file) << std::endl; return onePath + "/" + file; } } } } } } break; } return path; }