changeset 0:4ae1d7ffb1ae

Initial pthreads version
author Merten Sach <msach@mailbox.tu-berlin.de>
date Wed, 03 Aug 2011 14:26:31 +0200
parents
children 3840d91821c4
files .hgignore Makefile README.txt c-ray-mt.c scene sphfract
diffstat 6 files changed, 955 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Wed Aug 03 14:26:31 2011 +0200
     1.3 @@ -0,0 +1,6 @@
     1.4 +syntax: glob
     1.5 +
     1.6 +nbproject
     1.7 +c-ray-mt
     1.8 +*.ppm
     1.9 +*.o
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Wed Aug 03 14:26:31 2011 +0200
     2.3 @@ -0,0 +1,20 @@
     2.4 +obj = c-ray-mt.o
     2.5 +bin = c-ray-mt
     2.6 +
     2.7 +CC = gcc
     2.8 +CFLAGS = -O3 -ffast-math
     2.9 +
    2.10 +$(bin): $(obj)
    2.11 +	$(CC) -o $@ $(obj) -lm -lpthread
    2.12 +
    2.13 +.PHONY: clean
    2.14 +clean:
    2.15 +	rm -f $(obj) $(bin)
    2.16 +
    2.17 +.PHONY: install
    2.18 +install:
    2.19 +	cp $(bin) /usr/local/bin/$(bin)
    2.20 +
    2.21 +.PHONY: uninstall
    2.22 +uninstall:
    2.23 +	rm -f /usr/local/bin/$(bin)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/README.txt	Wed Aug 03 14:26:31 2011 +0200
     3.3 @@ -0,0 +1,27 @@
     3.4 +Kernel: Ray Tracing
     3.5 +
     3.6 +This is a kernel-type benchmark of a very simple and brute-force ray tracer.
     3.7 +
     3.8 +Installation:
     3.9 +
    3.10 +To install the kernel benchmark, navigate to the directory this file is located in, open up a terminal and simply type 'make'. For certain architectures 
    3.11 +or special compilation options, you might need to change compilation parameters in the makefile.
    3.12 +
    3.13 +Usage:
    3.14 +
    3.15 +You may execute the benchmark by navigating to this directory after compilation and typing
    3.16 +
    3.17 +./c-ray-mt -i FILENAME -s RESOLUTION -o OUTPUT.ppm 
    3.18 +
    3.19 +'FILENAME' has to be either "scene" or "sphfract" or another predefined scene description file if there is one.
    3.20 +'RESOLUTION' specifies the resolution of the produced image and has to be given in the form 1920x1200, for example.
    3.21 +'OUTPUT' is the name of the file the rendered image will be contained in after the benchmark ran.
    3.22 +
    3.23 +The specification of how many threads are used to perform the rendering depends on the parallel programming model.
    3.24 +
    3.25 +Benchmark Versions:
    3.26 +
    3.27 +Serial
    3.28 +POSIX Threads
    3.29 +OpenMP SuperScalar
    3.30 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/c-ray-mt.c	Wed Aug 03 14:26:31 2011 +0200
     4.3 @@ -0,0 +1,692 @@
     4.4 +/* c-ray-mt - a simple multithreaded raytracing filter.
     4.5 + * Copyright (C) 2006 John Tsiombikas <nuclear@siggraph.org>
     4.6 + *
     4.7 + * You are free to use, modify and redistribute this program under the
     4.8 + * terms of the GNU General Public License v2 or (at your option) later.
     4.9 + * see "http://www.gnu.org/licenses/gpl.txt" for details.
    4.10 + * ---------------------------------------------------------------------
    4.11 + * Usage:
    4.12 + *   compile:  just type make
    4.13 + *              (add any arch-specific optimizations for your compiler in CFLAGS first)
    4.14 + *       run:  cat scene | ./c-ray-mt [-t num-threads] >foo.ppm
    4.15 + *              (on broken systems such as windows try: c-ray-mt -i scene -o foo.ppm)
    4.16 + *     enjoy:  display foo.ppm
    4.17 + *              (with imagemagick, or use your favorite image viewer)
    4.18 + * ---------------------------------------------------------------------
    4.19 + * Scene file format:
    4.20 + *   # sphere (many)
    4.21 + *   s  x y z  rad   r g b   shininess   reflectivity
    4.22 + *   # light (many)
    4.23 + *   l  x y z
    4.24 + *   # camera (one)
    4.25 + *   c  x y z  fov   tx ty tz
    4.26 + * ---------------------------------------------------------------------
    4.27 + */
    4.28 +#include <stdio.h>
    4.29 +#include <stdlib.h>
    4.30 +#include <string.h>
    4.31 +#include <math.h>
    4.32 +#include <ctype.h>
    4.33 +#include <errno.h>
    4.34 +#include <pthread.h>
    4.35 +#include "VPThread_lib/VPThread.h"
    4.36 +
    4.37 +#define VER_MAJOR	1
    4.38 +#define VER_MINOR	1
    4.39 +#define VER_STR		"c-ray-mt v%d.%d\n"
    4.40 +
    4.41 +#if !defined(unix) && !defined(__unix__)
    4.42 +#ifdef __MACH__
    4.43 +#define unix		1
    4.44 +#define __unix__	1
    4.45 +#endif	/* __MACH__ */
    4.46 +#endif	/* unix */
    4.47 +
    4.48 +/* find the appropriate way to define explicitly sized types */
    4.49 +/* for C99 or GNU libc (also mach's libc) we can use stdint.h */
    4.50 +#if (__STDC_VERSION__ >= 199900) || defined(__GLIBC__) || defined(__MACH__)
    4.51 +#include <stdint.h>
    4.52 +#elif defined(unix) || defined(__unix__)	/* some UNIX systems have them in sys/types.h */
    4.53 +#include <sys/types.h>
    4.54 +#elif defined(__WIN32__) || defined(WIN32)	/* the nameless one */
    4.55 +typedef unsigned __int8 uint8_t;
    4.56 +typedef unsigned __int32 uint32_t;
    4.57 +#endif	/* sized type detection */
    4.58 +
    4.59 +struct vec3 {
    4.60 +	double x, y, z;
    4.61 +};
    4.62 +
    4.63 +struct ray {
    4.64 +	struct vec3 orig, dir;
    4.65 +};
    4.66 +
    4.67 +struct material {
    4.68 +	struct vec3 col;	/* color */
    4.69 +	double spow;		/* specular power */
    4.70 +	double refl;		/* reflection intensity */
    4.71 +};
    4.72 +
    4.73 +struct sphere {
    4.74 +	struct vec3 pos;
    4.75 +	double rad;
    4.76 +	struct material mat;
    4.77 +	struct sphere *next;
    4.78 +};
    4.79 +
    4.80 +struct spoint {
    4.81 +	struct vec3 pos, normal, vref;	/* position, normal and view reflection */
    4.82 +	double dist;		/* parametric distance of intersection along the ray */
    4.83 +};
    4.84 +
    4.85 +struct camera {
    4.86 +	struct vec3 pos, targ;
    4.87 +	double fov;
    4.88 +};
    4.89 +
    4.90 +struct thread_data {
    4.91 +	pthread_t tid;
    4.92 +	int sl_start, sl_count;
    4.93 +
    4.94 +	uint32_t *pixels;
    4.95 +};
    4.96 +
    4.97 +void render_scanline(int xsz, int ysz, int sl, uint32_t *fb, int samples);
    4.98 +struct vec3 trace(struct ray ray, int depth);
    4.99 +struct vec3 shade(struct sphere *obj, struct spoint *sp, int depth);
   4.100 +struct vec3 reflect(struct vec3 v, struct vec3 n);
   4.101 +struct vec3 cross_product(struct vec3 v1, struct vec3 v2);
   4.102 +struct ray get_primary_ray(int x, int y, int sample);
   4.103 +struct vec3 get_sample_pos(int x, int y, int sample);
   4.104 +struct vec3 jitter(int x, int y, int s);
   4.105 +int ray_sphere(const struct sphere *sph, struct ray ray, struct spoint *sp);
   4.106 +void load_scene(FILE *fp);
   4.107 +unsigned long get_msec(void);
   4.108 +
   4.109 +void *thread_func(void *tdata);
   4.110 +
   4.111 +#define MAX_LIGHTS		16				/* maximum number of lights */
   4.112 +#define RAY_MAG			1000.0			/* trace rays of this magnitude */
   4.113 +#define MAX_RAY_DEPTH	5				/* raytrace recursion limit */
   4.114 +#define FOV				0.78539816		/* field of view in rads (pi/4) */
   4.115 +#define HALF_FOV		(FOV * 0.5)
   4.116 +#define ERR_MARGIN		1e-6			/* an arbitrary error margin to avoid surface acne */
   4.117 +
   4.118 +/* bit-shift ammount for packing each color into a 32bit uint */
   4.119 +#ifdef LITTLE_ENDIAN
   4.120 +#define RSHIFT	16
   4.121 +#define BSHIFT	0
   4.122 +#else	/* big endian */
   4.123 +#define RSHIFT	0
   4.124 +#define BSHIFT	16
   4.125 +#endif	/* endianess */
   4.126 +#define GSHIFT	8	/* this is the same in both byte orders */
   4.127 +
   4.128 +/* some helpful macros... */
   4.129 +#define SQ(x)		((x) * (x))
   4.130 +#define MAX(a, b)	((a) > (b) ? (a) : (b))
   4.131 +#define MIN(a, b)	((a) < (b) ? (a) : (b))
   4.132 +#define DOT(a, b)	((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)
   4.133 +#define NORMALIZE(a)  do {\
   4.134 +	double len = sqrt(DOT(a, a));\
   4.135 +	(a).x /= len; (a).y /= len; (a).z /= len;\
   4.136 +} while(0);
   4.137 +
   4.138 +/* global state */
   4.139 +int xres = 800;
   4.140 +int yres = 600;
   4.141 +int rays_per_pixel = 1;
   4.142 +double aspect = 1.333333;
   4.143 +struct sphere *obj_list;
   4.144 +struct vec3 lights[MAX_LIGHTS];
   4.145 +int lnum = 0;
   4.146 +struct camera cam;
   4.147 +
   4.148 +int thread_num = 1;
   4.149 +struct thread_data *threads;
   4.150 +
   4.151 +int start = 0;
   4.152 +pthread_mutex_t start_mutex = PTHREAD_MUTEX_INITIALIZER;
   4.153 +pthread_cond_t start_cond = PTHREAD_COND_INITIALIZER;
   4.154 +
   4.155 +#define NRAN	1024
   4.156 +#define MASK	(NRAN - 1)
   4.157 +struct vec3 urand[NRAN];
   4.158 +int irand[NRAN];
   4.159 +
   4.160 +unsigned long rend_time, start_time;
   4.161 +
   4.162 +const char *usage = {
   4.163 +	"Usage: c-ray-mt [options]\n"
   4.164 +	"  Reads a scene file from stdin, writes the image to stdout, and stats to stderr.\n\n"
   4.165 +	"Options:\n"
   4.166 +	"  -t <num>   how many threads to use (default: 1)\n"
   4.167 +	"  -s WxH     where W is the width and H the height of the image\n"
   4.168 +	"  -r <rays>  shoot <rays> rays per pixel (antialiasing)\n"
   4.169 +	"  -i <file>  read from <file> instead of stdin\n"
   4.170 +	"  -o <file>  write to <file> instead of stdout\n"
   4.171 +	"  -h         this help screen\n\n"
   4.172 +};
   4.173 +
   4.174 +void raytrace(uint32_t *pixels);
   4.175 +
   4.176 +int main(int argc, char **argv) {
   4.177 +	int i;
   4.178 +	uint32_t *pixels;
   4.179 +        double sl, sl_per_thread;
   4.180 +	FILE *infile = stdin, *outfile = stdout;
   4.181 +
   4.182 +	for(i=1; i<argc; i++) {
   4.183 +		if(argv[i][0] == '-' && argv[i][2] == 0) {
   4.184 +			char *sep;
   4.185 +			switch(argv[i][1]) {
   4.186 +			case 't':
   4.187 +				if(!isdigit(argv[++i][0])) {
   4.188 +					fprintf(stderr, "-t mus be followed by the number of worker threads to spawn\n");
   4.189 +					return EXIT_FAILURE;
   4.190 +				}
   4.191 +				thread_num = atoi(argv[i]);
   4.192 +				if(!thread_num) {
   4.193 +					fprintf(stderr, "invalid number of threads specified: %d\n", thread_num);
   4.194 +					return EXIT_FAILURE;
   4.195 +				}
   4.196 +				break;
   4.197 +					
   4.198 +			case 's':
   4.199 +				if(!isdigit(argv[++i][0]) || !(sep = strchr(argv[i], 'x')) || !isdigit(*(sep + 1))) {
   4.200 +					fputs("-s must be followed by something like \"640x480\"\n", stderr);
   4.201 +					return EXIT_FAILURE;
   4.202 +				}
   4.203 +				xres = atoi(argv[i]);
   4.204 +				yres = atoi(sep + 1);
   4.205 +				aspect = (double)xres / (double)yres;
   4.206 +				break;
   4.207 +
   4.208 +			case 'i':
   4.209 +				if(!(infile = fopen(argv[++i], "rb"))) {
   4.210 +					fprintf(stderr, "failed to open input file %s: %s\n", argv[i], strerror(errno));
   4.211 +					return EXIT_FAILURE;
   4.212 +				}
   4.213 +				break;
   4.214 +
   4.215 +			case 'o':
   4.216 +				if(!(outfile = fopen(argv[++i], "wb"))) {
   4.217 +					fprintf(stderr, "failed to open output file %s: %s\n", argv[i], strerror(errno));
   4.218 +					return EXIT_FAILURE;
   4.219 +				}
   4.220 +				break;
   4.221 +
   4.222 +			case 'r':
   4.223 +				if(!isdigit(argv[++i][0])) {
   4.224 +					fputs("-r must be followed by a number (rays per pixel)\n", stderr);
   4.225 +					return EXIT_FAILURE;
   4.226 +				}
   4.227 +				rays_per_pixel = atoi(argv[i]);
   4.228 +				break;
   4.229 +
   4.230 +			case 'h':
   4.231 +				fputs(usage, stdout);
   4.232 +				return 0;
   4.233 +				
   4.234 +			default:
   4.235 +				fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
   4.236 +				fputs(usage, stderr);
   4.237 +				return EXIT_FAILURE;
   4.238 +			}
   4.239 +		} else {
   4.240 +			fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
   4.241 +			fputs(usage, stderr);
   4.242 +			return EXIT_FAILURE;
   4.243 +		}
   4.244 +	}
   4.245 +
   4.246 +        
   4.247 +        if(!(pixels = malloc(xres * yres * sizeof *pixels))) {
   4.248 +		perror("pixel buffer allocation failed");
   4.249 +		return EXIT_FAILURE;
   4.250 +	}
   4.251 +	load_scene(infile);
   4.252 +        
   4.253 +        raytrace(pixels);
   4.254 +	
   4.255 +	/* output statistics to stderr */
   4.256 +	fprintf(stderr, "Rendering took: %lu seconds (%lu milliseconds)\n", rend_time / 1000, rend_time);
   4.257 +
   4.258 +	/* output the image */
   4.259 +	fprintf(outfile, "P6\n%d %d\n255\n", xres, yres);
   4.260 +	for(i=0; i<xres * yres; i++) {
   4.261 +		fputc((pixels[i] >> RSHIFT) & 0xff, outfile);
   4.262 +		fputc((pixels[i] >> GSHIFT) & 0xff, outfile);
   4.263 +		fputc((pixels[i] >> BSHIFT) & 0xff, outfile);
   4.264 +	}
   4.265 +	fflush(outfile);
   4.266 +
   4.267 +	if(infile != stdin) fclose(infile);
   4.268 +	if(outfile != stdout) fclose(outfile);
   4.269 +
   4.270 +	struct sphere *walker = obj_list;
   4.271 +	while(walker) {
   4.272 +		struct sphere *tmp = walker;
   4.273 +		walker = walker->next;
   4.274 +		free(tmp);
   4.275 +	}
   4.276 +	free(pixels);
   4.277 +	free(threads);
   4.278 +	return 0;
   4.279 +}
   4.280 +
   4.281 +/* this is run after the VMS is set up*/
   4.282 +void raytrace(uint32_t *pixels)
   4.283 +{
   4.284 +    int i;
   4.285 +    double sl, sl_per_thread;
   4.286 +    
   4.287 +    /* initialize the random number tables for the jitter */
   4.288 +    for(i=0; i<NRAN; i++) urand[i].x = (double)rand() / RAND_MAX - 0.5;
   4.289 +    for(i=0; i<NRAN; i++) urand[i].y = (double)rand() / RAND_MAX - 0.5;
   4.290 +    for(i=0; i<NRAN; i++) irand[i] = (int)(NRAN * ((double)rand() / RAND_MAX));
   4.291 +
   4.292 +    if(thread_num > yres) {
   4.293 +            fprintf(stderr, "more threads than scanlines specified, reducing number of threads to %d\n", yres);
   4.294 +            thread_num = yres;
   4.295 +    }
   4.296 +
   4.297 +    if(!(threads = malloc(thread_num * sizeof *threads))) {
   4.298 +            perror("failed to allocate thread table");
   4.299 +            exit(EXIT_FAILURE);
   4.300 +    }
   4.301 +
   4.302 +    sl = 0.0;
   4.303 +    sl_per_thread = (double)yres / (double)thread_num;
   4.304 +    for(i=0; i<thread_num; i++) {
   4.305 +            threads[i].sl_start = (int)sl;
   4.306 +            sl += sl_per_thread;
   4.307 +            threads[i].sl_count = (int)sl - threads[i].sl_start;
   4.308 +            threads[i].pixels = pixels;
   4.309 +
   4.310 +            if(pthread_create(&threads[i].tid, 0, thread_func, &threads[i]) != 0) {
   4.311 +                    perror("failed to spawn thread");
   4.312 +                    exit(EXIT_FAILURE);
   4.313 +            }
   4.314 +    }
   4.315 +    threads[thread_num - 1].sl_count = yres - threads[thread_num - 1].sl_start;
   4.316 +
   4.317 +    fprintf(stderr, VER_STR, VER_MAJOR, VER_MINOR);
   4.318 +
   4.319 +    pthread_mutex_lock(&start_mutex);
   4.320 +    start_time = get_msec();
   4.321 +    start = 1;
   4.322 +    pthread_cond_broadcast(&start_cond);
   4.323 +    pthread_mutex_unlock(&start_mutex);
   4.324 +
   4.325 +    for(i=0; i<thread_num; i++) {
   4.326 +            pthread_join(threads[i].tid, 0);
   4.327 +    }
   4.328 +    rend_time = get_msec() - start_time;
   4.329 +}
   4.330 +
   4.331 +/* render a frame of xsz/ysz dimensions into the provided framebuffer */
   4.332 +void render_scanline(int xsz, int ysz, int sl, uint32_t *fb, int samples) {
   4.333 +	int i, s;
   4.334 +	double rcp_samples = 1.0 / (double)samples;
   4.335 +
   4.336 +	for(i=0; i<xsz; i++) {
   4.337 +		double r, g, b;
   4.338 +		r = g = b = 0.0;
   4.339 +			
   4.340 +		for(s=0; s<samples; s++) {
   4.341 +			struct vec3 col = trace(get_primary_ray(i, sl, s), 0);
   4.342 +			r += col.x;
   4.343 +			g += col.y;
   4.344 +			b += col.z;
   4.345 +		}
   4.346 +
   4.347 +		r = r * rcp_samples;
   4.348 +		g = g * rcp_samples;
   4.349 +		b = b * rcp_samples;
   4.350 +			
   4.351 +		fb[sl * xsz + i] = ((uint32_t)(MIN(r, 1.0) * 255.0) & 0xff) << RSHIFT |
   4.352 +							((uint32_t)(MIN(g, 1.0) * 255.0) & 0xff) << GSHIFT |
   4.353 +							((uint32_t)(MIN(b, 1.0) * 255.0) & 0xff) << BSHIFT;
   4.354 +	}
   4.355 +}
   4.356 +
   4.357 +/* trace a ray throught the scene recursively (the recursion happens through
   4.358 + * shade() to calculate reflection rays if necessary).
   4.359 + */
   4.360 +struct vec3 trace(struct ray ray, int depth) {
   4.361 +	struct vec3 col;
   4.362 +	struct spoint sp, nearest_sp;
   4.363 +	struct sphere *nearest_obj = 0;
   4.364 +	struct sphere *iter = obj_list->next;
   4.365 +
   4.366 +	/* if we reached the recursion limit, bail out */
   4.367 +	if(depth >= MAX_RAY_DEPTH) {
   4.368 +		col.x = col.y = col.z = 0.0;
   4.369 +		return col;
   4.370 +	}
   4.371 +	
   4.372 +	/* find the nearest intersection ... */
   4.373 +	while(iter) {
   4.374 +		if(ray_sphere(iter, ray, &sp)) {
   4.375 +			if(!nearest_obj || sp.dist < nearest_sp.dist) {
   4.376 +				nearest_obj = iter;
   4.377 +				nearest_sp = sp;
   4.378 +			}
   4.379 +		}
   4.380 +		iter = iter->next;
   4.381 +	}
   4.382 +
   4.383 +	/* and perform shading calculations as needed by calling shade() */
   4.384 +	if(nearest_obj) {
   4.385 +		col = shade(nearest_obj, &nearest_sp, depth);
   4.386 +	} else {
   4.387 +		col.x = col.y = col.z = 0.0;
   4.388 +	}
   4.389 +
   4.390 +	return col;
   4.391 +}
   4.392 +
   4.393 +/* Calculates direct illumination with the phong reflectance model.
   4.394 + * Also handles reflections by calling trace again, if necessary.
   4.395 + */
   4.396 +struct vec3 shade(struct sphere *obj, struct spoint *sp, int depth) {
   4.397 +	int i;
   4.398 +	struct vec3 col = {0, 0, 0};
   4.399 +
   4.400 +	/* for all lights ... */
   4.401 +	for(i=0; i<lnum; i++) {
   4.402 +		double ispec, idiff;
   4.403 +		struct vec3 ldir;
   4.404 +		struct ray shadow_ray;
   4.405 +		struct sphere *iter = obj_list->next;
   4.406 +		int in_shadow = 0;
   4.407 +
   4.408 +		ldir.x = lights[i].x - sp->pos.x;
   4.409 +		ldir.y = lights[i].y - sp->pos.y;
   4.410 +		ldir.z = lights[i].z - sp->pos.z;
   4.411 +
   4.412 +		shadow_ray.orig = sp->pos;
   4.413 +		shadow_ray.dir = ldir;
   4.414 +
   4.415 +		/* shoot shadow rays to determine if we have a line of sight with the light */
   4.416 +		while(iter) {
   4.417 +			if(ray_sphere(iter, shadow_ray, 0)) {
   4.418 +				in_shadow = 1;
   4.419 +				break;
   4.420 +			}
   4.421 +			iter = iter->next;
   4.422 +		}
   4.423 +
   4.424 +		/* and if we're not in shadow, calculate direct illumination with the phong model. */
   4.425 +		if(!in_shadow) {
   4.426 +			NORMALIZE(ldir);
   4.427 +
   4.428 +			idiff = MAX(DOT(sp->normal, ldir), 0.0);
   4.429 +			ispec = obj->mat.spow > 0.0 ? pow(MAX(DOT(sp->vref, ldir), 0.0), obj->mat.spow) : 0.0;
   4.430 +
   4.431 +			col.x += idiff * obj->mat.col.x + ispec;
   4.432 +			col.y += idiff * obj->mat.col.y + ispec;
   4.433 +			col.z += idiff * obj->mat.col.z + ispec;
   4.434 +		}
   4.435 +	}
   4.436 +
   4.437 +	/* Also, if the object is reflective, spawn a reflection ray, and call trace()
   4.438 +	 * to calculate the light arriving from the mirror direction.
   4.439 +	 */
   4.440 +	if(obj->mat.refl > 0.0) {
   4.441 +		struct ray ray;
   4.442 +		struct vec3 rcol;
   4.443 +
   4.444 +		ray.orig = sp->pos;
   4.445 +		ray.dir = sp->vref;
   4.446 +		ray.dir.x *= RAY_MAG;
   4.447 +		ray.dir.y *= RAY_MAG;
   4.448 +		ray.dir.z *= RAY_MAG;
   4.449 +
   4.450 +		rcol = trace(ray, depth + 1);
   4.451 +		col.x += rcol.x * obj->mat.refl;
   4.452 +		col.y += rcol.y * obj->mat.refl;
   4.453 +		col.z += rcol.z * obj->mat.refl;
   4.454 +	}
   4.455 +
   4.456 +	return col;
   4.457 +}
   4.458 +
   4.459 +/* calculate reflection vector */
   4.460 +struct vec3 reflect(struct vec3 v, struct vec3 n) {
   4.461 +	struct vec3 res;
   4.462 +	double dot = v.x * n.x + v.y * n.y + v.z * n.z;
   4.463 +	res.x = -(2.0 * dot * n.x - v.x);
   4.464 +	res.y = -(2.0 * dot * n.y - v.y);
   4.465 +	res.z = -(2.0 * dot * n.z - v.z);
   4.466 +	return res;
   4.467 +}
   4.468 +
   4.469 +struct vec3 cross_product(struct vec3 v1, struct vec3 v2) {
   4.470 +	struct vec3 res;
   4.471 +	res.x = v1.y * v2.z - v1.z * v2.y;
   4.472 +	res.y = v1.z * v2.x - v1.x * v2.z;
   4.473 +	res.z = v1.x * v2.y - v1.y * v2.x;
   4.474 +	return res;
   4.475 +}
   4.476 +
   4.477 +/* determine the primary ray corresponding to the specified pixel (x, y) */
   4.478 +struct ray get_primary_ray(int x, int y, int sample) {
   4.479 +	struct ray ray;
   4.480 +	float m[3][3];
   4.481 +	struct vec3 i, j = {0, 1, 0}, k, dir, orig, foo;
   4.482 +
   4.483 +	k.x = cam.targ.x - cam.pos.x;
   4.484 +	k.y = cam.targ.y - cam.pos.y;
   4.485 +	k.z = cam.targ.z - cam.pos.z;
   4.486 +	NORMALIZE(k);
   4.487 +
   4.488 +	i = cross_product(j, k);
   4.489 +	j = cross_product(k, i);
   4.490 +	m[0][0] = i.x; m[0][1] = j.x; m[0][2] = k.x;
   4.491 +	m[1][0] = i.y; m[1][1] = j.y; m[1][2] = k.y;
   4.492 +	m[2][0] = i.z; m[2][1] = j.z; m[2][2] = k.z;
   4.493 +	
   4.494 +	ray.orig.x = ray.orig.y = ray.orig.z = 0.0;
   4.495 +	ray.dir = get_sample_pos(x, y, sample);
   4.496 +	ray.dir.z = 1.0 / HALF_FOV;
   4.497 +	ray.dir.x *= RAY_MAG;
   4.498 +	ray.dir.y *= RAY_MAG;
   4.499 +	ray.dir.z *= RAY_MAG;
   4.500 +	
   4.501 +	dir.x = ray.dir.x + ray.orig.x;
   4.502 +	dir.y = ray.dir.y + ray.orig.y;
   4.503 +	dir.z = ray.dir.z + ray.orig.z;
   4.504 +	foo.x = dir.x * m[0][0] + dir.y * m[0][1] + dir.z * m[0][2];
   4.505 +	foo.y = dir.x * m[1][0] + dir.y * m[1][1] + dir.z * m[1][2];
   4.506 +	foo.z = dir.x * m[2][0] + dir.y * m[2][1] + dir.z * m[2][2];
   4.507 +
   4.508 +	orig.x = ray.orig.x * m[0][0] + ray.orig.y * m[0][1] + ray.orig.z * m[0][2] + cam.pos.x;
   4.509 +	orig.y = ray.orig.x * m[1][0] + ray.orig.y * m[1][1] + ray.orig.z * m[1][2] + cam.pos.y;
   4.510 +	orig.z = ray.orig.x * m[2][0] + ray.orig.y * m[2][1] + ray.orig.z * m[2][2] + cam.pos.z;
   4.511 +
   4.512 +	ray.orig = orig;
   4.513 +	ray.dir.x = foo.x + orig.x;
   4.514 +	ray.dir.y = foo.y + orig.y;
   4.515 +	ray.dir.z = foo.z + orig.z;
   4.516 +	
   4.517 +	return ray;
   4.518 +}
   4.519 +
   4.520 +
   4.521 +struct vec3 get_sample_pos(int x, int y, int sample) {
   4.522 +	struct vec3 pt;
   4.523 +	static double sf = 0.0;
   4.524 +
   4.525 +	if(sf == 0.0) {
   4.526 +		sf = 1.5 / (double)xres;
   4.527 +	}
   4.528 +
   4.529 +	pt.x = ((double)x / (double)xres) - 0.5;
   4.530 +	pt.y = -(((double)y / (double)yres) - 0.65) / aspect;
   4.531 +
   4.532 +	if(sample) {
   4.533 +		struct vec3 jt = jitter(x, y, sample);
   4.534 +		pt.x += jt.x * sf;
   4.535 +		pt.y += jt.y * sf / aspect;
   4.536 +	}
   4.537 +	return pt;
   4.538 +}
   4.539 +
   4.540 +/* jitter function taken from Graphics Gems I. */
   4.541 +struct vec3 jitter(int x, int y, int s) {
   4.542 +	struct vec3 pt;
   4.543 +	pt.x = urand[(x + (y << 2) + irand[(x + s) & MASK]) & MASK].x;
   4.544 +	pt.y = urand[(y + (x << 2) + irand[(y + s) & MASK]) & MASK].y;
   4.545 +	return pt;
   4.546 +}
   4.547 +
   4.548 +/* Calculate ray-sphere intersection, and return {1, 0} to signify hit or no hit.
   4.549 + * Also the surface point parameters like position, normal, etc are returned through
   4.550 + * the sp pointer if it is not NULL.
   4.551 + */
   4.552 +int ray_sphere(const struct sphere *sph, struct ray ray, struct spoint *sp) {
   4.553 +	double a, b, c, d, sqrt_d, t1, t2;
   4.554 +	
   4.555 +	a = SQ(ray.dir.x) + SQ(ray.dir.y) + SQ(ray.dir.z);
   4.556 +	b = 2.0 * ray.dir.x * (ray.orig.x - sph->pos.x) +
   4.557 +				2.0 * ray.dir.y * (ray.orig.y - sph->pos.y) +
   4.558 +				2.0 * ray.dir.z * (ray.orig.z - sph->pos.z);
   4.559 +	c = SQ(sph->pos.x) + SQ(sph->pos.y) + SQ(sph->pos.z) +
   4.560 +				SQ(ray.orig.x) + SQ(ray.orig.y) + SQ(ray.orig.z) +
   4.561 +				2.0 * (-sph->pos.x * ray.orig.x - sph->pos.y * ray.orig.y - sph->pos.z * ray.orig.z) - SQ(sph->rad);
   4.562 +	
   4.563 +	if((d = SQ(b) - 4.0 * a * c) < 0.0) return 0;
   4.564 +
   4.565 +	sqrt_d = sqrt(d);
   4.566 +	t1 = (-b + sqrt_d) / (2.0 * a);
   4.567 +	t2 = (-b - sqrt_d) / (2.0 * a);
   4.568 +
   4.569 +	if((t1 < ERR_MARGIN && t2 < ERR_MARGIN) || (t1 > 1.0 && t2 > 1.0)) return 0;
   4.570 +
   4.571 +	if(sp) {
   4.572 +		if(t1 < ERR_MARGIN) t1 = t2;
   4.573 +		if(t2 < ERR_MARGIN) t2 = t1;
   4.574 +		sp->dist = t1 < t2 ? t1 : t2;
   4.575 +		
   4.576 +		sp->pos.x = ray.orig.x + ray.dir.x * sp->dist;
   4.577 +		sp->pos.y = ray.orig.y + ray.dir.y * sp->dist;
   4.578 +		sp->pos.z = ray.orig.z + ray.dir.z * sp->dist;
   4.579 +		
   4.580 +		sp->normal.x = (sp->pos.x - sph->pos.x) / sph->rad;
   4.581 +		sp->normal.y = (sp->pos.y - sph->pos.y) / sph->rad;
   4.582 +		sp->normal.z = (sp->pos.z - sph->pos.z) / sph->rad;
   4.583 +
   4.584 +		sp->vref = reflect(ray.dir, sp->normal);
   4.585 +		NORMALIZE(sp->vref);
   4.586 +	}
   4.587 +	return 1;
   4.588 +}
   4.589 +
   4.590 +/* Load the scene from an extremely simple scene description file */
   4.591 +#define DELIM	" \t\n"
   4.592 +void load_scene(FILE *fp) {
   4.593 +	char line[256], *ptr, type;
   4.594 +
   4.595 +	obj_list = malloc(sizeof(struct sphere));
   4.596 +	obj_list->next = 0;
   4.597 +	
   4.598 +	while((ptr = fgets(line, 256, fp))) {
   4.599 +		int i;
   4.600 +		struct vec3 pos, col;
   4.601 +		double rad, spow, refl;
   4.602 +		
   4.603 +		while(*ptr == ' ' || *ptr == '\t') ptr++;
   4.604 +		if(*ptr == '#' || *ptr == '\n') continue;
   4.605 +
   4.606 +		if(!(ptr = strtok(line, DELIM))) continue;
   4.607 +		type = *ptr;
   4.608 +		
   4.609 +		for(i=0; i<3; i++) {
   4.610 +			if(!(ptr = strtok(0, DELIM))) break;
   4.611 +			*((double*)&pos.x + i) = atof(ptr);
   4.612 +		}
   4.613 +
   4.614 +		if(type == 'l') {
   4.615 +			lights[lnum++] = pos;
   4.616 +			continue;
   4.617 +		}
   4.618 +
   4.619 +		if(!(ptr = strtok(0, DELIM))) continue;
   4.620 +		rad = atof(ptr);
   4.621 +
   4.622 +		for(i=0; i<3; i++) {
   4.623 +			if(!(ptr = strtok(0, DELIM))) break;
   4.624 +			*((double*)&col.x + i) = atof(ptr);
   4.625 +		}
   4.626 +
   4.627 +		if(type == 'c') {
   4.628 +			cam.pos = pos;
   4.629 +			cam.targ = col;
   4.630 +			cam.fov = rad;
   4.631 +			continue;
   4.632 +		}
   4.633 +
   4.634 +		if(!(ptr = strtok(0, DELIM))) continue;
   4.635 +		spow = atof(ptr);
   4.636 +
   4.637 +		if(!(ptr = strtok(0, DELIM))) continue;
   4.638 +		refl = atof(ptr);
   4.639 +
   4.640 +		if(type == 's') {
   4.641 +			struct sphere *sph = malloc(sizeof *sph);
   4.642 +			sph->next = obj_list->next;
   4.643 +			obj_list->next = sph;
   4.644 +
   4.645 +			sph->pos = pos;
   4.646 +			sph->rad = rad;
   4.647 +			sph->mat.col = col;
   4.648 +			sph->mat.spow = spow;
   4.649 +			sph->mat.refl = refl;
   4.650 +		} else {
   4.651 +			fprintf(stderr, "unknown type: %c\n", type);
   4.652 +		}
   4.653 +	}
   4.654 +}
   4.655 +
   4.656 +
   4.657 +/* provide a millisecond-resolution timer for each system */
   4.658 +#if defined(unix) || defined(__unix__)
   4.659 +#include <time.h>
   4.660 +#include <sys/time.h>
   4.661 +unsigned long get_msec(void) {
   4.662 +	static struct timeval timeval, first_timeval;
   4.663 +	
   4.664 +	gettimeofday(&timeval, 0);
   4.665 +	if(first_timeval.tv_sec == 0) {
   4.666 +		first_timeval = timeval;
   4.667 +		return 0;
   4.668 +	}
   4.669 +	return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000;
   4.670 +}
   4.671 +#elif defined(__WIN32__) || defined(WIN32)
   4.672 +#include <windows.h>
   4.673 +unsigned long get_msec(void) {
   4.674 +	return GetTickCount();
   4.675 +}
   4.676 +#else
   4.677 +#error "I don't know how to measure time on your platform"
   4.678 +#endif
   4.679 +
   4.680 +void *thread_func(void *tdata) {
   4.681 +	int i;
   4.682 +	struct thread_data *td = (struct thread_data*)tdata;
   4.683 +
   4.684 +	pthread_mutex_lock(&start_mutex);
   4.685 +	while(!start) {
   4.686 +		pthread_cond_wait(&start_cond, &start_mutex);
   4.687 +	}
   4.688 +	pthread_mutex_unlock(&start_mutex);
   4.689 +
   4.690 +	for(i=0; i<td->sl_count; i++) {
   4.691 +		render_scanline(xres, yres, i + td->sl_start, td->pixels, rays_per_pixel);
   4.692 +	}
   4.693 +
   4.694 +	return 0;
   4.695 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/scene	Wed Aug 03 14:26:31 2011 +0200
     5.3 @@ -0,0 +1,18 @@
     5.4 +# spheres
     5.5 +#	position		radius	color			shininess	reflectivity
     5.6 +s	-1.5 -0.3 -1	0.7		1.0 0.2 0.05		50.0	0.3
     5.7 +s	1.5 -0.4 0		0.6		0.1 0.85 1.0		50.0	0.4
     5.8 +
     5.9 +# walls
    5.10 +s	0 -1000 2		999		0.1 0.2 0.6			80.0	0.5
    5.11 +
    5.12 +# bouncing ball
    5.13 +s	0 0 2			1		1.0 0.5 0.1			60.0	0.7
    5.14 +
    5.15 +# lights...
    5.16 +l	-50 100 -50
    5.17 +l	40 40 150
    5.18 +
    5.19 +# camera (there can be only one!)
    5.20 +#	position	FOV		target
    5.21 +c	0 6 -17		45		0 -1 0
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/sphfract	Wed Aug 03 14:26:31 2011 +0200
     6.3 @@ -0,0 +1,192 @@
     6.4 +s	0 0 0 	1.0	0.25 0.25 0.25  50.0	0.65
     6.5 +s	1.4 0 0 	0.4	0.25 0.25 0.25  50.0	0.65
     6.6 +s	1.96 0 0 	0.16	0.25 0.25 0.25  50.0	0.65
     6.7 +s	2.184 0 0 	0.064	0.25 0.25 0.25  50.0	0.65
     6.8 +s	1.96 0.224 0 	0.064	0.25 0.25 0.25  50.0	0.65
     6.9 +s	1.96 -0.224 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.10 +s	1.96 0 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.11 +s	1.96 0 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.12 +s	1.4 0.56 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.13 +s	1.624 0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.14 +s	1.176 0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.15 +s	1.4 0.784 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.16 +s	1.4 0.56 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.17 +s	1.4 0.56 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.18 +s	1.4 -0.56 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.19 +s	1.624 -0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.20 +s	1.176 -0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.21 +s	1.4 -0.784 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.22 +s	1.4 -0.56 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.23 +s	1.4 -0.56 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.24 +s	1.4 0 0.56 	0.16	0.25 0.25 0.25  50.0	0.65
    6.25 +s	1.624 0 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.26 +s	1.176 0 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.27 +s	1.4 0.224 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.28 +s	1.4 -0.224 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.29 +s	1.4 0 0.784 	0.064	0.25 0.25 0.25  50.0	0.65
    6.30 +s	1.4 0 -0.56 	0.16	0.25 0.25 0.25  50.0	0.65
    6.31 +s	1.624 0 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.32 +s	1.176 0 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.33 +s	1.4 0.224 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.34 +s	1.4 -0.224 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.35 +s	1.4 0 -0.784 	0.064	0.25 0.25 0.25  50.0	0.65
    6.36 +s	-1.4 0 0 	0.4	0.25 0.25 0.25  50.0	0.65
    6.37 +s	-1.96 0 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.38 +s	-2.184 0 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.39 +s	-1.96 0.224 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.40 +s	-1.96 -0.224 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.41 +s	-1.96 0 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.42 +s	-1.96 0 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.43 +s	-1.4 0.56 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.44 +s	-1.176 0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.45 +s	-1.624 0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.46 +s	-1.4 0.784 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.47 +s	-1.4 0.56 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.48 +s	-1.4 0.56 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.49 +s	-1.4 -0.56 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.50 +s	-1.176 -0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.51 +s	-1.624 -0.56 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.52 +s	-1.4 -0.784 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.53 +s	-1.4 -0.56 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.54 +s	-1.4 -0.56 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.55 +s	-1.4 0 0.56 	0.16	0.25 0.25 0.25  50.0	0.65
    6.56 +s	-1.176 0 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.57 +s	-1.624 0 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.58 +s	-1.4 0.224 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.59 +s	-1.4 -0.224 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.60 +s	-1.4 0 0.784 	0.064	0.25 0.25 0.25  50.0	0.65
    6.61 +s	-1.4 0 -0.56 	0.16	0.25 0.25 0.25  50.0	0.65
    6.62 +s	-1.176 0 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.63 +s	-1.624 0 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.64 +s	-1.4 0.224 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.65 +s	-1.4 -0.224 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.66 +s	-1.4 0 -0.784 	0.064	0.25 0.25 0.25  50.0	0.65
    6.67 +s	0 1.4 0 	0.4	0.25 0.25 0.25  50.0	0.65
    6.68 +s	0.56 1.4 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.69 +s	0.784 1.4 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.70 +s	0.56 1.624 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.71 +s	0.56 1.176 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.72 +s	0.56 1.4 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.73 +s	0.56 1.4 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.74 +s	-0.56 1.4 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.75 +s	-0.784 1.4 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.76 +s	-0.56 1.624 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.77 +s	-0.56 1.176 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.78 +s	-0.56 1.4 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.79 +s	-0.56 1.4 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.80 +s	0 1.96 0 	0.16	0.25 0.25 0.25  50.0	0.65
    6.81 +s	0.224 1.96 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.82 +s	-0.224 1.96 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.83 +s	0 2.184 0 	0.064	0.25 0.25 0.25  50.0	0.65
    6.84 +s	0 1.96 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.85 +s	0 1.96 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
    6.86 +s	0 1.4 0.56 	0.16	0.25 0.25 0.25  50.0	0.65
    6.87 +s	0.224 1.4 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.88 +s	-0.224 1.4 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.89 +s	0 1.624 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.90 +s	0 1.176 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.91 +s	0 1.4 0.784 	0.064	0.25 0.25 0.25  50.0	0.65
    6.92 +s	0 1.4 -0.56 	0.16	0.25 0.25 0.25  50.0	0.65
    6.93 +s	0.224 1.4 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.94 +s	-0.224 1.4 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.95 +s	0 1.624 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.96 +s	0 1.176 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
    6.97 +s	0 1.4 -0.784 	0.064	0.25 0.25 0.25  50.0	0.65
    6.98 +s	0 -1.4 0 	0.4	0.25 0.25 0.25  50.0	0.65
    6.99 +s	0.56 -1.4 0 	0.16	0.25 0.25 0.25  50.0	0.65
   6.100 +s	0.784 -1.4 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.101 +s	0.56 -1.176 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.102 +s	0.56 -1.624 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.103 +s	0.56 -1.4 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
   6.104 +s	0.56 -1.4 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
   6.105 +s	-0.56 -1.4 0 	0.16	0.25 0.25 0.25  50.0	0.65
   6.106 +s	-0.784 -1.4 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.107 +s	-0.56 -1.176 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.108 +s	-0.56 -1.624 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.109 +s	-0.56 -1.4 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
   6.110 +s	-0.56 -1.4 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
   6.111 +s	0 -1.96 0 	0.16	0.25 0.25 0.25  50.0	0.65
   6.112 +s	0.224 -1.96 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.113 +s	-0.224 -1.96 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.114 +s	0 -2.184 0 	0.064	0.25 0.25 0.25  50.0	0.65
   6.115 +s	0 -1.96 0.224 	0.064	0.25 0.25 0.25  50.0	0.65
   6.116 +s	0 -1.96 -0.224 	0.064	0.25 0.25 0.25  50.0	0.65
   6.117 +s	0 -1.4 0.56 	0.16	0.25 0.25 0.25  50.0	0.65
   6.118 +s	0.224 -1.4 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.119 +s	-0.224 -1.4 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.120 +s	0 -1.176 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.121 +s	0 -1.624 0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.122 +s	0 -1.4 0.784 	0.064	0.25 0.25 0.25  50.0	0.65
   6.123 +s	0 -1.4 -0.56 	0.16	0.25 0.25 0.25  50.0	0.65
   6.124 +s	0.224 -1.4 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.125 +s	-0.224 -1.4 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.126 +s	0 -1.176 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.127 +s	0 -1.624 -0.56 	0.064	0.25 0.25 0.25  50.0	0.65
   6.128 +s	0 -1.4 -0.784 	0.064	0.25 0.25 0.25  50.0	0.65
   6.129 +s	0 0 1.4 	0.4	0.25 0.25 0.25  50.0	0.65
   6.130 +s	0.56 0 1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.131 +s	0.784 0 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.132 +s	0.56 0.224 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.133 +s	0.56 -0.224 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.134 +s	0.56 0 1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.135 +s	0.56 0 1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.136 +s	-0.56 0 1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.137 +s	-0.784 0 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.138 +s	-0.56 0.224 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.139 +s	-0.56 -0.224 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.140 +s	-0.56 0 1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.141 +s	-0.56 0 1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.142 +s	0 0.56 1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.143 +s	0.224 0.56 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.144 +s	-0.224 0.56 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.145 +s	0 0.784 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.146 +s	0 0.56 1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.147 +s	0 0.56 1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.148 +s	0 -0.56 1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.149 +s	0.224 -0.56 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.150 +s	-0.224 -0.56 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.151 +s	0 -0.784 1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.152 +s	0 -0.56 1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.153 +s	0 -0.56 1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.154 +s	0 0 1.96 	0.16	0.25 0.25 0.25  50.0	0.65
   6.155 +s	0.224 0 1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.156 +s	-0.224 0 1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.157 +s	0 0.224 1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.158 +s	0 -0.224 1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.159 +s	0 0 2.184 	0.064	0.25 0.25 0.25  50.0	0.65
   6.160 +s	0 0 -1.4 	0.4	0.25 0.25 0.25  50.0	0.65
   6.161 +s	0.56 0 -1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.162 +s	0.784 0 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.163 +s	0.56 0.224 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.164 +s	0.56 -0.224 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.165 +s	0.56 0 -1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.166 +s	0.56 0 -1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.167 +s	-0.56 0 -1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.168 +s	-0.784 0 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.169 +s	-0.56 0.224 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.170 +s	-0.56 -0.224 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.171 +s	-0.56 0 -1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.172 +s	-0.56 0 -1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.173 +s	0 0.56 -1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.174 +s	0.224 0.56 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.175 +s	-0.224 0.56 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.176 +s	0 0.784 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.177 +s	0 0.56 -1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.178 +s	0 0.56 -1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.179 +s	0 -0.56 -1.4 	0.16	0.25 0.25 0.25  50.0	0.65
   6.180 +s	0.224 -0.56 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.181 +s	-0.224 -0.56 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.182 +s	0 -0.784 -1.4 	0.064	0.25 0.25 0.25  50.0	0.65
   6.183 +s	0 -0.56 -1.176 	0.064	0.25 0.25 0.25  50.0	0.65
   6.184 +s	0 -0.56 -1.624 	0.064	0.25 0.25 0.25  50.0	0.65
   6.185 +s	0 0 -1.96 	0.16	0.25 0.25 0.25  50.0	0.65
   6.186 +s	0.224 0 -1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.187 +s	-0.224 0 -1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.188 +s	0 0.224 -1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.189 +s	0 -0.224 -1.96 	0.064	0.25 0.25 0.25  50.0	0.65
   6.190 +s	0 0 -2.184 	0.064	0.25 0.25 0.25  50.0	0.65
   6.191 +s  0 -10002.25 0  10000  0.2 0.35 0.5  80.0  0.4
   6.192 +s  0  10100.00 0  10000  0.5 0.2 0.1  40.0  0.0
   6.193 +l	-50 68 -50
   6.194 +l	40 40 150
   6.195 +c	-7 6 -12 45  0 -0.65 0