--- 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
--- /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')
--- /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")
--- 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);
--- 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);
--- 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
--- 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
--- /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]))
--- 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
--- 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
--- 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
--- 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)
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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
--- 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;
--- 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<Float> &allts) const {return false;};
@@ -307,4 +308,17 @@
BBox get_bbox() const;
};
+template <class T> 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<Vertex> VertexArray;
+typedef Array<NormalVertex> NormalVertexArray;
+typedef Array<Triangle> TriangleArray;
+
#endif
--- /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')
--- 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