1 |
|
/*! \file vr-lite-cam.c |
2 |
|
* |
3 |
|
* \author Nick Seltzer |
4 |
|
*/ |
5 |
|
|
6 |
|
/* |
7 |
|
* COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) |
8 |
|
* All rights reserved. |
9 |
|
*/ |
10 |
|
|
11 |
#include <stdio.h> |
#include <stdio.h> |
12 |
#include <math.h> |
#include <math.h> |
13 |
#include <stdbool.h> |
#include <stdbool.h> |
14 |
#include "teem/nrrd.h" |
#include "teem/nrrd.h" |
15 |
#include "teem/gage.h" |
#include "teem/gage.h" |
16 |
|
|
17 |
|
#include <sys/time.h> |
18 |
|
|
19 |
|
static double GetTime () |
20 |
|
{ |
21 |
|
struct timeval tv; |
22 |
|
|
23 |
|
gettimeofday (&tv, 0); |
24 |
|
|
25 |
double dot3(double vec1[3], double vec2[3]) |
return (double)tv.tv_sec + 0.000001 * (double)tv.tv_usec; |
26 |
|
} |
27 |
|
|
28 |
|
#define STATIC_INLINE static inline |
29 |
|
|
30 |
|
STATIC_INLINE double dot3(double vec1[3], double vec2[3]) |
31 |
{ |
{ |
32 |
return (vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2]); |
return (vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2]); |
33 |
} |
} |
34 |
|
|
35 |
double mag3(double vec[3]) |
STATIC_INLINE double mag3(double vec[3]) |
36 |
{ |
{ |
37 |
return sqrt(dot3(vec, vec)); |
return sqrt(dot3(vec, vec)); |
38 |
} |
} |
39 |
|
|
40 |
void norm3(double vec[3], double res[3]) |
STATIC_INLINE void norm3(double vec[3], double res[3]) |
41 |
{ |
{ |
42 |
double mag = mag3(vec); |
double mag = mag3(vec); |
43 |
res[0] = vec[0] / mag; |
res[0] = vec[0] / mag; |
45 |
res[2] = vec[2] / mag; |
res[2] = vec[2] / mag; |
46 |
} |
} |
47 |
|
|
48 |
void add3(double vec1[3], double vec2[3], double res[3]) |
STATIC_INLINE void add3(double vec1[3], double vec2[3], double res[3]) |
49 |
{ |
{ |
50 |
res[0] = vec1[0] + vec2[0]; |
res[0] = vec1[0] + vec2[0]; |
51 |
res[1] = vec1[1] + vec2[1]; |
res[1] = vec1[1] + vec2[1]; |
52 |
res[2] = vec1[2] + vec2[2]; |
res[2] = vec1[2] + vec2[2]; |
53 |
} |
} |
54 |
|
|
55 |
void sub3(double vec1[3], double vec2[3], double res[3]) |
STATIC_INLINE void sub3(double vec1[3], double vec2[3], double res[3]) |
56 |
{ |
{ |
57 |
res[0] = vec1[0] - vec2[0]; |
res[0] = vec1[0] - vec2[0]; |
58 |
res[1] = vec1[1] - vec2[1]; |
res[1] = vec1[1] - vec2[1]; |
60 |
} |
} |
61 |
|
|
62 |
// Note res cannot be vec1 or vec2 |
// Note res cannot be vec1 or vec2 |
63 |
void cross(double vec1[3], double vec2[3], double res[3]) |
STATIC_INLINE void cross(double vec1[3], double vec2[3], double res[3]) |
64 |
{ |
{ |
65 |
res[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; |
res[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; |
66 |
res[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]; |
res[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]; |
67 |
res[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0]; |
res[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0]; |
68 |
} |
} |
69 |
|
|
70 |
void scale_vec3(double scl, double vec[3], double res[3]) |
STATIC_INLINE void scale_vec3(double scl, double vec[3], double res[3]) |
71 |
{ |
{ |
72 |
res[0] = scl * vec[0]; |
res[0] = scl * vec[0]; |
73 |
res[1] = scl * vec[1]; |
res[1] = scl * vec[1]; |
74 |
res[2] = scl * vec[2]; |
res[2] = scl * vec[2]; |
75 |
} |
} |
76 |
|
|
77 |
bool inside(double pos[3]) |
STATIC_INLINE bool inside(double pos[3]) |
78 |
{ |
{ |
79 |
// XXX - Hack |
// XXX - Hack |
80 |
if(pos[0] < -0.5 || pos[0] > 175.5) return false; |
if(pos[0] < -0.5 || pos[0] > 175.5) return false; |
83 |
return true; |
return true; |
84 |
} |
} |
85 |
|
|
86 |
double lerp(double out_min, double out_max, double in_min, double in, double in_max) |
STATIC_INLINE double lerp(double out_min, double out_max, double in_min, double in, double in_max) |
87 |
{ |
{ |
88 |
return (out_min * (in_max - in) + out_max * (in - in_min)) / (in_max - in_min); |
return (out_min * (in_max - in) + out_max * (in - in_min)) / (in_max - in_min); |
89 |
} |
} |
90 |
|
|
91 |
unsigned char ulerp(double in_min, double in, double in_max) |
STATIC_INLINE unsigned char ulerp(double in_min, double in, double in_max) |
92 |
{ |
{ |
93 |
return (unsigned char)((0.0f * (in_max - in) + 255.0f * (in - in_min)) / (in_max - in_min)); |
return (unsigned char)((0.0f * (in_max - in) + 255.0f * (in - in_min)) / (in_max - in_min)); |
94 |
} |
} |
96 |
int main () |
int main () |
97 |
{ |
{ |
98 |
char *infile = "../../data/vfrhand-nohip.nhdr"; |
char *infile = "../../data/vfrhand-nohip.nhdr"; |
99 |
char *outfile = "vr-lite-cam-teem.pgm"; |
char *outfile = "vr-lite-cam.pgm"; |
100 |
double Zero[3] = {0, 0, 0}; |
double Zero[3] = {0, 0, 0}; |
101 |
double camEye[3] = {127.331, -1322.05, 272.53}; |
double camEye[3] = {127.331, -1322.05, 272.53}; |
102 |
double camAt[3] = {63.0, 82.6536, 98.0}; |
double camAt[3] = {63.0, 82.6536, 98.0}; |
305 |
return -1; |
return -1; |
306 |
} |
} |
307 |
|
|
308 |
|
double t0 = GetTime(); |
309 |
for(vi = 0; vi < imgResV; vi++) |
for(vi = 0; vi < imgResV; vi++) |
310 |
{ |
{ |
311 |
rayV = lerp(-camVmax, camVmax, -0.5, (double)(vi), (double)(imgResV) - 0.5); |
rayV = lerp(-camVmax, camVmax, -0.5, (double)(vi), (double)(imgResV) - 0.5); |
395 |
*(uc_out_data + vi * imgResU + ui) = ulerp(min_gray, *(out_data + ui * imgResV * 4 + vi * 4 + 0), max_gray); |
*(uc_out_data + vi * imgResU + ui) = ulerp(min_gray, *(out_data + ui * imgResV * 4 + vi * 4 + 0), max_gray); |
396 |
} |
} |
397 |
} |
} |
398 |
|
double totalTime = GetTime() - t0; |
399 |
|
|
400 |
|
printf("usr=%f\n", totalTime); |
401 |
|
|
402 |
// Write out data |
// Write out data |
403 |
Nrrd *nout; |
Nrrd *nout; |