25 |
#define MIN_OPAC_MID ((float)(MIN_VALUE+OPAC_HALF_WID)) |
#define MIN_OPAC_MID ((float)(MIN_VALUE+OPAC_HALF_WID)) |
26 |
#define MAX_OPAC_MID ((float)(MAX_VALUE-OPAC_HALF_WID)) |
#define MAX_OPAC_MID ((float)(MAX_VALUE-OPAC_HALF_WID)) |
27 |
|
|
28 |
|
#define OPAC_DELTA 100 |
29 |
|
|
30 |
/* pixel dimensions of output */ |
/* pixel dimensions of output */ |
31 |
#define WIDTH 480 |
#define WIDTH 480 |
32 |
#define HEIGHT 345 |
#define HEIGHT 345 |
39 |
#define WRLD_CENTER_X 0.5 |
#define WRLD_CENTER_X 0.5 |
40 |
#define WRLD_CENTER_Y 0.5 |
#define WRLD_CENTER_Y 0.5 |
41 |
|
|
|
#define STEP_SIZE 1 |
|
|
#define SLEEP_MS 250 |
|
|
|
|
42 |
static inline void CheckError () |
static inline void CheckError () |
43 |
{ |
{ |
44 |
GLenum errCode; |
GLenum errCode; |
50 |
|
|
51 |
/***** Globals for viewing, etc. *****/ |
/***** Globals for viewing, etc. *****/ |
52 |
|
|
53 |
Nrrd *Diderot; // input image nrrd |
VR_World_t *World; |
54 |
unsigned int Width; // view window width |
unsigned int Width; // view window width |
55 |
unsigned int Height; // view window height |
unsigned int Height; // view window height |
56 |
bool NeedsRedraw; |
bool NeedsRedraw; |
57 |
bool NeedsRecompute; |
bool NeedsRecompute; |
58 |
|
float OpacMid = 550.0; |
59 |
|
|
60 |
|
|
61 |
// Callback function called by GLUT to render screen |
// Callback function called by GLUT to render screen |
93 |
glMatrixMode (GL_MODELVIEW); |
glMatrixMode (GL_MODELVIEW); |
94 |
glLoadIdentity (); |
glLoadIdentity (); |
95 |
gluLookAt ( |
gluLookAt ( |
|
// WRLD_CENTER_X, WRLD_CENTER_Y, 1.0, |
|
96 |
0.0, 0.0, 1.0, |
0.0, 0.0, 1.0, |
|
// WRLD_CENTER_X, WRLD_CENTER_Y, 0.0, |
|
97 |
0.0, 0.0, 0.0, |
0.0, 0.0, 0.0, |
98 |
0.0, 1.0, 0.0); |
0.0, 1.0, 0.0); |
99 |
|
|
103 |
|
|
104 |
} |
} |
105 |
|
|
106 |
|
void GLFWCALL KeyCB (int key, int action) |
107 |
|
{ |
108 |
|
if (action == GLFW_PRESS) { |
109 |
|
switch (key) { |
110 |
|
case '+': { |
111 |
|
float mid = OpacMid + OPAC_DELTA; |
112 |
|
if (mid <= MAX_OPAC_MID) { |
113 |
|
OpacMid = mid; |
114 |
|
VR_InVarSet_valOpacMid(World, mid); |
115 |
|
NeedsRecompute = true; |
116 |
|
} |
117 |
|
} break; |
118 |
|
case '-': { |
119 |
|
float mid = OpacMid - OPAC_DELTA; |
120 |
|
if (mid >= MIN_OPAC_MID) { |
121 |
|
OpacMid = mid; |
122 |
|
VR_InVarSet_valOpacMid(World, mid); |
123 |
|
NeedsRecompute = true; |
124 |
|
} |
125 |
|
} break; |
126 |
|
default: |
127 |
|
break; |
128 |
|
} |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
void GetData (VR_World_t *wrld, Nrrd *nRGB) |
void GetData (VR_World_t *wrld, Nrrd *nRGB) |
133 |
{ |
{ |
134 |
if (VR_OutputGet_outRGBA (wrld, nRGB)) { |
if (VR_OutputGet_outRGBA (wrld, nRGB)) { |
160 |
|
|
161 |
// Set GLFW event callbacks |
// Set GLFW event callbacks |
162 |
glfwSetWindowSizeCallback (WindowSizeCB); |
glfwSetWindowSizeCallback (WindowSizeCB); |
163 |
/* FIXME: set up key callback */ |
glfwSetCharCallback (KeyCB); |
164 |
|
|
165 |
// initialize the Diderot program |
// initialize the Diderot program |
166 |
VR_World_t *wrld = VR_Init (); |
VR_World_t *wrld = VR_Init (); |
167 |
|
World = wrld; |
168 |
|
|
169 |
|
// initialize inputs |
170 |
|
VR_InVarSet_valOpacMid(wrld, OpacMid); |
171 |
|
Nrrd *nin = nrrdNew(); |
172 |
|
/* read in the nrrd from file */ |
173 |
|
if (nrrdLoad(nin, "data/vfrhand-nohip.nhdr", NULL) != 0) { |
174 |
|
char *msg = biffGetDone(NRRD); |
175 |
|
fprintf (stderr, "Error loading data: %s", msg); |
176 |
|
exit (1); |
177 |
|
} |
178 |
|
VR_InVarSet_hand (wrld, nin); |
179 |
|
// nrrdNix (nin); |
180 |
|
|
181 |
// nrrd for getting computational state |
// nrrd for getting computational state |
182 |
Nrrd *nRGB = nrrdNew(); |
Nrrd *nRGB = nrrdNew(); |
183 |
|
|
|
// get and render initial state |
|
|
GetData (wrld, nRGB); |
|
|
Draw (nRGB); |
|
|
|
|
184 |
// Main loop (repeated while window is not closed and [ESC] is not pressed) |
// Main loop (repeated while window is not closed and [ESC] is not pressed) |
185 |
NeedsRecompute = true; |
NeedsRecompute = true; |
186 |
while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) { |
while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) { |
187 |
if (NeedsRecompute) { |
if (NeedsRecompute) { |
188 |
|
printf("computing ... "); fflush(stdout); |
189 |
// recompute |
// recompute |
190 |
VR_Initially (wrld); |
if (VR_Initially (wrld)) { |
191 |
VR_Run (wrld, 0); |
// error |
192 |
|
fprintf(stderr, "Error initializing world: %s", VR_GetErrors(wrld)); |
193 |
|
exit(1); |
194 |
|
} |
195 |
|
int nSteps = VR_Run (wrld, 0); |
196 |
|
printf(" %d steps\n", nSteps); |
197 |
// get output image |
// get output image |
198 |
if (VR_OutputGet_outRGBA (wrld, nRGB)) { |
if (VR_OutputGet_outRGBA (wrld, nRGB)) { |
199 |
// error |
// error |
200 |
fprintf(stderr, "Error getting nrrd data\n"); |
fprintf(stderr, "Error getting nrrd data: %s", VR_GetErrors(wrld)); |
201 |
exit(1); |
exit(1); |
202 |
} |
} |
203 |
|
NeedsRecompute = false; |
204 |
NeedsRedraw = true; |
NeedsRedraw = true; |
205 |
} |
} |
206 |
if (NeedsRedraw) { |
if (NeedsRedraw) { |