partial rewrite part 2, the project now fully compiles again

metadata
Wenzel Jakob 2010-09-13 21:19:04 +02:00
parent 1d39bd053f
commit a5035b6b10
43 changed files with 214 additions and 222 deletions

View File

@ -21,6 +21,7 @@
#include <mitsuba/mitsuba.h> #include <mitsuba/mitsuba.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;

View File

@ -22,7 +22,7 @@
#include <mitsuba/mitsuba.h> #include <mitsuba/mitsuba.h>
#include <mitsuba/core/stream.h> #include <mitsuba/core/stream.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -53,9 +53,6 @@ public:
/// Return the file path /// Return the file path
inline const fs::path &getPath() const { return m_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 /// Open a file with a given open mode
void open(const fs::path &filename, EFileMode mode = EReadOnly); void open(const fs::path &filename, EFileMode mode = EReadOnly);

View File

@ -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 /// Convert a time difference (in ms) to a string representation
extern MTS_EXPORT_CORE std::string timeToString(Float time); 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 /// Trim spaces (' ', '\\n', '\\r', '\\t') from the ends of a string
extern MTS_EXPORT_CORE std::string trim(const std::string& str); 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 /// Allocate an aligned region of memory
extern MTS_EXPORT_CORE void * __restrict allocAligned(size_t size); extern MTS_EXPORT_CORE void * __restrict allocAligned(size_t size);

View File

@ -21,6 +21,9 @@
#include <mitsuba/render/sampler.h> #include <mitsuba/render/sampler.h>
#include <mitsuba/render/renderproc_wr.h> #include <mitsuba/render/renderproc_wr.h>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -55,7 +58,7 @@ public:
virtual void toBitmap(Bitmap *bitmap) const = 0; virtual void toBitmap(Bitmap *bitmap) const = 0;
/// Develop the film and write the result to the specified filename /// 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 /// Ignoring the crop window, return the resolution of the underlying sensor
inline const Vector2i &getSize() const { return m_size; } inline const Vector2i &getSize() const { return m_size; }
@ -89,7 +92,7 @@ public:
virtual void serialize(Stream *stream, InstanceManager *manager) const; virtual void serialize(Stream *stream, InstanceManager *manager) const;
/// Does the destination already exist? /// 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 /// Return the properties of this film
inline const Properties &getProperties() const { return m_properties; } inline const Properties &getProperties() const { return m_properties; }

View File

@ -372,13 +372,13 @@ public:
inline const std::vector<ConfigurableObject *> &getReferencedObjects() const { return m_objects; } inline const std::vector<ConfigurableObject *> &getReferencedObjects() const { return m_objects; }
/// Return the name of the file containing the original description of this scene /// 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 /// 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 /// 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 /// 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? /// Does the destination file already exist?
inline bool destinationExists() const { return m_camera->getFilm()->destinationExists(m_destinationFile); } inline bool destinationExists() const { return m_camera->getFilm()->destinationExists(m_destinationFile); }
@ -416,8 +416,8 @@ private:
std::vector<Subsurface *> m_ssIntegrators; std::vector<Subsurface *> m_ssIntegrators;
std::vector<ConfigurableObject *> m_objects; std::vector<ConfigurableObject *> m_objects;
std::vector<NetworkedObject *> m_netObjects; std::vector<NetworkedObject *> m_netObjects;
std::string m_sourceFile; fs::path m_sourceFile;
std::string m_destinationFile; fs::path m_destinationFile;
DiscretePDF m_luminairePDF; DiscretePDF m_luminairePDF;
AABB m_aabb; AABB m_aabb;
BSphere m_bsphere; BSphere m_bsphere;

View File

@ -122,7 +122,7 @@ protected:
private: private:
struct TestResult { struct TestResult {
bool success; bool success;
std::string input, output; fs::path input, output;
std::string message; std::string message;
}; };

View File

@ -17,12 +17,12 @@
*/ */
#include <mitsuba/render/bsdf.h> #include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/consttexture.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/hw/renderer.h> #include <mitsuba/hw/renderer.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
/** /**
* Simple one-sided Lambertian (i.e. perfectly diffuse) material * Simple one-sided Lambertian (i.e. perfectly diffuse) material
*/ */

View File

@ -17,7 +17,7 @@
*/ */
#include <mitsuba/render/bsdf.h> #include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/consttexture.h>
#include <mitsuba/hw/renderer.h> #include <mitsuba/hw/renderer.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -17,7 +17,7 @@
*/ */
#include <mitsuba/render/bsdf.h> #include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/consttexture.h>
#include <mitsuba/hw/gpuprogram.h> #include <mitsuba/hw/gpuprogram.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -17,7 +17,7 @@
*/ */
#include <mitsuba/render/bsdf.h> #include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/consttexture.h>
#include <mitsuba/hw/gpuprogram.h> #include <mitsuba/hw/gpuprogram.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -17,7 +17,7 @@
*/ */
#include <mitsuba/render/bsdf.h> #include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/consttexture.h>
#include <mitsuba/hw/gpuprogram.h> #include <mitsuba/hw/gpuprogram.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -26,11 +26,9 @@
#include <dae.h> #include <dae.h>
#include <dom/domCOLLADA.h> #include <dom/domCOLLADA.h>
#include <dom/domProfile_COMMON.h> #include <dom/domProfile_COMMON.h>
#include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp>
#include <fstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#if defined(__OSX__) #if defined(__OSX__)
#include <OpenGL/glu.h> #include <OpenGL/glu.h>
@ -809,11 +807,12 @@ void loadImage(GeometryConverter *cvt, std::ostream &os, const fs::path &texture
idToTexture[identifier] = identifier; idToTexture[identifier] = identifier;
fileToId[filename] = 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 targetPath = textureDir / path.leaf();
fs::path resolved = filename; 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' " 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."); "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()); resolved = fRes->resolve(path.leaf());
if (!fs::exists(resolved)) { if (!fs::exists(resolved)) {
SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str()); SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str());
std::string result = cvt->locateResource(filename); resolved = cvt->locateResource(filename);
if (result == "") if (resolved.empty())
SLog(EError, "Unable to locate a resource -- aborting conversion."); SLog(EError, "Unable to locate a resource -- aborting conversion.");
resolved = result;
} }
} }
ref<FileStream> input = new FileStream(resolved, FileStream::EReadOnly); ref<FileStream> input = new FileStream(resolved, FileStream::EReadOnly);
@ -1094,16 +1092,17 @@ GLvoid __stdcall tessError(GLenum error) {
GLvoid __stdcall tessEdgeFlag(GLboolean) { GLvoid __stdcall tessEdgeFlag(GLboolean) {
} }
void GeometryConverter::convertCollada(const std::string &inputFile, void GeometryConverter::convertCollada(const fs::path &inputFile,
std::ostream &os, std::ostream &os,
const fs::path &textureDirectory, const fs::path &textureDirectory,
const fs::path &meshesDirectory) { const fs::path &meshesDirectory) {
DAE *dae = new DAE(); DAE *dae = new DAE();
SLog(EInfo, "Loading \"%s\" ..", inputFile.c_str()); SLog(EInfo, "Loading \"%s\" ..", inputFile.leaf().c_str());
if (dae->load(inputFile.c_str()) != DAE_OK) if (dae->load(inputFile.file_string().c_str()) != DAE_OK)
SLog(EError, "Could not load \"%s\"!", inputFile.c_str()); 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<domVisual_scene> domVisual_scene *visualScene = daeSafeCast<domVisual_scene>
(document->getDescendant("visual_scene")); (document->getDescendant("visual_scene"));
if (!visualScene) if (!visualScene)

View File

@ -29,12 +29,10 @@
#include <xercesc/framework/Wrapper4InputSource.hpp> #include <xercesc/framework/Wrapper4InputSource.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp> #include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/util/XMLUni.hpp> #include <xercesc/util/XMLUni.hpp>
#include <boost/filesystem/fstream.hpp> #include <mitsuba/core/fresolver.h>
#include <mitsuba/mitsuba.h> #include <boost/algorithm/string.hpp>
#include <fstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#include <set> #include <set>
XERCES_CPP_NAMESPACE_USE XERCES_CPP_NAMESPACE_USE
@ -129,21 +127,19 @@ bool cleanupPass(DOMNode *node, const std::set<std::string> &removals) {
return false; return false;
} }
void GeometryConverter::convert(const std::string &inputFile, void GeometryConverter::convert(const fs::path &inputFile,
const std::string &outputDirectory, const fs::path &outputDirectory,
const std::string &sceneName, const fs::path &sceneName,
const std::string &adjustmentFile) { const fs::path &adjustmentFile) {
fs::path textureDirectory = "textures"; fs::path textureDirectory = "textures";
fs::path meshesDirectory = "meshes"; fs::path meshesDirectory = "meshes";
fs::path outputFile = sceneName; fs::path outputFile = sceneName;
if (outputDirectory != "") { if (!outputDirectory.empty()) {
fs::path outPath (outputDirectory); textureDirectory = outputDirectory / "textures";
meshesDirectory = outputDirectory / "meshes";
textureDirectory = outPath / "textures"; outputFile = outputDirectory / sceneName;
meshesDirectory = outPath / "meshes";
outputFile = outPath / sceneName;
} }
SLog(EInfo, "Creating directories .."); SLog(EInfo, "Creating directories ..");
@ -155,15 +151,18 @@ void GeometryConverter::convert(const std::string &inputFile,
std::ostringstream os; std::ostringstream os;
SLog(EInfo, "Beginning conversion .."); 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); convertCollada(inputFile, os, textureDirectory, meshesDirectory);
} else if (endsWith(toLowerCase(inputFile), ".obj")) { } else if (extension == ".obj") {
convertOBJ(inputFile, os, textureDirectory, meshesDirectory); convertOBJ(inputFile, os, textureDirectory, meshesDirectory);
} else { } else {
SLog(EError, "Unknown input format (must end in either .DAE, .ZAE or .OBJ)"); SLog(EError, "Unknown input format (must end in either .DAE, .ZAE or .OBJ)");
} }
if (adjustmentFile != "") { if (adjustmentFile.empty()) {
SLog(EInfo, "Applying adjustments .."); SLog(EInfo, "Applying adjustments ..");
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS); DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
@ -178,8 +177,8 @@ void GeometryConverter::convert(const std::string &inputFile,
xmlString.length(), "bufID", false); xmlString.length(), "bufID", false);
Wrapper4InputSource *wrapper = new Wrapper4InputSource(memBufIS, false); Wrapper4InputSource *wrapper = new Wrapper4InputSource(memBufIS, false);
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = parser->parse(wrapper); 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<std::string> removals, emptyList; std::set<std::string> removals, emptyList;
cleanupPass(adj, emptyList); cleanupPass(adj, emptyList);
findRemovals(adj, removals); findRemovals(adj, removals);
@ -236,6 +235,6 @@ void GeometryConverter::convert(const std::string &inputFile,
ofile << os.str(); ofile << os.str();
ofile.close(); ofile.close();
} }
m_filename = outputFile.file_string(); m_filename = outputFile;
} }

