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_KDTREEACCEL_H
00029 #define PBRT_ACCELERATORS_KDTREEACCEL_H
00030
00031
00032 #include "pbrt.h"
00033 #include "primitive.h"
00034
00035
00036 struct KdAccelNode;
00037 struct BoundEdge;
00038 class KdTreeAccel : public Aggregate {
00039 public:
00040
00041 KdTreeAccel(const vector<Reference<Primitive> > &p,
00042 int icost = 80, int scost = 1, float ebonus = 0.5f, int maxp = 1,
00043 int maxDepth = -1);
00044 BBox WorldBound() const { return bounds; }
00045 bool CanIntersect() const { return true; }
00046 ~KdTreeAccel();
00047 bool Intersect(const Ray &ray, Intersection *isect) const;
00048 bool IntersectP(const Ray &ray) const;
00049 private:
00050
00051 void buildTree(int nodeNum, const BBox &bounds,
00052 const vector<BBox> &primBounds, uint32_t *primNums, int nprims, int depth,
00053 BoundEdge *edges[3], uint32_t *prims0, uint32_t *prims1, int badRefines = 0);
00054
00055
00056 int isectCost, traversalCost, maxPrims, maxDepth;
00057 float emptyBonus;
00058 vector<Reference<Primitive> > primitives;
00059 KdAccelNode *nodes;
00060 int nAllocedNodes, nextFreeNode;
00061 BBox bounds;
00062 MemoryArena arena;
00063 };
00064
00065
00066 struct KdToDo {
00067 const KdAccelNode *node;
00068 float tmin, tmax;
00069 };
00070
00071
00072 KdTreeAccel *CreateKdTreeAccelerator(const vector<Reference<Primitive> > &prims,
00073 const ParamSet &ps);
00074
00075 #endif // PBRT_ACCELERATORS_KDTREEACCEL_H