diff --git a/include/mitsuba/core/util.h b/include/mitsuba/core/util.h index ba166c29..4db19c60 100644 --- a/include/mitsuba/core/util.h +++ b/include/mitsuba/core/util.h @@ -30,6 +30,12 @@ extern MTS_EXPORT_CORE std::string timeToString(Float time); /// Convert a string to lower case extern MTS_EXPORT_CORE std::string toLowerCase(const std::string &string); +/// Convert a string to upper case +extern MTS_EXPORT_CORE std::string toUpperCase(const std::string &string); + +/// Trim spaces (' ', '\n', '\r', '\t') from the ends of a string +extern MTS_EXPORT_CORE std::string trim(const std::string& str); + /// Determines whether a string ends with the string given as second parameter extern MTS_EXPORT_CORE bool endsWith(const std::string& str, const std::string& end); diff --git a/src/converter/converter.cpp b/src/converter/converter.cpp index 1fa89412..7a81edee 100644 --- a/src/converter/converter.cpp +++ b/src/converter/converter.cpp @@ -118,7 +118,7 @@ void GeometryConverter::convert(const std::string &inputFile, std::string meshesDirectory = "meshes"; std::string outputFile = sceneName; -#ifndef WIN32 +#if !defined(WIN32) if (outputDirectory != "") { textureDirectory = outputDirectory + "/textures"; meshesDirectory = outputDirectory + "/meshes"; @@ -127,26 +127,26 @@ void GeometryConverter::convert(const std::string &inputFile, int status = mkdir(textureDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (status != 0 && errno != EEXIST) - SLog(EError, "Could not create the directory \"textures\""); + SLog(EError, "Could not create the directory \"%s\"", textureDirectory.c_str()); status = mkdir(meshesDirectory.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (status != 0 && errno != EEXIST) - SLog(EError, "Could not create the directory \"meshes\""); + SLog(EError, "Could not create the directory \"%s\"", meshesDirectory.c_str()); textureDirectory += "/"; meshesDirectory += "/"; #else if (outputDirectory != "") { - textureDirectory = textureDirectory + "\\textures"; - meshesDirectory = meshesDirectory + "\\meshes"; + textureDirectory = outputDirectory + "\\textures"; + meshesDirectory = outputDirectory + "\\meshes"; outputFile = outputDirectory + std::string("\\") + sceneName; } int status = CreateDirectory(textureDirectory.c_str(), NULL); if (status == 0 && GetLastError() != ERROR_ALREADY_EXISTS) - SLog(EError, "Could not create the directory \"textures\""); + SLog(EError, "Could not create the directory \"%s\"", textureDirectory.c_str()); status = CreateDirectory(meshesDirectory.c_str(), NULL); if (status == 0 && GetLastError() != ERROR_ALREADY_EXISTS) - SLog(EError, "Could not create the directory \"meshes\""); + SLog(EError, "Could not create the directory \"%s\"", meshesDirectory.c_str()); textureDirectory += "\\"; meshesDirectory += "\\"; diff --git a/src/converter/obj.cpp b/src/converter/obj.cpp index f3536b91..ec5539d8 100644 --- a/src/converter/obj.cpp +++ b/src/converter/obj.cpp @@ -100,7 +100,7 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string if (buf == "newmtl") { addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap); std::getline(is, line); - mtlName = line.substr(1, line.length()-2); + mtlName = trim(line.substr(1, line.length()-1)); diffuse = Spectrum(0.0f); diffuseMap = ""; maskMap = ""; @@ -113,10 +113,10 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const std::string diffuse.fromLinearRGB(r, g, b); } else if (buf == "map_Kd") { std::getline(is, line); - diffuseMap = line.substr(1, line.length()-2); + diffuseMap = trim(line.substr(1, line.length()-1)); } else if (buf == "map_d") { std::getline(is, line); - maskMap = line.substr(1, line.length()-2); + maskMap = trim(line.substr(1, line.length()-1)); } else { /* Ignore */ std::getline(is, line); @@ -145,7 +145,7 @@ void GeometryConverter::convertOBJ(const std::string &inputFile, while (is >> buf) { if (buf == "mtllib") { std::getline(is, line); - std::string mtlName = line.substr(1, line.length()-2); + std::string mtlName = trim(line.substr(1, line.length()-1)); ref fRes = FileResolver::getInstance()->clone(); fRes->addPathFromFile(fRes->resolveAbsolute(inputFile)); std::string fullMtlName = fRes->resolve(mtlName); diff --git a/src/libcore/util.cpp b/src/libcore/util.cpp index 394cbb54..707d5bb2 100644 --- a/src/libcore/util.cpp +++ b/src/libcore/util.cpp @@ -122,12 +122,31 @@ std::vector tokenize(const std::string &string, const std::string & return tokens; } -std::string toLowerCase(const std::string &pString) { - std::string result; - result.reserve(pString.length()); +std::string trim(const std::string& str) { + std::string::size_type + start = str.find_first_not_of(" \t\r\n"), + end = str.find_last_not_of(" \t\r\n"); - for (unsigned int i=0; i 2) { - name = line.substr(1, line.length()-2); + name = trim(line.substr(1, line.length()-1)); Log(EInfo, "Loading geometry \"%s\"", name.c_str()); } } else if (buf == "usemtl") { std::string line; std::getline(is, line); - std::string materialName = line.substr(1, line.length()-2); + std::string materialName = trim(line.substr(1, line.length()-1)); if (m_materials.find(materialName) != m_materials.end()) currentMaterial = m_materials[materialName]; else @@ -78,7 +78,7 @@ public: } else if (buf == "mtllib") { std::string line; std::getline(is, line); - std::string mtlName = line.substr(1, line.length()-2); + std::string mtlName = trim(line.substr(1, line.length()-1)); ref fRes = FileResolver::getInstance()->clone(); fRes->addPathFromFile(fRes->resolveAbsolute(props.getString("filename"))); std::string fullMtlName = fRes->resolve(mtlName); @@ -159,7 +159,7 @@ public: std::string line, tmp; std::getline(is, line); - mtlName = line.substr(1, line.length()-2); + mtlName = trim(line.substr(1, line.length()-1)); } else if (buf == "Kd") { Float r, g, b; is >> r >> g >> b;