View File

@ -30,29 +30,29 @@ public:
m_fov = -1; m_fov = -1;
} }
void convert(const std::string &inputFile, void convert(const fs::path &inputFile,
const std::string &outputDirectory, const fs::path &outputDirectory,
const std::string &sceneName, const fs::path &sceneName,
const std::string &adjustmentFile); 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 setSRGB(bool srgb) { m_srgb = srgb; }
inline void setMapSmallerSide(bool mapSmallerSide) { m_mapSmallerSide = mapSmallerSide; } inline void setMapSmallerSide(bool mapSmallerSide) { m_mapSmallerSide = mapSmallerSide; }
inline void setResolution(int xres, int yres) { m_xres = xres; m_yres = yres; } inline void setResolution(int xres, int yres) { m_xres = xres; m_yres = yres; }
inline void setSamplesPerPixel(int samplesPerPixel) { m_samplesPerPixel = samplesPerPixel; } inline void setSamplesPerPixel(int samplesPerPixel) { m_samplesPerPixel = samplesPerPixel; }
inline void setFov(Float fov) { m_fov = fov; } 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: 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 &textureDirectory,
const fs::path &meshesDirectory); 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 &textureDirectory,
const fs::path &meshesDirectory); const fs::path &meshesDirectory);
public: public:
bool m_srgb, m_mapSmallerSide; bool m_srgb, m_mapSmallerSide;
int m_xres, m_yres, m_samplesPerPixel; int m_xres, m_yres, m_samplesPerPixel;
Float m_fov; Float m_fov;
std::string m_filename; fs::path m_filename;
}; };

