SurfacePoint.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   SurfacePoint.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   Fall 2008
00005    
00006    @brief
00007       Core class representing a single point on the surface of a Shape, 
00008    which was likely generated by either an intersection with a Ray or random 
00009    sampling on the surface of the shape.  SurfacePoint encapsulates all of the 
00010    different information about a surface point and is used for shading 
00011    evaluation (BSDF), emittance evaluation (Emitter), and so-called importance 
00012    evaluation (Sensor).
00013    
00014       Milton supports the useful distinction between geometric and shading 
00015    normals defined at a point, where the geometric normal 
00016    (SurfacePoint::normalG) is the actual normal of the underlying surface at a 
00017    point, and the shading normal (SurfacePoint::normalS) is a (possibly) 
00018    perturbed version of the geometric normal.  Shading normals attempt to 
00019    simulate more complex underlying geometry by varying the apparent normal 
00020    across the surface of a simpler surface such as a plane. It is important to 
00021    note that shading normals have no physical basic whatsoever -- they are 
00022    merely a useful (and very common) method for faking higher resolution (ie. 
00023    more expensive) geometry. See the bump mapping implementation in Material 
00024    for an example use of shading normals.
00025    
00026    @note
00027       When finding the closest intersection point between a Ray and a set of 
00028    objects in the scene, SurfacePoint is used to hold the 'current' closest 
00029    object and any metadata that shape may need to <b>lazily</b> fill in the 
00030    rest of the SurfacePoint structure later on (see Shape::initSurfacePoint).
00031    <!-------------------------------------------------------------------->**/
00032 
00033 #include "SurfacePoint.h"
00034 #include <Material.h>
00035 #include <Ray.h>
00036 
00037 SurfacePoint::~SurfacePoint() {
00038    safeDelete(bsdf);
00039    
00040    if (emitter != Material::s_nullEmitter)
00041       safeDelete(emitter);
00042    
00043    if (sensor != Material::s_nullSensor)
00044       safeDelete(sensor);
00045 }
00046 
00047 bool SurfacePoint::init(const Ray &ray, real_t t) {
00048    ASSERT(ray.direction.isUnit());
00049    
00050    if (!Ray::isValid(t))
00051       return false;
00052    
00053    // initialize position
00054    position = ray.origin + t * ray.direction;
00055    
00056    // default to normal aligning with incident vector
00057    normalG  = -ray.direction;
00058    
00059    init();
00060    bsdf->setWi(ray.direction);
00061    
00062    return true;
00063 }
00064 
00065 void SurfacePoint::init() {
00066    ASSERT(shape);
00067    
00068    // fill in normalG, uv, and material properties (bsdf, emitter, normalS)
00069    shape->initSurfacePoint(*this);
00070    
00071    ASSERT(bsdf);
00072    ASSERT(emitter);
00073    ASSERT(sensor);
00074    ASSERT(normalG.isUnit());
00075    ASSERT(normalS.isUnit());
00076 }
00077 
00078 std::ostream &operator<<(std::ostream &os, const SurfacePoint &pt) {
00079    os << "{ " << endl
00080       << "  shape   = " << pt.shape       << endl
00081       << "  pos     = " << pt.position    << endl
00082       << "  normalG = " << pt.normalG     << endl
00083       << "  normalS = " << pt.normalS     << endl
00084       << "  normalC = " << pt.normalCase  << endl
00085       << "  index   = " << pt.index       << endl
00086     //<< "  ior     = " << pt.ior         << endl
00087       << "  (u,v)   = " << "(" << pt.uv.u << ", " << pt.uv.v << ")" << endl
00088       << "}";
00089    
00090    return os;
00091 }
00092 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6