00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "checkerboard.h"
00025
00026
00027 namespace lux
00028 {
00029 MethodType aaMethod;
00030 }
00031
00032 using namespace lux;
00033
00034
00035 Texture<float> * Checkerboard::CreateFloatTexture(const Transform &tex2world,
00036 const TextureParams &tp) {
00037 int dim = tp.FindInt("dimension", 2);
00038 if (dim != 2 && dim != 3) {
00039
00040 std::stringstream ss;
00041 ss<<dim<<" dimensional checkerboard texture not supported";
00042 luxError(LUX_UNIMPLEMENT,LUX_ERROR,ss.str().c_str());
00043 return NULL;
00044 }
00045 boost::shared_ptr<Texture<float> > tex1 = tp.GetFloatTexture("tex1", 1.f);
00046 boost::shared_ptr<Texture<float> > tex2 = tp.GetFloatTexture("tex2", 0.f);
00047 if (dim == 2) {
00048
00049 TextureMapping2D *map = NULL;
00050 string type = tp.FindString("mapping");
00051 if (type == "" || type == "uv") {
00052 float su = tp.FindFloat("uscale", 1.);
00053 float sv = tp.FindFloat("vscale", 1.);
00054 float du = tp.FindFloat("udelta", 0.);
00055 float dv = tp.FindFloat("vdelta", 0.);
00056 map = new UVMapping2D(su, sv, du, dv);
00057 }
00058 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00059 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00060 else if (type == "planar")
00061 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00062 tp.FindVector("v2", Vector(0,1,0)),
00063 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00064 else {
00065
00066 std::stringstream ss;
00067 ss<<"2D texture mapping '"<<type<<"' unknown";
00068 luxError(LUX_BADTOKEN,LUX_ERROR,ss.str().c_str());
00069 map = new UVMapping2D;
00070 }
00071 string aamode = tp.FindString("aamode");
00072 if (aamode == "") aamode = "closedform";
00073 return new Checkerboard2D<float>(map, tex1, tex2, aamode);
00074 }
00075 else {
00076
00077 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00078
00079 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00080 imap->Apply3DTextureMappingOptions(tp);
00081 return new Checkerboard3D<float>(map, tex1, tex2);
00082 }
00083 }
00084
00085 Texture<Spectrum> * Checkerboard::CreateSpectrumTexture(const Transform &tex2world,
00086 const TextureParams &tp) {
00087 int dim = tp.FindInt("dimension", 2);
00088 if (dim != 2 && dim != 3) {
00089
00090 std::stringstream ss;
00091 ss<<dim<<" dimensional checkerboard texture not supported";
00092 luxError(LUX_UNIMPLEMENT,LUX_ERROR,ss.str().c_str());
00093 return NULL;
00094 }
00095 boost::shared_ptr<Texture<Spectrum> > tex1 = tp.GetSpectrumTexture("tex1", 1.f);
00096 boost::shared_ptr<Texture<Spectrum> > tex2 = tp.GetSpectrumTexture("tex2", 0.f);
00097 if (dim == 2) {
00098
00099 TextureMapping2D *map = NULL;
00100 string type = tp.FindString("mapping");
00101 if (type == "" || type == "uv") {
00102 float su = tp.FindFloat("uscale", 1.);
00103 float sv = tp.FindFloat("vscale", 1.);
00104 float du = tp.FindFloat("udelta", 0.);
00105 float dv = tp.FindFloat("vdelta", 0.);
00106 map = new UVMapping2D(su, sv, du, dv);
00107 }
00108 else if (type == "spherical") map = new SphericalMapping2D(tex2world.GetInverse());
00109 else if (type == "cylindrical") map = new CylindricalMapping2D(tex2world.GetInverse());
00110 else if (type == "planar")
00111 map = new PlanarMapping2D(tp.FindVector("v1", Vector(1,0,0)),
00112 tp.FindVector("v2", Vector(0,1,0)),
00113 tp.FindFloat("udelta", 0.f), tp.FindFloat("vdelta", 0.f));
00114 else {
00115
00116 std::stringstream ss;
00117 ss<<"2D texture mapping '"<<type<<"' unknown";
00118 luxError(LUX_BADTOKEN,LUX_ERROR,ss.str().c_str());
00119 map = new UVMapping2D;
00120 }
00121 string aamode = tp.FindString("aamode");
00122 if (aamode == "") aamode = "closedform";
00123 return new Checkerboard2D<Spectrum>(map, tex1, tex2, aamode);
00124 }
00125 else {
00126
00127 TextureMapping3D *map = new IdentityMapping3D(tex2world);
00128
00129 IdentityMapping3D *imap = (IdentityMapping3D*) map;
00130 imap->Apply3DTextureMappingOptions(tp);
00131 return new Checkerboard3D<Spectrum>(map, tex1, tex2);
00132 }
00133 }