src/rcrt/bxdf/BSDF.cpp

Go to the documentation of this file.
00001 #include "BSDF.h"
00002 
00003 using namespace std;
00004 
00005 namespace rcrt
00006 {
00007 
00008 BSDF::BSDF()
00009 {
00010 }
00011 
00012 BSDF::~BSDF()
00013 {
00014 }
00015 
00016 void BSDF::addBXDF(BXDF* bxdf)
00017 {
00018         bxdfs.push_back(bxdf);
00019 }
00020 
00021 RGBColor BSDF::eval(const Vec3D& wOut, const Vec3D& wInc, const Vec3D& gNormal, const Vec3D& sNormal) const
00022 {
00023         bool ignoreBTDFs = false;
00024         if ((wInc * gNormal) * (wOut * sNormal) < 0){
00025                 // ignore BTDFs
00026                 ignoreBTDFs = true;
00027         }
00028         RGBColor col(0);
00029         for (unsigned int i = 0; i < bxdfs.size(); i++){
00030                 if(ignoreBTDFs){
00031                         switch(bxdfs[i]->type){
00032                         case REFLECTIVE:
00033                                 col = col + bxdfs[i]->eval(wOut, wInc, sNormal); break;
00034                         case TRANSMISSIVE:
00035                                 break;
00036                         default://BOTH
00037                                 col = col + bxdfs[i]->eval(wOut, wInc, sNormal);
00038                         }
00039                 } else {
00040                         switch(bxdfs[i]->type){
00041                         case REFLECTIVE:
00042                                 break;
00043                         case TRANSMISSIVE:
00044                                 col = col + bxdfs[i]->eval(wOut, wInc, sNormal); break;
00045                         default://BOTH
00046                                 col = col + bxdfs[i]->eval(wOut, wInc, sNormal);
00047                         }                       
00048                 }
00049         }
00050         return col;
00051 }
00052 
00053 bool BSDF::hasDiffuse() const
00054 {
00055         for(unsigned int i = 0; i < bxdfs.size(); i++)
00056                 if(bxdfs[i]->diffuse())
00057                         return true;
00058         return false;
00059 }
00060 
00061 bool BSDF::hasSpecular() const
00062 {
00063         for(unsigned int i = 0; i < bxdfs.size(); i++)
00064                 if(bxdfs[i]->specular())
00065                         return true;
00066         return false;
00067 }
00068 
00069 bool BSDF::hasTransmissive() const
00070 {
00071         for(unsigned int i = 0; i < bxdfs.size(); i++)
00072                 if(bxdfs[i]->type == TRANSMISSIVE
00073                                 || bxdfs[i]->type == BOTH)
00074                         return true;
00075         return false;
00076 }
00077 
00078 RGBColor BSDF::evalSpecular(const Vec3D& wOut, const Vec3D& wInc, const Vec3D& gNormal, const Vec3D& sNormal) const
00079 {
00080         RGBColor col(0);
00081         for (unsigned int i = 0; i < bxdfs.size(); i++){
00082                 if ((bxdfs[i]->type == REFLECTIVE || bxdfs[i]->type == BOTH)
00083                                 && bxdfs[i]->specular())
00084                         col = col + bxdfs[i]->evalSpecular(wOut, wInc, sNormal);
00085         }
00086         return col;
00087 }
00088 
00089 RGBColor BSDF::evalDiffuse(const Vec3D& wOut, const Vec3D& wInc, const Vec3D& gNormal, const Vec3D& sNormal) const
00090 {
00091         RGBColor col(0);
00092         for (unsigned int i = 0; i < bxdfs.size(); i++)
00093                 if ((bxdfs[i]->type == REFLECTIVE || bxdfs[i]->type == BOTH)
00094                                 && bxdfs[i]->diffuse())
00095                         col = col + bxdfs[i]->evalDiffuse(wOut, wInc, sNormal);
00096         return col;
00097 }
00098 
00099 
00100 RGBColor BSDF::getKdiffuse() const
00101 {
00102         RGBColor diff(0);
00103         int n = 0;
00104         for (unsigned int i = 0; i < bxdfs.size(); i++){
00105                 if((bxdfs[i]->type == REFLECTIVE || bxdfs[i]->type == BOTH)
00106                                 && bxdfs[i]->diffuse()){
00107                         diff = diff + bxdfs[i]->getKd();
00108                         n++;
00109                 }
00110         }
00111         if(n == 0) return 0;
00112         return diff / n;
00113 }
00114 
00115 RGBColor BSDF::getKspecular() const
00116 {
00117         RGBColor spec(0);
00118         int n = 0;
00119         for (unsigned int i = 0; i < bxdfs.size(); i++){
00120                 if((bxdfs[i]->type == REFLECTIVE || bxdfs[i]->type == BOTH)
00121                                 && bxdfs[i]->specular()){
00122                         spec = spec + bxdfs[i]->getKs();
00123                         n++;
00124                 }               
00125         }
00126         if(n == 0) return 0;
00127         return spec / n;
00128 }
00129 
00130 RGBColor BSDF::getKtransmit() const
00131 {
00132         RGBColor trans(0);
00133         int n = 0;
00134         for (unsigned int i = 0; i < bxdfs.size(); i++){
00135                 if((bxdfs[i]->type == TRANSMISSIVE || bxdfs[i]->type == BOTH)){
00136                         trans = trans + bxdfs[i]->getKt();
00137                         n++;
00138                 }               
00139         }
00140         if(n == 0) return 0;
00141         return trans / n;       
00142 }
00143 
00144 }

Generated on Thu Jan 31 19:26:19 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3