src/rcrt/BIH.hpp

Go to the documentation of this file.
00001 #ifndef BIH_HPP_
00002 #define BIH_HPP_
00003 
00004 #include "Traceable.h"
00005 #include <vector>
00006 #include "primitives/AABB.h"
00007 #include "BIHNode.hpp"
00008 
00009 namespace rcrt
00010 {
00011 
00023 template<class T>
00024 class BIH : public Traceable
00025 {
00026 private:
00027         AABB boundingBox;
00028         BIHNode<T>* rootNode;
00029         
00030 public:
00034         BIH<T>()
00035         {
00036                 rootNode = 0;
00037         }
00038         
00045         BIH<T>(std::vector<T*>* trList)
00046         {
00047                 rootNode = 0;
00048                 setTraceables(trList);          
00049         }
00050         
00057         void setTraceables(std::vector<T*>* trList)
00058         {
00059                 if(rootNode)
00060                         delete rootNode;
00061                 if(trList->empty())
00062                         return;
00063                 std::cout << "[BIH]: building BIH size = "<< trList->size() << std::endl;
00064                 
00065                 boundingBox = calcBoundingBox(trList);
00066                 
00067                 rootNode = new BIHNode<T>(boundingBox, trList, 0, trList->size()-1);
00068                 std::cout << "       built BIH" << std::endl;
00069         }
00070         
00071         virtual ~BIH()
00072         {
00073                 if(rootNode)
00074                         delete rootNode;
00075         }
00076         
00081         virtual Intersection intersect(Ray& r) const
00082         {
00083                 if(rootNode)
00084                         return rootNode->intersect(r, r.minDist(), r.maxDist());
00085                 else
00086                         return Intersection();
00087         }
00088                 
00092         virtual const AABB& getBoundingBox() const
00093         {
00094                 return boundingBox;
00095         }
00096         
00100         virtual const Point3D& getCentroid() const
00101         {
00102                 return boundingBox.getCentroid();
00103         }
00104         
00108         std::vector<T*>* getTraceables() const
00109         {
00110                 if(rootNode)
00111                         return rootNode->getTraceables();
00112                 else
00113                         return 0;
00114         }
00115         
00120         static AABB calcBoundingBox(std::vector<T*>* trList)
00121         {
00122                 AABB box;
00123                 for(unsigned int i = 0; i < trList->size(); i++){
00124                         box.extend(trList->at(i)->getBoundingBox());
00125                 }
00126                 return box;
00127         }
00128         
00129         AABB clipBox(AABB& cbox) const {
00130                 return getBoundingBox();
00131         }
00132         
00133 };
00134 
00135 
00136 }
00137 
00138 
00139 #endif /*BIH_HPP_*/

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