From f0a2e2436e57de8c78d8730327dfa4f47566b7b0 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Fri, 13 Aug 2010 17:03:49 +0200 Subject: [PATCH] dielectric now puts equal weight on both components, locale fixes, many importer improvements --- src/bsdfs/dielectric.cpp | 22 +++++++++++------ src/collada/converter.cpp | 52 +++++++++++++++++++++++++++++++-------- src/collada/converter.h | 7 +++++- src/collada/main.cpp | 38 ++++++++++++++++++++-------- src/mitsuba/mitsuba.cpp | 4 +++ src/mitsuba/mtssrv.cpp | 4 +++ src/qtgui/main.cpp | 4 +++ 7 files changed, 102 insertions(+), 29 deletions(-) diff --git a/src/bsdfs/dielectric.cpp b/src/bsdfs/dielectric.cpp index 4b332a85..4a9d4411 100644 --- a/src/bsdfs/dielectric.cpp +++ b/src/bsdfs/dielectric.cpp @@ -3,6 +3,8 @@ MTS_NAMESPACE_BEGIN +const bool importanceSampleComponents = false; + /** * Models an interface between two materials with non-matched indices of refraction. * The microscopic surface structure is assumed to be perfectly flat, resulting @@ -169,15 +171,15 @@ public: /* Calculate the refracted/reflected vectors+coefficients */ if (sampleTransmission && sampleReflection) { /* Importance sample according to the reflectance/transmittance */ - if (bRec.sample.x < fr) { + if (bRec.sample.x < importanceSampleComponents ? fr : 0.5f) { reflect(bRec.wi, bRec.wo); bRec.sampledComponent = 0; bRec.sampledType = EDeltaReflection; - pdf = fr * std::abs(Frame::cosTheta(bRec.wo)); + pdf = (importanceSampleComponents ? fr : 0.5f) * std::abs(Frame::cosTheta(bRec.wo)); /* Cancel out the cosine term */ return m_reflectance * fr; } else { - pdf = 1-fr; + pdf = importanceSampleComponents ? (1-fr) : 0.5f; bRec.sampledComponent = 1; bRec.sampledType = EDeltaTransmission; @@ -217,11 +219,15 @@ public: Float result = 0.0f; if (sampleTransmission && sampleReflection) { - Float fr = fresnel(Frame::cosTheta(bRec.wi), m_extIOR, m_intIOR); - if (reflection) - result = fr; - else - result = 1-fr; + if (!importanceSampleComponents) { + result = 0.f; + } else { + Float fr = fresnel(Frame::cosTheta(bRec.wi), m_extIOR, m_intIOR); + if (reflection) + result = fr; + else + result = 1-fr; + } } else if (sampleReflection) { result = reflection ? 1.0f : 0.0f; } else if (sampleTransmission) { diff --git a/src/collada/converter.cpp b/src/collada/converter.cpp index 28f2c6f6..f77f5215 100644 --- a/src/collada/converter.cpp +++ b/src/collada/converter.cpp @@ -369,7 +369,18 @@ void writeGeometry(std::string id, int geomIndex, std::string matID, Transform t void loadGeometry(std::string nodeName, Transform transform, std::ostream &os, domGeometry &geom, StringMap &matLookupTable) { - SLog(EInfo, "Converting geometry \"%s\" (instantiated by %s)..", geom.getName(), nodeName.c_str()); + std::string geomName; + if (geom.getName() != NULL) { + geomName = geom.getName(); + } else { + if (geom.getId() != NULL) { + geomName = geom.getId(); + } else { + static int unnamedGeomCtr = 0; + geomName = formatString("unnamedGeom_%i", unnamedGeomCtr); + } + } + SLog(EInfo, "Converting geometry \"%s\" (instantiated by %s)..", geomName.c_str(), nodeName.c_str()); domMesh *mesh = geom.getMesh().cast(); if (!mesh) @@ -718,7 +729,7 @@ void loadImage(ColladaConverter *cvt, std::ostream &os, domImage &image, StringM os << "\t" << endl << endl; } -void loadCamera(Transform transform, std::ostream &os, domCamera &camera) { +void loadCamera(ColladaConverter *cvt, Transform transform, std::ostream &os, domCamera &camera) { SLog(EInfo, "Converting camera \"%s\" ..", camera.getName()); Float aspect = 1.0f; int xres=768; @@ -737,6 +748,10 @@ void loadCamera(Transform transform, std::ostream &os, domCamera &camera) { if (ortho) { if (ortho->getAspect_ratio().cast() != 0) aspect = (Float) ortho->getAspect_ratio()->getValue(); + if (cvt->m_xres != -1) { + xres = cvt->m_xres; + aspect = (Float) cvt->m_xres / (Float) cvt->m_yres; + } os << "\t" << endl; } @@ -745,6 +760,10 @@ void loadCamera(Transform transform, std::ostream &os, domCamera &camera) { if (persp) { if (persp->getAspect_ratio().cast() != 0) aspect = (Float) persp->getAspect_ratio()->getValue(); + if (cvt->m_xres != -1) { + xres = cvt->m_xres; + aspect = (Float) cvt->m_xres / (Float) cvt->m_yres; + } os << "\t" << endl; if (persp->getXfov().cast()) { Float yFov = radToDeg(2 * std::atan(std::tan(degToRad((Float) persp->getXfov()->getValue())/2) / aspect)); @@ -754,6 +773,7 @@ void loadCamera(Transform transform, std::ostream &os, domCamera &camera) { os << "\t\t" << endl; os << "\t\tgetZnear()->getValue() << "\"/>" << endl; os << "\t\tgetZfar()->getValue() << "\"/>" << endl; + os << "\t\tm_mapSmallerSide ? "true" : "false") << "\"/>" << endl; } else if (persp->getYfov().cast()) { Float xFov = radToDeg(2 * std::atan(std::tan(degToRad((Float) persp->getYfov()->getValue())/2) * aspect)); if (aspect > 1.0f) @@ -762,6 +782,7 @@ void loadCamera(Transform transform, std::ostream &os, domCamera &camera) { os << "\t\t" << endl; os << "\t\tgetZnear()->getValue() << "\"/>" << endl; os << "\t\tgetZfar()->getValue() << "\"/>" << endl; + os << "\t\tm_mapSmallerSide ? "true" : "false") << "\"/>" << endl; } } @@ -780,8 +801,19 @@ void loadCamera(Transform transform, std::ostream &os, domCamera &camera) { os << "\t" << endl << endl; } -void loadNode(Transform transform, std::ostream &os, domNode &node) { - SLog(EInfo, "Converting node \"%s\" ..", node.getName()); +void loadNode(ColladaConverter *cvt, Transform transform, std::ostream &os, domNode &node) { + std::string nodeName; + if (node.getName() != NULL) { + nodeName = node.getName(); + } else { + if (node.getId() != NULL) { + nodeName = node.getId(); + } else { + static int unnamedNodeCtr = 0; + nodeName = formatString("unnamedNode_%i", unnamedNodeCtr); + } + } + SLog(EInfo, "Converting node \"%s\" ..", nodeName.c_str()); daeTArray > children = node.getChildren(); /* Parse transformations */ @@ -840,7 +872,7 @@ void loadNode(Transform transform, std::ostream &os, domNode &node) { if (!geom) SLog(EError, "Could not find a referenced geometry object!"); - loadGeometry(node.getName(), transform, os, *geom, matLookupTable); + loadGeometry(nodeName, transform, os, *geom, matLookupTable); } /* Iterate over all light references */ @@ -860,13 +892,13 @@ void loadNode(Transform transform, std::ostream &os, domNode &node) { domCamera *camera = daeSafeCast(inst->getUrl().getElement()); if (camera == NULL) SLog(EError, "Could not find a referenced camera!"); - loadCamera(transform, os, *camera); + loadCamera(cvt, transform, os, *camera); } /* Recursively iterate through sub-nodes */ domNode_Array &nodes = node.getNode_array(); for (size_t i=0; i elements */ domInstance_node_Array &instanceNodes = node.getInstance_node_array(); @@ -874,7 +906,7 @@ void loadNode(Transform transform, std::ostream &os, domNode &node) { domNode *node = daeSafeCast(instanceNodes[i]->getUrl().getElement()); if (!node) SLog(EError, "Could not find a referenced node!"); - loadNode(transform, os, *node); + loadNode(cvt, transform, os, *node); } } @@ -980,7 +1012,7 @@ void ColladaConverter::convert(const std::string &inputFile, os << "\tAutomatically converted from COLLADA" << endl << endl; os << "-->" << endl << endl; os << "" << endl; - os << "\t" << endl << endl; + os << "\t" << endl << endl; SLog(EInfo, "Converting to \"%s\" ..", outputFile.c_str()); @@ -1000,7 +1032,7 @@ void ColladaConverter::convert(const std::string &inputFile, } for (size_t i=0; i" << endl; diff --git a/src/collada/converter.h b/src/collada/converter.h index e06e01f9..e0d8135b 100644 --- a/src/collada/converter.h +++ b/src/collada/converter.h @@ -6,6 +6,8 @@ class ColladaConverter { public: inline ColladaConverter() { m_srgb = false; + m_mapSmallerSide = true; + m_xres = m_yres = -1; } void convert(const std::string &inputFile, @@ -16,6 +18,9 @@ public: virtual std::string locateResource(const std::string &resource) = 0; void setSRGB(bool srgb) { m_srgb = srgb; } + void setMapSmallerSide(bool mapSmallerSide) { m_mapSmallerSide = mapSmallerSide; } + void setResolution(int xres, int yres) { m_xres = xres; m_yres = yres; } public: - bool m_srgb; + bool m_srgb, m_mapSmallerSide; + int m_xres, m_yres; }; diff --git a/src/collada/main.cpp b/src/collada/main.cpp index 3a7ac370..52e92871 100644 --- a/src/collada/main.cpp +++ b/src/collada/main.cpp @@ -53,20 +53,38 @@ void help() { << "Options/Arguments:" << endl << " -h Display this help text" << endl << endl << " -s Assume that colors are in sRGB space." << endl << endl + << " -m Map the larger image side to the full field of view" << endl << endl + << " -r x Override the image resolution to e.g. 1920×1080" << endl << endl << "Please see the documentation for more information." << endl; } int colladaMain(int argc, char **argv) { - bool srgb = false; - char optchar; - + bool srgb = false, mapSmallerSide = true; + char optchar, *end_ptr = NULL; + int xres = -1, yres = -1; + optind = 1; - while ((optchar = getopt(argc, argv, "sh")) != -1) { + while ((optchar = getopt(argc, argv, "shmr:")) != -1) { switch (optchar) { case 's': srgb = true; break; + case 'm': + mapSmallerSide = false; + break; + case 'r': { + std::vector tokens = tokenize(optarg, "x"); + if (tokens.size() != 2) + SLog(EError, "Invalid resolution argument supplied!"); + xres = strtol(tokens[0].c_str(), &end_ptr, 10); + if (*end_ptr != '\0') + SLog(EError, "Invalid resolution argument supplied!"); + yres = strtol(tokens[1].c_str(), &end_ptr, 10); + if (*end_ptr != '\0') + SLog(EError, "Invalid resolution argument supplied!"); + } + break; case 'h': default: help(); @@ -81,6 +99,8 @@ int colladaMain(int argc, char **argv) { ConsoleColladaConverter converter; converter.setSRGB(srgb); + converter.setResolution(xres, yres); + converter.setMapSmallerSide(mapSmallerSide); converter.convert(argv[optind], "", argv[optind+1], argc > optind+2 ? argv[optind+2] : ""); return 0; @@ -129,6 +149,10 @@ int ubi_main(int argc, char **argv) { MTS_AUTORELEASE_END() #endif +#if !defined(WIN32) + setlocale(LC_ALL, "C"); +#endif + try { /* An OpenGL context may be required for the GLU tesselator */ ref session = Session::create(); @@ -149,9 +173,6 @@ int ubi_main(int argc, char **argv) { renderer->shutdown(); device->shutdown(); session->shutdown(); - } catch (const std::exception &e) { - std::cerr << "Caught a critical exeption: " << e.what() << std::endl; - retval = -1; } catch(const XMLException &toCatch) { SLog(EError, "Caught a Xerces exception: %s", XMLString::transcode(toCatch.getMessage())); @@ -160,9 +181,6 @@ int ubi_main(int argc, char **argv) { SLog(EError, "Caught a Xerces exception: %s", XMLString::transcode(toCatch.getMessage())); retval = -1; - } catch (...) { - std::cerr << "Caught a critical exeption of unknown type!" << endl; - retval = -1; } XMLPlatformUtils::Terminate(); diff --git a/src/mitsuba/mitsuba.cpp b/src/mitsuba/mitsuba.cpp index c1d09bc0..8028dcfc 100644 --- a/src/mitsuba/mitsuba.cpp +++ b/src/mitsuba/mitsuba.cpp @@ -364,6 +364,10 @@ int main(int argc, char **argv) { resolver->addPath(__ubi_bundlepath()); MTS_AUTORELEASE_END() #endif + +#if !defined(WIN32) + setlocale(LC_NUMERIC, "C"); +#endif /* Initialize Xerces-C */ try { diff --git a/src/mitsuba/mtssrv.cpp b/src/mitsuba/mtssrv.cpp index 2bc979cd..cd1fe47a 100644 --- a/src/mitsuba/mtssrv.cpp +++ b/src/mitsuba/mtssrv.cpp @@ -362,6 +362,10 @@ int main(int argc, char **argv) { SLog(EError, "Could not find the required version of winsock.dll!"); #endif +#if !defined(WIN32) + setlocale(LC_NUMERIC, "C"); +#endif + #ifdef __LINUX__ FileResolver *resolver = FileResolver::getInstance(); resolver->addPath("/usr/share/mitsuba"); diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index f0814ce4..aa5cecdd 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -128,6 +128,10 @@ int main(int argc, char *argv[]) { } #endif +#if !defined(WIN32) + setlocale(LC_NUMERIC, "C"); +#endif + #if !defined(WIN32) /* Avoid zombies processes when running the server */ struct sigaction sa;