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_GRID_H
00029 #define PBRT_ACCELERATORS_GRID_H
00030
00031
00032 #include "pbrt.h"
00033 #include "primitive.h"
00034
00035
00036 struct Voxel;
00037
00038
00039 struct Voxel {
00040
00041 uint32_t size() const { return primitives.size(); }
00042 Voxel() { }
00043 Voxel(Reference<Primitive> op) {
00044 allCanIntersect = false;
00045 primitives.push_back(op);
00046 }
00047 void AddPrimitive(Reference<Primitive> prim) {
00048 primitives.push_back(prim);
00049 }
00050 bool Intersect(const Ray &ray, Intersection *isect, RWMutexLock &lock);
00051 bool IntersectP(const Ray &ray, RWMutexLock &lock);
00052 private:
00053 vector<Reference<Primitive> > primitives;
00054 bool allCanIntersect;
00055 };
00056
00057
00058
00059
00060 class GridAccel : public Aggregate {
00061 public:
00062
00063 GridAccel(const vector<Reference<Primitive> > &p, bool refineImmediately);
00064 BBox WorldBound() const;
00065 bool CanIntersect() const { return true; }
00066 ~GridAccel();
00067 bool Intersect(const Ray &ray, Intersection *isect) const;
00068 bool IntersectP(const Ray &ray) const;
00069 private:
00070
00071 int posToVoxel(const Point &P, int axis) const {
00072 int v = Float2Int((P[axis] - bounds.pMin[axis]) *
00073 invWidth[axis]);
00074 return Clamp(v, 0, nVoxels[axis]-1);
00075 }
00076 float voxelToPos(int p, int axis) const {
00077 return bounds.pMin[axis] + p * width[axis];
00078 }
00079 inline int offset(int x, int y, int z) const {
00080 return z*nVoxels[0]*nVoxels[1] + y*nVoxels[0] + x;
00081 }
00082
00083
00084 vector<Reference<Primitive> > primitives;
00085 int nVoxels[3];
00086 BBox bounds;
00087 Vector width, invWidth;
00088 Voxel **voxels;
00089 MemoryArena voxelArena;
00090 mutable RWMutex *rwMutex;
00091 };
00092
00093
00094 GridAccel *CreateGridAccelerator(const vector<Reference<Primitive> > &prims,
00095 const ParamSet &ps);
00096
00097 #endif // PBRT_ACCELERATORS_GRID_H