NaiveSpatialAccel.cpp
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file NaiveSpatialAccel.cpp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Fall 2008 00005 00006 @brief 00007 Naive/identity spatial acceleration (no acceleration) which runs through 00008 all primitives linearly when testing for intersections 00009 <!-------------------------------------------------------------------->**/ 00010 00011 #include "NaiveSpatialAccel.h" 00012 #include <SurfacePoint.h> 00013 00014 real_t NaiveSpatialAccel::getIntersection(const Ray &ray, SurfacePoint &pt) { 00015 { 00016 real_t tMin, tMax; 00017 00018 // check for intersection between ray and root node's bounding box 00019 if (!m_aabb.intersects(ray, tMin, tMax)) 00020 return false; 00021 00022 ASSERT(tMin <= tMax); 00023 } 00024 00025 real_t tMin = INFINITY; 00026 unsigned normalCase = pt.normalCase; 00027 unsigned index = pt.index; 00028 Shape *shape = pt.shape; 00029 00030 for(unsigned i = m_primitives->size(); i--;) { 00031 pt.shape = NULL; 00032 pt.index = (unsigned)(-1); 00033 00034 Intersectable *curIntersectable = (*m_primitives)[i]; 00035 const real_t t = curIntersectable->getIntersection(ray, pt); 00036 00037 // TODO: why not just (t < tMin) -- fails on some cases.. figure out why 00038 if (t > EPSILON && t < tMin) { 00039 //std::cerr << tMin << std::endl; 00040 tMin = t; 00041 00042 shape = (pt.shape ? : static_cast<Shape*>(curIntersectable)); 00043 index = (pt.index == ((unsigned)(-1)) ? i : pt.index); 00044 normalCase = pt.normalCase; 00045 } 00046 } 00047 00048 pt.shape = shape; 00049 pt.normalCase = normalCase; 00050 pt.index = index; 00051 00052 return tMin; 00053 } 00054 00055 bool NaiveSpatialAccel::intersects(const Ray &ray, real_t clipMax) { 00056 { 00057 real_t tMin, tMax; 00058 00059 // check for intersection between ray and root node's bounding box 00060 if (!m_aabb.intersects(ray, tMin, tMax)) 00061 return false; 00062 00063 ASSERT(tMin <= tMax); 00064 } 00065 00066 for(unsigned i = m_primitives->size(); i--;) { 00067 Intersectable *curIntersectable = (*m_primitives)[i]; 00068 00069 if (curIntersectable->intersects(ray, clipMax)) 00070 return true; 00071 } 00072 00073 return false; 00074 } 00075
Generated on 28 Feb 2009 for Milton by
1.5.6