00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_RAYTRACER_WORLD_H
00021 #define ARCHON_RAYTRACER_WORLD_H
00022
00023 #include <exception>
00024 #include <string>
00025 #include <vector>
00026
00027 #include <archon/math/vector.H>
00028 #include <archon/util/color.H>
00029 #include <archon/util/image.H>
00030 #include <archon/util/kdtree.H>
00031
00032 #include "object.H"
00033 #include "light.H"
00034
00035 namespace Archon
00036 {
00037 namespace Raytracer
00038 {
00039 using namespace Utilities;
00040 using namespace Math;
00041
00042 struct Photon: public KDTree::Element
00043 {
00044 Vector3 position;
00045 Vector3 power;
00046 Vector3 getPosition() const { return position; }
00047 Photon(const Vector3 &position, const Vector3 &power):
00048 position(position), power(power) {}
00049 };
00050
00051 class World
00052 {
00053 private:
00054 const double globalAmbientIntencity;
00055 const Vector4 backgroundColor;
00056 const double significanceThreshold;
00057 const int maxDepth;
00058 const bool enableTransmission;
00059 const unsigned photonsInEstimate;
00060 const bool showOnlyPhotonMap;
00061
00062 std::vector<Image> textureList;
00063 std::vector<Surface *> surfaceList;
00064 std::vector<Vector3 *> vertexList;
00065 std::vector<Object *> objectList;
00066 std::vector<Light *> lightList;
00067
00068 std::vector<Photon> photons;
00069 KDTree causticPhotonMap;
00070
00071 Vector4 trace(const Line3 &ray,
00072 const Object *originObject,
00073 const Object::Part * originPart,
00074 int depth, double significance,
00075 bool transmission);
00076
00077 public:
00078 World(const Vector4 &backgroundColor = ColorRGBA(Color::black),
00079 double significanceThreshold = 0.01,
00080 int maxDepth = 10,
00081 bool enableTransmission = true,
00082 unsigned photonsInEstimate = 30,
00083 bool showOnlyPhotonMap = false);
00084
00085 World(double globalAmbientIntencity = 0.1,
00086 const Vector4 &backgroundColor = ColorRGBA(Color::black),
00087 double significanceThreshold = 0.01,
00088 int maxDepth = 10,
00089 bool enableTransmission = true,
00090 unsigned photonsInEstimate = 30,
00091 bool showOnlyPhotonMap = false);
00092 ~World();
00093
00094 void addTexture(Image t) { textureList.push_back(t); }
00095 void addSurface(Surface *s) { surfaceList.push_back(s); }
00096 void addVertex(Vector3 *v) { vertexList.push_back(v); }
00097 void addObject(Object *o) { objectList.push_back(o); }
00098 void addLight(Light *l) { lightList.push_back(l); }
00099
00100 Vector4 trace(const Line3 &ray) { return trace(ray, 0, 0, 1, 1, false); }
00101
00102 void photonTrace(unsigned);
00103
00104 void photonTrace(const Line3 &ray, std::vector<Photon> &photons,
00105 const Object *originObject,
00106 const Object::Part *originPart,
00107 int depth, bool transmission,
00108 bool caustic, const Vector3 &power);
00109
00110 class InternalErrorException
00111 {
00112 const std::string message;
00113 public:
00114 InternalErrorException(std::string m): message(m) {}
00115 };
00116 };
00117 }
00118 }
00119
00120 #endif // ARCHON_RAYTRACER_WORLD_H