# HG changeset patch # User Radek Brich # Date 1207609512 -7200 # Node ID a23b5089b9c3c4963cee598981711d1f7a29e861 # Parent 64e456ab823d80e59794cfa832f84d0bf0d8308c moving to SCons build system diff -r 64e456ab823d -r a23b5089b9c3 .bzrignore --- a/.bzrignore Fri Apr 04 13:54:47 2008 +0200 +++ b/.bzrignore Tue Apr 08 01:05:12 2008 +0200 @@ -12,3 +12,4 @@ models/dragon bin/* docs/* +.sconsign.dblite diff -r 64e456ab823d -r a23b5089b9c3 SConstruct --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SConstruct Tue Apr 08 01:05:12 2008 +0200 @@ -0,0 +1,12 @@ +Decider('MD5-timestamp') + +# CXX=icpc +# CCFLAGS=-g -fno-strict-aliasing -I$(ROOT)/include +# -Wall | -w1 + +# float: -fsingle-precision-constant +# double: -DPYRIT_DOUBLE +(objs,pymodule) = SConscript('src/SConscript', build_dir='build/lib', duplicate=0) + +SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0, exports='objs') +SConscript('demos/SConscript', build_dir='build/demos', exports='pymodule') diff -r 64e456ab823d -r a23b5089b9c3 ccdemos/SConscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ccdemos/SConscript Tue Apr 08 01:05:12 2008 +0200 @@ -0,0 +1,16 @@ +Import('objs') + +env = Environment(CPPPATH = ['.','#include']) + +import os +SDL_CCFLAGS = os.popen('sdl-config --cflags').read() +SDL_LDFLAGS = os.popen('sdl-config --libs').read() +sdlenv = env.Clone() +sdlenv.Append(LINKFLAGS=SDL_LDFLAGS, CCFLAGS=SDL_CCFLAGS) + +image_obj = env.Object('image.c', CC="$CXX") +sdlenv.Program(['realtime.cc']+objs) +sdlenv.Program(['realtime_bunny.cc']+objs) +sdlenv.Program(['realtime_dragon.cc']+objs) +sdlenv.Program(['spheres_shadow.cc']+objs+image_obj, LIBS="png") +sdlenv.Program(['textures.cc']+objs+image_obj, LIBS="png") diff -r 64e456ab823d -r a23b5089b9c3 ccdemos/image.c --- a/ccdemos/image.c Fri Apr 04 13:54:47 2008 +0200 +++ b/ccdemos/image.c Tue Apr 08 01:05:12 2008 +0200 @@ -43,11 +43,11 @@ (*img)->pixel_size = pixelsize; (*img)->width = width; (*img)->height = height; - (*img)->data = (char *) malloc(width * height * pixelsize); + (*img)->data = (unsigned char *) malloc(width * height * pixelsize); return(0); } -int destroy_image(struct image **img) +void destroy_image(struct image **img) { free((*img)->data); free(*img); @@ -61,7 +61,7 @@ FILE *f; png_structp png; /* PNG data */ png_infop pnginfo; /* PNG info */ - char *data; + unsigned char *data; if ((f = fopen(fname, "wb")) == NULL) return (0); diff -r 64e456ab823d -r a23b5089b9c3 ccdemos/image.h --- a/ccdemos/image.h Fri Apr 04 13:54:47 2008 +0200 +++ b/ccdemos/image.h Tue Apr 08 01:05:12 2008 +0200 @@ -9,11 +9,11 @@ int pixel_size; /* should be 1 for grayscale and 3 for RGB*/ int width; int height; - char *data; + unsigned char *data; }; int new_image(struct image **img, int width, int height, int pixelsize); -int destroy_image(struct image **img); +void destroy_image(struct image **img); int save_png(const char *fname, struct image *img); diff -r 64e456ab823d -r a23b5089b9c3 ccdemos/spheres_shadow.cc --- a/ccdemos/spheres_shadow.cc Fri Apr 04 13:54:47 2008 +0200 +++ b/ccdemos/spheres_shadow.cc Tue Apr 08 01:05:12 2008 +0200 @@ -118,7 +118,7 @@ new_image(&img, w, h, 3); Float *fd = fdata; - for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { + for (unsigned char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { if (*fd > 1.0) *cd = 255; else diff -r 64e456ab823d -r a23b5089b9c3 ccdemos/textures.cc --- a/ccdemos/textures.cc Fri Apr 04 13:54:47 2008 +0200 +++ b/ccdemos/textures.cc Tue Apr 08 01:05:12 2008 +0200 @@ -285,7 +285,7 @@ new_image(&img, w, h, 3); Float *fd = fdata; - for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { + for (unsigned char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { if (*fd > 1.0) *cd = 255; else diff -r 64e456ab823d -r a23b5089b9c3 demos/SConscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/SConscript Tue Apr 08 01:05:12 2008 +0200 @@ -0,0 +1,24 @@ +Import('pymodule') + +env = Environment() +env.Append(BUILDERS = {'Touch':Builder(action=Action(''), single_source=True)}) +env.Append(BUILDERS = {'Copy':Builder(action=Copy('$TARGET','$SOURCE'), single_source=True)}) +env.Touch('boxes.py') +env.Touch('buddha.py') +env.Touch('bunny.py') +env.Touch('car.py') +env.Touch('dragon.py') +env.Touch('spheres_ao.py') +env.Touch('spheres_glass.py') +env.Touch('spheres_shadow.py') +env.Touch('triangles_monkey.py') +env.Touch('triangles_sphere.py') + +env.Touch('objreader.py') +env.Touch('plyreader.py') +env.Touch('lworeader.py') + +env.Touch('monkey.obj') +env.Touch('sphere.obj') + +env.Copy(str(pymodule[0]).split('/')[-1], str(pymodule[0])) diff -r 64e456ab823d -r a23b5089b9c3 demos/boxes.py --- a/demos/boxes.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/boxes.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Material, Box, Light import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/buddha.py --- a/demos/buddha.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/buddha.py Tue Apr 08 01:05:12 2008 +0200 @@ -3,9 +3,6 @@ # this demo needs buddha model from # http://graphics.stanford.edu/data/3Dscanrep/ -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Light, Sphere, Triangle, Material from plyreader import LoadStanfordPlyFile import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/bunny.py --- a/demos/bunny.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/bunny.py Tue Apr 08 01:05:12 2008 +0200 @@ -3,9 +3,6 @@ # this demo needs bunny model from # http://graphics.stanford.edu/data/3Dscanrep/ -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Light, Box, Triangle, Material from plyreader import LoadStanfordPlyFile import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/car.py --- a/demos/car.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/car.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Light, Sphere, Triangle, Material, Camera from lworeader import LoadLightwaveLwoFile import Image @@ -18,7 +15,7 @@ mat = Material(colour=(0.9, 0.9, 0.9)) LoadLightwaveLwoFile(rt, "../models/car/Nissan300ZX.lwo", mat, smooth=False, scale=0.4) -light = Light(position=(-5.0, 2.0, 8.0), colour=(0.7, 0.7, 0.7)) +light = Light(position=(-5.0, 10.0, 8.0), colour=(0.9, 0.9, 0.9)) rt.addlight(light) imagesize = (800, 600) diff -r 64e456ab823d -r a23b5089b9c3 demos/dragon.py --- a/demos/dragon.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/dragon.py Tue Apr 08 01:05:12 2008 +0200 @@ -3,9 +3,6 @@ # this demo needs dragon model from # http://graphics.stanford.edu/data/3Dscanrep/ -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Light, Sphere, Triangle, Material from plyreader import LoadStanfordPlyFile import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/spheres_ao.py --- a/demos/spheres_ao.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/spheres_ao.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Material, Box, Sphere, Light import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/spheres_glass.py --- a/demos/spheres_glass.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/spheres_glass.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Material, Box, Sphere, Light #, SphericalLight import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/spheres_shadow.py --- a/demos/spheres_shadow.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/spheres_shadow.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Material, Box, Sphere, Light import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/triangles_monkey.py --- a/demos/triangles_monkey.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/triangles_monkey.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material from objreader import LoadWavefrontObjFile import Image diff -r 64e456ab823d -r a23b5089b9c3 demos/triangles_sphere.py --- a/demos/triangles_sphere.py Fri Apr 04 13:54:47 2008 +0200 +++ b/demos/triangles_sphere.py Tue Apr 08 01:05:12 2008 +0200 @@ -1,8 +1,5 @@ #!/usr/bin/python -import sys -sys.path.append(open('ModulePath').read().strip()) - from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material from objreader import LoadWavefrontObjFile import Image diff -r 64e456ab823d -r a23b5089b9c3 include/quaternion.h --- a/include/quaternion.h Fri Apr 04 13:54:47 2008 +0200 +++ b/include/quaternion.h Tue Apr 08 01:05:12 2008 +0200 @@ -50,7 +50,7 @@ Quaternion normalize() { - Float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d); + Float f = (Float)1.0f / sqrtf(a * a + b * b + c * c + d * d); a *= f; b *= f; c *= f; diff -r 64e456ab823d -r a23b5089b9c3 include/scene.h --- a/include/scene.h Fri Apr 04 13:54:47 2008 +0200 +++ b/include/scene.h Tue Apr 08 01:05:12 2008 +0200 @@ -295,6 +295,7 @@ public: Vertex *A, *B, *C; + Triangle() {}; Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial); bool intersect(const Ray &ray, Float &dist) const; bool intersect_all(const Ray &ray, Float dist, vector &allts) const {return false;}; @@ -307,4 +308,17 @@ BBox get_bbox() const; }; +template class Array +{ + T *array; +public: + Array(int n) { array = new T[n]; }; + ~Array() { delete[] array; }; + const T &operator[](int i) const { return array[i]; }; +}; + +typedef Array VertexArray; +typedef Array NormalVertexArray; +typedef Array TriangleArray; + #endif diff -r 64e456ab823d -r a23b5089b9c3 src/SConscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/SConscript Tue Apr 08 01:05:12 2008 +0200 @@ -0,0 +1,25 @@ +env = Environment(CPPPATH = '#include') + +import os +PY_CCFLAGS = os.popen('python-config --includes').read() +PY_LDFLAGS = os.popen('python-config --libs').read() +pyenv = env.Clone() +pyenv.Append(LINKFLAGS=PY_LDFLAGS, CCFLAGS=PY_CCFLAGS) +env.Append() + +sources = [ + 'raytracer.cc', 'scene.cc', 'sampler.cc', + 'container.cc', 'kdtree.cc', 'octree.cc', 'noise.cc'] + +objs = [] +shared_objs = [] +for src in sources: + objs.append( env.Object(src) ) + shared_objs.append( env.SharedObject(src) ) + +pymodule = pyenv.SharedLibrary( + ['raytracermodule.cc']+shared_objs, + SHLIBPREFIX = '', + CCFLAGS = '$CCFLAGS -Wno-write-strings') + +Return('objs pymodule') diff -r 64e456ab823d -r a23b5089b9c3 src/raytracermodule.cc --- a/src/raytracermodule.cc Fri Apr 04 13:54:47 2008 +0200 +++ b/src/raytracermodule.cc Tue Apr 08 01:05:12 2008 +0200 @@ -736,7 +736,7 @@ static PyObject* Raytracer_render(PyObject* self, PyObject* args) { int w = 0, h = 0; - char *chardata; + unsigned char *chardata; Float *data; PyObject *o; @@ -756,9 +756,9 @@ // convert data to char printf("[pyrit] Converting image data (float to char)\n"); - chardata = (char *) malloc(w*h*3); + chardata = (unsigned char *) malloc(w*h*3); Float *d = data; - for (char *c = chardata; c != chardata + w*h*3; c++, d++) { + for (unsigned char *c = chardata; c != chardata + w*h*3; c++, d++) { if (*d > 1.0) *c = 255; else