pyrit_verbosity: new variable for controlling amount of output, see common.h pyrit
authorRadek Brich <radek.brich@devl.cz>
Sat, 08 Dec 2007 16:02:37 +0100
branchpyrit
changeset 30 33f95441790e
parent 29 574c34441a1c
child 31 b4e09433934a
pyrit_verbosity: new variable for controlling amount of output, see common.h fix Makefile dependencies for raytracer_module fix bad view in buddha.py caused by last commit
TODO
demos/buddha.py
include/common.h
src/Makefile
src/kdtree.cc
src/raytracer.cc
--- a/TODO	Sat Dec 08 14:07:42 2007 +0100
+++ b/TODO	Sat Dec 08 16:02:37 2007 +0100
@@ -5,6 +5,7 @@
  * update Python binding: Camera, new classes
  * more complex demos
  * namespace
+ * refractions, glass
 
 New Classes?
 ============
--- a/demos/buddha.py	Sat Dec 08 14:07:42 2007 +0100
+++ b/demos/buddha.py	Sat Dec 08 16:02:37 2007 +0100
@@ -12,8 +12,8 @@
 
 rt = Raytracer()
 mat = Material(colour=(0.9, 0.9, 0.9))
-LoadStanfordPlyFile(rt, "../models/happy/happy_vrip_res2.ply",
-	mat, smooth=True, scale=20.0, trans=(-3,0,0))
+LoadStanfordPlyFile(rt, "../models/happy/happy_vrip_res4.ply",
+	mat, smooth=True, scale=20.0, trans=(0,-3,0))
 
 light = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.6))
 rt.addlight(light)
--- a/include/common.h	Sat Dec 08 14:07:42 2007 +0100
+++ b/include/common.h	Sat Dec 08 16:02:37 2007 +0100
@@ -15,14 +15,26 @@
 # define Inf FLT_MAX
 #endif
 
-inline void infomsg(const char *format, ...)
+/* verbosity level:
+0: only errors (E)
+1: major status messages (*)
+2: minor status, progress (-)
+3: debug messages (D)
+4: more debug
+default = 2
+*/
+extern int pyrit_verbosity;
+
+inline void dbgmsg(const int vlevel, const char *format, ...)
 {
-#ifndef PYRIT_QUIET
-	va_list ap;
-	va_start(ap, format);
-	vprintf(format, ap);
-	va_end(ap);
-#endif
+	if (pyrit_verbosity >= vlevel)
+	{
+		va_list ap;
+		va_start(ap, format);
+		vprintf(format, ap);
+		va_end(ap);
+		fflush(stdout);
+	}
 }
 
 #endif
--- a/src/Makefile	Sat Dec 08 14:07:42 2007 +0100
+++ b/src/Makefile	Sat Dec 08 16:02:37 2007 +0100
@@ -47,5 +47,5 @@
 kdtree.o: kdtree.cc kdtree.h scene.h common.h
 raytracer.o: raytracer.cc raytracer.h scene.h vector.h noise.h common.h
 
-raytracermodule.o: raytracermodule.cc raytracer.h scene.h vector.h common.h
+raytracermodule.o: raytracermodule.cc $(LIBOBJS)
 	$(CXX) -c -o $@ $(DEFS) $(CCFLAGS) $(PY_CCFLAGS) $<
--- a/src/kdtree.cc	Sat Dec 08 14:07:42 2007 +0100
+++ b/src/kdtree.cc	Sat Dec 08 16:02:37 2007 +0100
@@ -270,7 +270,7 @@
 
 void KdTree::build()
 {
-	infomsg("* building kd-tree\n");
+	dbgmsg(1, "* building kd-tree\n");
 	root = new KdNode();
 	ShapeList::iterator shape;
 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
--- a/src/raytracer.cc	Sat Dec 08 14:07:42 2007 +0100
+++ b/src/raytracer.cc	Sat Dec 08 16:02:37 2007 +0100
@@ -13,6 +13,8 @@
 #include <malloc.h>
 #include "raytracer.h"
 
+int pyrit_verbosity = 2;
+
 // Hammersley spherical point distribution
 // http://www.cse.cuhk.edu.hk/~ttwong/papers/udpoint/udpoints.html
 Vector3 Raytracer::SphereDistribute(int i, int n, Float extent, Vector3 &normal)
@@ -319,7 +321,7 @@
 	Vector3 dy = camera->v * (-S/camera->f);
 
 #ifdef PTHREADS
-	infomsg("* pthreads enabled, using %d threads\n", num_threads);
+	dbgmsg(1, "* pthreads enabled, using %d threads\n", num_threads);
 	pthread_t threads[num_threads];
 	for (int t = 0; t < num_threads; t++)
 		threads[t] = pthread_self();
@@ -327,7 +329,8 @@
 #endif
 
 	/* for each pixel... */
-	infomsg("* rendering row   0 (  0%% done)");
+	dbgmsg(1, "* raytracing...\n");
+	dbgmsg(2, "- row   0 (  0%% done)");
 	for (int y = 0; y < h; y += subsample)
 	{
 		d = (RenderrowData*) malloc(sizeof(RenderrowData));
@@ -342,7 +345,7 @@
 		/* create new thread and increase 't' */
 		int rc = pthread_create(&threads[t++], NULL, renderrow, (void *)d);
 		if (rc) {
-			infomsg("\nERROR: return code from pthread_create() is %d\n", rc);
+			dbgmsg(0, "\nE pthread_create unsuccessful, return code was %d\n", rc);
 			exit(1);
 		}
 		/* when 't' owerflows, reset it */
@@ -358,12 +361,12 @@
 		free(d);
 #endif
 		dfix += dy*subsample;
-		infomsg("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4d (%2d%% done)", y, y*100/(h-1));
+		dbgmsg(2, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4d (%2d%% done)", y, y*100/(h-1));
 	}
-	infomsg("\n");
+	dbgmsg(2, "\n");
 
 #ifdef PTHREADS
-	infomsg("* waiting for threads to finish\n");
+	dbgmsg(2, "- waiting for threads to finish\n");
 	for (t = 0; t < num_threads; t++)
 		if (pthread_join(threads[t], (void**)&d) == 0)
 			free(d);