author | Radek Brich <radek.brich@devl.cz> |
Wed, 09 Apr 2008 17:55:29 +0200 | |
branch | pyrit |
changeset 64 | 5785cca4cdb9 |
parent 52 | a6413a3d741d |
child 78 | 9569e9f35374 |
permissions | -rw-r--r-- |
34
28f6e8b9d5d1
quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
1 |
/* |
44 | 2 |
* common.h: common functions and definitions |
3 |
* |
|
4 |
* This file is part of Pyrit Ray Tracer. |
|
5 |
* |
|
48
a4913301c626
begin moving subsampling and oversampling to Sampler
Radek Brich <radek.brich@devl.cz>
parents:
44
diff
changeset
|
6 |
* Copyright 2006, 2007, 2008 Radek Brich |
34
28f6e8b9d5d1
quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
7 |
* |
44 | 8 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9 |
* of this software and associated documentation files (the "Software"), to deal |
|
10 |
* in the Software without restriction, including without limitation the rights |
|
11 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12 |
* copies of the Software, and to permit persons to whom the Software is |
|
13 |
* furnished to do so, subject to the following conditions: |
|
14 |
* |
|
15 |
* The above copyright notice and this permission notice shall be included in |
|
16 |
* all copies or substantial portions of the Software. |
|
17 |
* |
|
18 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
23 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
24 |
* THE SOFTWARE. |
|
34
28f6e8b9d5d1
quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
25 |
*/ |
28f6e8b9d5d1
quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents:
30
diff
changeset
|
26 |
|
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
#ifndef COMMON_H |
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
#define COMMON_H |
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
|
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
30 |
#include <stdio.h> |
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
31 |
#include <stdarg.h> |
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
#include <float.h> |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
33 |
#include <pthread.h> |
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
|
22 | 35 |
#ifdef PYRIT_DOUBLE |
36 |
# define Float double |
|
37 |
# define Eps DBL_EPSILON |
|
38 |
# define Inf DBL_MAX |
|
39 |
#else |
|
40 |
# define Float float |
|
41 |
# define Eps 1e-6 |
|
42 |
# define Inf FLT_MAX |
|
43 |
#endif |
|
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
44 |
|
30
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
45 |
/* verbosity level: |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
46 |
0: only errors (E) |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
47 |
1: major status messages (*) |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
48 |
2: minor status, progress (-) |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
49 |
3: debug messages (D) |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
50 |
4: thread debug |
30
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
51 |
default = 2 |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
52 |
*/ |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
53 |
extern int pyrit_verbosity; |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
54 |
|
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
55 |
inline void dbgmsg(const int vlevel, const char *format, ...) |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
56 |
{ |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
57 |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
30
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
58 |
if (pyrit_verbosity >= vlevel) |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
59 |
{ |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
60 |
if (pyrit_verbosity >= 4) |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
61 |
pthread_mutex_lock(&mutex); |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
62 |
|
30
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
63 |
va_list ap; |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
64 |
va_start(ap, format); |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
65 |
vprintf(format, ap); |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
66 |
va_end(ap); |
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
67 |
fflush(stdout); |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
68 |
|
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
69 |
if (pyrit_verbosity >= 4) |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
70 |
pthread_mutex_unlock(&mutex); |
30
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
71 |
} |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
72 |
} |
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
73 |
|
37
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
74 |
template<typename Type> const Type &min3(const Type &a, const Type &b, const Type &c) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
75 |
{ |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
76 |
if (a <= b) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
77 |
{ |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
78 |
if (a <= c) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
79 |
return a; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
80 |
else |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
81 |
return c; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
82 |
} |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
83 |
else |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
84 |
{ |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
85 |
if (b <= c) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
86 |
return b; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
87 |
else |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
88 |
return c; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
89 |
} |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
90 |
} |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
91 |
|
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
92 |
template<typename Type> const Type &max3(const Type &a, const Type &b, const Type &c) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
93 |
{ |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
94 |
if (a >= b) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
95 |
{ |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
96 |
if (a >= c) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
97 |
return a; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
98 |
else |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
99 |
return c; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
100 |
} |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
101 |
else |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
102 |
{ |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
103 |
if (b >= c) |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
104 |
return b; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
105 |
else |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
106 |
return c; |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
107 |
} |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
108 |
} |
5f954c0d34fc
octree traversal rewritten to avoid recursion
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
109 |
|
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
110 |
#endif |