diff --git a/include/mitsuba/core/fresolver.h b/include/mitsuba/core/fresolver.h index 051626e3..f2a8fb0d 100644 --- a/include/mitsuba/core/fresolver.h +++ b/include/mitsuba/core/fresolver.h @@ -21,6 +21,7 @@ #include #include +#include namespace fs = boost::filesystem; diff --git a/include/mitsuba/core/fstream.h b/include/mitsuba/core/fstream.h index b33c206e..988a92e5 100644 --- a/include/mitsuba/core/fstream.h +++ b/include/mitsuba/core/fstream.h @@ -22,7 +22,7 @@ #include #include #include - + namespace fs = boost::filesystem; MTS_NAMESPACE_BEGIN @@ -53,9 +53,6 @@ public: /// Return the file path inline const fs::path &getPath() const { return m_path; } - /// Check whether a file exists - static bool exists(const std::string &filename); - /// Open a file with a given open mode void open(const fs::path &filename, EFileMode mode = EReadOnly); diff --git a/include/mitsuba/core/util.h b/include/mitsuba/core/util.h index 2ecdd8a3..9cc55cab 100644 --- a/include/mitsuba/core/util.h +++ b/include/mitsuba/core/util.h @@ -45,21 +45,9 @@ extern MTS_EXPORT_CORE std::string indent(const std::string &string, int amount= /// Convert a time difference (in ms) to a string representation 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 starts with the string given as second parameter -extern MTS_EXPORT_CORE bool startsWith(const std::string& str, const std::string& start); - -/// 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); - /// Allocate an aligned region of memory extern MTS_EXPORT_CORE void * __restrict allocAligned(size_t size); diff --git a/include/mitsuba/render/film.h b/include/mitsuba/render/film.h index 1b340b26..e0482876 100644 --- a/include/mitsuba/render/film.h +++ b/include/mitsuba/render/film.h @@ -21,6 +21,9 @@ #include #include +#include + +namespace fs = boost::filesystem; MTS_NAMESPACE_BEGIN @@ -55,7 +58,7 @@ public: virtual void toBitmap(Bitmap *bitmap) const = 0; /// Develop the film and write the result to the specified filename - virtual void develop(const std::string &fileName) = 0; + virtual void develop(const fs::path &fileName) = 0; /// Ignoring the crop window, return the resolution of the underlying sensor inline const Vector2i &getSize() const { return m_size; } @@ -89,7 +92,7 @@ public: virtual void serialize(Stream *stream, InstanceManager *manager) const; /// Does the destination already exist? - virtual bool destinationExists(const std::string &baseName) const = 0; + virtual bool destinationExists(const fs::path &baseName) const = 0; /// Return the properties of this film inline const Properties &getProperties() const { return m_properties; } diff --git a/include/mitsuba/render/scene.h b/include/mitsuba/render/scene.h index 01070a64..22091132 100644 --- a/include/mitsuba/render/scene.h +++ b/include/mitsuba/render/scene.h @@ -372,13 +372,13 @@ public: inline const std::vector &getReferencedObjects() const { return m_objects; } /// Return the name of the file containing the original description of this scene - inline const std::string getSourceFile() const { return m_sourceFile; } + inline const fs::path getSourceFile() const { return m_sourceFile; } /// Set the name of the file containing the original description of this scene - void setSourceFile(const std::string &name) { m_sourceFile = name; } + void setSourceFile(const fs::path &name) { m_sourceFile = name; } /// Return the render output filename - inline const std::string getDestinationFile() const { return m_destinationFile; } + inline const fs::path getDestinationFile() const { return m_destinationFile; } /// Set the render output filename - void setDestinationFile(const std::string &name) { m_destinationFile = name; } + void setDestinationFile(const fs::path &name) { m_destinationFile = name; } /// Does the destination file already exist? inline bool destinationExists() const { return m_camera->getFilm()->destinationExists(m_destinationFile); } @@ -416,8 +416,8 @@ private: std::vector m_ssIntegrators; std::vector m_objects; std::vector m_netObjects; - std::string m_sourceFile; - std::string m_destinationFile; + fs::path m_sourceFile; + fs::path m_destinationFile; DiscretePDF m_luminairePDF; AABB m_aabb; BSphere m_bsphere; diff --git a/include/mitsuba/render/testcase.h b/include/mitsuba/render/testcase.h index 064303ee..69ae15ea 100644 --- a/include/mitsuba/render/testcase.h +++ b/include/mitsuba/render/testcase.h @@ -122,7 +122,7 @@ protected: private: struct TestResult { bool success; - std::string input, output; + fs::path input, output; std::string message; }; diff --git a/src/bsdfs/lambertian.cpp b/src/bsdfs/lambertian.cpp index 469d0efa..c38675ec 100644 --- a/src/bsdfs/lambertian.cpp +++ b/src/bsdfs/lambertian.cpp @@ -17,12 +17,12 @@ */ #include -#include +#include +#include #include MTS_NAMESPACE_BEGIN - /** * Simple one-sided Lambertian (i.e. perfectly diffuse) material */ diff --git a/src/bsdfs/mask.cpp b/src/bsdfs/mask.cpp index 91cdc203..2e374952 100644 --- a/src/bsdfs/mask.cpp +++ b/src/bsdfs/mask.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include MTS_NAMESPACE_BEGIN diff --git a/src/bsdfs/microfacet.cpp b/src/bsdfs/microfacet.cpp index 04d4583e..9e14ed32 100644 --- a/src/bsdfs/microfacet.cpp +++ b/src/bsdfs/microfacet.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include MTS_NAMESPACE_BEGIN diff --git a/src/bsdfs/phong.cpp b/src/bsdfs/phong.cpp index a5f785b2..430c262a 100644 --- a/src/bsdfs/phong.cpp +++ b/src/bsdfs/phong.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include MTS_NAMESPACE_BEGIN diff --git a/src/bsdfs/ward.cpp b/src/bsdfs/ward.cpp index 36f783fd..4f40f250 100644 --- a/src/bsdfs/ward.cpp +++ b/src/bsdfs/ward.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include MTS_NAMESPACE_BEGIN diff --git a/src/converter/collada.cpp b/src/converter/collada.cpp index be8ce48b..e2b5bb0a 100644 --- a/src/converter/collada.cpp +++ b/src/converter/collada.cpp @@ -26,11 +26,9 @@ #include #include #include -#include -#include +#include #include #include -#include #if defined(__OSX__) #include @@ -809,11 +807,12 @@ void loadImage(GeometryConverter *cvt, std::ostream &os, const fs::path &texture idToTexture[identifier] = identifier; fileToId[filename] = identifier; - boost::filesystem::path path = boost::filesystem::path(filename, boost::filesystem::native); + fs::path path = fs::path(filename); fs::path targetPath = textureDir / path.leaf(); fs::path resolved = filename; - if (endsWith(filename, ".rgb")) + std::string extension = boost::to_lower_copy(fs::extension(path)); + if (extension == ".rgb") SLog(EWarn, "Maya RGB images must be converted to PNG, EXR or JPEG! The 'imgcvt' " "utility found in the Maya binary directory can be used to do this."); @@ -823,10 +822,9 @@ void loadImage(GeometryConverter *cvt, std::ostream &os, const fs::path &texture resolved = fRes->resolve(path.leaf()); if (!fs::exists(resolved)) { SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str()); - std::string result = cvt->locateResource(filename); - if (result == "") + resolved = cvt->locateResource(filename); + if (resolved.empty()) SLog(EError, "Unable to locate a resource -- aborting conversion."); - resolved = result; } } ref input = new FileStream(resolved, FileStream::EReadOnly); @@ -1094,16 +1092,17 @@ GLvoid __stdcall tessError(GLenum error) { GLvoid __stdcall tessEdgeFlag(GLboolean) { } -void GeometryConverter::convertCollada(const std::string &inputFile, +void GeometryConverter::convertCollada(const fs::path &inputFile, std::ostream &os, const fs::path &textureDirectory, const fs::path &meshesDirectory) { DAE *dae = new DAE(); - SLog(EInfo, "Loading \"%s\" ..", inputFile.c_str()); - if (dae->load(inputFile.c_str()) != DAE_OK) - SLog(EError, "Could not load \"%s\"!", inputFile.c_str()); + SLog(EInfo, "Loading \"%s\" ..", inputFile.leaf().c_str()); + if (dae->load(inputFile.file_string().c_str()) != DAE_OK) + SLog(EError, "Could not load \"%s\"!", + inputFile.file_string().c_str()); - domCOLLADA *document = dae->getDom(inputFile.c_str()); + domCOLLADA *document = dae->getDom(inputFile.file_string().c_str()); domVisual_scene *visualScene = daeSafeCast (document->getDescendant("visual_scene")); if (!visualScene) diff --git a/src/converter/converter.cpp b/src/converter/converter.cpp index fff4e4d6..bb82f401 100644 --- a/src/converter/converter.cpp +++ b/src/converter/converter.cpp @@ -29,12 +29,10 @@ #include #include #include -#include -#include -#include +#include +#include #include #include -#include #include XERCES_CPP_NAMESPACE_USE @@ -129,21 +127,19 @@ bool cleanupPass(DOMNode *node, const std::set &removals) { return false; } -void GeometryConverter::convert(const std::string &inputFile, - const std::string &outputDirectory, - const std::string &sceneName, - const std::string &adjustmentFile) { +void GeometryConverter::convert(const fs::path &inputFile, + const fs::path &outputDirectory, + const fs::path &sceneName, + const fs::path &adjustmentFile) { fs::path textureDirectory = "textures"; fs::path meshesDirectory = "meshes"; fs::path outputFile = sceneName; - if (outputDirectory != "") { - fs::path outPath (outputDirectory); - - textureDirectory = outPath / "textures"; - meshesDirectory = outPath / "meshes"; - outputFile = outPath / sceneName; + if (!outputDirectory.empty()) { + textureDirectory = outputDirectory / "textures"; + meshesDirectory = outputDirectory / "meshes"; + outputFile = outputDirectory / sceneName; } SLog(EInfo, "Creating directories .."); @@ -155,15 +151,18 @@ void GeometryConverter::convert(const std::string &inputFile, std::ostringstream os; SLog(EInfo, "Beginning conversion .."); - if (endsWith(toLowerCase(inputFile), ".dae") || endsWith(toLowerCase(inputFile), ".zae")) { + + std::string extension = boost::to_lower_copy(fs::extension(inputFile)); + + if (extension == ".dae" || extension == ".zae") { convertCollada(inputFile, os, textureDirectory, meshesDirectory); - } else if (endsWith(toLowerCase(inputFile), ".obj")) { + } else if (extension == ".obj") { convertOBJ(inputFile, os, textureDirectory, meshesDirectory); } else { SLog(EError, "Unknown input format (must end in either .DAE, .ZAE or .OBJ)"); } - if (adjustmentFile != "") { + if (adjustmentFile.empty()) { SLog(EInfo, "Applying adjustments .."); static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS); @@ -178,8 +177,8 @@ void GeometryConverter::convert(const std::string &inputFile, xmlString.length(), "bufID", false); Wrapper4InputSource *wrapper = new Wrapper4InputSource(memBufIS, false); XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = parser->parse(wrapper); - XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *adj = parser->parseURI(adjustmentFile.c_str()); - + XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *adj = parser->parseURI(adjustmentFile.file_string().c_str()); + std::set removals, emptyList; cleanupPass(adj, emptyList); findRemovals(adj, removals); @@ -236,6 +235,6 @@ void GeometryConverter::convert(const std::string &inputFile, ofile << os.str(); ofile.close(); } - m_filename = outputFile.file_string(); + m_filename = outputFile; } diff --git a/src/converter/converter.h b/src/converter/converter.h index f44e6915..bed731a5 100644 --- a/src/converter/converter.h +++ b/src/converter/converter.h @@ -30,29 +30,29 @@ public: m_fov = -1; } - void convert(const std::string &inputFile, - const std::string &outputDirectory, - const std::string &sceneName, - const std::string &adjustmentFile); + void convert(const fs::path &inputFile, + const fs::path &outputDirectory, + const fs::path &sceneName, + const fs::path &adjustmentFile); - virtual std::string locateResource(const std::string &resource) = 0; + virtual fs::path locateResource(const fs::path &resource) = 0; inline void setSRGB(bool srgb) { m_srgb = srgb; } inline void setMapSmallerSide(bool mapSmallerSide) { m_mapSmallerSide = mapSmallerSide; } inline void setResolution(int xres, int yres) { m_xres = xres; m_yres = yres; } inline void setSamplesPerPixel(int samplesPerPixel) { m_samplesPerPixel = samplesPerPixel; } inline void setFov(Float fov) { m_fov = fov; } - inline const std::string &getFilename() const { return m_filename; } + inline const fs::path &getFilename() const { return m_filename; } private: - void convertCollada(const std::string &inputFile, std::ostream &os, + void convertCollada(const fs::path &inputFile, std::ostream &os, const fs::path &textureDirectory, const fs::path &meshesDirectory); - void convertOBJ(const std::string &inputFile, std::ostream &os, + void convertOBJ(const fs::path &inputFile, std::ostream &os, const fs::path &textureDirectory, const fs::path &meshesDirectory); public: bool m_srgb, m_mapSmallerSide; int m_xres, m_yres, m_samplesPerPixel; Float m_fov; - std::string m_filename; + fs::path m_filename; }; diff --git a/src/converter/mtsimport.cpp b/src/converter/mtsimport.cpp index 7f568616..5b8584ec 100644 --- a/src/converter/mtsimport.cpp +++ b/src/converter/mtsimport.cpp @@ -46,8 +46,8 @@ public: inline ConsoleGeometryConverter() { } - std::string locateResource(const std::string &resource) { - return ""; + fs::path locateResource(const fs::path &resource) { + return fs::path(); } }; diff --git a/src/converter/obj.cpp b/src/converter/obj.cpp index c50ce752..fa984b93 100644 --- a/src/converter/obj.cpp +++ b/src/converter/obj.cpp @@ -28,7 +28,7 @@ std::string copyTexture(GeometryConverter *cvt, const fs::path &textureDir, std::string filename) { SLog(EInfo, "Copying texture \"%s\" ..", filename.c_str()); - boost::filesystem::path path = boost::filesystem::path(filename, boost::filesystem::native); + boost::filesystem::path path = boost::filesystem::path(filename); fs::path targetPath = textureDir / path.leaf(); fs::path resolved = filename; @@ -38,10 +38,9 @@ std::string copyTexture(GeometryConverter *cvt, const fs::path &textureDir, std: resolved = fRes->resolve(path.leaf()); if (!fs::exists(resolved)) { SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str()); - std::string result = cvt->locateResource(filename); - if (result == "") + resolved = cvt->locateResource(filename); + if (resolved.empty()) SLog(EError, "Unable to locate a resource -- aborting conversion."); - resolved = result; } } @@ -132,22 +131,22 @@ void parseMaterials(GeometryConverter *cvt, std::ostream &os, const fs::path &te addMaterial(cvt, os, mtlName, texturesDir, diffuse, diffuseMap, maskMap); } -void GeometryConverter::convertOBJ(const std::string &inputFile, +void GeometryConverter::convertOBJ(const fs::path &inputFile, std::ostream &os, const fs::path &textureDirectory, const fs::path &meshesDirectory) { - std::ifstream is(inputFile.c_str()); + fs::ifstream is(inputFile); if (is.bad() || is.fail()) - SLog(EError, "Could not open OBJ file '%s'!", inputFile.c_str()); - + SLog(EError, "Could not open OBJ file '%s'!", inputFile.file_string().c_str()); + os << "" << endl << endl; os << "" << endl << endl; os << "" << endl; os << "\t" << endl << endl; - + std::string buf, line; while (is >> buf) { if (buf == "mtllib") { @@ -167,7 +166,7 @@ void GeometryConverter::convertOBJ(const std::string &inputFile, } Properties objProps("obj"); - objProps.setString("filename", inputFile); + objProps.setString("filename", inputFile.file_string()); ref rootShape = static_cast (PluginManager::getInstance()-> createObject(Shape::m_theClass, objProps)); diff --git a/src/films/exrfilm.cpp b/src/films/exrfilm.cpp index 4658e0ff..d666de0a 100644 --- a/src/films/exrfilm.cpp +++ b/src/films/exrfilm.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "banner.h" MTS_NAMESPACE_BEGIN @@ -152,7 +153,7 @@ public: } } - void develop(const std::string &destFile) { + void develop(const fs::path &destFile) { Log(EDebug, "Developing film .."); ref bitmap = new Bitmap(m_cropSize.x, m_cropSize.y, 128); float *targetPixels = bitmap->getFloatData(); @@ -190,19 +191,21 @@ public: } } - std::string filename = destFile; - if (!endsWith(filename, ".exr")) - filename += ".exr"; - Log(EInfo, "Writing image to \"%s\" ..", filename.c_str()); + fs::path filename = destFile; + std::string extension = boost::to_lower_copy(fs::extension(filename)); + if (extension != ".exr") + filename.replace_extension(".exr"); + + Log(EInfo, "Writing image to \"%s\" ..", filename.leaf().c_str()); ref stream = new FileStream(filename, FileStream::ETruncWrite); bitmap->save(Bitmap::EEXR, stream); } - bool destinationExists(const std::string &baseName) const { - std::string filename = baseName; - if (!endsWith(filename, ".exr")) - filename += ".exr"; - return FileStream::exists(filename); + bool destinationExists(const fs::path &baseName) const { + fs::path filename = baseName; + if (boost::to_lower_copy(filename.extension()) != ".exr") + filename.replace_extension(".exr"); + return fs::exists(filename); } std::string toString() const { diff --git a/src/films/mfilm.cpp b/src/films/mfilm.cpp index 58b03fae..5838d116 100644 --- a/src/films/mfilm.cpp +++ b/src/films/mfilm.cpp @@ -18,6 +18,7 @@ #include #include +#include MTS_NAMESPACE_BEGIN @@ -169,14 +170,15 @@ public: } } - void develop(const std::string &destFile) { - std::string filename = destFile; - if (!endsWith(filename, ".m")) - filename += ".m"; + void develop(const fs::path &destFile) { + fs::path filename = destFile; + std::string extension = boost::to_lower_copy(fs::extension(filename)); + if (extension != ".m") + filename.replace_extension(".m"); - Log(EInfo, "Writing image to \"%s\" ..", filename.c_str()); + Log(EInfo, "Writing image to \"%s\" ..", filename.leaf().c_str()); - FILE *f = fopen(filename.c_str(), "w"); + FILE *f = fopen(filename.file_string().c_str(), "w"); if (!f) Log(EError, "Output file cannot be created!"); @@ -216,11 +218,11 @@ public: fclose(f); } - bool destinationExists(const std::string &baseName) const { - std::string filename = baseName; - if (!endsWith(filename, ".m")) - filename += ".m"; - return FileStream::exists(filename); + bool destinationExists(const fs::path &baseName) const { + fs::path filename = baseName; + if (boost::to_lower_copy(filename.extension()) != ".m") + filename.replace_extension(".m"); + return fs::exists(filename); } std::string toString() const { diff --git a/src/films/pngfilm.cpp b/src/films/pngfilm.cpp index 95817b93..51f35f0e 100644 --- a/src/films/pngfilm.cpp +++ b/src/films/pngfilm.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include "banner.h" MTS_NAMESPACE_BEGIN @@ -180,7 +182,7 @@ public: - (Float) 0.055; } - void develop(const std::string &destFile) { + void develop(const fs::path &destFile) { Log(EDebug, "Developing film .."); ref bitmap = new Bitmap(m_cropSize.x, m_cropSize.y, m_bpp); uint8_t *targetPixels = bitmap->getData(); @@ -314,23 +316,25 @@ public: } } - std::string filename = destFile; - if (!endsWith(filename, ".png")) - filename += ".png"; + fs::path filename = destFile; + std::string extension = boost::to_lower_copy(fs::extension(filename)); + if (extension != ".png") + filename.replace_extension(".png"); - Log(EInfo, "Writing image to \"%s\" ..", filename.c_str()); + Log(EInfo, "Writing image to \"%s\" ..", filename.leaf().c_str()); ref stream = new FileStream(filename, FileStream::ETruncWrite); bitmap->setGamma(m_gamma); bitmap->save(Bitmap::EPNG, stream); } - bool destinationExists(const std::string &baseName) const { - std::string filename = baseName; - if (!endsWith(filename, ".png")) - filename += ".png"; - return FileStream::exists(filename); + bool destinationExists(const fs::path &baseName) const { + fs::path filename = baseName; + if (boost::to_lower_copy(filename.extension()) != ".png") + filename.replace_extension(".png"); + return fs::exists(filename); } + std::string toString() const { std::ostringstream oss; oss << "PNGFilm[" << std::endl diff --git a/src/integrators/misc/irrcache_proc.cpp b/src/integrators/misc/irrcache_proc.cpp index 9901b0ef..621259d6 100644 --- a/src/integrators/misc/irrcache_proc.cpp +++ b/src/integrators/misc/irrcache_proc.cpp @@ -17,6 +17,7 @@ */ #include +#include #include "irrcache_proc.h" MTS_NAMESPACE_BEGIN diff --git a/src/integrators/vpl/vpl.cpp b/src/integrators/vpl/vpl.cpp index a821488e..e3d83119 100644 --- a/src/integrators/vpl/vpl.cpp +++ b/src/integrators/vpl/vpl.cpp @@ -16,6 +16,7 @@ along with this program. If not, see . */ +#include #include #include #include diff --git a/src/libcore/fstream.cpp b/src/libcore/fstream.cpp index b3075873..91e5a8a1 100644 --- a/src/libcore/fstream.cpp +++ b/src/libcore/fstream.cpp @@ -48,21 +48,6 @@ std::string FileStream::toString() const { return oss.str(); } -bool FileStream::exists(const std::string &filename) { -#ifdef WIN32 - WIN32_FIND_DATA lpFindFileData; - HANDLE hFind = FindFirstFile(filename.c_str(), &lpFindFileData); - if (hFind == INVALID_HANDLE_VALUE) { - return false; - } else { - FindClose(hFind); - return true; - } -#else - return (access(filename.c_str(), F_OK) == 0); -#endif -} - void FileStream::open(const fs::path &path, EFileMode mode) { AssertEx(m_file == 0, "A file has already been opened using this stream"); diff --git a/src/libcore/util.cpp b/src/libcore/util.cpp index 46b59515..af570e44 100644 --- a/src/libcore/util.cpp +++ b/src/libcore/util.cpp @@ -148,26 +148,6 @@ std::string trim(const std::string& str) { end == std::string::npos ? str.length() - 1 : end - start + 1); } -std::string toLowerCase(const std::string &string) { - std::string result; - result.reserve(string.length()); - - for (unsigned int i=0; irender(m_queue, this, m_sceneResID, m_cameraResID, m_samplerResID)) { cancelled = true; Log(EWarn, "Rendering of scene \"%s\" did not complete successfully!", - m_scene->getSourceFile().c_str()); + m_scene->getSourceFile().leaf().c_str()); } m_scene->postprocess(m_queue, this, m_sceneResID, m_cameraResID, m_samplerResID); @@ -120,7 +120,7 @@ void RenderJob::run() { m_testSupervisor->analyze(m_scene); } catch (const std::exception &ex) { Log(EWarn, "Rendering of scene \"%s\" did not complete successfully, caught exception: %s", - m_scene->getSourceFile().c_str(), ex.what()); + m_scene->getSourceFile().leaf().c_str(), ex.what()); cancelled = true; } diff --git a/src/librender/shandler.cpp b/src/librender/shandler.cpp index 8af551bc..9abb2628 100644 --- a/src/librender/shandler.cpp +++ b/src/librender/shandler.cpp @@ -20,6 +20,7 @@ #include #include #include +#include MTS_NAMESPACE_BEGIN @@ -101,7 +102,7 @@ void SceneHandler::startElement(const XMLCh* const xmlName, void SceneHandler::endElement(const XMLCh* const xmlName) { std::string name = transcode(xmlName); ParseContext &context = m_context.top(); - std::string type = toLowerCase(context.attributes["type"]); + std::string type = boost::to_lower_copy(context.attributes["type"]); context.properties.setPluginName(type); if (context.attributes.find("id") != context.attributes.end()) context.properties.setID(context.attributes["id"]); diff --git a/src/librender/testcase.cpp b/src/librender/testcase.cpp index 2bc4847b..2cc85380 100644 --- a/src/librender/testcase.cpp +++ b/src/librender/testcase.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include MTS_NAMESPACE_BEGIN @@ -172,21 +172,25 @@ void TestSupervisor::analyze(const Scene *scene) { TestResult result; result.input = scene->getSourceFile(); - result.output = scene->getDestinationFile() + ".m"; + result.output = scene->getDestinationFile(); + result.output.replace_extension(".m"); result.success = false; - std::string refFilename = scene->getDestinationFile() + ".ref"; + fs::path refFilename = scene->getDestinationFile(); + refFilename.replace_extension(".ref"); - std::ifstream is(result.output.c_str()); - std::ifstream is_ref(refFilename.c_str()); + fs::ifstream is(result.output); + fs::ifstream is_ref(refFilename); if (is.fail()) { - result.message = formatString("Could not open '%s'!", result.output.c_str()); + result.message = formatString("Could not open '%s'!", + result.output.file_string().c_str()); m_mutex->lock(); m_numFailed++; m_results.push_back(result); m_mutex->unlock(); return; } if (is_ref.fail()) { - result.message = formatString("Could not open '%s'!", refFilename.c_str()); + result.message = formatString("Could not open '%s'!", + refFilename.file_string().c_str()); m_mutex->lock(); m_numFailed++; m_results.push_back(result); m_mutex->unlock(); @@ -265,7 +269,7 @@ void TestSupervisor::printSummary() const { if (result.success) continue; Log(EWarn, "============================================================"); - Log(EWarn, " Failure: Test case %zi (\"%s\")", i+1, result.input.c_str()); + Log(EWarn, " Failure: Test case %zi (\"%s\")", i+1, result.input.file_string().c_str()); Log(EWarn, " Message: \"%s\"", result.message.c_str()); Log(EWarn, "============================================================"); } diff --git a/src/luminaires/spot.cpp b/src/luminaires/spot.cpp index 776e6dc3..3d51c655 100644 --- a/src/luminaires/spot.cpp +++ b/src/luminaires/spot.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include MTS_NAMESPACE_BEGIN diff --git a/src/medium/flake.cpp b/src/medium/flake.cpp index 1cb92531..93eabd97 100644 --- a/src/medium/flake.cpp +++ b/src/medium/flake.cpp @@ -238,7 +238,7 @@ public: m_D.normalize(); SHVector4D phaseExpansion; - if (FileStream::exists("flake-phase.dat")) { + if (fs::exists("flake-phase.dat")) { stream = new FileStream("flake-phase.dat", FileStream::EReadOnly); phaseExpansion = SHVector4D(stream); stream->close(); diff --git a/src/medium/heterogeneous-flake.cpp b/src/medium/heterogeneous-flake.cpp index af50d9f5..75b80b60 100644 --- a/src/medium/heterogeneous-flake.cpp +++ b/src/medium/heterogeneous-flake.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -164,7 +165,7 @@ public: Log(EInfo, " sampling recursions = %i", m_samplingRecursions); bool computePhaseProjection = true; - if (FileStream::exists("flake-phase.dat")) { + if (fs::exists("flake-phase.dat")) { /* Avoid recomputing this every time */ stream = new FileStream("flake-phase.dat", FileStream::EReadOnly); unsigned int header = stream->readUInt(); diff --git a/src/medium/heterogeneous.cpp b/src/medium/heterogeneous.cpp index de665d3a..64d196d0 100644 --- a/src/medium/heterogeneous.cpp +++ b/src/medium/heterogeneous.cpp @@ -17,6 +17,7 @@ */ #include +#include #include MTS_NAMESPACE_BEGIN @@ -95,16 +96,16 @@ public: } - std::string volData = props.getString("filename"); - volData = FileResolver::getInstance()->resolve(volData); + fs::path volData = Thread::getThread()->getFileResolver()->resolve( + props.getString("filename")); /* Medium to world transformation - can't have nonuniform scales. Also note that a uniform scale factor of 100 will not reduce densities by that amount */ m_mediumToWorld = props.getTransform("toWorld", Transform()); - Log(EInfo, "Loading volume data from \"%s\" ..", volData.c_str()); - std::ifstream is(volData.c_str()); + Log(EInfo, "Loading volume data from \"%s\" ..", volData.file_string().c_str()); + fs::ifstream is(volData); if (is.bad() || is.fail()) Log(EError, "Invalid medium data file specified"); diff --git a/src/mitsuba/mtsutil.cpp b/src/mitsuba/mtsutil.cpp index abbd815b..fa93d781 100644 --- a/src/mitsuba/mtsutil.cpp +++ b/src/mitsuba/mtsutil.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,7 @@ void help() { while ((dirinfo = readdir(directory)) != NULL) { std::string fname(dirinfo->d_name); - if (!endsWith(fname, ".dylib") && !endsWith(fname, ".so")) + if (!boost::ends_with(fname, ".dylib") && !boost::ends_with(fname, ".so")) continue; std::string fullName = dirPath + "/" + fname; #else @@ -110,7 +111,7 @@ void help() { Plugin utility(shortName, fullName); if (!utility.isUtility()) continue; - if (startsWith(shortName, "test_")) { + if (boost::starts_with(shortName, "test_")) { testcases << "\t" << shortName; for (int i=0; i<22-(int) shortName.length(); ++i) testcases << ' '; @@ -287,7 +288,7 @@ int ubi_main(int argc, char **argv) { while ((dirinfo = readdir(directory)) != NULL) { std::string fname(dirinfo->d_name); - if (!endsWith(fname, ".dylib") && !endsWith(fname, ".so")) + if (!boost::ends_with(fname, ".dylib") && !boost::ends_with(fname, ".so")) continue; std::string fullName = dirPath + "/" + fname; #else @@ -302,7 +303,7 @@ int ubi_main(int argc, char **argv) { std::string fullName = dirPath + "\\" + fname; #endif std::string shortName = fname.substr(0, strrchr(fname.c_str(), '.') - fname.c_str()); - if (!startsWith(shortName, "test_") || seen.find(shortName) != seen.end()) + if (!boost::starts_with(shortName, "test_") || seen.find(shortName) != seen.end()) continue; seen.insert(shortName); Plugin plugin(shortName, fullName); diff --git a/src/phase/hg.cpp b/src/phase/hg.cpp index 963906ab..c4140987 100644 --- a/src/phase/hg.cpp +++ b/src/phase/hg.cpp @@ -17,6 +17,8 @@ */ #include +#include +#include MTS_NAMESPACE_BEGIN diff --git a/src/phase/kkay.cpp b/src/phase/kkay.cpp index 5ab252ae..2a00b544 100644 --- a/src/phase/kkay.cpp +++ b/src/phase/kkay.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include MTS_NAMESPACE_BEGIN diff --git a/src/qtgui/importdlg.cpp b/src/qtgui/importdlg.cpp index 998f85e4..673078f3 100644 --- a/src/qtgui/importdlg.cpp +++ b/src/qtgui/importdlg.cpp @@ -150,13 +150,13 @@ void ImportDialog::accept() { dialog->hide(); delete dialog; - if (importingThread->getResult().length() > 0) { + if (!importingThread->getResult().empty()) { size_t warningCount = logger->getWarningCount() - initialWarningCount; if (warningCount > 0) QMessageBox::warning(this, tr("Scene Import"), tr("Encountered %1 warnings while importing -- please see " "the log for details.").arg(warningCount), QMessageBox::Ok); - ((MainWindow *) parent())->loadFile(QString(importingThread->getResult().c_str())); + ((MainWindow *) parent())->loadFile(QString(importingThread->getResult().file_string().c_str())); } else { QMessageBox::critical(this, tr("Scene Import"), tr("Conversion failed -- please see the log for details."), diff --git a/src/qtgui/sceneimporter.cpp b/src/qtgui/sceneimporter.cpp index 0a4eedb7..81a22cec 100644 --- a/src/qtgui/sceneimporter.cpp +++ b/src/qtgui/sceneimporter.cpp @@ -25,21 +25,21 @@ public: inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) { } - std::string locateResource(const std::string &resource) { - LocateResourceDialog locateResource(m_parent, resource.c_str()); + fs::path locateResource(const fs::path &resource) { + LocateResourceDialog locateResource(m_parent, resource.file_string().c_str()); locateResource.setWindowModality(Qt::ApplicationModal); - if (locateResource.exec()) - return locateResource.getFilename().toStdString(); + if (locateResource.exec()) + return fs::path(locateResource.getFilename().toStdString()); - return ""; + return fs::path(); } private: QWidget *m_parent; }; SceneImporter::SceneImporter(QWidget *parent, FileResolver *resolver, - const std::string &sourceFile, const std::string &directory, - const std::string &targetScene, const std::string &adjustmentFile, + const fs::path &sourceFile, const fs::path &directory, + const fs::path &targetScene, const fs::path &adjustmentFile, bool sRGB) : Thread("impt"), m_parent(parent), m_resolver(resolver), m_sourceFile(sourceFile), m_directory(directory), diff --git a/src/qtgui/sceneimporter.h b/src/qtgui/sceneimporter.h index 2261da77..745f1488 100644 --- a/src/qtgui/sceneimporter.h +++ b/src/qtgui/sceneimporter.h @@ -21,32 +21,33 @@ #include #include +#include using namespace mitsuba; class SceneImporter : public Thread { public: SceneImporter(QWidget *parent, FileResolver *resolver, - const std::string &sourceFile, const std::string &directory, - const std::string &targetScene, const std::string &adjustmentFile, + const fs::path &sourceFile, const fs::path &directory, + const fs::path &targetScene, const fs::path &adjustmentFile, bool sRGB); void run(); inline void wait(int ms) { m_wait->wait(ms); } - inline const std::string &getResult() const { return m_result; } + inline const fs::path &getResult() const { return m_result; } protected: virtual ~SceneImporter(); private: QWidget *m_parent; ref m_resolver; ref m_wait; - std::string m_sourceFile; - std::string m_directory; - std::string m_targetScene; - std::string m_adjustmentFile; - std::string m_result; + fs::path m_sourceFile; + fs::path m_directory; + fs::path m_targetScene; + fs::path m_adjustmentFile; + fs::path m_result; bool m_srgb; }; diff --git a/src/qtgui/sceneloader.cpp b/src/qtgui/sceneloader.cpp index ec17d957..c0e385d4 100644 --- a/src/qtgui/sceneloader.cpp +++ b/src/qtgui/sceneloader.cpp @@ -22,6 +22,7 @@ #include #include #include +#include SceneLoader::SceneLoader(FileResolver *resolver, const std::string &filename) : Thread("load"), m_resolver(resolver), m_filename(filename) { @@ -54,7 +55,7 @@ void SceneLoader::run() { m_result->diffuseSources = settings.value("preview_diffuseSources", true).toBool(); m_result->diffuseReceivers = settings.value("preview_diffuseReceivers", false).toBool(); - if (endsWith(lowerCase, ".exr")) { + if (boost::ends_with(lowerCase, ".exr")) { /* This is an image, not a scene */ ref fs = new FileStream(m_filename, FileStream::EReadOnly); ref bitmap = new Bitmap(Bitmap::EEXR, fs); diff --git a/src/shapes/hair.cpp b/src/shapes/hair.cpp index 957dbb2a..bad59cc4 100644 --- a/src/shapes/hair.cpp +++ b/src/shapes/hair.cpp @@ -21,7 +21,6 @@ #include #include #include -#include MTS_NAMESPACE_BEGIN diff --git a/src/shapes/obj.cpp b/src/shapes/obj.cpp index 1f1475bc..d8cd435f 100644 --- a/src/shapes/obj.cpp +++ b/src/shapes/obj.cpp @@ -18,7 +18,10 @@ #include #include -#include +#include +#include +#include +#include MTS_NAMESPACE_BEGIN @@ -34,13 +37,13 @@ public: }; WavefrontOBJ(const Properties &props) : Shape(props) { - ref fResolver = Thread::getThread()->getFileResolver(); - fs::path path = fresolver->resolve(props.getString("filename")); - m_name = path.filename(); + FileResolver *fResolver = Thread::getThread()->getFileResolver(); + fs::path path = fResolver->resolve(props.getString("filename")); + m_name = path.stem(); /* Load the geometry */ - Log(EInfo, "Loading geometry from \"%s\" ..", m_name.c_str()); - std::ifstream is(path); + Log(EInfo, "Loading geometry from \"%s\" ..", path.leaf().c_str()); + fs::ifstream is(path); if (is.bad() || is.fail()) Log(EError, "Geometry file '%s' not found!", path.file_string().c_str()); @@ -97,10 +100,9 @@ public: } else if (buf == "mtllib") { std::string line; std::getline(is, line); - std::string mtlName = trim(line.substr(1, line.length()-1)); ref frClone = fResolver->clone(); - frClone->addPathFromFile(path); - fs::path mtlName = frClone->resolve(mtlName); + frClone->addPath(fs::complete(path).parent_path()); + fs::path mtlName = frClone->resolve(trim(line.substr(1, line.length()-1))); if (fs::exists(mtlName)) parseMaterials(mtlName); else @@ -183,9 +185,10 @@ public: void parseMaterials(const fs::path &mtlPath) { Log(EInfo, "Loading OBJ materials from \"%s\" ..", mtlPath.filename().c_str()); - std::ifstream is(mtlPath); + fs::ifstream is(mtlPath); if (is.bad() || is.fail()) - Log(EError, "Unexpected I/O error while accessing material file '%s'!", mtlFileName.c_str()); + Log(EError, "Unexpected I/O error while accessing material file '%s'!", + mtlPath.file_string().c_str()); std::string buf; std::string mtlName; Spectrum diffuse; diff --git a/src/shapes/serialized.cpp b/src/shapes/serialized.cpp index e48f4a9f..541f023a 100644 --- a/src/shapes/serialized.cpp +++ b/src/shapes/serialized.cpp @@ -17,6 +17,9 @@ */ #include +#include +#include +#include MTS_NAMESPACE_BEGIN @@ -26,12 +29,13 @@ MTS_NAMESPACE_BEGIN class SerializedMesh : public TriMesh { public: SerializedMesh(const Properties &props) : TriMesh(props) { - m_name = props.getString("filename"); - std::string filePath = FileResolver::getInstance()->resolve(m_name); + fs::path filePath = Thread::getThread()->getFileResolver()->resolve( + props.getString("filename")); + m_name = filePath.stem(); /* Load the geometry */ - Log(EInfo, "Loading geometry from \"%s\" ..", m_name.c_str()); - ref stream = new FileStream(filePath.c_str(), FileStream::EReadOnly); + Log(EInfo, "Loading geometry from \"%s\" ..", filePath.leaf().c_str()); + ref stream = new FileStream(filePath, FileStream::EReadOnly); stream->setByteOrder(Stream::ENetworkByteOrder); ref mesh = new TriMesh(stream); m_triangleCount = mesh->getTriangleCount(); diff --git a/src/shapes/sphere.cpp b/src/shapes/sphere.cpp index 0707233d..00e91003 100644 --- a/src/shapes/sphere.cpp +++ b/src/shapes/sphere.cpp @@ -17,6 +17,10 @@ */ #include +#include +#include +#include +#include MTS_NAMESPACE_BEGIN diff --git a/src/textures/ldrtexture.cpp b/src/textures/ldrtexture.cpp index 21629786..53c949bd 100644 --- a/src/textures/ldrtexture.cpp +++ b/src/textures/ldrtexture.cpp @@ -17,6 +17,8 @@ */ #include +#include +#include #include #include #include @@ -24,6 +26,7 @@ #include #include #include +#include MTS_NAMESPACE_BEGIN @@ -33,24 +36,24 @@ MTS_NAMESPACE_BEGIN class LDRTexture : public Texture { public: LDRTexture(const Properties &props) : Texture(props) { - m_filename = props.getString("filename"); - m_filename = FileResolver::getInstance()->resolve(m_filename); + m_filename = Thread::getThread()->getFileResolver()->resolve( + props.getString("filename")); m_gamma = props.getFloat("gamma", -1); /* -1 means sRGB */ - Log(EInfo, "Loading texture \"%s\"", m_filename.c_str()); + Log(EInfo, "Loading texture \"%s\"", m_filename.leaf().c_str()); ref fs = new FileStream(m_filename, FileStream::EReadOnly); - std::string lower = toLowerCase(m_filename); + std::string extension = boost::to_lower_copy(m_filename.extension()); - if (endsWith(lower, ".jpg") || endsWith(lower, ".jpeg")) + if (extension == ".jpg" || extension == ".jpeg") m_format = Bitmap::EJPEG; - else if (endsWith(lower, ".png")) + else if (extension == ".png") m_format = Bitmap::EPNG; - else if (endsWith(lower, ".tga")) + else if (extension == ".tga") m_format = Bitmap::ETGA; - else if (endsWith(lower, ".bmp")) + else if (extension == ".bmp") m_format = Bitmap::EBMP; else - Log(EError, "Cannot deduce the file type of '%s'!", m_filename.c_str()); + Log(EError, "Cannot deduce the file type of '%s'!", m_filename.file_string().c_str()); ref bitmap = new Bitmap(m_format, fs); initializeFrom(bitmap); @@ -59,7 +62,7 @@ public: LDRTexture(Stream *stream, InstanceManager *manager) : Texture(stream, manager) { m_filename = stream->readString(); - Log(EInfo, "Unserializing texture \"%s\"", m_filename.c_str()); + Log(EInfo, "Unserializing texture \"%s\"", m_filename.leaf().c_str()); m_gamma = stream->readFloat(); m_format = static_cast(stream->readInt()); unsigned int size = stream->readUInt(); @@ -70,7 +73,7 @@ public: initializeFrom(bitmap); if (Scheduler::getInstance()->hasRemoteWorkers() - && !FileStream::exists(m_filename)) { + && !fs::exists(m_filename)) { /* This code is running on a machine different from the one that created the stream. Because we might later have to handle a call to serialize(), the @@ -159,7 +162,7 @@ public: void serialize(Stream *stream, InstanceManager *manager) const { Texture::serialize(stream, manager); - stream->writeString(m_filename); + stream->writeString(m_filename.file_string()); stream->writeFloat(m_gamma); stream->writeInt(m_format); if (m_stream.get()) { @@ -201,7 +204,7 @@ public: protected: ref m_mipmap; ref m_stream; - std::string m_filename; + fs::path m_filename; Bitmap::EFileFormat m_format; Spectrum m_average, m_maximum; Float m_gamma; @@ -255,7 +258,7 @@ private: }; Shader *LDRTexture::createShader(Renderer *renderer) const { - return new LDRTextureShader(renderer, m_filename, m_mipmap->getLDRBitmap()); + return new LDRTextureShader(renderer, m_filename.leaf(), m_mipmap->getLDRBitmap()); } MTS_IMPLEMENT_CLASS_S(LDRTexture, false, Texture) diff --git a/src/volume/hgridvolume.cpp b/src/volume/hgridvolume.cpp index d6eb5094..3421a851 100644 --- a/src/volume/hgridvolume.cpp +++ b/src/volume/hgridvolume.cpp @@ -18,6 +18,9 @@ #include #include +#include +#include +#include MTS_NAMESPACE_BEGIN @@ -65,7 +68,7 @@ public: } void loadDictionary(const std::string &filename) { - std::string resolved = FileResolver::getInstance()->resolve(filename); + fs::path resolved = Thread::getThread()->getFileResolver()->resolve(filename); Log(EInfo, "Loading hierarchical grid dictionary \"%s\"", filename.c_str()); ref stream = new FileStream(resolved, FileStream::EReadOnly); stream->setByteOrder(Stream::ELittleEndian);