00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PBRT_PRIMITIVE_H
00025 #define PBRT_PRIMITIVE_H
00026
00027 #include "pbrt.h"
00028 #include "shape.h"
00029 #include "material.h"
00030
00031 class COREDLL Primitive : public ReferenceCounted {
00032 public:
00033
00034 virtual ~Primitive();
00035 virtual BBox WorldBound() const = 0;
00036 virtual bool CanIntersect() const;
00037 virtual bool Intersect(const Ray &r,
00038 Intersection *in) const = 0;
00039 virtual bool IntersectP(const Ray &r) const = 0;
00040 virtual void
00041 Refine(vector<Reference<Primitive> > &refined) const;
00042 void FullyRefine(vector<Reference<Primitive> > &refined)
00043 const;
00044 virtual const AreaLight *GetAreaLight() const = 0;
00045 virtual BSDF *GetBSDF(const DifferentialGeometry &dg,
00046 const Transform &WorldToObject) const = 0;
00047 };
00048 struct COREDLL Intersection {
00049
00050 Intersection() { primitive = NULL; }
00051 BSDF *GetBSDF(const RayDifferential &ray) const;
00052 Spectrum Le(const Vector &wo) const;
00053 DifferentialGeometry dg;
00054 const Primitive *primitive;
00055 Transform WorldToObject;
00056 };
00057 class COREDLL GeometricPrimitive : public Primitive {
00058 public:
00059
00060 bool CanIntersect() const;
00061 void Refine(vector<Reference<Primitive> > &refined) const;
00062 virtual BBox WorldBound() const;
00063 virtual bool Intersect(const Ray &r,
00064 Intersection *isect) const;
00065 virtual bool IntersectP(const Ray &r) const;
00066 GeometricPrimitive(const Reference<Shape> &s,
00067 const Reference<Material> &m,
00068 AreaLight *a);
00069 const AreaLight *GetAreaLight() const;
00070 BSDF *GetBSDF(const DifferentialGeometry &dg,
00071 const Transform &WorldToObject) const;
00072 private:
00073
00074 Reference<Shape> shape;
00075 Reference<Material> material;
00076 AreaLight *areaLight;
00077 };
00078 class COREDLL InstancePrimitive : public Primitive {
00079 public:
00080
00081 InstancePrimitive(Reference<Primitive> &i,
00082 const Transform &i2w) {
00083 instance = i;
00084 InstanceToWorld = i2w;
00085 WorldToInstance = i2w.GetInverse();
00086 }
00087 bool Intersect(const Ray &r, Intersection *in) const;
00088 bool IntersectP(const Ray &r) const;
00089 const AreaLight *GetAreaLight() const { return NULL; }
00090 BSDF *GetBSDF(const DifferentialGeometry &dg,
00091 const Transform &WorldToObject) const {
00092 return NULL;
00093 }
00094 BBox WorldBound() const {
00095 return InstanceToWorld(instance->WorldBound());
00096 }
00097 private:
00098
00099 Reference<Primitive> instance;
00100 Transform InstanceToWorld, WorldToInstance;
00101 };
00102 class COREDLL Aggregate : public Primitive {
00103 public:
00104
00105 const AreaLight *GetAreaLight() const;
00106 BSDF *GetBSDF(const DifferentialGeometry &dg,
00107 const Transform &) const;
00108 };
00109 #endif // PBRT_PRIMITIVE_H