PBRT
|
00001 00002 /* 00003 pbrt source code Copyright(c) 1998-2012 Matt Pharr and Greg Humphreys. 00004 00005 This file is part of pbrt. 00006 00007 Redistribution and use in source and binary forms, with or without 00008 modification, are permitted provided that the following conditions are 00009 met: 00010 00011 - Redistributions of source code must retain the above copyright 00012 notice, this list of conditions and the following disclaimer. 00013 00014 - Redistributions in binary form must reproduce the above copyright 00015 notice, this list of conditions and the following disclaimer in the 00016 documentation and/or other materials provided with the distribution. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00019 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00020 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00021 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00022 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00030 */ 00031 00032 #if defined(_MSC_VER) 00033 #pragma once 00034 #endif 00035 00036 #ifndef PBRT_TEXTURES_IMAGEMAP_H 00037 #define PBRT_TEXTURES_IMAGEMAP_H 00038 00039 // textures/imagemap.h* 00040 #include "pbrt.h" 00041 #include "texture.h" 00042 #include "mipmap.h" 00043 #include "paramset.h" 00044 #include <map> 00045 00046 // TexInfo Declarations 00047 struct TexInfo { 00048 TexInfo(const string &f, bool dt, float ma, ImageWrap wm, float sc, float ga) 00049 : filename(f), doTrilinear(dt), maxAniso(ma), wrapMode(wm), scale(sc), gamma(ga) { } 00050 string filename; 00051 bool doTrilinear; 00052 float maxAniso; 00053 ImageWrap wrapMode; 00054 float scale, gamma; 00055 bool operator<(const TexInfo &t2) const { 00056 if (filename != t2.filename) return filename < t2.filename; 00057 if (doTrilinear != t2.doTrilinear) return doTrilinear < t2.doTrilinear; 00058 if (maxAniso != t2.maxAniso) return maxAniso < t2.maxAniso; 00059 if (scale != t2.scale) return scale < t2.scale; 00060 if (gamma != t2.gamma) return gamma < t2.gamma; 00061 return wrapMode < t2.wrapMode; 00062 } 00063 }; 00064 00065 00066 00067 // ImageTexture Declarations 00068 template <typename Tmemory, typename Treturn> 00069 class ImageTexture : public Texture<Treturn> { 00070 public: 00071 // ImageTexture Public Methods 00072 ImageTexture(TextureMapping2D *m, const string &filename, bool doTri, 00073 float maxAniso, ImageWrap wm, float scale, float gamma); 00074 Treturn Evaluate(const DifferentialGeometry &) const; 00075 ~ImageTexture(); 00076 static void ClearCache() { 00077 typename std::map<TexInfo, MIPMap<Tmemory> *>::iterator iter; 00078 iter = textures.begin(); 00079 while (iter != textures.end()) { 00080 delete iter->second; 00081 ++iter; 00082 } 00083 textures.erase(textures.begin(), textures.end()); 00084 } 00085 private: 00086 // ImageTexture Private Methods 00087 static MIPMap<Tmemory> *GetTexture(const string &filename, 00088 bool doTrilinear, float maxAniso, ImageWrap wm, float scale, float gamma); 00089 static void convertIn(const RGBSpectrum &from, RGBSpectrum *to, 00090 float scale, float gamma) { 00091 *to = Pow(scale * from, gamma); 00092 } 00093 static void convertIn(const RGBSpectrum &from, float *to, 00094 float scale, float gamma) { 00095 *to = powf(scale * from.y(), gamma); 00096 } 00097 static void convertOut(const RGBSpectrum &from, Spectrum *to) { 00098 float rgb[3]; 00099 from.ToRGB(rgb); 00100 *to = Spectrum::FromRGB(rgb); 00101 } 00102 static void convertOut(float from, float *to) { 00103 *to = from; 00104 } 00105 00106 // ImageTexture Private Data 00107 MIPMap<Tmemory> *mipmap; 00108 TextureMapping2D *mapping; 00109 static std::map<TexInfo, MIPMap<Tmemory> *> textures; 00110 }; 00111 00112 00113 ImageTexture<float, float> *CreateImageFloatTexture(const Transform &tex2world, 00114 const TextureParams &tp); 00115 ImageTexture<RGBSpectrum, Spectrum> *CreateImageSpectrumTexture(const Transform &tex2world, 00116 const TextureParams &tp); 00117 00118 #endif // PBRT_TEXTURES_IMAGEMAP_H