From a424a29602d3d9c7b38959103fe11c8911a85f3d Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Tue, 10 Dec 2013 17:02:07 +0100 Subject: [PATCH] added a new Texture::isMonochromatic function --- include/mitsuba/hw/basicshader.h | 20 ++++++++++++++++++++ include/mitsuba/render/texture.h | 9 ++++++++- src/libpython/render.cpp | 1 + src/librender/texture.cpp | 1 + src/textures/bitmap.cpp | 4 ++++ src/textures/checkerboard.cpp | 5 +++++ src/textures/curvature.cpp | 4 ++++ src/textures/gridtexture.cpp | 5 +++++ src/textures/scale.cpp | 4 ++++ src/textures/vertexcolors.cpp | 4 ++++ src/textures/wireframe.cpp | 5 +++++ 11 files changed, 61 insertions(+), 1 deletion(-) diff --git a/include/mitsuba/hw/basicshader.h b/include/mitsuba/hw/basicshader.h index 7743f722..5f0c24fc 100644 --- a/include/mitsuba/hw/basicshader.h +++ b/include/mitsuba/hw/basicshader.h @@ -73,6 +73,10 @@ public: return false; } + inline bool isMonochromatic() const { + return m_value == Spectrum(m_value[0]); + } + Shader *createShader(Renderer *renderer) const; ref getBitmap(const Vector2i &resolutionHint) const; @@ -128,6 +132,10 @@ public: return false; } + inline bool isMonochromatic() const { + return true; + } + Shader *createShader(Renderer *renderer) const; ref getBitmap(const Vector2i &resolutionHint) const; @@ -187,6 +195,10 @@ public: return m_a->usesRayDifferentials() || m_b->usesRayDifferentials(); } + inline bool isMonochromatic() const { + return m_a->isMonochromatic() && m_b->isMonochromatic(); + } + Shader *createShader(Renderer *renderer) const; ref getBitmap(const Vector2i &resolutionHint) const; @@ -246,6 +258,10 @@ public: return m_a->usesRayDifferentials() || m_b->usesRayDifferentials(); } + inline bool isMonochromatic() const { + return m_a->isMonochromatic() && m_b->isMonochromatic(); + } + Shader *createShader(Renderer *renderer) const; ref getBitmap(const Vector2i &resolutionHint) const; @@ -306,6 +322,10 @@ public: return m_a->usesRayDifferentials() || m_b->usesRayDifferentials(); } + inline bool isMonochromatic() const { + return m_a->isMonochromatic() && m_b->isMonochromatic(); + } + Shader *createShader(Renderer *renderer) const; void serialize(Stream *stream, InstanceManager *manager) const; diff --git a/include/mitsuba/render/texture.h b/include/mitsuba/render/texture.h index 4b981330..0484dfc5 100644 --- a/include/mitsuba/render/texture.h +++ b/include/mitsuba/render/texture.h @@ -63,9 +63,16 @@ public: /// Return the resolution in pixels, if applicable virtual Vector3i getResolution() const; - /// Return whether the texture takes on a single constant value + /// Return whether the texture takes on a constant value everywhere virtual bool isConstant() const; + /** + * \brief Return whether the texture is monochromatic / spectrally uniform + * + * The implementation may conservatively return \c false if it is not sure. + */ + virtual bool isMonochromatic() const; + /** * \brief Does this texture perform any pre-filtering when * ray differentials are available? diff --git a/src/libpython/render.cpp b/src/libpython/render.cpp index b768e6e8..1fdb80f1 100644 --- a/src/libpython/render.cpp +++ b/src/libpython/render.cpp @@ -482,6 +482,7 @@ void export_render() { .def("getSensor", shape_getSensor, BP_RETURN_VALUE) .def("hasBSDF", &Shape::hasBSDF) .def("getBSDF", shape_getBSDF, BP_RETURN_VALUE) + .def("setBSDF", &Shape::setBSDF) .def("getPrimitiveCount", &Shape::getPrimitiveCount) .def("getEffectivePrimitiveCount", &Shape::getEffectivePrimitiveCount) .def("copyAttachments", &Shape::copyAttachments); diff --git a/src/librender/texture.cpp b/src/librender/texture.cpp index 15f804a7..d6de7d08 100644 --- a/src/librender/texture.cpp +++ b/src/librender/texture.cpp @@ -46,6 +46,7 @@ Spectrum Texture::getAverage() const { NotImplementedError("getAverage"); } Spectrum Texture::getMinimum() const { NotImplementedError("getMinimum"); } Spectrum Texture::getMaximum() const { NotImplementedError("getMaximum"); } bool Texture::isConstant() const { NotImplementedError("isConstant"); } +bool Texture::isMonochromatic() const { NotImplementedError("isMonochromatic"); } bool Texture::usesRayDifferentials() const { NotImplementedError("usesRayDifferentials"); } ref Texture::getBitmap(const Vector2i &) const { NotImplementedError("getBitmap"); } diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index d9d87a9e..73c2f74b 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -542,6 +542,10 @@ public: return true; } + bool isMonochromatic() const { + return m_mipmap1.get() != NULL; + } + Vector3i getResolution() const { if (m_mipmap3.get()) { return Vector3i( diff --git a/src/textures/checkerboard.cpp b/src/textures/checkerboard.cpp index ba47871d..dfe93516 100644 --- a/src/textures/checkerboard.cpp +++ b/src/textures/checkerboard.cpp @@ -105,6 +105,11 @@ public: return false; } + bool isMonochromatic() const { + return Spectrum(m_color0[0]) == m_color0 + && Spectrum(m_color1[0]) == m_color1; + } + std::string toString() const { std::ostringstream oss; oss << "Checkerboard[" << endl diff --git a/src/textures/curvature.cpp b/src/textures/curvature.cpp index 4f5180e3..ef4055b1 100644 --- a/src/textures/curvature.cpp +++ b/src/textures/curvature.cpp @@ -105,6 +105,10 @@ public: return Spectrum(1.0f); } + bool isMonochromatic() const { + return false; + } + bool isConstant() const { return false; } diff --git a/src/textures/gridtexture.cpp b/src/textures/gridtexture.cpp index b3a4b379..557d0b91 100644 --- a/src/textures/gridtexture.cpp +++ b/src/textures/gridtexture.cpp @@ -122,6 +122,11 @@ public: return false; } + bool isMonochromatic() const { + return Spectrum(m_color0[0]) == m_color0 + && Spectrum(m_color1[0]) == m_color1; + } + std::string toString() const { return "GridTexture[]"; } diff --git a/src/textures/scale.cpp b/src/textures/scale.cpp index 5a484700..6f4be15a 100644 --- a/src/textures/scale.cpp +++ b/src/textures/scale.cpp @@ -138,6 +138,10 @@ public: return m_nested->usesRayDifferentials(); } + bool isMonochromatic() const { + return m_nested->isMonochromatic(); + } + Shader *createShader(Renderer *renderer) const; void serialize(Stream *stream, InstanceManager *manager) const { diff --git a/src/textures/vertexcolors.cpp b/src/textures/vertexcolors.cpp index bef5b3a8..2343790d 100644 --- a/src/textures/vertexcolors.cpp +++ b/src/textures/vertexcolors.cpp @@ -80,6 +80,10 @@ public: return false; } + bool isMonochromatic() const { + return false; /* No way to tell from here, really .. */ + } + std::string toString() const { return "VertexColors[]"; } diff --git a/src/textures/wireframe.cpp b/src/textures/wireframe.cpp index e0b216b5..944b26ad 100644 --- a/src/textures/wireframe.cpp +++ b/src/textures/wireframe.cpp @@ -152,6 +152,11 @@ public: return false; } + bool isMonochromatic() const { + return Spectrum(m_edgeColor[0]) == m_edgeColor + && Spectrum(m_interiorColor[0]) == m_interiorColor; + } + std::string toString() const { std::ostringstream oss; oss << "WireFrame[" << endl