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_LUX_H
00024 #define LUX_LUX_H
00025
00026
00027
00028 #include <cmath>
00029 #ifdef __CYGWIN__
00030 #include <ieeefp.h>
00031 #endif
00032
00033 #include <boost/archive/text_oarchive.hpp>
00034 #include <boost/archive/text_iarchive.hpp>
00035 #include <boost/serialization/vector.hpp>
00036 #include <boost/serialization/string.hpp>
00037 #include <boost/serialization/split_member.hpp>
00038
00039 #include <boost/shared_ptr.hpp>
00040 #include <boost/enable_shared_from_this.hpp>
00041
00042 #if defined (__INTEL_COMPILER) && !defined(WIN32)
00043
00044 inline float expf(float a) { return exp(a); }
00045 #endif
00046
00047 #if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
00048 # include <malloc.h>
00049 # if !defined(WIN32) || defined(__CYGWIN__)
00050 # include <alloca.h>
00051 # endif
00052 #endif
00053 #if defined(__FreeBSD__)
00054 # define memalign(A,B) malloc(B)
00055 #endif
00056 #if defined(WIN32) && !defined(__CYGWIN__)
00057 # include <float.h>
00058 # pragma warning (disable: 4244) // conversion from double to float (VS2005) - Radiance
00059 # pragma warning (disable: 4305) // truncation from double to float (VS2005) - Radiance
00060 # pragma warning (disable: 4996) // deprecated functions (VS2005) - Radiance
00061 # pragma warning (disable: 4267) // conversion from 'size_t' [asio\detail\socket_ops.hpp; boost\serialization\collections_save_imp.hpp] - zcott
00062 # pragma warning (disable: 4311) // pointer truncation from 'void *' to 'long' [Fl_Widget.H; Fl_Menu_Item.H;; asio\detail\win_iocp_socket_service.hpp] - zcott
00063 # pragma warning(disable : 4312) // conversion from 'long' to 'void *' of greater size [Fl_Widget.H; Fl_Menu_Item.H; asio\detail\win_iocp_socket_service.hpp] - zcott
00064
00065 # pragma warning (disable: 4267 4251 4065 4102)
00066 # pragma warning (disable: 4190) // extern "C" nonsense when returning a template
00067
00068 # include <windows.h>
00069 #endif
00070 #include <stdlib.h>
00071 #define _GNU_SOURCE 1 //NOBOOK
00072 #include <stdio.h>
00073 #include <string.h>
00074 #include <string>
00075 using std::string;
00076 #include <vector>
00077 using std::vector;
00078 #include <iostream>
00079 using std::ostream;
00080 #include <algorithm>
00081 using std::min;
00082 using std::max;
00083 using std::swap;
00084 using std::sort;
00085 #include <assert.h>
00086
00087
00088 #if defined(WIN32) && !defined(__CYGWIN__)
00089 # define memalign(a,b) _aligned_malloc(b, a)
00090 # define alloca _alloca
00091 # define isnan _isnan
00092 # define isinf(f) (!_finite((f)))
00093 #elif defined(__APPLE__)
00094 # define memalign(a,b) valloc(b)
00095 # if (__GNUC__ == 3) || (__GNUC__ == 4)
00096 extern "C" {
00097 int isinf(double);
00098 int isnan(double);
00099 }
00100 # endif // ONLY GCC 3
00101 #elif defined(__OpenBSD__)
00102 # define memalign(a,b) malloc(b)
00103 #elif defined(sgi)
00104 # define for if (0) ; else for
00105 #endif
00106
00107
00108 typedef double StatsCounterType;
00109 typedef unsigned char u_char;
00110 typedef unsigned short u_short;
00111 typedef unsigned int u_int;
00112 typedef unsigned long u_long;
00113 #define BC_GRID_SIZE 40
00114 typedef vector<int> SampleGrid[BC_GRID_SIZE][BC_GRID_SIZE];
00115 #define GRID(v) (int((v) * BC_GRID_SIZE))
00116
00117
00118 class Timer;
00119 class MemoryArena;
00120 template<class T, int logBlockSize = 2> class BlockedArray;
00121 class ProgressReporter;
00122 class StatsCounter;
00123 class StatsRatio;
00124 class StatsPercentage;
00125
00126 #include "randomgen.h"
00127
00128 namespace lux
00129 {
00130 class Matrix4x4;
00131 class ParamSet;
00132 template <class T> struct ParamSetItem;
00133 class Vector;
00134 class Point;
00135 class Normal;
00136 class Ray;
00137 class RayDifferential;
00138 class BBox;
00139 class Transform;
00140 class DifferentialGeometry;
00141 class TextureParams;
00142 class Scene;
00143 class Primitive;
00144 class AreaLightPrimitive;
00145 class InstancePrimitive;
00146 class MotionPrimitive;
00147 class Aggregate;
00148 class Intersection;
00149 class RGBColor;
00150 class ImageData;
00151 class SWCSpectrum;
00152 class SpectrumWavelengths;
00153 class Color;
00154 class RGBColor;
00155 class XYZColor;
00156 class SPD;
00157 class Camera;
00158 class ProjectiveCamera;
00159 class Sampler;
00160 class PixelSampler;
00161 class IntegrationSampler;
00162 class Sample;
00163 class Filter;
00164 class Film;
00165 class ToneMap;
00166 class BxDF;
00167 class BRDF;
00168 class BTDF;
00169 class Fresnel;
00170 class FresnelConductor;
00171 class FresnelDielectric;
00172 class FresnelNoOp;
00173 class SpecularReflection;
00174 class SpecularTransmission;
00175 class Lambertian;
00176 class OrenNayar;
00177 class Microfacet;
00178 class MicrofacetDistribution;
00179 class BSDF;
00180 class Material;
00181 struct CompositingParams;
00182 class TextureMapping2D;
00183 class UVMapping2D;
00184 class SphericalMapping2D;
00185 class CylindricalMapping2D;
00186 class PlanarMapping2D;
00187 class TextureMapping3D;
00188 class IdentityMapping3D;
00189 class TriangleMesh;
00190 class PlyMesh;
00191 template <class T> class Texture;
00192 class VolumeRegion;
00193 class Light;
00194 struct VisibilityTester;
00195 class AreaLight;
00196 class Shape;
00197 class PrimitiveSet;
00198 class Integrator;
00199 class SurfaceIntegrator;
00200 class VolumeIntegrator;
00201 class RandomGenerator;
00202 class RenderFarm;
00203 class Contribution;
00204 class ContributionBuffer;
00205 class ContributionSystem;
00206 class MotionSystem;
00207 class Distribution1D;
00208 class IrregularDistribution1D;
00209 }
00210
00211
00212 #ifdef M_PI
00213 # undef M_PI
00214 #endif
00215 #define M_PI 3.14159265358979323846f
00216 #define INV_PI 0.31830988618379067154f
00217 #define INV_TWOPI 0.15915494309189533577f
00218 #ifndef INFINITY
00219 # define INFINITY HUGE_VAL
00220
00221 #endif
00222 #define LUX_VERSION 0.6
00223 #define LUX_VERSION_STRING "0.6.1"
00224 #define COLOR_SAMPLES 3
00225 #if defined(WIN32) && !defined(__CYGWIN__)
00226 # define LUX_PATH_SEP ";"
00227 #else
00228 # define LUX_PATH_SEP ":"
00229 #endif
00230
00231
00232 bool ParseFile(const char *filename);
00233 namespace lux
00234 {
00235
00236 unsigned int DJBHash(const std::string& str);
00237
00238 bool SolveLinearSystem2x2(const float A[2][2], const float B[2], float x[2]);
00239
00240 ImageData *ReadImage(const string &name);
00241 }
00242
00243
00244
00245 namespace lux {
00246
00247 struct TsPack {
00248 SpectrumWavelengths *swl;
00249 RandomGenerator *rng;
00250 MemoryArena *arena;
00251 Camera *camera;
00252 float time;
00253 };
00254
00255 }
00256
00257
00258 template<class T> inline T Lerp(float t, T v1, T v2) {
00259 return (1.f - t) * v1 + t * v2;
00260 }
00261 template<class T> inline T Clamp(T val, T low, T high) {
00262 return val > low ? (val < high ? val : high) : low;
00263 }
00264 inline int Round2Int(double val) {
00265 return static_cast<int>(val > 0. ? val + .5 : val - .5);
00266 }
00267 inline int Round2Int(float val) {
00268 return static_cast<int>(val > 0.f ? val + .5f : val - .5f);
00269 }
00270 inline int Mod(int a, int b) {
00271
00272 if (b == 0)
00273 b = 1;
00274
00275 a %= b;
00276 if (a < 0)
00277 a += b;
00278 return a;
00279 }
00280 inline float Radians(float deg) {
00281 return (M_PI / 180.f) * deg;
00282 }
00283 inline float Degrees(float rad) {
00284 return (180.f / M_PI) * rad;
00285 }
00286 inline float Log2(float x) {
00287 return logf(x) / logf(2.f);
00288 }
00289 inline int Log2Int(float v) {
00290 return Round2Int(Log2(v));
00291 }
00292 inline bool IsPowerOf2(int v) {
00293 return (v & (v - 1)) == 0;
00294 }
00295 inline u_int RoundUpPow2(u_int v) {
00296 v--;
00297 v |= v >> 1;
00298 v |= v >> 2;
00299 v |= v >> 4;
00300 v |= v >> 8;
00301 v |= v >> 16;
00302 return v+1;
00303 }
00304 template<class T> inline int Float2Int(T val) {
00305 return static_cast<int>(val);
00306 }
00307 inline int Floor2Int(double val) {
00308 return static_cast<int>(floor(val));
00309 }
00310 inline int Floor2Int(float val) {
00311 return static_cast<int>(floorf(val));
00312 }
00313 inline int Ceil2Int(double val) {
00314 return static_cast<int>(ceil(val));
00315 }
00316 inline int Ceil2Int(float val) {
00317 return static_cast<int>(ceilf(val));
00318 }
00319 inline bool Quadratic(float A, float B, float C, float *t0, float *t1) {
00320
00321 float discrim = B * B - 4.f * A * C;
00322 if (discrim < 0.f)
00323 return false;
00324 float rootDiscrim = sqrtf(discrim);
00325
00326 float q;
00327 if (B < 0)
00328 q = -.5f * (B - rootDiscrim);
00329 else
00330 q = -.5f * (B + rootDiscrim);
00331 *t0 = q / A;
00332 *t1 = C / q;
00333 if (*t0 > *t1)
00334 swap(*t0, *t1);
00335 return true;
00336 }
00337 inline float SmoothStep(float min, float max, float value) {
00338 float v = Clamp((value - min) / (max - min), 0.f, 1.f);
00339 return v * v * (-2.f * v + 3.f);
00340 }
00341
00342 #endif // LUX_LUX_H