View File

@ -46,8 +46,8 @@ public:
inline ConsoleGeometryConverter() { inline ConsoleGeometryConverter() {
} }
std::string locateResource(const std::string &resource) { fs::path locateResource(const fs::path &resource) {
return ""; return fs::path();
} }
}; };

View File

@ -28,7 +28,7 @@
std::string copyTexture(GeometryConverter *cvt, const fs::path &textureDir, std::string filename) { std::string copyTexture(GeometryConverter *cvt, const fs::path &textureDir, std::string filename) {
SLog(EInfo, "Copying texture \"%s\" ..", filename.c_str()); 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 targetPath = textureDir / path.leaf();
fs::path resolved = filename; fs::path resolved = filename;
@ -38,10 +38,9 @@ std::string copyTexture(GeometryConverter *cvt, const fs::path &textureDir, std:
resolved = fRes->resolve(path.leaf()); resolved = fRes->resolve(path.leaf());
if (!fs::exists(resolved)) { if (!fs::exists(resolved)) {
SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str()); SLog(EWarn, "Found neither \"%s\" nor \"%s\"!", filename.c_str(), resolved.file_string().c_str());
std::string result = cvt->locateResource(filename); resolved = cvt->locateResource(filename);
if (result == "") if (resolved.empty())
SLog(EError, "Unable to locate a resource -- aborting conversion."); 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); 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, std::ostream &os,
const fs::path &textureDirectory, const fs::path &textureDirectory,
const fs::path &meshesDirectory) { const fs::path &meshesDirectory) {
std::ifstream is(inputFile.c_str()); fs::ifstream is(inputFile);
if (is.bad() || is.fail()) 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 << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << endl << endl; os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << endl << endl;
os << "<!--" << endl << endl; os << "<!--" << endl << endl;
os << "\tAutomatically converted from Wavefront OBJ" << endl << endl; os << "\tAutomatically converted from Wavefront OBJ" << endl << endl;
os << "-->" << endl << endl; os << "-->" << endl << endl;
os << "<scene>" << endl; os << "<scene>" << endl;
os << "\t<integrator id=\"integrator\" type=\"direct\"/>" << endl << endl; os << "\t<integrator id=\"integrator\" type=\"direct\"/>" << endl << endl;
std::string buf, line; std::string buf, line;
while (is >> buf) { while (is >> buf) {
if (buf == "mtllib") { if (buf == "mtllib") {
@ -167,7 +166,7 @@ void GeometryConverter::convertOBJ(const std::string &inputFile,
} }
Properties objProps("obj"); Properties objProps("obj");
objProps.setString("filename", inputFile); objProps.setString("filename", inputFile.file_string());
ref<Shape> rootShape = static_cast<Shape *> (PluginManager::getInstance()-> ref<Shape> rootShape = static_cast<Shape *> (PluginManager::getInstance()->
createObject(Shape::m_theClass, objProps)); createObject(Shape::m_theClass, objProps));

View File

@ -19,6 +19,7 @@
#include <mitsuba/render/film.h> #include <mitsuba/render/film.h>
#include <mitsuba/core/fstream.h> #include <mitsuba/core/fstream.h>
#include <mitsuba/core/bitmap.h> #include <mitsuba/core/bitmap.h>
#include <boost/algorithm/string.hpp>
#include "banner.h" #include "banner.h"
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -152,7 +153,7 @@ public:
} }
} }
void develop(const std::string &destFile) { void develop(const fs::path &destFile) {
Log(EDebug, "Developing film .."); Log(EDebug, "Developing film ..");
ref<Bitmap> bitmap = new Bitmap(m_cropSize.x, m_cropSize.y, 128); ref<Bitmap> bitmap = new Bitmap(m_cropSize.x, m_cropSize.y, 128);
float *targetPixels = bitmap->getFloatData(); float *targetPixels = bitmap->getFloatData();
@ -190,19 +191,21 @@ public:
} }
} }
std::string filename = destFile; fs::path filename = destFile;
if (!endsWith(filename, ".exr")) std::string extension = boost::to_lower_copy(fs::extension(filename));
filename += ".exr"; if (extension != ".exr")
Log(EInfo, "Writing image to \"%s\" ..", filename.c_str()); filename.replace_extension(".exr");
Log(EInfo, "Writing image to \"%s\" ..", filename.leaf().c_str());
ref<FileStream> stream = new FileStream(filename, FileStream::ETruncWrite); ref<FileStream> stream = new FileStream(filename, FileStream::ETruncWrite);
bitmap->save(Bitmap::EEXR, stream); bitmap->save(Bitmap::EEXR, stream);
} }
bool destinationExists(const std::string &baseName) const { bool destinationExists(const fs::path &baseName) const {
std::string filename = baseName; fs::path filename = baseName;
if (!endsWith(filename, ".exr")) if (boost::to_lower_copy(filename.extension()) != ".exr")
filename += ".exr"; filename.replace_extension(".exr");
return FileStream::exists(filename); return fs::exists(filename);
} }
std::string toString() const { std::string toString() const {

View File

@ -18,6 +18,7 @@
#include <mitsuba/render/film.h> #include <mitsuba/render/film.h>
#include <mitsuba/core/bitmap.h> #include <mitsuba/core/bitmap.h>
#include <boost/algorithm/string.hpp>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -169,14 +170,15 @@ public:
} }
} }
void develop(const std::string &destFile) { void develop(const fs::path &destFile) {
std::string filename = destFile; fs::path filename = destFile;
if (!endsWith(filename, ".m")) std::string extension = boost::to_lower_copy(fs::extension(filename));
filename += ".m"; 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) if (!f)
Log(EError, "Output file cannot be created!"); Log(EError, "Output file cannot be created!");
@ -216,11 +218,11 @@ public:
fclose(f); fclose(f);
} }
bool destinationExists(const std::string &baseName) const { bool destinationExists(const fs::path &baseName) const {
std::string filename = baseName; fs::path filename = baseName;
if (!endsWith(filename, ".m")) if (boost::to_lower_copy(filename.extension()) != ".m")
filename += ".m"; filename.replace_extension(".m");
return FileStream::exists(filename); return fs::exists(filename);
} }
std::string toString() const { std::string toString() const {

View File

@ -18,6 +18,8 @@
#include <mitsuba/render/film.h> #include <mitsuba/render/film.h>
#include <mitsuba/core/bitmap.h> #include <mitsuba/core/bitmap.h>
#include <mitsuba/core/fstream.h>
#include <boost/algorithm/string.hpp>
#include "banner.h" #include "banner.h"
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -180,7 +182,7 @@ public:
- (Float) 0.055; - (Float) 0.055;
} }
void develop(const std::string &destFile) { void develop(const fs::path &destFile) {
Log(EDebug, "Developing film .."); Log(EDebug, "Developing film ..");
ref<Bitmap> bitmap = new Bitmap(m_cropSize.x, m_cropSize.y, m_bpp); ref<Bitmap> bitmap = new Bitmap(m_cropSize.x, m_cropSize.y, m_bpp);
uint8_t *targetPixels = bitmap->getData(); uint8_t *targetPixels = bitmap->getData();
@ -314,23 +316,25 @@ public:
} }
} }
std::string filename = destFile; fs::path filename = destFile;
if (!endsWith(filename, ".png")) std::string extension = boost::to_lower_copy(fs::extension(filename));
filename += ".png"; 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<FileStream> stream = new FileStream(filename, FileStream::ETruncWrite); ref<FileStream> stream = new FileStream(filename, FileStream::ETruncWrite);
bitmap->setGamma(m_gamma); bitmap->setGamma(m_gamma);
bitmap->save(Bitmap::EPNG, stream); bitmap->save(Bitmap::EPNG, stream);
} }
bool destinationExists(const std::string &baseName) const { bool destinationExists(const fs::path &baseName) const {
std::string filename = baseName; fs::path filename = baseName;
if (!endsWith(filename, ".png")) if (boost::to_lower_copy(filename.extension()) != ".png")
filename += ".png"; filename.replace_extension(".png");
return FileStream::exists(filename); return fs::exists(filename);
} }
std::string toString() const { std::string toString() const {
std::ostringstream oss; std::ostringstream oss;
oss << "PNGFilm[" << std::endl oss << "PNGFilm[" << std::endl

View File

@ -17,6 +17,7 @@
*/ */
#include <mitsuba/core/plugin.h> #include <mitsuba/core/plugin.h>
#include <mitsuba/core/statistics.h>
#include "irrcache_proc.h" #include "irrcache_proc.h"
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <mitsuba/core/statistics.h>
#include <mitsuba/hw/vpl.h> #include <mitsuba/hw/vpl.h>
#include <mitsuba/hw/session.h> #include <mitsuba/hw/session.h>
#include <mitsuba/hw/device.h> #include <mitsuba/hw/device.h>

View File

@ -48,21 +48,6 @@ std::string FileStream::toString() const {
return oss.str(); 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) { void FileStream::open(const fs::path &path, EFileMode mode) {
AssertEx(m_file == 0, "A file has already been opened using this stream"); AssertEx(m_file == 0, "A file has already been opened using this stream");

View File

@ -148,26 +148,6 @@ std::string trim(const std::string& str) {
end == std::string::npos ? str.length() - 1 : end - start + 1); 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; i<string.length(); i++)
result += std::tolower(string[i]);
return result;
}
std::string toUpperCase(const std::string &string) {
std::string result;
result.reserve(string.length());
for (unsigned int i=0; i<string.length(); i++)
result += toupper(string[i]);
return result;
}
std::string indent(const std::string &string, int amount) { std::string indent(const std::string &string, int amount) {
/* This could probably be done faster (is not /* This could probably be done faster (is not
really speed-critical though) */ really speed-critical though) */

View File

@ -112,7 +112,7 @@ void RenderJob::run() {
if (!m_scene->render(m_queue, this, m_sceneResID, m_cameraResID, m_samplerResID)) { if (!m_scene->render(m_queue, this, m_sceneResID, m_cameraResID, m_samplerResID)) {
cancelled = true; cancelled = true;
Log(EWarn, "Rendering of scene \"%s\" did not complete successfully!", 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); m_scene->postprocess(m_queue, this, m_sceneResID, m_cameraResID, m_samplerResID);
@ -120,7 +120,7 @@ void RenderJob::run() {
m_testSupervisor->analyze(m_scene); m_testSupervisor->analyze(m_scene);
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
Log(EWarn, "Rendering of scene \"%s\" did not complete successfully, caught exception: %s", 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; cancelled = true;
} }

View File

@ -20,6 +20,7 @@
#include <xercesc/parsers/SAXParser.hpp> #include <xercesc/parsers/SAXParser.hpp>
#include <mitsuba/render/shandler.h> #include <mitsuba/render/shandler.h>
#include <mitsuba/core/fresolver.h> #include <mitsuba/core/fresolver.h>
#include <boost/algorithm/string.hpp>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -101,7 +102,7 @@ void SceneHandler::startElement(const XMLCh* const xmlName,
void SceneHandler::endElement(const XMLCh* const xmlName) { void SceneHandler::endElement(const XMLCh* const xmlName) {
std::string name = transcode(xmlName); std::string name = transcode(xmlName);
ParseContext &context = m_context.top(); 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); context.properties.setPluginName(type);
if (context.attributes.find("id") != context.attributes.end()) if (context.attributes.find("id") != context.attributes.end())
context.properties.setID(context.attributes["id"]); context.properties.setID(context.attributes["id"]);

View File

@ -19,7 +19,7 @@
#include <mitsuba/render/scene.h> #include <mitsuba/render/scene.h>
#include <mitsuba/render/testcase.h> #include <mitsuba/render/testcase.h>
#include <boost/math/distributions/students_t.hpp> #include <boost/math/distributions/students_t.hpp>
#include <fstream> #include <boost/filesystem/fstream.hpp>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -172,21 +172,25 @@ void TestSupervisor::analyze(const Scene *scene) {
TestResult result; TestResult result;
result.input = scene->getSourceFile(); result.input = scene->getSourceFile();
result.output = scene->getDestinationFile() + ".m"; result.output = scene->getDestinationFile();
result.output.replace_extension(".m");
result.success = false; 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()); fs::ifstream is(result.output);
std::ifstream is_ref(refFilename.c_str()); fs::ifstream is_ref(refFilename);
if (is.fail()) { 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_mutex->lock();
m_numFailed++; m_results.push_back(result); m_numFailed++; m_results.push_back(result);
m_mutex->unlock(); m_mutex->unlock();
return; return;
} }
if (is_ref.fail()) { 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_mutex->lock();
m_numFailed++; m_results.push_back(result); m_numFailed++; m_results.push_back(result);
m_mutex->unlock(); m_mutex->unlock();
@ -265,7 +269,7 @@ void TestSupervisor::printSummary() const {
if (result.success) if (result.success)
continue; continue;
Log(EWarn, "============================================================"); 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, " Message: \"%s\"", result.message.c_str());
Log(EWarn, "============================================================"); Log(EWarn, "============================================================");
} }

View File

@ -17,7 +17,7 @@
*/ */
#include <mitsuba/render/scene.h> #include <mitsuba/render/scene.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/consttexture.h>
#include <mitsuba/hw/gpuprogram.h> #include <mitsuba/hw/gpuprogram.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -238,7 +238,7 @@ public:
m_D.normalize(); m_D.normalize();
SHVector4D phaseExpansion; SHVector4D phaseExpansion;
if (FileStream::exists("flake-phase.dat")) { if (fs::exists("flake-phase.dat")) {
stream = new FileStream("flake-phase.dat", FileStream::EReadOnly); stream = new FileStream("flake-phase.dat", FileStream::EReadOnly);
phaseExpansion = SHVector4D(stream); phaseExpansion = SHVector4D(stream);
stream->close(); stream->close();

View File

@ -18,6 +18,7 @@
#include <mitsuba/render/scene.h> #include <mitsuba/render/scene.h>
#include <mitsuba/render/volume.h> #include <mitsuba/render/volume.h>
#include <mitsuba/core/fstream.h>
#include <mitsuba/core/shvector4d.h> #include <mitsuba/core/shvector4d.h>
#include <fstream> #include <fstream>
@ -164,7 +165,7 @@ public:
Log(EInfo, " sampling recursions = %i", m_samplingRecursions); Log(EInfo, " sampling recursions = %i", m_samplingRecursions);
bool computePhaseProjection = true; bool computePhaseProjection = true;
if (FileStream::exists("flake-phase.dat")) { if (fs::exists("flake-phase.dat")) {
/* Avoid recomputing this every time */ /* Avoid recomputing this every time */
stream = new FileStream("flake-phase.dat", FileStream::EReadOnly); stream = new FileStream("flake-phase.dat", FileStream::EReadOnly);
unsigned int header = stream->readUInt(); unsigned int header = stream->readUInt();

View File

@ -17,6 +17,7 @@
*/ */
#include <mitsuba/render/scene.h> #include <mitsuba/render/scene.h>
#include <mitsuba/core/fresolver.h>
#include <fstream> #include <fstream>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -95,16 +96,16 @@ public:
} }
std::string volData = props.getString("filename"); fs::path volData = Thread::getThread()->getFileResolver()->resolve(
volData = FileResolver::getInstance()->resolve(volData); props.getString("filename"));
/* Medium to world transformation - can't have nonuniform scales. Also note /* Medium to world transformation - can't have nonuniform scales. Also note
that a uniform scale factor of 100 will not reduce densities by that that a uniform scale factor of 100 will not reduce densities by that
amount */ amount */
m_mediumToWorld = props.getTransform("toWorld", Transform()); m_mediumToWorld = props.getTransform("toWorld", Transform());
Log(EInfo, "Loading volume data from \"%s\" ..", volData.c_str()); Log(EInfo, "Loading volume data from \"%s\" ..", volData.file_string().c_str());
std::ifstream is(volData.c_str()); fs::ifstream is(volData);
if (is.bad() || is.fail()) if (is.bad() || is.fail())
Log(EError, "Invalid medium data file specified"); Log(EError, "Invalid medium data file specified");

View File

@ -28,6 +28,7 @@
#include <mitsuba/render/util.h> #include <mitsuba/render/util.h>
#include <mitsuba/render/renderjob.h> #include <mitsuba/render/renderjob.h>
#include <mitsuba/render/shandler.h> #include <mitsuba/render/shandler.h>
#include <boost/algorithm/string.hpp>
#include <fstream> #include <fstream>
#include <stdexcept> #include <stdexcept>
#include <sys/types.h> #include <sys/types.h>
@ -89,7 +90,7 @@ void help() {
while ((dirinfo = readdir(directory)) != NULL) { while ((dirinfo = readdir(directory)) != NULL) {
std::string fname(dirinfo->d_name); 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; continue;
std::string fullName = dirPath + "/" + fname; std::string fullName = dirPath + "/" + fname;
#else #else
@ -110,7 +111,7 @@ void help() {
Plugin utility(shortName, fullName); Plugin utility(shortName, fullName);
if (!utility.isUtility()) if (!utility.isUtility())
continue; continue;
if (startsWith(shortName, "test_")) { if (boost::starts_with(shortName, "test_")) {
testcases << "\t" << shortName; testcases << "\t" << shortName;
for (int i=0; i<22-(int) shortName.length(); ++i) for (int i=0; i<22-(int) shortName.length(); ++i)
testcases << ' '; testcases << ' ';
@ -287,7 +288,7 @@ int ubi_main(int argc, char **argv) {
while ((dirinfo = readdir(directory)) != NULL) { while ((dirinfo = readdir(directory)) != NULL) {
std::string fname(dirinfo->d_name); 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; continue;
std::string fullName = dirPath + "/" + fname; std::string fullName = dirPath + "/" + fname;
#else #else
@ -302,7 +303,7 @@ int ubi_main(int argc, char **argv) {
std::string fullName = dirPath + "\\" + fname; std::string fullName = dirPath + "\\" + fname;
#endif #endif
std::string shortName = fname.substr(0, strrchr(fname.c_str(), '.') - fname.c_str()); 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; continue;
seen.insert(shortName); seen.insert(shortName);
Plugin plugin(shortName, fullName); Plugin plugin(shortName, fullName);

View File

@ -17,6 +17,8 @@
*/ */
#include <mitsuba/render/medium.h> #include <mitsuba/render/medium.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/core/frame.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -18,6 +18,8 @@
#include <mitsuba/render/medium.h> #include <mitsuba/render/medium.h>
#include <mitsuba/core/random.h> #include <mitsuba/core/random.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/core/frame.h>
#include <boost/math/special_functions/gamma.hpp> #include <boost/math/special_functions/gamma.hpp>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -150,13 +150,13 @@ void ImportDialog::accept() {
dialog->hide(); dialog->hide();
delete dialog; delete dialog;
if (importingThread->getResult().length() > 0) { if (!importingThread->getResult().empty()) {
size_t warningCount = logger->getWarningCount() - initialWarningCount; size_t warningCount = logger->getWarningCount() - initialWarningCount;
if (warningCount > 0) if (warningCount > 0)
QMessageBox::warning(this, tr("Scene Import"), QMessageBox::warning(this, tr("Scene Import"),
tr("Encountered %1 warnings while importing -- please see " tr("Encountered %1 warnings while importing -- please see "
"the log for details.").arg(warningCount), QMessageBox::Ok); "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 { } else {
QMessageBox::critical(this, tr("Scene Import"), QMessageBox::critical(this, tr("Scene Import"),
tr("Conversion failed -- please see the log for details."), tr("Conversion failed -- please see the log for details."),

View File

@ -25,21 +25,21 @@ public:
inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) { inline GUIGeometryConverter(QWidget *parent) : m_parent(parent) {
} }
std::string locateResource(const std::string &resource) { fs::path locateResource(const fs::path &resource) {
LocateResourceDialog locateResource(m_parent, resource.c_str()); LocateResourceDialog locateResource(m_parent, resource.file_string().c_str());
locateResource.setWindowModality(Qt::ApplicationModal); locateResource.setWindowModality(Qt::ApplicationModal);
if (locateResource.exec()) if (locateResource.exec())
return locateResource.getFilename().toStdString(); return fs::path(locateResource.getFilename().toStdString());
return ""; return fs::path();
} }
private: private:
QWidget *m_parent; QWidget *m_parent;
}; };
SceneImporter::SceneImporter(QWidget *parent, FileResolver *resolver, SceneImporter::SceneImporter(QWidget *parent, FileResolver *resolver,
const std::string &sourceFile, const std::string &directory, const fs::path &sourceFile, const fs::path &directory,
const std::string &targetScene, const std::string &adjustmentFile, const fs::path &targetScene, const fs::path &adjustmentFile,
bool sRGB) bool sRGB)
: Thread("impt"), m_parent(parent), m_resolver(resolver), : Thread("impt"), m_parent(parent), m_resolver(resolver),
m_sourceFile(sourceFile), m_directory(directory), m_sourceFile(sourceFile), m_directory(directory),

View File

@ -21,32 +21,33 @@
#include <QtGui> #include <QtGui>
#include <mitsuba/core/lock.h> #include <mitsuba/core/lock.h>
#include <mitsuba/core/fresolver.h>
using namespace mitsuba; using namespace mitsuba;
class SceneImporter : public Thread { class SceneImporter : public Thread {
public: public:
SceneImporter(QWidget *parent, FileResolver *resolver, SceneImporter(QWidget *parent, FileResolver *resolver,
const std::string &sourceFile, const std::string &directory, const fs::path &sourceFile, const fs::path &directory,
const std::string &targetScene, const std::string &adjustmentFile, const fs::path &targetScene, const fs::path &adjustmentFile,
bool sRGB); bool sRGB);
void run(); void run();
inline void wait(int ms) { m_wait->wait(ms); } 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: protected:
virtual ~SceneImporter(); virtual ~SceneImporter();
private: private:
QWidget *m_parent; QWidget *m_parent;
ref<FileResolver> m_resolver; ref<FileResolver> m_resolver;
ref<WaitFlag> m_wait; ref<WaitFlag> m_wait;
std::string m_sourceFile; fs::path m_sourceFile;
std::string m_directory; fs::path m_directory;
std::string m_targetScene; fs::path m_targetScene;
std::string m_adjustmentFile; fs::path m_adjustmentFile;
std::string m_result; fs::path m_result;
bool m_srgb; bool m_srgb;
}; };

View File

@ -22,6 +22,7 @@
#include <mitsuba/render/shandler.h> #include <mitsuba/render/shandler.h>
#include <mitsuba/core/fresolver.h> #include <mitsuba/core/fresolver.h>
#include <mitsuba/core/fstream.h> #include <mitsuba/core/fstream.h>
#include <boost/algorithm/string.hpp>
SceneLoader::SceneLoader(FileResolver *resolver, const std::string &filename) SceneLoader::SceneLoader(FileResolver *resolver, const std::string &filename)
: Thread("load"), m_resolver(resolver), m_filename(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->diffuseSources = settings.value("preview_diffuseSources", true).toBool();
m_result->diffuseReceivers = settings.value("preview_diffuseReceivers", false).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 */ /* This is an image, not a scene */
ref<FileStream> fs = new FileStream(m_filename, FileStream::EReadOnly); ref<FileStream> fs = new FileStream(m_filename, FileStream::EReadOnly);
ref<Bitmap> bitmap = new Bitmap(Bitmap::EEXR, fs); ref<Bitmap> bitmap = new Bitmap(Bitmap::EEXR, fs);

View File

@ -21,7 +21,6 @@
#include <mitsuba/core/plugin.h> #include <mitsuba/core/plugin.h>
#include <mitsuba/core/fresolver.h> #include <mitsuba/core/fresolver.h>
#include <mitsuba/core/properties.h> #include <mitsuba/core/properties.h>
#include <boost/filesystem/fstream.hpp>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -18,7 +18,10 @@
#include <mitsuba/render/trimesh.h> #include <mitsuba/render/trimesh.h>
#include <mitsuba/core/plugin.h> #include <mitsuba/core/plugin.h>
#include <boost/filesystem/fstream.hpp> #include <mitsuba/core/fresolver.h>
#include <mitsuba/render/luminaire.h>
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/subsurface.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -34,13 +37,13 @@ public:
}; };
WavefrontOBJ(const Properties &props) : Shape(props) { WavefrontOBJ(const Properties &props) : Shape(props) {
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver(); FileResolver *fResolver = Thread::getThread()->getFileResolver();
fs::path path = fresolver->resolve(props.getString("filename")); fs::path path = fResolver->resolve(props.getString("filename"));
m_name = path.filename(); m_name = path.stem();
/* Load the geometry */ /* Load the geometry */
Log(EInfo, "Loading geometry from \"%s\" ..", m_name.c_str()); Log(EInfo, "Loading geometry from \"%s\" ..", path.leaf().c_str());
std::ifstream is(path); fs::ifstream is(path);
if (is.bad() || is.fail()) if (is.bad() || is.fail())
Log(EError, "Geometry file '%s' not found!", path.file_string().c_str()); Log(EError, "Geometry file '%s' not found!", path.file_string().c_str());
@ -97,10 +100,9 @@ public:
} else if (buf == "mtllib") { } else if (buf == "mtllib") {
std::string line; std::string line;
std::getline(is, line); std::getline(is, line);
std::string mtlName = trim(line.substr(1, line.length()-1));
ref<FileResolver> frClone = fResolver->clone(); ref<FileResolver> frClone = fResolver->clone();
frClone->addPathFromFile(path); frClone->addPath(fs::complete(path).parent_path());
fs::path mtlName = frClone->resolve(mtlName); fs::path mtlName = frClone->resolve(trim(line.substr(1, line.length()-1)));
if (fs::exists(mtlName)) if (fs::exists(mtlName))
parseMaterials(mtlName); parseMaterials(mtlName);
else else
@ -183,9 +185,10 @@ public:
void parseMaterials(const fs::path &mtlPath) { void parseMaterials(const fs::path &mtlPath) {
Log(EInfo, "Loading OBJ materials from \"%s\" ..", mtlPath.filename().c_str()); Log(EInfo, "Loading OBJ materials from \"%s\" ..", mtlPath.filename().c_str());
std::ifstream is(mtlPath); fs::ifstream is(mtlPath);
if (is.bad() || is.fail()) 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 buf;
std::string mtlName; std::string mtlName;
Spectrum diffuse; Spectrum diffuse;

View File

@ -17,6 +17,9 @@
*/ */
#include <mitsuba/render/trimesh.h> #include <mitsuba/render/trimesh.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/core/fstream.h>
#include <mitsuba/core/fresolver.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -26,12 +29,13 @@ MTS_NAMESPACE_BEGIN
class SerializedMesh : public TriMesh { class SerializedMesh : public TriMesh {
public: public:
SerializedMesh(const Properties &props) : TriMesh(props) { SerializedMesh(const Properties &props) : TriMesh(props) {
m_name = props.getString("filename"); fs::path filePath = Thread::getThread()->getFileResolver()->resolve(
std::string filePath = FileResolver::getInstance()->resolve(m_name); props.getString("filename"));
m_name = filePath.stem();
/* Load the geometry */ /* Load the geometry */
Log(EInfo, "Loading geometry from \"%s\" ..", m_name.c_str()); Log(EInfo, "Loading geometry from \"%s\" ..", filePath.leaf().c_str());
ref<FileStream> stream = new FileStream(filePath.c_str(), FileStream::EReadOnly); ref<FileStream> stream = new FileStream(filePath, FileStream::EReadOnly);
stream->setByteOrder(Stream::ENetworkByteOrder); stream->setByteOrder(Stream::ENetworkByteOrder);
ref<TriMesh> mesh = new TriMesh(stream); ref<TriMesh> mesh = new TriMesh(stream);
m_triangleCount = mesh->getTriangleCount(); m_triangleCount = mesh->getTriangleCount();

View File

@ -17,6 +17,10 @@
*/ */
#include <mitsuba/render/shape.h> #include <mitsuba/render/shape.h>
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/luminaire.h>
#include <mitsuba/render/subsurface.h>
#include <mitsuba/core/properties.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN

View File

@ -17,6 +17,8 @@
*/ */
#include <mitsuba/core/bitmap.h> #include <mitsuba/core/bitmap.h>
#include <mitsuba/core/fresolver.h>
#include <mitsuba/core/fstream.h>
#include <mitsuba/core/mstream.h> #include <mitsuba/core/mstream.h>
#include <mitsuba/core/sched.h> #include <mitsuba/core/sched.h>
#include <mitsuba/render/texture.h> #include <mitsuba/render/texture.h>
@ -24,6 +26,7 @@
#include <mitsuba/hw/renderer.h> #include <mitsuba/hw/renderer.h>
#include <mitsuba/hw/gputexture.h> #include <mitsuba/hw/gputexture.h>
#include <mitsuba/hw/gpuprogram.h> #include <mitsuba/hw/gpuprogram.h>
#include <boost/algorithm/string.hpp>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -33,24 +36,24 @@ MTS_NAMESPACE_BEGIN
class LDRTexture : public Texture { class LDRTexture : public Texture {
public: public:
LDRTexture(const Properties &props) : Texture(props) { LDRTexture(const Properties &props) : Texture(props) {
m_filename = props.getString("filename"); m_filename = Thread::getThread()->getFileResolver()->resolve(
m_filename = FileResolver::getInstance()->resolve(m_filename); props.getString("filename"));
m_gamma = props.getFloat("gamma", -1); /* -1 means sRGB */ 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<FileStream> fs = new FileStream(m_filename, FileStream::EReadOnly); ref<FileStream> 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; m_format = Bitmap::EJPEG;
else if (endsWith(lower, ".png")) else if (extension == ".png")
m_format = Bitmap::EPNG; m_format = Bitmap::EPNG;
else if (endsWith(lower, ".tga")) else if (extension == ".tga")
m_format = Bitmap::ETGA; m_format = Bitmap::ETGA;
else if (endsWith(lower, ".bmp")) else if (extension == ".bmp")
m_format = Bitmap::EBMP; m_format = Bitmap::EBMP;
else 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> bitmap = new Bitmap(m_format, fs); ref<Bitmap> bitmap = new Bitmap(m_format, fs);
initializeFrom(bitmap); initializeFrom(bitmap);
@ -59,7 +62,7 @@ public:
LDRTexture(Stream *stream, InstanceManager *manager) LDRTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) { : Texture(stream, manager) {
m_filename = stream->readString(); 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_gamma = stream->readFloat();
m_format = static_cast<Bitmap::EFileFormat>(stream->readInt()); m_format = static_cast<Bitmap::EFileFormat>(stream->readInt());
unsigned int size = stream->readUInt(); unsigned int size = stream->readUInt();
@ -70,7 +73,7 @@ public:
initializeFrom(bitmap); initializeFrom(bitmap);
if (Scheduler::getInstance()->hasRemoteWorkers() if (Scheduler::getInstance()->hasRemoteWorkers()
&& !FileStream::exists(m_filename)) { && !fs::exists(m_filename)) {
/* This code is running on a machine different from /* This code is running on a machine different from
the one that created the stream. Because we might the one that created the stream. Because we might
later have to handle a call to serialize(), the later have to handle a call to serialize(), the
@ -159,7 +162,7 @@ public:
void serialize(Stream *stream, InstanceManager *manager) const { void serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager); Texture::serialize(stream, manager);
stream->writeString(m_filename); stream->writeString(m_filename.file_string());
stream->writeFloat(m_gamma); stream->writeFloat(m_gamma);
stream->writeInt(m_format); stream->writeInt(m_format);
if (m_stream.get()) { if (m_stream.get()) {
@ -201,7 +204,7 @@ public:
protected: protected:
ref<MIPMap> m_mipmap; ref<MIPMap> m_mipmap;
ref<MemoryStream> m_stream; ref<MemoryStream> m_stream;
std::string m_filename; fs::path m_filename;
Bitmap::EFileFormat m_format; Bitmap::EFileFormat m_format;
Spectrum m_average, m_maximum; Spectrum m_average, m_maximum;
Float m_gamma; Float m_gamma;
@ -255,7 +258,7 @@ private:
}; };
Shader *LDRTexture::createShader(Renderer *renderer) const { 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) MTS_IMPLEMENT_CLASS_S(LDRTexture, false, Texture)

View File

@ -18,6 +18,9 @@
#include <mitsuba/render/volume.h> #include <mitsuba/render/volume.h>
#include <mitsuba/core/plugin.h> #include <mitsuba/core/plugin.h>
#include <mitsuba/core/properties.h>
#include <mitsuba/core/fstream.h>
#include <mitsuba/core/fresolver.h>
MTS_NAMESPACE_BEGIN MTS_NAMESPACE_BEGIN
@ -65,7 +68,7 @@ public:
} }
void loadDictionary(const std::string &filename) { 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()); Log(EInfo, "Loading hierarchical grid dictionary \"%s\"", filename.c_str());
ref<FileStream> stream = new FileStream(resolved, FileStream::EReadOnly); ref<FileStream> stream = new FileStream(resolved, FileStream::EReadOnly);
stream->setByteOrder(Stream::ELittleEndian); stream->setByteOrder(Stream::ELittleEndian);