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