00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if defined(_MSC_VER)
00025 #pragma once
00026 #endif
00027
00028 #ifndef PBRT_ACCELERATORS_BVH_H
00029 #define PBRT_ACCELERATORS_BVH_H
00030
00031
00032 #include "pbrt.h"
00033 #include "primitive.h"
00034 struct BVHBuildNode;
00035
00036
00037 struct BVHPrimitiveInfo;
00038 struct LinearBVHNode;
00039
00040
00041 class BVHAccel : public Aggregate {
00042 public:
00043
00044 BVHAccel(const vector<Reference<Primitive> > &p, uint32_t maxPrims = 1,
00045 const string &sm = "sah");
00046 BBox WorldBound() const;
00047 bool CanIntersect() const { return true; }
00048 ~BVHAccel();
00049 bool Intersect(const Ray &ray, Intersection *isect) const;
00050 bool IntersectP(const Ray &ray) const;
00051 private:
00052
00053 BVHBuildNode *recursiveBuild(MemoryArena &buildArena,
00054 vector<BVHPrimitiveInfo> &buildData, uint32_t start, uint32_t end,
00055 uint32_t *totalNodes, vector<Reference<Primitive> > &orderedPrims);
00056 uint32_t flattenBVHTree(BVHBuildNode *node, uint32_t *offset);
00057
00058
00059 uint32_t maxPrimsInNode;
00060 enum SplitMethod { SPLIT_MIDDLE, SPLIT_EQUAL_COUNTS, SPLIT_SAH };
00061 SplitMethod splitMethod;
00062 vector<Reference<Primitive> > primitives;
00063 LinearBVHNode *nodes;
00064 };
00065
00066
00067 BVHAccel *CreateBVHAccelerator(const vector<Reference<Primitive> > &prims,
00068 const ParamSet &ps);
00069
00070 #endif // PBRT_ACCELERATORS_BVH_H