00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "lux.h"
00026 #include "primitive.h"
00027
00028 namespace lux
00029 {
00030
00031 struct BVHAccelTreeNode {
00032 BBox bbox;
00033 Primitive* primitive;
00034 boost::shared_ptr<BVHAccelTreeNode> leftChild;
00035 boost::shared_ptr<BVHAccelTreeNode> rightSibling;
00036 };
00037
00038 struct BVHAccelArrayNode {
00039 BBox bbox;
00040 Primitive* primitive;
00041 u_int skipIndex;
00042 };
00043
00044
00045 class BVHAccel : public Aggregate {
00046 public:
00047
00048 BVHAccel(const vector<boost::shared_ptr<Primitive> > &p, int treetype, int csamples, int icost, int tcost, float ebonus);
00049 virtual ~BVHAccel();
00050 virtual BBox WorldBound() const;
00051 virtual bool CanIntersect() const { return true; }
00052 virtual bool Intersect(const Ray &ray, Intersection *isect) const;
00053 virtual bool IntersectP(const Ray &ray) const;
00054
00055 virtual void GetPrimitives(vector<boost::shared_ptr<Primitive> > &prims);
00056
00057 static Aggregate *CreateAccelerator(const vector<boost::shared_ptr<Primitive> > &prims, const ParamSet &ps);
00058
00059 private:
00060
00061 boost::shared_ptr<BVHAccelTreeNode> BuildHierarchy(vector<boost::shared_ptr<BVHAccelTreeNode> > &list, u_int begin, u_int end, u_int axis);
00062 void FindBestSplit(vector<boost::shared_ptr<BVHAccelTreeNode> > &list, u_int begin, u_int end, float *splitValue, u_int *bestAxis);
00063 u_int BuildArray(boost::shared_ptr<BVHAccelTreeNode> node, u_int offset);
00064
00065
00066 u_char treeType;
00067 int costSamples, isectCost, traversalCost;
00068 float emptyBonus;
00069 u_int nPrims;
00070 boost::shared_ptr<Primitive> *prims;
00071 u_int nNodes;
00072 BVHAccelArrayNode *bvhTree;
00073 };
00074
00075 }
00076