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