00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "lux.h"
00025 #include "camera.h"
00026 #include "film.h"
00027 #include "sampling.h"
00028 #include "error.h"
00029
00030 using namespace lux;
00031
00032
00033 Camera::~Camera() {
00034 delete film;
00035 }
00036 Camera::Camera(const Transform &world2cam,
00037 float hither, float yon,
00038 float sopen, float sclose, Film *f) {
00039 WorldToCamera = world2cam;
00040 CameraToWorld = WorldToCamera.GetInverse();
00041 ClipHither = hither;
00042 ClipYon = yon;
00043 ShutterOpen = sopen;
00044 ShutterClose = sclose;
00045 film = f;
00046 if (WorldToCamera.HasScale())
00047 luxError(LUX_UNIMPLEMENT,LUX_WARNING,"Scaling detected in world-to-camera transformation!\n The system has numerous assumptions, implicit and explicit,\nthat this transform will have no scale factors in it.\nProceed at your own risk; your image may have errors or\nthe system may crash as a result of this.");
00048 }
00049 bool Camera::IsVisibleFromEyes(const Scene *scene, const Point &lenP, const Point &worldP, Sample* sample_gen, Ray *ray_gen) const
00050 {
00051 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::IsVisibleFromEyes() method called");
00052 return false;
00053 }
00054 float Camera::GetConnectingFactor(const Point &lenP, const Point &worldP, const Vector &wo, const Normal &n) const
00055 {
00056 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::GetConnectingFactor() method called");
00057 return 0;
00058 }
00059 void Camera::GetFlux2RadianceFactors(Film *film, float *factors, int xPixelCount, int yPixelCount) const
00060 {
00061 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::GetFlux2RadianceFactors() method called");
00062 }
00063 bool Camera::IsDelta() const
00064 {
00065 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::IsDelta() method called");
00066 return true;
00067 }
00068 void Camera::SamplePosition(float u1, float u2, Point *p, float *pdf) const
00069 {
00070 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::SamplePosition() method called");
00071 }
00072 float Camera::EvalPositionPdf() const
00073 {
00074 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::EvalPositionPdf() method called");
00075 return 0;
00076 }
00077 bool Camera::Intersect(const Ray &ray, Intersection *isect) const
00078 {
00079 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::Intersect() method called");
00080 return false;
00081 }
00082
00083 ProjectiveCamera::ProjectiveCamera(const Transform &w2c,
00084 const Transform &proj, const float Screen[4],
00085 float hither, float yon, float sopen,
00086 float sclose, float lensr, float focald, Film *f)
00087 : Camera(w2c, hither, yon, sopen, sclose, f) {
00088
00089 LensRadius = lensr;
00090 FocalDistance = focald;
00091
00092 CameraToScreen = proj;
00093 WorldToScreen = CameraToScreen * WorldToCamera;
00094
00095 ScreenToRaster = Scale(float(film->xResolution),
00096 float(film->yResolution), 1.f) *
00097 Scale(1.f / (Screen[1] - Screen[0]),
00098 1.f / (Screen[2] - Screen[3]), 1.f) *
00099 Translate(Vector(-Screen[0], -Screen[3], 0.f));
00100 RasterToScreen = ScreenToRaster.GetInverse();
00101 RasterToCamera = CameraToScreen.GetInverse() * RasterToScreen;
00102 WorldToRaster = ScreenToRaster * WorldToScreen;
00103 RasterToWorld = WorldToRaster.GetInverse();
00104 }
00105 bool ProjectiveCamera::GenerateSample(const Point &p, Sample *sample) const
00106 {
00107 Point p_raster = WorldToRaster(p);
00108 sample->imageX = p_raster.x;
00109 sample->imageY = p_raster.y;
00110
00111
00112
00113 if (sample->imageX>=0 && sample->imageX<film->xResolution &&
00114 sample->imageY>=0 && sample->imageY<film->yResolution )
00115 return true;
00116 else
00117 return false;
00118
00119 return true;
00120 }